Fix legacy write flash

This commit is contained in:
Bjoern Kerler 2023-06-14 23:41:05 +02:00
parent 64049911fc
commit 4290a5c436
No known key found for this signature in database
GPG key ID: 52E823BB96A55380

View file

@ -1524,9 +1524,14 @@ class DALegacy(metaclass=LogBase):
length, parttype = self.get_parttype(length, parttype)
storage = self.get_storage()
fh = False
fill = 0
if filename is not None:
fh = open(filename, "rb")
fsize = os.stat(filename).st_size
length = min(fsize, length)
if length % 512 != 0:
fill = 512 - (length % 512)
length += fill
fh.seek(offset)
self.mtk.daloader.progress.show_progress("Write", 0, length, display)
self.usbwrite(self.Cmd.SDMMC_WRITE_DATA_CMD)
@ -1544,6 +1549,8 @@ class DALegacy(metaclass=LogBase):
count = min(0x100000, length - offset)
if fh:
data = bytearray(fh.read(count))
if len(data) < count:
data.extend(b"\x00" * fill)
else:
data = wdata[offset:offset + count]
self.usbwrite(data)