Skip to content

Commit dbe9ea8

Browse files
committed
tinyprog: Pad to full minor sector write size
Either the TinyProg-BootLoader state machines, or the SPI flash chip used on the TinyFPGA BX, seems unable to *properly* program a partial minor sector (ie, writing less than 256 octets), leading to a failed write/verify cycle. This seems to happen at the end of any programming that is not an exact multiple of 256 octets. Since the whole 256 octets is already erased in program_sectors(), we pad out the short write to a full 256 octets (with 0xff, which is the value read for "erased", to reduce wear on on the flash cells). For more detail on diagnosing this, see: timvideos/litex-buildenv#137
1 parent 6e31253 commit dbe9ea8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

programmer/tinyprog/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,22 @@ def program_sectors(self, addr, data):
499499
for minor_offset in range(0, 4 * 1024, minor_sector_size):
500500
minor_write_data = current_write_data[
501501
minor_offset:minor_offset + minor_sector_size]
502+
503+
# The TinyFPGA firmware and/or flash chip does not handle
504+
# partial minor sector writes properly, so pad out short
505+
# writes to a whole minor sector. (This is safe because
506+
# we explicitly erased the whole sector above, so the
507+
# following bytes must be freshly erased. Usually it will
508+
# only happen on the final minor sector to be written.)
509+
#
510+
if (len(minor_write_data) < minor_sector_size):
511+
pad_len = minor_sector_size - len(minor_write_data)
512+
padding = b'\xff' * pad_len
513+
514+
minor_write_data = bytearray(minor_write_data)
515+
minor_write_data.extend(padding)
516+
assert(len(minor_write_data) == minor_sector_size)
517+
502518
self.write(
503519
current_addr + minor_offset,
504520
minor_write_data,

0 commit comments

Comments
 (0)