mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-30 00:33:41 +08:00
Allow legacy C3X Panda flash erase to complete
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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("<BBHH", 0x5a, endpoint, len(payload), MAX_RESPONSE)
|
||||
self.spi.xfer(self._frame(header))
|
||||
self._wait_ack(0x79, 0x11, 1)
|
||||
self.spi.xfer(self._frame(payload))
|
||||
if expect_disconnect:
|
||||
return b""
|
||||
reply = self._wait_ack(0x85, 0x13, MAX_RESPONSE + 4)
|
||||
reply = self._wait_ack(0x85, 0x13, MAX_RESPONSE + 4, reply_timeout)
|
||||
size = int.from_bytes(reply[1:3], "little")
|
||||
if size > 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("<BHHH", request, value, index, 0), expect_disconnect)
|
||||
# A legacy bootstub waits for flash erase to finish before acknowledging it.
|
||||
reply_timeout = TIMEOUT / 1000 if request == 0xb2 else 0.25
|
||||
reply = self._exchange(0, struct.pack("<BHHH", request, value, index, 0), expect_disconnect, reply_timeout)
|
||||
if request in (0xb1, 0xb2):
|
||||
if len(reply) != 12 or reply[4:8] != FLASHER_MAGIC or reply[2] != request or (request == 0xb2 and reply[1] != 0xff):
|
||||
raise PandaSpiException(f"Legacy bootstub failed flash operation {request:#x}")
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "b231c85afbb4eb1b7b47390b71499697f7f4f46f8ad758dfb64ed1f09d4a71f0", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "9dcc7363e6266ae6f2ecee245ef0e7898a5882d43288e8d1b9659633beb512ee", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user