|
@@ -245,7 +245,7 @@ class LPC:
|
245
|
245
|
self._send_command("C {} {} {}\r\n".format(flash, ram, count).encode(
|
246
|
246
|
"utf-8"))
|
247
|
247
|
|
248
|
|
- def go(self, address=0, mode=b"T"):
|
|
248
|
+ def go(self, address=0, mode="T"):
|
249
|
249
|
"""Jump to the given address, in the given mode of execution
|
250
|
250
|
|
251
|
251
|
Of course, this function generally causes the ISP command handler to
|
|
@@ -366,15 +366,23 @@ class LPC:
|
366
|
366
|
self.prepare_write(sector)
|
367
|
367
|
self.erase(sector)
|
368
|
368
|
|
369
|
|
- # Write sectors in reversed order to make sure sector 0 is invalid
|
370
|
|
- # until the end
|
|
369
|
+ # Write sectors, with 0 at the end
|
371
|
370
|
ss = self._chip.sector_segments
|
372
|
|
- for sector in reversed(sectors_used):
|
|
371
|
+ if 0 in sectors_used:
|
|
372
|
+ sectors_used.remove(0)
|
|
373
|
+ sectors_used.append(0)
|
|
374
|
+ for sector in sectors_used:
|
373
|
375
|
if verbose:
|
374
|
376
|
print("Writing sector {}".format(sector))
|
375
|
377
|
# Get the data we'll be writing
|
376
|
378
|
secdat = ihex.tobinstr(start=ss[sector][0], end=ss[sector][1]-1)
|
377
|
379
|
|
|
380
|
+ # If we're writing sector 0, set the checksum
|
|
381
|
+ if sector == 0:
|
|
382
|
+ iv = struct.unpack('<7I', secdat[0:28])
|
|
383
|
+ cs = struct.pack('<i', -sum(iv))
|
|
384
|
+ secdat = secdat[:28] + cs + secdat[32:]
|
|
385
|
+
|
378
|
386
|
# Write data to RAM
|
379
|
387
|
bs = 0x100
|
380
|
388
|
for i in range(0, len(secdat), bs):
|
|
@@ -408,8 +416,14 @@ class LPC:
|
408
|
416
|
raise
|
409
|
417
|
|
410
|
418
|
# Verify the sector
|
|
419
|
+ if sector == 0:
|
|
420
|
+ # Avoid comparing first 64 bytes of sector 0 because these are
|
|
421
|
+ # remapped to flash boot sector
|
|
422
|
+ secdat = secdat[64:]
|
|
423
|
+ flash = flash[64:]
|
411
|
424
|
if secdat != flash:
|
412
|
425
|
print("failed!")
|
|
426
|
+ raise ISPError("Flash verification failed")
|
413
|
427
|
else:
|
414
|
428
|
print()
|
415
|
429
|
|