Skip to content

Fix chip detection failure on Alpine Linux and other non-standard distros#414

Merged
makermelissa merged 1 commit intoadafruit:mainfrom
makermelissa-piclaw:fix-bcm-detection-alpine
Apr 22, 2026
Merged

Fix chip detection failure on Alpine Linux and other non-standard distros#414
makermelissa merged 1 commit intoadafruit:mainfrom
makermelissa-piclaw:fix-bcm-detection-alpine

Conversation

@makermelissa-piclaw
Copy link
Copy Markdown
Contributor

Problem

On Alpine Linux (aarch64), detector.chip.id raises a bare AttributeError on Raspberry Pi boards (#342). This happens because:

  1. /proc/cpuinfo on Alpine aarch64 doesn't include a Hardware field
  2. There's no device-tree compatible check for Broadcom BCM chips in _linux_id()
  3. When both hardware and compatible are None, compatible.split(',') crashes with AttributeError, which gets silently swallowed by __getattr__ and surfaces as a confusing bare AttributeError()

Fix

Three changes in chip.py:

  1. Add early device-tree check for BCM chips — matches brcm,bcm2 in /proc/device-tree/compatible, which is present on all Raspberry Pi boards regardless of distro. This is consistent with how other chip families (TI, Allwinner, Rockchip, etc.) are already detected via device-tree.

  2. Guard against NoneType crash — if compatible is None, use an empty list instead of crashing on .split().

  3. Improve __getattr__ error message — include the attribute name ("id") so the error is actually debuggable.

Fixes #342

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 adafruit#342
Copy link
Copy Markdown
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@makermelissa makermelissa merged commit 31cac12 into adafruit:main Apr 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

detector.chip.id raise AttributeError() # Avoid infinite recursion on RPI 3 B

2 participants