25
25
MIPS24KC = "MIPS24KC"
26
26
MIPS24KEC = "MIPS24KEC"
27
27
28
+ BCM_RANGE = {'BCM2708' , 'BCM2709' , 'BCM2835' , 'BCM2837' , 'bcm2708' , 'bcm2709' ,
29
+ 'bcm2835' , 'bcm2837' }
30
+
28
31
class Chip :
29
32
"""Attempt detection of current chip / CPU."""
30
33
def __init__ (self , detector ):
@@ -61,13 +64,13 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
61
64
return BINHO
62
65
63
66
platform = sys .platform
64
- if platform == " linux" or platform == " linux2" :
67
+ if platform in ( ' linux' , ' linux2' ) :
65
68
return self ._linux_id ()
66
- if platform == " esp8266" :
69
+ if platform == ' esp8266' :
67
70
return ESP8266
68
- if platform == " samd21" :
71
+ if platform == ' samd21' :
69
72
return SAMD21
70
- if platform == " pyboard" :
73
+ if platform == ' pyboard' :
71
74
return STM32
72
75
# nothing found!
73
76
return None
@@ -76,18 +79,18 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s
76
79
def _linux_id (self ): # pylint: disable=too-many-branches
77
80
"""Attempt to detect the CPU on a computer running the Linux kernel."""
78
81
79
- if self .detector .check_dt_compatible_value (" qcom,apq8016" ):
82
+ if self .detector .check_dt_compatible_value (' qcom,apq8016' ):
80
83
return APQ8016
81
84
82
- if self .detector .check_dt_compatible_value (" fu500" ):
85
+ if self .detector .check_dt_compatible_value (' fu500' ):
83
86
return HFU540
84
87
85
88
linux_id = None
86
- hardware = self .detector .get_cpuinfo_field (" Hardware" )
89
+ hardware = self .detector .get_cpuinfo_field (' Hardware' )
87
90
88
91
if hardware is None :
89
- vendor_id = self .detector .get_cpuinfo_field (" vendor_id" )
90
- if vendor_id in (" GenuineIntel" , " AuthenticAMD" ):
92
+ vendor_id = self .detector .get_cpuinfo_field (' vendor_id' )
93
+ if vendor_id in (' GenuineIntel' , ' AuthenticAMD' ):
91
94
linux_id = GENERIC_X86
92
95
93
96
compatible = self .detector .get_device_compatible ()
@@ -112,20 +115,34 @@ def _linux_id(self): # pylint: disable=too-many-branches
112
115
elif "MIPS 24KEc" in cpu_model :
113
116
linux_id = MIPS24KEC
114
117
115
- elif hardware in ("BCM2708" , "BCM2709" , "BCM2835" ):
116
- linux_id = BCM2XXX
117
- elif "AM33XX" in hardware :
118
- linux_id = AM33XX
119
- elif "sun8i" in hardware :
120
- linux_id = SUN8I
121
- elif "ODROIDC" in hardware :
122
- linux_id = S805
123
- elif "ODROID-C2" in hardware :
124
- linux_id = S905
125
- elif "ODROID-N2" in hardware :
126
- linux_id = S922X
127
- elif "SAMA5" in hardware :
128
- linux_id = SAMA5
118
+ # we still haven't identified the hardware, so
119
+ # convert it to a list and let the remaining
120
+ # conditions attempt.
121
+ if not linux_id :
122
+ hardware = [
123
+ entry .replace ('\x00 ' , '' ) for entry in compatible .split (',' )
124
+ ]
125
+
126
+ if not linux_id :
127
+ if 'AM33XX' in hardware :
128
+ linux_id = AM33XX
129
+ elif 'sun8i' in hardware :
130
+ linux_id = SUN8I
131
+ elif 'ODROIDC' in hardware :
132
+ linux_id = S805
133
+ elif 'ODROID-C2' in hardware :
134
+ linux_id = S905
135
+ elif 'ODROID-N2' in hardware :
136
+ linux_id = S922X
137
+ elif 'SAMA5' in hardware :
138
+ linux_id = SAMA5
139
+ else :
140
+ if isinstance (hardware , str ):
141
+ if hardware in BCM_RANGE :
142
+ linux_id = BCM2XXX
143
+ elif isinstance (hardware , list ):
144
+ if set (hardware ) & BCM_RANGE :
145
+ linux_id = BCM2XXX
129
146
130
147
return linux_id
131
148
0 commit comments