Skip to content

Commit dceca91

Browse files
committed
tinyprog: optimize re-writes by not erasing matching sectors or empty pages
1 parent 025618c commit dceca91

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

programmer/tinyprog/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,32 @@ def program_sectors(self, addr, data):
494494
for offset in range(0, len(data), sector_size):
495495
current_addr = addr + offset
496496
current_write_data = data[offset:offset + sector_size]
497+
498+
# Determine if we need to write this sector at all
499+
current_flash_data = self.read(
500+
current_addr,
501+
sector_size,
502+
disable_progress=True,
503+
max_length=sector_size)
504+
505+
if current_flash_data == current_write_data:
506+
# skip this sector since it matches
507+
pbar.update(sector_size)
508+
continue
509+
497510
self.erase(current_addr, sector_size, disable_progress=True)
498511

499512
minor_sector_size = 256
500513
for minor_offset in range(0, 4 * 1024, minor_sector_size):
501514
minor_write_data = current_write_data[
502515
minor_offset:minor_offset + minor_sector_size]
516+
517+
# if the minor data is all 0xFF then it will match
518+
# the erased bits and doesn't need to be re-sent
519+
if minor_write_data == chr(0xFF) * len(minor_write_data):
520+
pbar.update(len(minor_write_data))
521+
continue;
522+
503523
self.write(
504524
current_addr + minor_offset,
505525
minor_write_data,

0 commit comments

Comments
 (0)