From b99d79692409514d296d85f367897fa2f86daaa5 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 10 Feb 2026 20:31:44 -0800 Subject: [PATCH] Revert "remove mcu_type (#2324)" This reverts commit 8922b48a300bd3b77fb640aa128bb03c6f43733c. --- board/jungle/__init__.py | 10 ++++++++-- python/__init__.py | 30 +++++++++++++++++++----------- tests/hitl/1_program.py | 14 ++++++++------ tests/hitl/2_health.py | 3 +++ tests/hitl/reset_jungles.py | 4 +++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/board/jungle/__init__.py b/board/jungle/__init__.py index e9e7e96b..dfb7d98c 100644 --- a/board/jungle/__init__.py +++ b/board/jungle/__init__.py @@ -52,7 +52,7 @@ class PandaJungle(Panda): def flash(self, fn=None, code=None, reconnect=True): if not fn: - fn = os.path.join(FW_PATH, McuType.H7.config.app_fn.replace("panda", "panda_jungle")) + fn = os.path.join(FW_PATH, self._mcu_type.config.app_fn.replace("panda", "panda_jungle")) super().flash(fn=fn, code=code, reconnect=reconnect) def recover(self, timeout: int | None = 60, reset: bool = True) -> bool: @@ -73,9 +73,15 @@ class PandaJungle(Panda): self.flash() return True + def get_mcu_type(self) -> McuType: + hw_type = self.get_type() + if hw_type in PandaJungle.H7_DEVICES: + return McuType.H7 + raise ValueError(f"unknown HW type: {hw_type}") + def up_to_date(self, fn=None) -> bool: if fn is None: - fn = os.path.join(FW_PATH, McuType.H7.config.app_fn.replace("panda", "panda_jungle")) + fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn.replace("panda", "panda_jungle")) return super().up_to_date(fn=fn) # ******************* health ******************* diff --git a/python/__init__.py b/python/__init__.py index b3c93e5a..48960a40 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -145,6 +145,7 @@ class Panda: else: self._connect_serial = serial + # connect and set mcu type self.connect(claim) def _cli_select_panda(self): @@ -201,9 +202,13 @@ class Panda: self._serial = serial self._connect_serial = serial self._handle_open = True + self._mcu_type = self.get_mcu_type() self.health_version, self.can_version, self.can_health_version = self.get_packets_versions() logger.debug("connected") + hw_type = self.get_type() + assert hw_type in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}" + # disable openpilot's heartbeat checks if self._disable_checks: self.set_heartbeat_disabled() @@ -330,9 +335,6 @@ class Panda: return [] def reset(self, enter_bootstub=False, enter_bootloader=False, reconnect=True): - if enter_bootstub or enter_bootloader: - assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}" - # no response is expected since it resets right away timeout = 5000 if isinstance(self._handle, PandaSpiHandle) else 15000 try: @@ -412,14 +414,16 @@ class Panda: pass def flash(self, fn=None, code=None, reconnect=True): - assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}" - if self.up_to_date(fn=fn): logger.info("flash: already up to date") return + hw_type = self.get_type() + if hw_type not in self.SUPPORTED_DEVICES: + raise RuntimeError(f"HW type {hw_type.hex()} is deprecated and can no longer be flashed.") + if not fn: - fn = os.path.join(FW_PATH, McuType.H7.config.app_fn) + fn = os.path.join(FW_PATH, self._mcu_type.config.app_fn) assert os.path.isfile(fn) logger.debug("flash: main version is %s", self.get_version()) if not self.bootstub: @@ -434,15 +438,13 @@ class Panda: logger.debug("flash: bootstub version is %s", self.get_version()) # do flash - Panda.flash_static(self._handle, code, mcu_type=McuType.H7) + Panda.flash_static(self._handle, code, mcu_type=self._mcu_type) # reconnect if reconnect: self.reconnect() def recover(self, timeout: int | None = 60, reset: bool = True) -> bool: - assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}" - dfu_serial = self.get_dfu_serial() if reset: @@ -487,7 +489,7 @@ class Panda: def up_to_date(self, fn=None) -> bool: current = self.get_signature() if fn is None: - fn = os.path.join(FW_PATH, McuType.H7.config.app_fn) + fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn) expected = Panda.get_signature_from_firmware(fn) return (current == expected) @@ -599,6 +601,12 @@ class Panda: else: return (0, 0, 0) + def get_mcu_type(self) -> McuType: + hw_type = self.get_type() + if hw_type in Panda.H7_DEVICES: + return McuType.H7 + raise ValueError(f"unknown HW type: {hw_type}") + def is_internal(self): return self.get_type() in Panda.INTERNAL_DEVICES @@ -619,7 +627,7 @@ class Panda: return self._serial def get_dfu_serial(self): - return PandaDFU.st_serial_to_dfu_serial(self._serial, McuType.H7) + return PandaDFU.st_serial_to_dfu_serial(self._serial, self._mcu_type) def get_uid(self): """ diff --git a/tests/hitl/1_program.py b/tests/hitl/1_program.py index bf20e82d..09c8b867 100644 --- a/tests/hitl/1_program.py +++ b/tests/hitl/1_program.py @@ -11,6 +11,7 @@ def check_signature(p): def test_dfu(p): + app_mcu_type = p.get_mcu_type() dfu_serial = p.get_dfu_serial() p.reset(enter_bootstub=True) @@ -18,7 +19,7 @@ def test_dfu(p): assert Panda.wait_for_dfu(dfu_serial, timeout=19), "failed to enter DFU" dfu = PandaDFU(dfu_serial) - assert dfu.get_mcu_type() == McuType.H7 + assert dfu.get_mcu_type() == app_mcu_type assert dfu_serial in PandaDFU.list() @@ -37,9 +38,9 @@ def test_known_bootstub(p): McuType.H7: ["bootstub.panda_h7.bin"], } - for kb in known_bootstubs[McuType.H7]: - app_serial = p.get_usb_serial() - assert app_serial is not None + for kb in known_bootstubs[p.get_mcu_type()]: + app_ids = (p.get_mcu_type(), p.get_usb_serial()) + assert None not in app_ids p.reset(enter_bootstub=True) p.reset(enter_bootloader=True) @@ -56,9 +57,10 @@ def test_known_bootstub(p): p.connect(claim=False, wait=True) - # check for serial mismatch + # check for MCU or serial mismatch with Panda(p._serial, claim=False) as np: - assert np.get_usb_serial() == app_serial + bootstub_ids = (np.get_mcu_type(), np.get_usb_serial()) + assert app_ids == bootstub_ids # ensure we can flash app and it jumps to app p.flash() diff --git a/tests/hitl/2_health.py b/tests/hitl/2_health.py index f1784b0a..8fac3e96 100644 --- a/tests/hitl/2_health.py +++ b/tests/hitl/2_health.py @@ -17,6 +17,8 @@ def test_hw_type(p): """ hw_type = p.get_type() + mcu_type = p.get_mcu_type() + assert mcu_type is not None app_uid = p.get_uid() usb_serial = p.get_usb_serial() @@ -28,6 +30,7 @@ def test_hw_type(p): with Panda(p.get_usb_serial()) as pp: assert pp.bootstub assert pp.get_type() == hw_type, "Bootstub and app hw type mismatch" + assert pp.get_mcu_type() == mcu_type, "Bootstub and app MCU type mismatch" assert pp.get_uid() == app_uid def test_heartbeat(p, panda_jungle): diff --git a/tests/hitl/reset_jungles.py b/tests/hitl/reset_jungles.py index 97702d80..09bd04ad 100755 --- a/tests/hitl/reset_jungles.py +++ b/tests/hitl/reset_jungles.py @@ -15,6 +15,7 @@ def recover(s): def flash(s): with PandaJungle(s) as p: p.flash() + return p.get_mcu_type() # Reset + flash all CI hardware to get it into a consistent state # * port 1: jungles-under-test @@ -41,4 +42,5 @@ if __name__ == "__main__": for s in SERIALS: assert PandaJungle.wait_for_panda(s, timeout=10) assert set(PandaJungle.list()) >= SERIALS - list(exc.map(flash, SERIALS, timeout=20)) + mcu_types = list(exc.map(flash, SERIALS, timeout=20)) + assert set(mcu_types) == {McuType.H7, }