Skip to content

Initial addition for Pine64 devices #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 9, 2020
Merged
59 changes: 46 additions & 13 deletions adafruit_platformdetect/board.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Detect boards."""
import os
import re

import adafruit_platformdetect.chip as ap_chip

# Allow for aligned constant definitions:
Expand Down Expand Up @@ -74,6 +75,10 @@
ONION_OMEGA = "ONION_OMEGA"
ONION_OMEGA2 = "ONION_OMEGA2"

PINE64 = "PINE64"
PINEBOOK = "PINEBOOK"
PINEPHONE = "PINEPHONE"

# pylint: enable=bad-whitespace

#OrangePI
Expand Down Expand Up @@ -249,44 +254,44 @@
),
RASPBERRY_PI_ZERO: (
'900092', '920092', '900093', '920093',
'1900092', '1920092', '1900093', '1920093', # warranty bit 24
'2900092', '2920092', '2900093', '2920093', # warranty bit 25
'1900092', '1920092', '1900093', '1920093', # warranty bit 24
'2900092', '2920092', '2900093', '2920093', # warranty bit 25
),
RASPBERRY_PI_ZERO_W: (
'9000c1',
'19000c1', '29000c1', # warranty bits
'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
'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
'1a02082', '1a22082', '1a32082', '1a52082', # warranty bit 24
'2a02082', '2a22082', '2a32082', '2a52082', # warranty bit 25
),
RASPBERRY_PI_3B_PLUS: (
'a020d3',
'1a020d3', '2a020d3', # warranty bits
'1a020d3', '2a020d3', # warranty bits
),
RASPBERRY_PI_CM3: (
'a020a0', 'a220a0',
'1a020a0', '2a020a0', # warranty bits
'1a020a0', '2a020a0', # warranty bits
'1a220a0', '2a220a0',
),
RASPBERRY_PI_3A_PLUS: (
'9020e0',
'19020e0', '29020e0', # warranty bits
'19020e0', '29020e0', # warranty bits
),
RASPBERRY_PI_CM3_PLUS: (
'a02100',
'1a02100', '2a02100', # warranty bits
'1a02100', '2a02100', # warranty bits
),
RASPBERRY_PI_4B: (
'a03111', 'b03111', 'c03111',
'a03112', 'b03112', 'c03112',
'1a03111', '2a03111', '1b03111', '2b03111', # warranty bits
'1a03111', '2a03111', '1b03111', '2b03111', # warranty bits
'1c03111', '2c03111', '1a03112', '2a03112',
'1b03112', '2b03112', '1c03112', '2c03112',
),
Expand All @@ -298,6 +303,13 @@
ONION_OMEGA2,
)

# Pine64 boards and devices
_PINE64_DEV_IDS = (
PINE64,
PINEBOOK,
PINEPHONE
)

class Board:
"""Attempt to detect specific boards."""
def __init__(self, detector):
Expand Down Expand Up @@ -357,6 +369,8 @@ def id(self):
board_id = ONION_OMEGA
elif chip_id == ap_chip.MIPS24KEC:
board_id = ONION_OMEGA2
elif chip_id == ap_chip.A64:
board_id = self._pine64_id()
return board_id
# pylint: enable=invalid-name

Expand Down Expand Up @@ -435,6 +449,8 @@ def _armbian_id(self):
return ORANGE_PI_R1
if board_value == "orangepizero":
return ORANGE_PI_ZERO
if board_value == "pinebook-a64":
return PINEBOOK
return None

def _sama5_id(self):
Expand Down Expand Up @@ -472,6 +488,18 @@ def _sifive_id(self):
return SIFIVE_UNLEASHED
return None

def _pine64_id(self):
"""Try to detect the id for Pine64 board or device."""
board_value = self.detector.get_device_model()
board = None
if 'pine64' in board_value.lower():
board = PINE64
elif 'pinebook' in board_value.lower():
board = PINEBOOK
elif 'pinephone' in board_value.lower():
board = PINEPHONE
return board

@property
def any_96boards(self):
"""Check whether the current board is any 96boards board."""
Expand Down Expand Up @@ -532,13 +560,18 @@ 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_pine64_board(self):
"""Check whether the current board is any Pine64 device."""
return self.id in _PINE64_DEV_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
self.any_sifive_board or self.any_onion_omega_board or self.any_pine64_board

@property
def ftdi_ft232h(self):
Expand Down
21 changes: 15 additions & 6 deletions adafruit_platformdetect/chip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Attempt detection of current chip / CPU."""
import sys
import os
import sys

AM33XX = "AM33XX"
IMX8MX = "IMX8MX"
Expand All @@ -24,36 +24,39 @@
BINHO = "BINHO"
MIPS24KC = "MIPS24KC"
MIPS24KEC = "MIPS24KEC"
A64 = "A64"

BCM_RANGE = {'BCM2708', 'BCM2709', 'BCM2835', 'BCM2837', 'bcm2708', 'bcm2709',
'bcm2835', 'bcm2837'}


class Chip:
"""Attempt detection of current chip / CPU."""

def __init__(self, detector):
self.detector = detector

@property
def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
"""Return a unique id for the detected chip, 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_FORCECHIP']
except KeyError: # no forced chip, continue with testing!
except KeyError: # no forced chip, continue with testing!
pass

# Special cases controlled by environment var
if os.environ.get('BLINKA_FT232H'):
from pyftdi.usbtools import UsbTools # pylint: disable=import-error
from pyftdi.usbtools import UsbTools # pylint: disable=import-error
# look for it based on PID/VID
count = len(UsbTools.find_all([(0x0403, 0x6014)]))
if count == 0:
raise RuntimeError('BLINKA_FT232H environment variable ' + \
'set, but no FT232H device found')
return FT232H
if os.environ.get('BLINKA_MCP2221'):
import hid # pylint: disable=import-error
import hid # pylint: disable=import-error
# look for it based on PID/VID
for dev in hid.enumerate():
if dev['vendor_id'] == 0x04D8 and dev['product_id'] == 0x00DD:
Expand All @@ -74,9 +77,10 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
return STM32
# nothing found!
return None

# pylint: enable=invalid-name

def _linux_id(self): # pylint: disable=too-many-branches
def _linux_id(self): # pylint: disable=too-many-branches,too-many-statements
"""Attempt to detect the CPU on a computer running the Linux kernel."""

if self.detector.check_dt_compatible_value('qcom,apq8016'):
Expand Down Expand Up @@ -109,6 +113,7 @@ def _linux_id(self): # pylint: disable=too-many-branches
linux_id = S922X

cpu_model = self.detector.get_cpuinfo_field("cpu model")

if cpu_model is not None:
if "MIPS 24Kc" in cpu_model:
linux_id = MIPS24KC
Expand Down Expand Up @@ -136,6 +141,10 @@ def _linux_id(self): # pylint: disable=too-many-branches
linux_id = S922X
elif 'SAMA5' in hardware:
linux_id = SAMA5
elif "Pinebook" in hardware:
linux_id = A64
elif "sun50iw1p1" in hardware:
linux_id = A64
else:
if isinstance(hardware, str):
if hardware in BCM_RANGE:
Expand Down
7 changes: 5 additions & 2 deletions bin/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
print("Is this a SiFive Unleashed? ", detector.board.SIFIVE_UNLEASHED)
print("Is this an embedded Linux system?", detector.board.any_embedded_linux)
print("Is this a generic Linux PC?", detector.board.GENERIC_LINUX_PC)
print("Is this an OS environment variable special case?", detector.board.FTDI_FT232H |
detector.board.MICROCHIP_MCP2221 )
print("Is this an OS environment variable special case?", detector.board.FTDI_FT232H |
detector.board.MICROCHIP_MCP2221)

if detector.board.any_raspberry_pi:
print("Raspberry Pi detected.")
Expand All @@ -36,3 +36,6 @@

if detector.board.any_onion_omega_board:
print("Onion Omega detected.")

if detector.board.any_pine64_board:
print("Pine64 device detected.")