| 139 |
139 |
|
| 140 |
140 |
# print "Incoming:\n\tVer: %i\n\tID: %c\n\tSeq: %i\n\tIP: %i\n" % (proto_ver, chr(pktid), rxseq, ip_addr)
|
| 141 |
141 |
|
|
142 |
memory_size_bytes = 0
|
|
143 |
sector_size_bytes = 0
|
| 142 |
144 |
def get_flash_info(self):
|
|
145 |
if (self.memory_size_bytes != 0) and (self.sector_size_bytes != 0):
|
|
146 |
return (self.memory_size_bytes, self.sector_size_bytes)
|
|
147 |
|
| 143 |
148 |
out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_WATS_TEH_FLASH_INFO_LOL, seq(), 0, 0)
|
| 144 |
149 |
in_pkt = self.send_and_recv(out_pkt)
|
| 145 |
150 |
|
| 146 |
|
(proto_ver, pktid, rxseq, sector_size_bytes, memory_size_bytes) = unpack_flash_info_fmt(in_pkt)
|
|
151 |
(proto_ver, pktid, rxseq, self.sector_size_bytes, self.memory_size_bytes) = unpack_flash_info_fmt(in_pkt)
|
| 147 |
152 |
|
| 148 |
153 |
if pktid != update_id_t.USRP2_FW_UPDATE_ID_HERES_TEH_FLASH_INFO_OMG:
|
| 149 |
154 |
raise Exception("Invalid reply %c from device." % (chr(pktid)))
|
| 150 |
155 |
|
| 151 |
|
return (memory_size_bytes, sector_size_bytes)
|
|
156 |
return (self.memory_size_bytes, self.sector_size_bytes)
|
| 152 |
157 |
|
| 153 |
158 |
def burn_fw(self, fw, fpga, reset, safe):
|
| 154 |
159 |
(flash_size, sector_size) = self.get_flash_info()
|
| ... | ... | |
| 167 |
172 |
|
| 168 |
173 |
if not is_valid_fpga_image(fpga_image):
|
| 169 |
174 |
raise Exception("Error: Invalid FPGA image file.")
|
|
175 |
|
|
176 |
if (len(fpga_image) + image_location) > flash_size:
|
|
177 |
raise Exception("Error: Cannot write past end of device")
|
| 170 |
178 |
|
| 171 |
179 |
print("Begin FPGA write: this should take about 1 minute...")
|
| 172 |
180 |
start_time = time.time()
|
| ... | ... | |
| 188 |
196 |
|
| 189 |
197 |
if not is_valid_fw_image(fw_image):
|
| 190 |
198 |
raise Exception("Error: Invalid firmware image file.")
|
|
199 |
|
|
200 |
if (len(fw_image) + image_location) > flash_size:
|
|
201 |
raise Exception("Error: Cannot write past end of device")
|
| 191 |
202 |
|
| 192 |
203 |
print("Begin firmware write: this should take about 1 second...")
|
| 193 |
204 |
start_time = time.time()
|
| ... | ... | |
| 204 |
215 |
self._status_cb("Writing")
|
| 205 |
216 |
writedata = image
|
| 206 |
217 |
#we split the image into smaller (256B) bits and send them down the wire
|
|
218 |
(mem_size, sector_size) = self.get_flash_info()
|
|
219 |
if (addr + len(writedata)) > mem_size:
|
|
220 |
raise Exception("Error: Cannot write past end of device")
|
|
221 |
|
| 207 |
222 |
while writedata:
|
| 208 |
223 |
out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_WRITE_TEH_FLASHES_LOL, seq(), addr, FLASH_DATA_PACKET_SIZE, writedata[:FLASH_DATA_PACKET_SIZE])
|
| 209 |
224 |
in_pkt = self.send_and_recv(out_pkt)
|
| ... | ... | |
| 287 |
302 |
def erase_image(self, addr, length):
|
| 288 |
303 |
self._status_cb("Erasing")
|
| 289 |
304 |
#get flash info first
|
|
305 |
(flash_size, sector_size) = self.get_flash_info()
|
|
306 |
if (addr + length) > flash_size:
|
|
307 |
raise Exception("Cannot erase past end of device")
|
|
308 |
|
| 290 |
309 |
out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_ERASE_TEH_FLASHES_LOL, seq(), addr, length)
|
| 291 |
310 |
in_pkt = self.send_and_recv(out_pkt)
|
| 292 |
311 |
|