Skip to content

Commit

Permalink
Merge pull request #14 from NVIDIA-AI-IOT-private/jetson
Browse files Browse the repository at this point in the history
added jetson chip and board detect
  • Loading branch information
ladyada authored Mar 11, 2019
2 parents c5e0039 + 3d682f2 commit 49ccd2a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
11 changes: 11 additions & 0 deletions adafruit_platformdetect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,14 @@ def get_device_model(self):
return model
except FileNotFoundError:
pass

def get_device_compatible(self):
"""
Search /proc/device-tree/compatible for the compatible chip name.
"""
try:
with open('/proc/device-tree/compatible', 'r') as model_file:
model = model_file.read()
return model
except FileNotFoundError:
pass
37 changes: 35 additions & 2 deletions adafruit_platformdetect/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
ORANGE_PI_PC = "ORANGE_PI_PC"
GIANT_BOARD = "GIANT_BOARD"

JETSON_TX1 = 'JETSON_TX1'
JETSON_TX2 = 'JETSON_TX2'
JETSON_XAVIER = 'JETSON_XAVIER'
JETSON_TXX = 'JETSON_TXX'

RASPBERRY_PI_B_REV1 = "RASPBERRY_PI_B_REV1"
RASPBERRY_PI_B_REV2 = "RASPBERRY_PI_B_REV2"
RASPBERRY_PI_B_PLUS = "RASPBERRY_PI_B_PLUS"
Expand All @@ -49,6 +54,13 @@
FTDI_FT232H = "FT232H"
# pylint: enable=bad-whitespace

_JETSON_IDS = (
JETSON_TX1,
JETSON_TX2,
JETSON_XAVIER,
JETSON_TXX
)

_RASPBERRY_PI_40_PIN_IDS = (
RASPBERRY_PI_B_PLUS,
RASPBERRY_PI_A_PLUS,
Expand Down Expand Up @@ -223,7 +235,7 @@ class Board:
def __init__(self, detector):
self.detector = detector

# pylint: disable=invalid-name
# pylint: disable=invalid-name, too-many-branches
@property
def id(self):
"""Return a unique id for the detected board, if any."""
Expand Down Expand Up @@ -259,6 +271,9 @@ def id(self):
board_id = ODROID_C2
elif chip_id == ap_chip.FT232H:
board_id = FTDI_FT232H
elif chip_id == ap_chip.TEGRAXXX:
board_id = self._tegra_id()

return board_id
# pylint: enable=invalid-name

Expand Down Expand Up @@ -318,6 +333,19 @@ def _sama5_id(self):
return GIANT_BOARD
return None

def _tegra_id(self):
"""Try to detect the id of aarch64 board."""
board_value = self.detector.get_device_model()
if 'tx1' in board_value:
return JETSON_TX1
elif 'quill' in board_value:
return JETSON_TX2
elif 'xavier' in board_value:
return JETSON_XAVIER
elif 'txx' in board_value:
return JETSON_TXX
return None

@property
def any_raspberry_pi(self):
"""Check whether the current board is any Raspberry Pi."""
Expand All @@ -343,11 +371,16 @@ def any_giant_board(self):
"""Check whether the current board is any defined Giant Board."""
return self.GIANT_BOARD

@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_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
self.any_orange_pi or self.any_giant_board or self.any_jetson_board

def __getattr__(self, attr):
"""
Expand Down
7 changes: 6 additions & 1 deletion adafruit_platformdetect/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
S805 = "S805"
S905 = "S905"
SAMA5 = "SAMA5"
TEGRAXXX = "TEGRAXXX"
GENERIC_X86 = "GENERIC_X86"
FT232H = "FT232H"

Expand Down Expand Up @@ -55,7 +56,7 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
pass

platform = sys.platform
if platform == "linux":
if platform == "linux" or platform == "linux2":
return self._linux_id()
if platform == "esp8266":
return ESP8266
Expand All @@ -77,6 +78,10 @@ def _linux_id(self):
vendor_id = self.detector.get_cpuinfo_field("vendor_id")
if vendor_id in ("GenuineIntel", "AuthenticAMD"):
linux_id = GENERIC_X86

compatible = self.detector.get_device_compatible()
if 'tegra' in compatible:
linux_id = TEGRAXXX
elif hardware in ("BCM2708", "BCM2709", "BCM2835"):
linux_id = BCM2XXX
elif "AM33XX" in hardware:
Expand Down
3 changes: 3 additions & 0 deletions bin/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@

if detector.board.any_raspberry_pi:
print("Raspberry Pi detected.")

if detector.board.any_jetson_board:
print("Jetson platform detected.")

0 comments on commit 49ccd2a

Please sign in to comment.