Skip to content

Commit 49ccd2a

Browse files
authored
Merge pull request #14 from NVIDIA-AI-IOT-private/jetson
added jetson chip and board detect
2 parents c5e0039 + 3d682f2 commit 49ccd2a

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

adafruit_platformdetect/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,14 @@ def get_device_model(self):
8585
return model
8686
except FileNotFoundError:
8787
pass
88+
89+
def get_device_compatible(self):
90+
"""
91+
Search /proc/device-tree/compatible for the compatible chip name.
92+
"""
93+
try:
94+
with open('/proc/device-tree/compatible', 'r') as model_file:
95+
model = model_file.read()
96+
return model
97+
except FileNotFoundError:
98+
pass

adafruit_platformdetect/board.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
ORANGE_PI_PC = "ORANGE_PI_PC"
2929
GIANT_BOARD = "GIANT_BOARD"
3030

31+
JETSON_TX1 = 'JETSON_TX1'
32+
JETSON_TX2 = 'JETSON_TX2'
33+
JETSON_XAVIER = 'JETSON_XAVIER'
34+
JETSON_TXX = 'JETSON_TXX'
35+
3136
RASPBERRY_PI_B_REV1 = "RASPBERRY_PI_B_REV1"
3237
RASPBERRY_PI_B_REV2 = "RASPBERRY_PI_B_REV2"
3338
RASPBERRY_PI_B_PLUS = "RASPBERRY_PI_B_PLUS"
@@ -49,6 +54,13 @@
4954
FTDI_FT232H = "FT232H"
5055
# pylint: enable=bad-whitespace
5156

57+
_JETSON_IDS = (
58+
JETSON_TX1,
59+
JETSON_TX2,
60+
JETSON_XAVIER,
61+
JETSON_TXX
62+
)
63+
5264
_RASPBERRY_PI_40_PIN_IDS = (
5365
RASPBERRY_PI_B_PLUS,
5466
RASPBERRY_PI_A_PLUS,
@@ -223,7 +235,7 @@ class Board:
223235
def __init__(self, detector):
224236
self.detector = detector
225237

226-
# pylint: disable=invalid-name
238+
# pylint: disable=invalid-name, too-many-branches
227239
@property
228240
def id(self):
229241
"""Return a unique id for the detected board, if any."""
@@ -259,6 +271,9 @@ def id(self):
259271
board_id = ODROID_C2
260272
elif chip_id == ap_chip.FT232H:
261273
board_id = FTDI_FT232H
274+
elif chip_id == ap_chip.TEGRAXXX:
275+
board_id = self._tegra_id()
276+
262277
return board_id
263278
# pylint: enable=invalid-name
264279

@@ -318,6 +333,19 @@ def _sama5_id(self):
318333
return GIANT_BOARD
319334
return None
320335

336+
def _tegra_id(self):
337+
"""Try to detect the id of aarch64 board."""
338+
board_value = self.detector.get_device_model()
339+
if 'tx1' in board_value:
340+
return JETSON_TX1
341+
elif 'quill' in board_value:
342+
return JETSON_TX2
343+
elif 'xavier' in board_value:
344+
return JETSON_XAVIER
345+
elif 'txx' in board_value:
346+
return JETSON_TXX
347+
return None
348+
321349
@property
322350
def any_raspberry_pi(self):
323351
"""Check whether the current board is any Raspberry Pi."""
@@ -343,11 +371,16 @@ def any_giant_board(self):
343371
"""Check whether the current board is any defined Giant Board."""
344372
return self.GIANT_BOARD
345373

374+
@property
375+
def any_jetson_board(self):
376+
"""Check whether the current board is any defined Jetson Board."""
377+
return self.id in _JETSON_IDS
378+
346379
@property
347380
def any_embedded_linux(self):
348381
"""Check whether the current board is any embedded Linux device."""
349382
return self.any_raspberry_pi or self.any_beaglebone or \
350-
self.any_orange_pi or self.any_giant_board
383+
self.any_orange_pi or self.any_giant_board or self.any_jetson_board
351384

352385
def __getattr__(self, attr):
353386
"""

adafruit_platformdetect/chip.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
S805 = "S805"
1212
S905 = "S905"
1313
SAMA5 = "SAMA5"
14+
TEGRAXXX = "TEGRAXXX"
1415
GENERIC_X86 = "GENERIC_X86"
1516
FT232H = "FT232H"
1617

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

5758
platform = sys.platform
58-
if platform == "linux":
59+
if platform == "linux" or platform == "linux2":
5960
return self._linux_id()
6061
if platform == "esp8266":
6162
return ESP8266
@@ -77,6 +78,10 @@ def _linux_id(self):
7778
vendor_id = self.detector.get_cpuinfo_field("vendor_id")
7879
if vendor_id in ("GenuineIntel", "AuthenticAMD"):
7980
linux_id = GENERIC_X86
81+
82+
compatible = self.detector.get_device_compatible()
83+
if 'tegra' in compatible:
84+
linux_id = TEGRAXXX
8085
elif hardware in ("BCM2708", "BCM2709", "BCM2835"):
8186
linux_id = BCM2XXX
8287
elif "AM33XX" in hardware:

bin/detect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818

1919
if detector.board.any_raspberry_pi:
2020
print("Raspberry Pi detected.")
21+
22+
if detector.board.any_jetson_board:
23+
print("Jetson platform detected.")

0 commit comments

Comments
 (0)