1
0
mirror of https://github.com/peterantypas/maiana.git synced 2025-05-16 07:20:08 -07:00

Increased robustness of FW update

This commit is contained in:
Peter Antypas 2021-11-08 17:46:31 -08:00
parent fc63130464
commit 7c210252d2

View File

@ -314,21 +314,19 @@ if __name__ == '__main__':
print "Erased {0} flash pages".format(numpages)
"""
if send_command(WRITE_UNPROT_CMD):
print "Write unprotect"
else:
print "Failed to unprotect flash"
sys.exit(1)
"""
addr = address
first_chunk = None
with open(sys.argv[2], "rb") as f:
while True:
chunk = f.read(256)
if len(chunk) == 0:
break
if addr == address:
# Preserve the first chunk and write it last.
# This makes FW update as close to atomic as possible.
first_chunk = chunk
else:
rem = len(chunk) % 4
for i in range(rem):
chunk += 0xff
@ -342,15 +340,15 @@ if __name__ == '__main__':
sys.stdout.write("Flashing: {0:3d}%\r".format(100*(addr-address)/st.st_size))
sys.stdout.flush()
if write_chunk(address, first_chunk):
sys.stdout.write("\r\nFlashed boot sector at address 0x{:08x}\r\n".format(address))
sys.stdout.flush()
else:
print "Failed to write boot sector!!!"
sys.exit(1)
print
"""
if send_command(WRITE_PROT_CMD):
print "Write protect"
else:
print "Failed to protect flash"
sys.exit(1)
"""
if not boot(address):
print "Failed to send GO command"