From 7001c3b382e6ef5efdc23c71f025a90e9d656ef3 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Mon, 23 Dec 2019 21:58:27 +0100 Subject: [PATCH 1/5] Addition of onion omega board running OpenWRT --- adafruit_platformdetect/board.py | 18 +++++++++++++++++- adafruit_platformdetect/chip.py | 6 ++++++ bin/detect.py | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 2d92a8bf..22f86dda 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -70,6 +70,9 @@ BINHO_NOVA = "BINHO_NOVA" +ONION_OMEGA = "ONION_OMEGA" +ONION_OMEGA2 = "ONION_OMEGA2" + # pylint: enable=bad-whitespace #OrangePI @@ -288,6 +291,12 @@ ), } +# Onion omega boards +_ONION_OMEGA_BOARD_IDS = ( + ONION_OMEGA, + ONION_OMEGA2, +) + class Board: """Attempt to detect specific boards.""" def __init__(self, detector): @@ -343,6 +352,8 @@ def id(self): board_id = MICROCHIP_MCP2221 elif chip_id == ap_chip.BINHO: board_id = BINHO_NOVA + elif chip_id == ap_chip.ONION: + board_id = ONION_OMEGA return board_id # pylint: enable=invalid-name @@ -489,13 +500,18 @@ def any_sifive_board(self): """Check whether the current board is any defined Jetson Board.""" return self.id in _SIFIVE_IDS + @property + def any_onion_omega_board(self): + """Check whether the current board is any defined OpenWRT board.""" + return self.id in _ONION_OMEGA_BOARD_IDS + @property def any_embedded_linux(self): """Check whether the current board is any embedded Linux device.""" return self.any_raspberry_pi or self.any_beaglebone or \ self.any_orange_pi or self.any_giant_board or self.any_jetson_board or \ self.any_coral_board or self.any_odroid_40_pin or self.any_96boards or \ - self.any_sifive_board + self.any_sifive_board or self.any_onion_omega_board @property def ftdi_ft232h(self): diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index a30840bc..20591197 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -22,6 +22,7 @@ HFU540 = "HFU540" MCP2221 = "MCP2221" BINHO = "BINHO" +ONION = "ONION_OMEGA" class Chip: """Attempt detection of current chip / CPU.""" @@ -103,6 +104,11 @@ def _linux_id(self): # pylint: disable=too-many-branches if compatible and 'amlogic, g12b' in compatible: linux_id = S922X + machine = self.detector.get_cpuinfo_field("machine") + + if machine in ("Onion Omega", "Onion Omega2"): + linux_id = ONION + elif hardware in ("BCM2708", "BCM2709", "BCM2835"): linux_id = BCM2XXX elif "AM33XX" in hardware: diff --git a/bin/detect.py b/bin/detect.py index a9ca2b8b..218cd177 100755 --- a/bin/detect.py +++ b/bin/detect.py @@ -33,3 +33,6 @@ if detector.board.any_odroid_40_pin: print("Odroid detected.") + +if detector.board.any_onion_omega_board: + print("Onion Omega detected.") From a35117b822dc473480bcf8be0df74dba0b732a53 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Tue, 31 Dec 2019 14:30:50 +0100 Subject: [PATCH 2/5] Change detection of Onion Omega boards based on its 'cpu model' --- adafruit_platformdetect/chip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 20591197..45552e93 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -104,9 +104,9 @@ def _linux_id(self): # pylint: disable=too-many-branches if compatible and 'amlogic, g12b' in compatible: linux_id = S922X - machine = self.detector.get_cpuinfo_field("machine") + cpu_model = self.detector.get_cpuinfo_field("cpu model") - if machine in ("Onion Omega", "Onion Omega2"): + if ("MIPS 24Kc") in cpu_model: linux_id = ONION elif hardware in ("BCM2708", "BCM2709", "BCM2835"): From 8286f1172e962e26f9447d0eff754cfc72ef5b07 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Tue, 31 Dec 2019 19:00:03 +0100 Subject: [PATCH 3/5] Change chip id for onion omega on detection. --- adafruit_platformdetect/chip.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 45552e93..e21b179a 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -22,7 +22,7 @@ HFU540 = "HFU540" MCP2221 = "MCP2221" BINHO = "BINHO" -ONION = "ONION_OMEGA" +MIPS24KC = "MIPS24KC" class Chip: """Attempt detection of current chip / CPU.""" @@ -106,8 +106,8 @@ def _linux_id(self): # pylint: disable=too-many-branches cpu_model = self.detector.get_cpuinfo_field("cpu model") - if ("MIPS 24Kc") in cpu_model: - linux_id = ONION + if "MIPS 24Kc" in cpu_model: + linux_id = MIPS24KC elif hardware in ("BCM2708", "BCM2709", "BCM2835"): linux_id = BCM2XXX From 1819e608a1d90b0f126b85fb6ada40464346e140 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Tue, 31 Dec 2019 19:03:25 +0100 Subject: [PATCH 4/5] Fix error on board.py replacing `ONION` by `MIPS24KC` --- adafruit_platformdetect/board.py | 1076 +++++++++++++++--------------- 1 file changed, 538 insertions(+), 538 deletions(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 22f86dda..8594a596 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -1,538 +1,538 @@ -"""Detect boards.""" -import os -import adafruit_platformdetect.chip as ap_chip - -# Allow for aligned constant definitions: -# pylint: disable=bad-whitespace -BEAGLEBONE = 'BEAGLEBONE' -BEAGLEBONE_BLACK = 'BEAGLEBONE_BLACK' -BEAGLEBONE_BLUE = 'BEAGLEBONE_BLUE' -BEAGLEBONE_BLACK_WIRELESS = 'BEAGLEBONE_BLACK_WIRELESS' -BEAGLEBONE_POCKETBEAGLE = 'BEAGLEBONE_POCKETBEAGLE' -BEAGLEBONE_GREEN = 'BEAGLEBONE_GREEN' -BEAGLEBONE_GREEN_WIRELESS = 'BEAGLEBONE_GREEN_WIRELESS' -BEAGLEBONE_BLACK_INDUSTRIAL = 'BEAGLEBONE_BLACK_INDUSTRIAL' -BEAGLEBONE_ENHANCED = 'BEAGLEBONE_ENHANCED' -BEAGLEBONE_USOMIQ = 'BEAGLEBONE_USOMIQ' -BEAGLEBONE_AIR = 'BEAGLEBONE_AIR' -BEAGLEBONE_POCKETBONE = 'BEAGLEBONE_POCKETBONE' -BEAGLELOGIC_STANDALONE = 'BEAGLELOGIC_STANDALONE' -OSD3358_DEV_BOARD = 'OSD3358_DEV_BOARD' -OSD3358_SM_RED = 'OSD3358_SM_RED' - -FEATHER_HUZZAH = "FEATHER_HUZZAH" -FEATHER_M0_EXPRESS = "FEATHER_M0_EXPRESS" -GENERIC_LINUX_PC = "GENERIC_LINUX_PC" -PYBOARD = "PYBOARD" -NODEMCU = "NODEMCU" -ORANGE_PI_PC = "ORANGE_PI_PC" -ORANGE_PI_R1 = "ORANGE_PI_R1" -ORANGE_PI_ZERO = "ORANGE_PI_ZERO" -GIANT_BOARD = "GIANT_BOARD" - -# NVIDIA Jetson boards -JETSON_TX1 = 'JETSON_TX1' -JETSON_TX2 = 'JETSON_TX2' -JETSON_XAVIER = 'JETSON_XAVIER' -JETSON_NANO = 'JETSON_NANO' - -# Google Coral dev board -CORAL_EDGE_TPU_DEV = "CORAL_EDGE_TPU_DEV" - -# Various Raspberry Pi models -RASPBERRY_PI_B_REV1 = "RASPBERRY_PI_B_REV1" -RASPBERRY_PI_B_REV2 = "RASPBERRY_PI_B_REV2" -RASPBERRY_PI_B_PLUS = "RASPBERRY_PI_B_PLUS" -RASPBERRY_PI_A = "RASPBERRY_PI_A" -RASPBERRY_PI_A_PLUS = "RASPBERRY_PI_A_PLUS" -RASPBERRY_PI_CM1 = "RASPBERRY_PI_CM1" -RASPBERRY_PI_ZERO = "RASPBERRY_PI_ZERO" -RASPBERRY_PI_ZERO_W = "RASPBERRY_PI_ZERO_W" -RASPBERRY_PI_2B = "RASPBERRY_PI_2B" -RASPBERRY_PI_3B = "RASPBERRY_PI_3B" -RASPBERRY_PI_3B_PLUS = "RASPBERRY_PI_3B_PLUS" -RASPBERRY_PI_CM3 = "RASPBERRY_PI_CM3" -RASPBERRY_PI_3A_PLUS = "RASPBERRY_PI_3A_PLUS" -RASPBERRY_PI_CM3_PLUS = "RASPBERRY_PI_CM3_PLUS" -RASPBERRY_PI_4B = "RASPBERRY_PI_4B" - -ODROID_C1 = "ODROID_C1" -ODROID_C1_PLUS = "ODROID_C1_PLUS" -ODROID_C2 = "ODROID_C2" -ODROID_N2 = "ODROID_N2" - -FTDI_FT232H = "FTDI_FT232H" -DRAGONBOARD_410C = "DRAGONBOARD_410C" - -SIFIVE_UNLEASHED = "SIFIVE_UNLEASHED" - -MICROCHIP_MCP2221 = "MICROCHIP_MCP2221" - -BINHO_NOVA = "BINHO_NOVA" - -ONION_OMEGA = "ONION_OMEGA" -ONION_OMEGA2 = "ONION_OMEGA2" - -# pylint: enable=bad-whitespace - -#OrangePI -_ORANGE_PI_IDS = ( - ORANGE_PI_PC, - ORANGE_PI_R1, - ORANGE_PI_ZERO -) - -_CORAL_IDS = ( - CORAL_EDGE_TPU_DEV, -) - -_JETSON_IDS = ( - JETSON_TX1, - JETSON_TX2, - JETSON_XAVIER, - JETSON_NANO -) - -_RASPBERRY_PI_40_PIN_IDS = ( - RASPBERRY_PI_B_PLUS, - RASPBERRY_PI_A_PLUS, - RASPBERRY_PI_ZERO, - RASPBERRY_PI_ZERO_W, - RASPBERRY_PI_2B, - RASPBERRY_PI_3B, - RASPBERRY_PI_3B_PLUS, - RASPBERRY_PI_3A_PLUS, - RASPBERRY_PI_4B -) - -_RASPBERRY_PI_CM_IDS = ( - RASPBERRY_PI_CM1, - RASPBERRY_PI_CM3, - RASPBERRY_PI_CM3_PLUS -) - -_ODROID_40_PIN_IDS = ( - ODROID_C1, - ODROID_C1_PLUS, - ODROID_C2, - ODROID_N2 -) - -_BEAGLEBONE_IDS = ( - BEAGLEBONE, - BEAGLEBONE_BLACK, - BEAGLEBONE_BLUE, - BEAGLEBONE_BLACK_WIRELESS, - BEAGLEBONE_POCKETBEAGLE, - BEAGLEBONE_GREEN, - BEAGLEBONE_GREEN_WIRELESS, - BEAGLEBONE_BLACK_INDUSTRIAL, - BEAGLEBONE_ENHANCED, - BEAGLEBONE_USOMIQ, - BEAGLEBONE_AIR, - BEAGLEBONE_POCKETBONE, - BEAGLELOGIC_STANDALONE, - OSD3358_DEV_BOARD, - OSD3358_SM_RED, -) - -_LINARO_96BOARDS_IDS = ( - DRAGONBOARD_410C, -) - - -_SIFIVE_IDS = ( - SIFIVE_UNLEASHED, -) - -# BeagleBone eeprom board ids from: -# https://github.com/beagleboard/image-builder -# Thanks to zmatt on freenode #beagle for pointers. -_BEAGLEBONE_BOARD_IDS = { - # Original bone/white: - BEAGLEBONE: ( - ('A4', 'A335BONE00A4'), - ('A5', 'A335BONE00A5'), - ('A6', 'A335BONE00A6'), - ('A6A', 'A335BONE0A6A'), - ('A6B', 'A335BONE0A6B'), - ('B', 'A335BONE000B'), - ), - BEAGLEBONE_BLACK: ( - ('A5', 'A335BNLT00A5'), - ('A5A', 'A335BNLT0A5A'), - ('A5B', 'A335BNLT0A5B'), - ('A5C', 'A335BNLT0A5C'), - ('A6', 'A335BNLT00A6'), - ('C', 'A335BNLT000C'), - ('C', 'A335BNLT00C0'), - ), - BEAGLEBONE_BLUE: ( - ('A2', 'A335BNLTBLA2'), - ), - BEAGLEBONE_BLACK_WIRELESS: ( - ('A5', 'A335BNLTBWA5'), - ), - BEAGLEBONE_POCKETBEAGLE: ( - ('A2', 'A335PBGL00A2'), - ), - BEAGLEBONE_GREEN: ( - ('1A', 'A335BNLT....'), - ('UNKNOWN', 'A335BNLTBBG1'), - ), - BEAGLEBONE_GREEN_WIRELESS: ( - ('W1A', 'A335BNLTGW1A'), - ), - BEAGLEBONE_BLACK_INDUSTRIAL: ( - ('A0', 'A335BNLTAIA0'), # Arrow - ('A0', 'A335BNLTEIA0'), # Element14 - ), - BEAGLEBONE_ENHANCED: ( - ('A', 'A335BNLTSE0A'), - ), - BEAGLEBONE_USOMIQ: ( - ('6', 'A335BNLTME06'), - ), - BEAGLEBONE_AIR: ( - ('A0', 'A335BNLTNAD0'), - ), - BEAGLEBONE_POCKETBONE: ( - ('0', 'A335BNLTBP00'), - ), - OSD3358_DEV_BOARD: ( - ('0.1', 'A335BNLTGH01'), - ), - OSD3358_SM_RED: ( - ('0', 'A335BNLTOS00'), - ), - BEAGLELOGIC_STANDALONE: ( - ('A', 'A335BLGC000A'), - ) -} - -# Pi revision codes from: -# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md - -# Each tuple here contains both the base codes, and the versions that indicate -# the Pi is overvolted / overclocked - for 4-digit codes, this will be prefixed -# with 1000, and for 6-digit codes it'll be prefixed with 1. These are placed -# on separate lines. - -_PI_REV_CODES = { - RASPBERRY_PI_B_REV1: ( - # Regular codes: - '0002', '0003', - - # Overvolted/clocked versions: - '1000002', '1000003', - ), - RASPBERRY_PI_B_REV2: ( - '0005', '0006', '000d', '000e', '000f', - '1000005', '1000006', '100000d', '100000e', '100000f', - ), - RASPBERRY_PI_B_PLUS: ( - '0010', '0013', '900032', - '1000010', '1000013', '1900032', - ), - RASPBERRY_PI_A: ( - '0007', '0008', '0009', - '1000007', '1000008', '1000009', - ), - RASPBERRY_PI_A_PLUS: ( - '0012', '0015', '900021', - '1000012', '1000015', '1900021', - ), - RASPBERRY_PI_CM1: ( - '0011', '0014', - '10000011', '10000014', - ), - RASPBERRY_PI_ZERO: ( - '900092', '920092', '900093', '920093', - '1900092', '1920092', '1900093', '1920093', # warranty bit 24 - '2900092', '2920092', '2900093', '2920093', # warranty bit 25 - ), - RASPBERRY_PI_ZERO_W: ( - '9000c1', - '19000c1', '29000c1', # warranty bits - ), - RASPBERRY_PI_2B: ( - 'a01040', 'a01041', 'a21041', 'a22042', - '1a01040', '1a01041', '1a21041', '1a22042', # warranty bit 24 - '2a01040', '2a01041', '2a21041', '2a22042', # warranty bit 25 - ), - RASPBERRY_PI_3B: ( - 'a02082', 'a22082', 'a32082', 'a52082', - '1a02082', '1a22082', '1a32082', '1a52082', # warranty bit 24 - '2a02082', '2a22082', '2a32082', '2a52082', # warranty bit 25 - ), - RASPBERRY_PI_3B_PLUS: ( - 'a020d3', - '1a020d3', '2a020d3', # warranty bits - ), - RASPBERRY_PI_CM3: ( - 'a020a0', 'a220a0', - '1a020a0', '2a020a0', # warranty bits - '1a220a0', '2a220a0', - ), - RASPBERRY_PI_3A_PLUS: ( - '9020e0', - '19020e0', '29020e0', # warranty bits - ), - RASPBERRY_PI_CM3_PLUS: ( - 'a02100', - '1a02100', '2a02100', # warranty bits - ), - RASPBERRY_PI_4B: ( - 'a03111', 'b03111', 'c03111', - 'a03112', 'b03112', 'c03112', - '1a03111', '2a03111', '1b03111', '2b03111', # warranty bits - '1c03111', '2c03111', '1a03112', '2a03112', - '1b03112', '2b03112', '1c03112', '2c03112', - ), -} - -# Onion omega boards -_ONION_OMEGA_BOARD_IDS = ( - ONION_OMEGA, - ONION_OMEGA2, -) - -class Board: - """Attempt to detect specific boards.""" - def __init__(self, detector): - self.detector = detector - - # pylint: disable=invalid-name, too-many-branches - @property - def id(self): - """Return a unique id for the detected board, if any.""" - # There are some times we want to trick the platform detection - # say if a raspberry pi doesn't have the right ID, or for testing - try: - return os.environ['BLINKA_FORCEBOARD'] - except KeyError: # no forced board, continue with testing! - pass - - chip_id = self.detector.chip.id - board_id = None - - if chip_id == ap_chip.BCM2XXX: - board_id = self._pi_id() - elif chip_id == ap_chip.AM33XX: - board_id = self._beaglebone_id() - elif chip_id == ap_chip.GENERIC_X86: - board_id = GENERIC_LINUX_PC - elif chip_id == ap_chip.SUN8I: - board_id = self._armbian_id() - elif chip_id == ap_chip.SAMA5: - board_id = self._sama5_id() - elif chip_id == ap_chip.IMX8MX: - board_id = self._imx8mx_id() - elif chip_id == ap_chip.ESP8266: - board_id = FEATHER_HUZZAH - elif chip_id == ap_chip.SAMD21: - board_id = FEATHER_M0_EXPRESS - elif chip_id == ap_chip.STM32: - board_id = PYBOARD - elif chip_id == ap_chip.S805: - board_id = ODROID_C1 - elif chip_id == ap_chip.S905: - board_id = ODROID_C2 - elif chip_id == ap_chip.S922X: - board_id = ODROID_N2 - elif chip_id == ap_chip.FT232H: - board_id = FTDI_FT232H - elif chip_id == ap_chip.APQ8016: - board_id = DRAGONBOARD_410C - elif chip_id in (ap_chip.T210, ap_chip.T186, ap_chip.T194): - board_id = self._tegra_id() - elif chip_id == ap_chip.HFU540: - board_id = self._sifive_id() - elif chip_id == ap_chip.MCP2221: - board_id = MICROCHIP_MCP2221 - elif chip_id == ap_chip.BINHO: - board_id = BINHO_NOVA - elif chip_id == ap_chip.ONION: - board_id = ONION_OMEGA - return board_id - # pylint: enable=invalid-name - - def _pi_id(self): - """Try to detect id of a Raspberry Pi.""" - # Check for Pi boards: - pi_rev_code = self._pi_rev_code() - if pi_rev_code: - for model, codes in _PI_REV_CODES.items(): - if pi_rev_code in codes: - return model - return None - - def _pi_rev_code(self): - """Attempt to find a Raspberry Pi revision code for this board.""" - # 2708 is Pi 1 - # 2709 is Pi 2 - # 2835 is Pi 3 (or greater) on 4.9.x kernel - # Anything else is not a Pi. - if self.detector.chip.id != ap_chip.BCM2XXX: - # Something else, not a Pi. - return None - return self.detector.get_cpuinfo_field('Revision') - - # pylint: disable=no-self-use - def _beaglebone_id(self): - """Try to detect id of a Beaglebone.""" - try: - with open("/sys/bus/nvmem/devices/0-00500/nvmem", "rb") as eeprom: - eeprom_bytes = eeprom.read(16) - except FileNotFoundError: - return None - - if eeprom_bytes[:4] != b'\xaaU3\xee': - return None - - id_string = eeprom_bytes[4:].decode("ascii") - for model, bb_ids in _BEAGLEBONE_BOARD_IDS.items(): - for bb_id in bb_ids: - if id_string == bb_id[1]: - return model - - return None - # pylint: enable=no-self-use - - def _armbian_id(self): - """Check whether the current board is an OrangePi PC or OrangePI R1.""" - board_value = self.detector.get_armbian_release_field('BOARD') - if board_value == "orangepipc": - return ORANGE_PI_PC - if board_value == "orangepi-r1": - return ORANGE_PI_R1 - if board_value == "orangepizero": - return ORANGE_PI_ZERO - return None - - def _sama5_id(self): - """Check what type sama5 board.""" - board_value = self.detector.get_device_model() - if "Giant Board" in board_value: - return GIANT_BOARD - return None - - def _imx8mx_id(self): - """Check what type iMX8M board.""" - board_value = self.detector.get_device_model() - if "Phanbell" in board_value: - return CORAL_EDGE_TPU_DEV - return None - - def _tegra_id(self): - """Try to detect the id of aarch64 board.""" - board_value = self.detector.get_device_model() - board = None - if 'tx1' in board_value.lower(): - board = JETSON_TX1 - elif 'quill' in board_value or "storm" in board_value or "lightning" in board_value: - board = JETSON_TX2 - elif 'xavier' in board_value.lower() or 'agx' in board_value.lower(): - board = JETSON_XAVIER - elif 'nano' in board_value.lower(): - board = JETSON_NANO - return board - - def _sifive_id(self): - """Try to detect the id for Sifive RISCV64 board.""" - board_value = self.detector.get_device_model() - if 'hifive-unleashed-a00' in board_value: - return SIFIVE_UNLEASHED - return None - - @property - def any_96boards(self): - """Check whether the current board is any 96boards board.""" - return self.id in _LINARO_96BOARDS_IDS - - @property - def any_raspberry_pi(self): - """Check whether the current board is any Raspberry Pi.""" - return self._pi_rev_code() is not None - - @property - def any_raspberry_pi_40_pin(self): - """Check whether the current board is any 40-pin Raspberry Pi.""" - return self.id in _RASPBERRY_PI_40_PIN_IDS - - @property - def any_raspberry_pi_cm(self): - """Check whether the current board is any Compute Module Raspberry Pi.""" - return self.id in _RASPBERRY_PI_CM_IDS - - @property - def any_beaglebone(self): - """Check whether the current board is any Beaglebone-family system.""" - return self.id in _BEAGLEBONE_IDS - - @property - def any_orange_pi(self): - """Check whether the current board is any defined Orange Pi.""" - return self.id in _ORANGE_PI_IDS - - @property - def any_coral_board(self): - """Check whether the current board is any defined Coral.""" - return self.CORAL_EDGE_TPU_DEV - - @property - def any_giant_board(self): - """Check whether the current board is any defined Giant Board.""" - return self.GIANT_BOARD - - @property - def any_odroid_40_pin(self): - """Check whether the current board is any defined 40-pin Odroid.""" - return self.id in _ODROID_40_PIN_IDS - - @property - def any_jetson_board(self): - """Check whether the current board is any defined Jetson Board.""" - return self.id in _JETSON_IDS - - @property - def any_sifive_board(self): - """Check whether the current board is any defined Jetson Board.""" - return self.id in _SIFIVE_IDS - - @property - def any_onion_omega_board(self): - """Check whether the current board is any defined OpenWRT board.""" - return self.id in _ONION_OMEGA_BOARD_IDS - - @property - def any_embedded_linux(self): - """Check whether the current board is any embedded Linux device.""" - return self.any_raspberry_pi or self.any_beaglebone or \ - self.any_orange_pi or self.any_giant_board or self.any_jetson_board or \ - self.any_coral_board or self.any_odroid_40_pin or self.any_96boards or \ - self.any_sifive_board or self.any_onion_omega_board - - @property - def ftdi_ft232h(self): - """Check whether the current board is an FTDI FT232H.""" - return self.id == FTDI_FT232H - - @property - def microchip_mcp2221(self): - """Check whether the current board is a Microchip MCP2221.""" - return self.id == MICROCHIP_MCP2221 - - @property - def binho_nova(self): - """Check whether the current board is an BINHO NOVA.""" - return self.id == BINHO_NOVA - - def __getattr__(self, attr): - """ - Detect whether the given attribute is the currently-detected board. See list - of constants at the top of this module for available options. - """ - if self.id == attr: - return True - return False +"""Detect boards.""" +import os +import adafruit_platformdetect.chip as ap_chip + +# Allow for aligned constant definitions: +# pylint: disable=bad-whitespace +BEAGLEBONE = 'BEAGLEBONE' +BEAGLEBONE_BLACK = 'BEAGLEBONE_BLACK' +BEAGLEBONE_BLUE = 'BEAGLEBONE_BLUE' +BEAGLEBONE_BLACK_WIRELESS = 'BEAGLEBONE_BLACK_WIRELESS' +BEAGLEBONE_POCKETBEAGLE = 'BEAGLEBONE_POCKETBEAGLE' +BEAGLEBONE_GREEN = 'BEAGLEBONE_GREEN' +BEAGLEBONE_GREEN_WIRELESS = 'BEAGLEBONE_GREEN_WIRELESS' +BEAGLEBONE_BLACK_INDUSTRIAL = 'BEAGLEBONE_BLACK_INDUSTRIAL' +BEAGLEBONE_ENHANCED = 'BEAGLEBONE_ENHANCED' +BEAGLEBONE_USOMIQ = 'BEAGLEBONE_USOMIQ' +BEAGLEBONE_AIR = 'BEAGLEBONE_AIR' +BEAGLEBONE_POCKETBONE = 'BEAGLEBONE_POCKETBONE' +BEAGLELOGIC_STANDALONE = 'BEAGLELOGIC_STANDALONE' +OSD3358_DEV_BOARD = 'OSD3358_DEV_BOARD' +OSD3358_SM_RED = 'OSD3358_SM_RED' + +FEATHER_HUZZAH = "FEATHER_HUZZAH" +FEATHER_M0_EXPRESS = "FEATHER_M0_EXPRESS" +GENERIC_LINUX_PC = "GENERIC_LINUX_PC" +PYBOARD = "PYBOARD" +NODEMCU = "NODEMCU" +ORANGE_PI_PC = "ORANGE_PI_PC" +ORANGE_PI_R1 = "ORANGE_PI_R1" +ORANGE_PI_ZERO = "ORANGE_PI_ZERO" +GIANT_BOARD = "GIANT_BOARD" + +# NVIDIA Jetson boards +JETSON_TX1 = 'JETSON_TX1' +JETSON_TX2 = 'JETSON_TX2' +JETSON_XAVIER = 'JETSON_XAVIER' +JETSON_NANO = 'JETSON_NANO' + +# Google Coral dev board +CORAL_EDGE_TPU_DEV = "CORAL_EDGE_TPU_DEV" + +# Various Raspberry Pi models +RASPBERRY_PI_B_REV1 = "RASPBERRY_PI_B_REV1" +RASPBERRY_PI_B_REV2 = "RASPBERRY_PI_B_REV2" +RASPBERRY_PI_B_PLUS = "RASPBERRY_PI_B_PLUS" +RASPBERRY_PI_A = "RASPBERRY_PI_A" +RASPBERRY_PI_A_PLUS = "RASPBERRY_PI_A_PLUS" +RASPBERRY_PI_CM1 = "RASPBERRY_PI_CM1" +RASPBERRY_PI_ZERO = "RASPBERRY_PI_ZERO" +RASPBERRY_PI_ZERO_W = "RASPBERRY_PI_ZERO_W" +RASPBERRY_PI_2B = "RASPBERRY_PI_2B" +RASPBERRY_PI_3B = "RASPBERRY_PI_3B" +RASPBERRY_PI_3B_PLUS = "RASPBERRY_PI_3B_PLUS" +RASPBERRY_PI_CM3 = "RASPBERRY_PI_CM3" +RASPBERRY_PI_3A_PLUS = "RASPBERRY_PI_3A_PLUS" +RASPBERRY_PI_CM3_PLUS = "RASPBERRY_PI_CM3_PLUS" +RASPBERRY_PI_4B = "RASPBERRY_PI_4B" + +ODROID_C1 = "ODROID_C1" +ODROID_C1_PLUS = "ODROID_C1_PLUS" +ODROID_C2 = "ODROID_C2" +ODROID_N2 = "ODROID_N2" + +FTDI_FT232H = "FTDI_FT232H" +DRAGONBOARD_410C = "DRAGONBOARD_410C" + +SIFIVE_UNLEASHED = "SIFIVE_UNLEASHED" + +MICROCHIP_MCP2221 = "MICROCHIP_MCP2221" + +BINHO_NOVA = "BINHO_NOVA" + +ONION_OMEGA = "ONION_OMEGA" +ONION_OMEGA2 = "ONION_OMEGA2" + +# pylint: enable=bad-whitespace + +#OrangePI +_ORANGE_PI_IDS = ( + ORANGE_PI_PC, + ORANGE_PI_R1, + ORANGE_PI_ZERO +) + +_CORAL_IDS = ( + CORAL_EDGE_TPU_DEV, +) + +_JETSON_IDS = ( + JETSON_TX1, + JETSON_TX2, + JETSON_XAVIER, + JETSON_NANO +) + +_RASPBERRY_PI_40_PIN_IDS = ( + RASPBERRY_PI_B_PLUS, + RASPBERRY_PI_A_PLUS, + RASPBERRY_PI_ZERO, + RASPBERRY_PI_ZERO_W, + RASPBERRY_PI_2B, + RASPBERRY_PI_3B, + RASPBERRY_PI_3B_PLUS, + RASPBERRY_PI_3A_PLUS, + RASPBERRY_PI_4B +) + +_RASPBERRY_PI_CM_IDS = ( + RASPBERRY_PI_CM1, + RASPBERRY_PI_CM3, + RASPBERRY_PI_CM3_PLUS +) + +_ODROID_40_PIN_IDS = ( + ODROID_C1, + ODROID_C1_PLUS, + ODROID_C2, + ODROID_N2 +) + +_BEAGLEBONE_IDS = ( + BEAGLEBONE, + BEAGLEBONE_BLACK, + BEAGLEBONE_BLUE, + BEAGLEBONE_BLACK_WIRELESS, + BEAGLEBONE_POCKETBEAGLE, + BEAGLEBONE_GREEN, + BEAGLEBONE_GREEN_WIRELESS, + BEAGLEBONE_BLACK_INDUSTRIAL, + BEAGLEBONE_ENHANCED, + BEAGLEBONE_USOMIQ, + BEAGLEBONE_AIR, + BEAGLEBONE_POCKETBONE, + BEAGLELOGIC_STANDALONE, + OSD3358_DEV_BOARD, + OSD3358_SM_RED, +) + +_LINARO_96BOARDS_IDS = ( + DRAGONBOARD_410C, +) + + +_SIFIVE_IDS = ( + SIFIVE_UNLEASHED, +) + +# BeagleBone eeprom board ids from: +# https://github.com/beagleboard/image-builder +# Thanks to zmatt on freenode #beagle for pointers. +_BEAGLEBONE_BOARD_IDS = { + # Original bone/white: + BEAGLEBONE: ( + ('A4', 'A335BONE00A4'), + ('A5', 'A335BONE00A5'), + ('A6', 'A335BONE00A6'), + ('A6A', 'A335BONE0A6A'), + ('A6B', 'A335BONE0A6B'), + ('B', 'A335BONE000B'), + ), + BEAGLEBONE_BLACK: ( + ('A5', 'A335BNLT00A5'), + ('A5A', 'A335BNLT0A5A'), + ('A5B', 'A335BNLT0A5B'), + ('A5C', 'A335BNLT0A5C'), + ('A6', 'A335BNLT00A6'), + ('C', 'A335BNLT000C'), + ('C', 'A335BNLT00C0'), + ), + BEAGLEBONE_BLUE: ( + ('A2', 'A335BNLTBLA2'), + ), + BEAGLEBONE_BLACK_WIRELESS: ( + ('A5', 'A335BNLTBWA5'), + ), + BEAGLEBONE_POCKETBEAGLE: ( + ('A2', 'A335PBGL00A2'), + ), + BEAGLEBONE_GREEN: ( + ('1A', 'A335BNLT....'), + ('UNKNOWN', 'A335BNLTBBG1'), + ), + BEAGLEBONE_GREEN_WIRELESS: ( + ('W1A', 'A335BNLTGW1A'), + ), + BEAGLEBONE_BLACK_INDUSTRIAL: ( + ('A0', 'A335BNLTAIA0'), # Arrow + ('A0', 'A335BNLTEIA0'), # Element14 + ), + BEAGLEBONE_ENHANCED: ( + ('A', 'A335BNLTSE0A'), + ), + BEAGLEBONE_USOMIQ: ( + ('6', 'A335BNLTME06'), + ), + BEAGLEBONE_AIR: ( + ('A0', 'A335BNLTNAD0'), + ), + BEAGLEBONE_POCKETBONE: ( + ('0', 'A335BNLTBP00'), + ), + OSD3358_DEV_BOARD: ( + ('0.1', 'A335BNLTGH01'), + ), + OSD3358_SM_RED: ( + ('0', 'A335BNLTOS00'), + ), + BEAGLELOGIC_STANDALONE: ( + ('A', 'A335BLGC000A'), + ) +} + +# Pi revision codes from: +# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + +# Each tuple here contains both the base codes, and the versions that indicate +# the Pi is overvolted / overclocked - for 4-digit codes, this will be prefixed +# with 1000, and for 6-digit codes it'll be prefixed with 1. These are placed +# on separate lines. + +_PI_REV_CODES = { + RASPBERRY_PI_B_REV1: ( + # Regular codes: + '0002', '0003', + + # Overvolted/clocked versions: + '1000002', '1000003', + ), + RASPBERRY_PI_B_REV2: ( + '0005', '0006', '000d', '000e', '000f', + '1000005', '1000006', '100000d', '100000e', '100000f', + ), + RASPBERRY_PI_B_PLUS: ( + '0010', '0013', '900032', + '1000010', '1000013', '1900032', + ), + RASPBERRY_PI_A: ( + '0007', '0008', '0009', + '1000007', '1000008', '1000009', + ), + RASPBERRY_PI_A_PLUS: ( + '0012', '0015', '900021', + '1000012', '1000015', '1900021', + ), + RASPBERRY_PI_CM1: ( + '0011', '0014', + '10000011', '10000014', + ), + RASPBERRY_PI_ZERO: ( + '900092', '920092', '900093', '920093', + '1900092', '1920092', '1900093', '1920093', # warranty bit 24 + '2900092', '2920092', '2900093', '2920093', # warranty bit 25 + ), + RASPBERRY_PI_ZERO_W: ( + '9000c1', + '19000c1', '29000c1', # warranty bits + ), + RASPBERRY_PI_2B: ( + 'a01040', 'a01041', 'a21041', 'a22042', + '1a01040', '1a01041', '1a21041', '1a22042', # warranty bit 24 + '2a01040', '2a01041', '2a21041', '2a22042', # warranty bit 25 + ), + RASPBERRY_PI_3B: ( + 'a02082', 'a22082', 'a32082', 'a52082', + '1a02082', '1a22082', '1a32082', '1a52082', # warranty bit 24 + '2a02082', '2a22082', '2a32082', '2a52082', # warranty bit 25 + ), + RASPBERRY_PI_3B_PLUS: ( + 'a020d3', + '1a020d3', '2a020d3', # warranty bits + ), + RASPBERRY_PI_CM3: ( + 'a020a0', 'a220a0', + '1a020a0', '2a020a0', # warranty bits + '1a220a0', '2a220a0', + ), + RASPBERRY_PI_3A_PLUS: ( + '9020e0', + '19020e0', '29020e0', # warranty bits + ), + RASPBERRY_PI_CM3_PLUS: ( + 'a02100', + '1a02100', '2a02100', # warranty bits + ), + RASPBERRY_PI_4B: ( + 'a03111', 'b03111', 'c03111', + 'a03112', 'b03112', 'c03112', + '1a03111', '2a03111', '1b03111', '2b03111', # warranty bits + '1c03111', '2c03111', '1a03112', '2a03112', + '1b03112', '2b03112', '1c03112', '2c03112', + ), +} + +# Onion omega boards +_ONION_OMEGA_BOARD_IDS = ( + ONION_OMEGA, + ONION_OMEGA2, +) + +class Board: + """Attempt to detect specific boards.""" + def __init__(self, detector): + self.detector = detector + + # pylint: disable=invalid-name, too-many-branches + @property + def id(self): + """Return a unique id for the detected board, if any.""" + # There are some times we want to trick the platform detection + # say if a raspberry pi doesn't have the right ID, or for testing + try: + return os.environ['BLINKA_FORCEBOARD'] + except KeyError: # no forced board, continue with testing! + pass + + chip_id = self.detector.chip.id + board_id = None + + if chip_id == ap_chip.BCM2XXX: + board_id = self._pi_id() + elif chip_id == ap_chip.AM33XX: + board_id = self._beaglebone_id() + elif chip_id == ap_chip.GENERIC_X86: + board_id = GENERIC_LINUX_PC + elif chip_id == ap_chip.SUN8I: + board_id = self._armbian_id() + elif chip_id == ap_chip.SAMA5: + board_id = self._sama5_id() + elif chip_id == ap_chip.IMX8MX: + board_id = self._imx8mx_id() + elif chip_id == ap_chip.ESP8266: + board_id = FEATHER_HUZZAH + elif chip_id == ap_chip.SAMD21: + board_id = FEATHER_M0_EXPRESS + elif chip_id == ap_chip.STM32: + board_id = PYBOARD + elif chip_id == ap_chip.S805: + board_id = ODROID_C1 + elif chip_id == ap_chip.S905: + board_id = ODROID_C2 + elif chip_id == ap_chip.S922X: + board_id = ODROID_N2 + elif chip_id == ap_chip.FT232H: + board_id = FTDI_FT232H + elif chip_id == ap_chip.APQ8016: + board_id = DRAGONBOARD_410C + elif chip_id in (ap_chip.T210, ap_chip.T186, ap_chip.T194): + board_id = self._tegra_id() + elif chip_id == ap_chip.HFU540: + board_id = self._sifive_id() + elif chip_id == ap_chip.MCP2221: + board_id = MICROCHIP_MCP2221 + elif chip_id == ap_chip.BINHO: + board_id = BINHO_NOVA + elif chip_id == ap_chip.MIPS24KC: + board_id = ONION_OMEGA + return board_id + # pylint: enable=invalid-name + + def _pi_id(self): + """Try to detect id of a Raspberry Pi.""" + # Check for Pi boards: + pi_rev_code = self._pi_rev_code() + if pi_rev_code: + for model, codes in _PI_REV_CODES.items(): + if pi_rev_code in codes: + return model + return None + + def _pi_rev_code(self): + """Attempt to find a Raspberry Pi revision code for this board.""" + # 2708 is Pi 1 + # 2709 is Pi 2 + # 2835 is Pi 3 (or greater) on 4.9.x kernel + # Anything else is not a Pi. + if self.detector.chip.id != ap_chip.BCM2XXX: + # Something else, not a Pi. + return None + return self.detector.get_cpuinfo_field('Revision') + + # pylint: disable=no-self-use + def _beaglebone_id(self): + """Try to detect id of a Beaglebone.""" + try: + with open("/sys/bus/nvmem/devices/0-00500/nvmem", "rb") as eeprom: + eeprom_bytes = eeprom.read(16) + except FileNotFoundError: + return None + + if eeprom_bytes[:4] != b'\xaaU3\xee': + return None + + id_string = eeprom_bytes[4:].decode("ascii") + for model, bb_ids in _BEAGLEBONE_BOARD_IDS.items(): + for bb_id in bb_ids: + if id_string == bb_id[1]: + return model + + return None + # pylint: enable=no-self-use + + def _armbian_id(self): + """Check whether the current board is an OrangePi PC or OrangePI R1.""" + board_value = self.detector.get_armbian_release_field('BOARD') + if board_value == "orangepipc": + return ORANGE_PI_PC + if board_value == "orangepi-r1": + return ORANGE_PI_R1 + if board_value == "orangepizero": + return ORANGE_PI_ZERO + return None + + def _sama5_id(self): + """Check what type sama5 board.""" + board_value = self.detector.get_device_model() + if "Giant Board" in board_value: + return GIANT_BOARD + return None + + def _imx8mx_id(self): + """Check what type iMX8M board.""" + board_value = self.detector.get_device_model() + if "Phanbell" in board_value: + return CORAL_EDGE_TPU_DEV + return None + + def _tegra_id(self): + """Try to detect the id of aarch64 board.""" + board_value = self.detector.get_device_model() + board = None + if 'tx1' in board_value.lower(): + board = JETSON_TX1 + elif 'quill' in board_value or "storm" in board_value or "lightning" in board_value: + board = JETSON_TX2 + elif 'xavier' in board_value.lower() or 'agx' in board_value.lower(): + board = JETSON_XAVIER + elif 'nano' in board_value.lower(): + board = JETSON_NANO + return board + + def _sifive_id(self): + """Try to detect the id for Sifive RISCV64 board.""" + board_value = self.detector.get_device_model() + if 'hifive-unleashed-a00' in board_value: + return SIFIVE_UNLEASHED + return None + + @property + def any_96boards(self): + """Check whether the current board is any 96boards board.""" + return self.id in _LINARO_96BOARDS_IDS + + @property + def any_raspberry_pi(self): + """Check whether the current board is any Raspberry Pi.""" + return self._pi_rev_code() is not None + + @property + def any_raspberry_pi_40_pin(self): + """Check whether the current board is any 40-pin Raspberry Pi.""" + return self.id in _RASPBERRY_PI_40_PIN_IDS + + @property + def any_raspberry_pi_cm(self): + """Check whether the current board is any Compute Module Raspberry Pi.""" + return self.id in _RASPBERRY_PI_CM_IDS + + @property + def any_beaglebone(self): + """Check whether the current board is any Beaglebone-family system.""" + return self.id in _BEAGLEBONE_IDS + + @property + def any_orange_pi(self): + """Check whether the current board is any defined Orange Pi.""" + return self.id in _ORANGE_PI_IDS + + @property + def any_coral_board(self): + """Check whether the current board is any defined Coral.""" + return self.CORAL_EDGE_TPU_DEV + + @property + def any_giant_board(self): + """Check whether the current board is any defined Giant Board.""" + return self.GIANT_BOARD + + @property + def any_odroid_40_pin(self): + """Check whether the current board is any defined 40-pin Odroid.""" + return self.id in _ODROID_40_PIN_IDS + + @property + def any_jetson_board(self): + """Check whether the current board is any defined Jetson Board.""" + return self.id in _JETSON_IDS + + @property + def any_sifive_board(self): + """Check whether the current board is any defined Jetson Board.""" + return self.id in _SIFIVE_IDS + + @property + def any_onion_omega_board(self): + """Check whether the current board is any defined OpenWRT board.""" + return self.id in _ONION_OMEGA_BOARD_IDS + + @property + def any_embedded_linux(self): + """Check whether the current board is any embedded Linux device.""" + return self.any_raspberry_pi or self.any_beaglebone or \ + self.any_orange_pi or self.any_giant_board or self.any_jetson_board or \ + self.any_coral_board or self.any_odroid_40_pin or self.any_96boards or \ + self.any_sifive_board or self.any_onion_omega_board + + @property + def ftdi_ft232h(self): + """Check whether the current board is an FTDI FT232H.""" + return self.id == FTDI_FT232H + + @property + def microchip_mcp2221(self): + """Check whether the current board is a Microchip MCP2221.""" + return self.id == MICROCHIP_MCP2221 + + @property + def binho_nova(self): + """Check whether the current board is an BINHO NOVA.""" + return self.id == BINHO_NOVA + + def __getattr__(self, attr): + """ + Detect whether the given attribute is the currently-detected board. See list + of constants at the top of this module for available options. + """ + if self.id == attr: + return True + return False From 7711eca97cf38a372a736ac3b9fb936cf1db8f24 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 2 Jan 2020 16:29:26 -0800 Subject: [PATCH 5/5] Added Onion Omega2 detection --- adafruit_platformdetect/board.py | 4 +++- adafruit_platformdetect/chip.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 8594a596..4caff304 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -71,7 +71,7 @@ BINHO_NOVA = "BINHO_NOVA" ONION_OMEGA = "ONION_OMEGA" -ONION_OMEGA2 = "ONION_OMEGA2" +ONION_OMEGA2 = "ONION_OMEGA2" # pylint: enable=bad-whitespace @@ -354,6 +354,8 @@ def id(self): board_id = BINHO_NOVA elif chip_id == ap_chip.MIPS24KC: board_id = ONION_OMEGA + elif chip_id == ap_chip.MIPS24KEC: + board_id = ONION_OMEGA2 return board_id # pylint: enable=invalid-name diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index e21b179a..4b33165c 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -23,6 +23,7 @@ MCP2221 = "MCP2221" BINHO = "BINHO" MIPS24KC = "MIPS24KC" +MIPS24KEC = "MIPS24KEC" class Chip: """Attempt detection of current chip / CPU.""" @@ -108,6 +109,8 @@ def _linux_id(self): # pylint: disable=too-many-branches if "MIPS 24Kc" in cpu_model: linux_id = MIPS24KC + elif "MIPS 24KEc" in cpu_model: + linux_id = MIPS24KEC elif hardware in ("BCM2708", "BCM2709", "BCM2835"): linux_id = BCM2XXX