From 43b1759b2c0f45dc06455c4ff8ac04bc28e65266 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 28 Nov 2026 11:50:19 -0600 Subject: [PATCH] reflash_internal_panda: support the upstream kernel's GPIO numbering (#2494) --- panda/scripts/reflash_internal_panda.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/panda/scripts/reflash_internal_panda.py b/panda/scripts/reflash_internal_panda.py index 7e9c49491c..0e5d2a72ca 100755 --- a/panda/scripts/reflash_internal_panda.py +++ b/panda/scripts/reflash_internal_panda.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +import glob +import os import time from panda import Panda, PandaDFU @@ -7,12 +9,21 @@ class GPIO: STM_BOOT0 = 134 +def tlmm_base() -> int: + # the SoC GPIO controller's sysfs number base: 0 on the downstream kernel, assigned at boot on the upstream one + for chip in glob.glob("/sys/class/gpio/gpiochip*"): + with open(os.path.join(chip, "label")) as f: + if f.read().strip() == "3400000.pinctrl": + with open(os.path.join(chip, "base")) as b: + return int(b.read()) + raise RuntimeError("SoC GPIO controller not found") + def gpio_init(pin, output): - with open(f"/sys/class/gpio/gpio{pin}/direction", 'wb') as f: + with open(f"/sys/class/gpio/gpio{tlmm_base() + pin}/direction", 'wb') as f: f.write(b"out" if output else b"in") def gpio_set(pin, high): - with open(f"/sys/class/gpio/gpio{pin}/value", 'wb') as f: + with open(f"/sys/class/gpio/gpio{tlmm_base() + pin}/value", 'wb') as f: f.write(b"1" if high else b"0")