From a06477487f40e01b3eb6e405b38c99020a26fc1c Mon Sep 17 00:00:00 2001 From: Piclaw Date: Wed, 22 Apr 2026 14:43:18 -0700 Subject: [PATCH] Fix chip detection failure on non-standard distros (Alpine, etc.) Three fixes in chip.py: 1. Add early device-tree check for Broadcom BCM chips. Previously, BCM detection relied solely on /proc/cpuinfo Hardware field, which is absent on aarch64 Alpine Linux (and potentially other distros). The new check matches 'brcm,bcm2' in /proc/device-tree/compatible, which is present on all Raspberry Pi boards regardless of distro. 2. Guard against NoneType crash when compatible is None. If both /proc/cpuinfo Hardware and /proc/device-tree/compatible are unavailable, compatible.split() would raise AttributeError, which gets silently swallowed by __getattr__ and surfaces as a confusing bare AttributeError. 3. Include attribute name in __getattr__ AttributeError for better debugging. Fixes #342 --- adafruit_platformdetect/chip.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index a1151e5..124c381 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -363,6 +363,9 @@ def _linux_id(self) -> Optional[str]: if self.detector.check_dt_compatible_value("particle,tachyon"): return chips.QCM6490 + if self.detector.check_dt_compatible_value("brcm,bcm2"): + return chips.BCM2XXX + linux_id = None hardware = self.detector.get_cpuinfo_field("Hardware") @@ -446,9 +449,12 @@ def _linux_id(self) -> Optional[str]: # convert it to a list and let the remaining # conditions attempt. if not linux_id: - hardware = [ - entry.replace("\x00", "") for entry in compatible.split(",") - ] + if compatible: + hardware = [ + entry.replace("\x00", "") for entry in compatible.split(",") + ] + else: + hardware = [] if not linux_id: if "AM33XX" in hardware: @@ -499,7 +505,7 @@ def __getattr__(self, attr: str) -> bool: list of constants at the top of this module for available options. """ if attr == "id": - raise AttributeError() # Avoid infinite recursion + raise AttributeError("id") # Avoid infinite recursion if self.id == attr: return True return False