From 80aae010eee720dcf99ed013c666758b4b5bbe8e Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:14:17 -0600 Subject: [PATCH] Allow legacy C3X Panda flash erase to complete --- openpilot/selfdrive/pandad/pandad.py | 2 +- panda/python/legacy_spi.py | 13 ++++++++----- prebuilt.json | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/openpilot/selfdrive/pandad/pandad.py b/openpilot/selfdrive/pandad/pandad.py index c673aaa1f8..3fd338d2ed 100755 --- a/openpilot/selfdrive/pandad/pandad.py +++ b/openpilot/selfdrive/pandad/pandad.py @@ -160,7 +160,7 @@ def main() -> None: if not panda_serials and not legacy_migration_attempted and HARDWARE.get_device_type() == "tizi": legacy_migration_attempted = True HARDWARE.reset_internal_panda() - time.sleep(0.2) + time.sleep(0.5) choice = startup_choice(Params()) filename = firmware_path(FW_PATH, McuType.H7.config.app_fn, choice) if (serial := migrate_legacy_tres_firmware(filename)) is not None: diff --git a/panda/python/legacy_spi.py b/panda/python/legacy_spi.py index f40922d49e..282a25db27 100644 --- a/panda/python/legacy_spi.py +++ b/panda/python/legacy_spi.py @@ -5,6 +5,7 @@ from operator import xor from pathlib import Path from panda import McuType, Panda +from panda.python.base import TIMEOUT from panda.python.spi import PandaSpiException, SpiDevice @@ -22,8 +23,8 @@ class LegacySpiFlasher: def _frame(data): return data + bytes([reduce(xor, data, 0xab)]) - def _wait_ack(self, expected, fill, length): - deadline = time.monotonic() + 0.25 + def _wait_ack(self, expected, fill, length, timeout=0.25): + deadline = time.monotonic() + timeout while time.monotonic() < deadline: reply = self.spi.xfer(bytes([fill]) * length) if reply[0] == expected: @@ -32,14 +33,14 @@ class LegacySpiFlasher: raise PandaSpiException("Legacy SPI request was rejected") raise PandaSpiException(f"Legacy SPI acknowledgment {expected:#x} timed out") - def _exchange(self, endpoint, payload, expect_disconnect=False): + def _exchange(self, endpoint, payload, expect_disconnect=False, reply_timeout=0.25): header = struct.pack(" MAX_RESPONSE or reduce(xor, reply[:size + 4], 0xab): raise PandaSpiException("Legacy SPI response length or checksum invalid") @@ -51,7 +52,9 @@ class LegacySpiFlasher: def controlWrite(self, request_type, request, value, index, data, expect_disconnect=False): if data: raise ValueError("Unexpected legacy SPI control payload") - reply = self._exchange(0, struct.pack("