From 5e3d17c72cf2cd90a57d1cd31771c3aacfc9f79b Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 15 Aug 2026 15:31:19 -0700 Subject: [PATCH] chestnut: fix flashing on old FW (#38639) --- openpilot/system/hardware/chestnut/flash.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openpilot/system/hardware/chestnut/flash.py b/openpilot/system/hardware/chestnut/flash.py index 32aa5a443a..f0d828031d 100755 --- a/openpilot/system/hardware/chestnut/flash.py +++ b/openpilot/system/hardware/chestnut/flash.py @@ -33,6 +33,7 @@ USBDEVFS_SETCONFIGURATION = 0x80045505 USBDEVFS_CLAIMINTERFACE = 0x8004550F USBDEVFS_RESET = 0x5514 USBDEVFS_CLEAR_HALT = 0x80045515 +MAX_REGISTER_READ_SIZE = 255 _deadline = float("inf") @@ -146,6 +147,7 @@ def claim_interface(path, setup=False): class Flash: def __init__(self): self.fd = -1 + self.max_register_read_size = MAX_REGISTER_READ_SIZE def close(self): if self.fd >= 0: @@ -160,6 +162,9 @@ class Flash: if in_rom_bootloader(vid_pid, product): raise RomFallback("chestnut fell back to the ROM bootloader") if path is not None: + speed = int(open(path + "/speed").read()) + # USB2 firmware truncates larger reads to one full packet without a terminating ZLP. + self.max_register_read_size = 64 if speed < 5000 else MAX_REGISTER_READ_SIZE self.fd = claim_interface(path) return time.sleep(0.1) @@ -231,8 +236,8 @@ class Flash: while len(out) < length: n = min(4096, length - len(out)) self.transaction(0x03, addr + len(out), max(4096, n)) - for off in range(0, n, 255): - out += self.reg_read(0x7000 + off, min(255, n - off)) + for off in range(0, n, self.max_register_read_size): + out += self.reg_read(0x7000 + off, min(self.max_register_read_size, n - off)) return bytes(out) def erase_sector(self, addr):