Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/board_list.py
9417 views
1
#!/usr/bin/env python3
2
3
import os
4
import re
5
import fnmatch
6
from collections.abc import Collection
7
8
'''
9
list of boards for build_binaries.py and custom build server
10
11
AP_FLAKE8_CLEAN
12
'''
13
14
15
class Board(object):
16
def __init__(self, name):
17
self.name = name
18
self.is_ap_periph = False
19
self.toolchain = 'arm-none-eabi' # FIXME: try to remove this?
20
self.hal = None # filled in below
21
self.autobuild_targets = [
22
'Tracker',
23
'Blimp',
24
'Copter',
25
'Heli',
26
'Plane',
27
'Rover',
28
'Sub',
29
]
30
31
32
def in_boardlist(boards : Collection[str], board : str) -> bool:
33
'''return true if board is in a collection of wildcard patterns'''
34
for pattern in boards:
35
if fnmatch.fnmatch(board, pattern):
36
return True
37
return False
38
39
40
class BoardList(object):
41
42
def set_hwdef_dir(self):
43
# work out wheer the hwdef files exist. This file
44
# (board_list.py) is copied into place on the autotest server,
45
# so it isn't always in the same relative position to the
46
# hwdef directories!
47
found = False
48
for relpath_bit in [
49
os.path.join("..", "..", "libraries"),
50
'libraries',
51
]:
52
probe = os.path.join(
53
os.path.dirname(os.path.realpath(__file__)),
54
relpath_bit, "AP_HAL_ChibiOS", "hwdef"
55
)
56
if os.path.exists(probe):
57
found = True
58
break
59
60
if not found:
61
raise ValueError("Did not find hwdef_dir")
62
63
realpath = os.path.join(
64
os.path.dirname(os.path.realpath(__file__)),
65
relpath_bit
66
)
67
68
self.hwdef_dir = []
69
for haldir in 'AP_HAL_ChibiOS', 'AP_HAL_Linux', 'AP_HAL_ESP32', 'AP_HAL_SITL':
70
self.hwdef_dir.append(os.path.join(realpath, haldir, "hwdef"))
71
72
def __init__(self):
73
self.set_hwdef_dir()
74
75
self.boards = []
76
77
for hwdef_dir in self.hwdef_dir:
78
self.add_hwdefs_from_hwdef_dir(hwdef_dir)
79
80
def add_hwdefs_from_hwdef_dir(self, hwdef_dir):
81
for adir in os.listdir(hwdef_dir):
82
if adir is None:
83
continue
84
if not os.path.isdir(os.path.join(hwdef_dir, adir)):
85
continue
86
if adir in ["scripts", "common", "STM32CubeConf"]:
87
continue
88
filepath = os.path.join(hwdef_dir, adir, "hwdef.dat")
89
if not os.path.exists(filepath):
90
continue
91
filepath = os.path.join(hwdef_dir, adir, "hwdef.dat")
92
93
# FIXME: we really should be using hwdef.py to parse
94
# these, but it's too slow. We use board_list in some
95
# places we can't afford to be slow.
96
text = self.read_hwdef(filepath)
97
98
board = Board(adir)
99
self.boards.append(board)
100
board_toolchain_set = False
101
for line in text:
102
if re.match(r"^\s*env AP_PERIPH 1", line):
103
board.is_ap_periph = 1
104
if re.match(r"^\s*env AP_PERIPH_HEAVY 1", line):
105
board.is_ap_periph = 1
106
107
# a hwdef can specify which vehicles this target is valid for:
108
match = re.match(r"AUTOBUILD_TARGETS\s*(.*)", line)
109
if match is not None:
110
mname = match.group(1)
111
if mname.lower() == 'none':
112
board.autobuild_targets = []
113
else:
114
board.autobuild_targets = [
115
x.rstrip().lstrip().lower() for x in mname.split(",")
116
]
117
118
m = re.match(r"\s*env\s*TOOLCHAIN\s*([-\w]+)\s*", line)
119
if m is not None:
120
board.toolchain = m.group(1)
121
board_toolchain_set = True
122
if board.toolchain == 'native':
123
board.toolchain = None
124
125
# toolchain not in hwdef; make up some defaults:
126
if not board_toolchain_set:
127
if "Linux" in hwdef_dir:
128
board.toolchain = 'arm-linux-gnueabihf'
129
elif "ChibiOS" in hwdef_dir:
130
board.toolchain = 'arm-none-eabi'
131
elif "ESP32" in hwdef_dir:
132
board.toolchain = 'xtensa-esp32-elf'
133
elif "SITL" in hwdef_dir:
134
board.toolchain = 'native'
135
else:
136
raise ValueError(f"Unable to determine toolchain for {hwdef_dir}")
137
138
if "Linux" in hwdef_dir:
139
board.hal = "Linux"
140
elif "ChibiOS" in hwdef_dir:
141
board.hal = "ChibiOS"
142
elif "ESP32" in hwdef_dir:
143
board.hal = "ESP32"
144
elif "SITL" in hwdef_dir:
145
board.hal = "SITL"
146
else:
147
raise ValueError(f"Unable to determine HAL for {hwdef_dir}")
148
149
def read_hwdef(self, filepath):
150
fh = open(filepath)
151
ret = []
152
text = fh.readlines()
153
for line in text:
154
m = re.match(r"^\s*include\s+(.+)\s*$", line)
155
if m is not None:
156
ret += self.read_hwdef(os.path.join(os.path.dirname(filepath), m.group(1)))
157
else:
158
ret += [line]
159
return ret
160
161
def find_autobuild_boards(self, build_target=None, skip : Collection[str] = None):
162
ret = []
163
for board in self.boards:
164
if board.is_ap_periph:
165
continue
166
ret.append(board.name)
167
168
# these were missing in the original list for unknown reasons.
169
# Omitting them for backwards-compatability here - but we
170
# should probably have a line in the hwdef indicating they
171
# shouldn't be auto-built...
172
if skip is None:
173
skip = [
174
# IOMCU:
175
"iomcu",
176
'iomcu_f103_8MHz',
177
178
# bdshot
179
"fmuv3-bdshot",
180
181
# renamed to KakuteH7Mini-Nand
182
"KakuteH7Miniv2",
183
184
# renamed to AtomRCF405NAVI
185
"AtomRCF405"
186
187
# other
188
"crazyflie2",
189
"CubeOrange-joey",
190
"luminousbee4",
191
"MazzyStarDrone",
192
"omnibusf4pro-one",
193
"skyviper-f412-rev1",
194
"SkystarsH7HD",
195
"*-ODID",
196
"*-ODID-heli",
197
]
198
199
ret = filter(lambda x : not in_boardlist(skip, x), ret)
200
201
# if the caller has supplied a vehicle to limit to then we do that here:
202
if build_target is not None:
203
# Slow down: n^2 algorithm ahead
204
newret = []
205
for x in ret:
206
for b in self.boards:
207
if b.name.lower() != x.lower():
208
continue
209
if build_target.lower() not in [y.lower() for y in b.autobuild_targets]:
210
continue
211
newret.append(x)
212
ret = newret
213
214
return sorted(list(ret))
215
216
def find_ap_periph_boards(self, skip : Collection[str] = None):
217
if skip is None:
218
skip = [
219
"CubeOrange-periph-heavy",
220
"f103-HWESC",
221
"f103-Trigger",
222
"G4-ESC",
223
]
224
ret = []
225
for x in self.boards:
226
if not x.is_ap_periph:
227
continue
228
if in_boardlist(skip, x.name):
229
continue
230
ret.append(x.name)
231
return sorted(list(ret))
232
233
234
AUTOBUILD_BOARDS = BoardList().find_autobuild_boards()
235
AP_PERIPH_BOARDS = BoardList().find_ap_periph_boards()
236
237
if __name__ == '__main__':
238
import argparse
239
parser = argparse.ArgumentParser(description='list boards to build')
240
241
parser.add_argument('target')
242
parser.add_argument('--per-line', action='store_true', default=False, help='list one per line for use with xargs')
243
args = parser.parse_args()
244
board_list = BoardList()
245
target = args.target
246
if target == "AP_Periph":
247
blist = board_list.find_ap_periph_boards()
248
else:
249
blist = board_list.find_autobuild_boards(target)
250
blist = sorted(blist)
251
if args.per_line:
252
for b in blist:
253
print(b)
254
else:
255
print(blist)
256
257