dfuse.py: fix handling of unaligned page

This commit is contained in:
NIIBE Yutaka
2011-11-24 13:54:12 +09:00
parent 62520ed0f4
commit 0232c0a595

View File

@@ -215,6 +215,9 @@ class DFU_STM32:
addr = start_addr & 0xfffffc00
if not last_addr == 0:
i = 0
if last_addr > addr:
addr = last_addr
else:
while last_addr < addr:
self.dfuse_erase(last_addr)
if i & 0x03 == 0x03:
@@ -249,11 +252,13 @@ class DFU_STM32:
sys.stdout.flush()
last_addr += 1024
i += 1
if addr != start_addr:
# fill by 0xff
data = '\xff' * (start_addr & 0x3ff) + data
self.dfuse_set_address_pointer(addr)
i = 0
if addr != start_addr:
self.dfuse_set_address_pointer(start_addr)
self.dfuse_write_memory(data[0:(addr + 1024 - start_addr)])
data = data[(addr + 1024 - start_addr):]
addr += 1024
self.dfuse_set_address_pointer(addr)
while addr < end_addr:
self.dfuse_write_memory(data[i*1024:(i+1)*1024])
if i & 0x03 == 0x03:
@@ -303,8 +308,19 @@ class DFU_STM32:
last_addr += 1024
i += 1
if addr != start_addr:
# fill by 0xff
data = '\xff' * (start_addr & 0x3ff) + data
self.dfuse_set_address_pointer(addr)
self.ll_clear_status()
self.ll_clear_status()
block = self.dfuse_read_memory()
j = 0
for c in data[0:(addr + 1024 - start_addr)]:
if (ord(c)&0xff) != block[j + start_addr - addr]:
raise ValueError, "verify failed at %08x" % (addr + i*1024+j)
j += 1
data = data[(addr + 1024 - start_addr):]
addr += 1024
self.ll_clear_status()
self.ll_clear_status()
self.dfuse_set_address_pointer(addr)
self.ll_clear_status()
self.ll_clear_status()