Skip to content

Commit 68fbb39

Browse files
committed
Find EEPROM device more reliably on BeagleBones
- Use glob builtin to find device on i2c address 0x50 matching `0-0050*` instead of checking paths one at a time
1 parent 287633c commit 68fbb39

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

adafruit_platformdetect/board.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
"""
2222

23+
import glob
2324
import os
2425
import re
2526

@@ -321,20 +322,23 @@ def _beaglebone_id(self) -> Optional[str]:
321322
if "beaglev-starlight" in board_value:
322323
return boards.BEAGLEV_STARLIGHT
323324

325+
# find device alias at i2c address 0x50 (0-00500, 0-00501, etc)
326+
nvmem_devices = glob.glob('/sys/bus/nvmem/devices/0-0050*')
327+
# do not expect there to be more than one eeprom
328+
if len(nvmem_devices) > 1:
329+
return None
330+
331+
eeprom_dir = nvmem_devices[0]
324332
try:
325-
with open("/sys/bus/nvmem/devices/0-00500/nvmem", "rb") as eeprom:
333+
with open(f"{eeprom_dir}/nvmem", "rb") as eeprom:
326334
eeprom_bytes = eeprom.read(16)
327335
except FileNotFoundError:
328336
try:
329-
with open("/sys/bus/nvmem/devices/0-00501/nvmem", "rb") as eeprom:
337+
# Special Case for AI64
338+
with open("/sys/bus/nvmem/devices/2-00500/nvmem", "rb") as eeprom:
330339
eeprom_bytes = eeprom.read(16)
331340
except FileNotFoundError:
332-
try:
333-
# Special Case for AI64
334-
with open("/sys/bus/nvmem/devices/2-00500/nvmem", "rb") as eeprom:
335-
eeprom_bytes = eeprom.read(16)
336-
except FileNotFoundError:
337-
return None
341+
return None
338342

339343
if eeprom_bytes[:4] != b"\xaaU3\xee":
340344
return None

0 commit comments

Comments
 (0)