Skip to content

Commit 55c2343

Browse files
committed
waf: boards.py: use chibios_hwdef.py to get boards list
1 parent ead48b6 commit 55c2343

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

Tools/ardupilotwaf/boards.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
_board_classes = {}
1313
_board = None
1414

15+
# modify our search path:
16+
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))
17+
import chibios_hwdef
18+
1519
class BoardMeta(type):
1620
def __init__(cls, name, bases, dct):
1721
super(BoardMeta, cls).__init__(name, bases, dct)
@@ -603,19 +607,9 @@ def get_ap_periph_boards():
603607
continue
604608
hwdef = os.path.join(dirname, d, 'hwdef.dat')
605609
if os.path.exists(hwdef):
606-
with open(hwdef, "r") as f:
607-
content = f.read()
608-
if 'AP_PERIPH' in content:
609-
list_ap.append(d)
610-
continue
611-
# process any include lines:
612-
for m in re.finditer(r"^include\s+([^\s]*)", content, re.MULTILINE):
613-
include_path = os.path.join(os.path.dirname(hwdef), m.group(1))
614-
with open(include_path, "r") as g:
615-
content = g.read()
616-
if 'AP_PERIPH' in content:
617-
list_ap.append(d)
618-
break
610+
ch = chibios_hwdef.ChibiOSHWDef(hwdef=[hwdef], quiet=True)
611+
if ch.is_periph_fw():
612+
list_ap.append(d)
619613

620614
list_ap = list(set(list_ap))
621615
return list_ap

libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def __init__(self, quiet=False, bootloader=False, signed_fw=False, outdir=None,
128128
# list of shared up timers
129129
self.shared_up = []
130130

131+
# boolean indicating whether we have read and processed self.hwdef
132+
self.processed_hwdefs = False
133+
131134
def is_int(self, str):
132135
'''check if a string is an integer'''
133136
try:
@@ -3131,7 +3134,33 @@ def add_iomcu_firmware_defaults(self, f):
31313134

31323135
self.add_firmware_defaults_from_file(f, "defaults_iofirmware.h", "IOMCU Firmware")
31333136

3137+
def is_periph_fw_unprocessed_file(self, hwdef):
3138+
'''helper/recursion function for is_periph_fw_unprocessed'''
3139+
with open(hwdef, "r") as f:
3140+
content = f.read()
3141+
if 'AP_PERIPH' in content:
3142+
return True
3143+
# process any include lines:
3144+
for m in re.finditer(r"^include\s+([^\s]*)", content, re.MULTILINE):
3145+
include_path = os.path.join(os.path.dirname(hwdef), m.group(1))
3146+
if self.is_periph_fw_unprocessed_file(include_path):
3147+
return True
3148+
3149+
def is_periph_fw_unprocessed(self):
3150+
'''it takes ~2 seconds to process all hwdefs. This is a shortcut to
3151+
make things much faster in the cvase we are filtering boads to
3152+
just peripherals. Note that this parsing is very coarse -
3153+
AP_PERIPH could be in a comment, for example, and this method
3154+
will still return True. Also can't "undef" AP_PERIPH.
3155+
'''
3156+
for hwdef in self.hwdef:
3157+
if self.is_periph_fw_unprocessed_file(hwdef):
3158+
return True
3159+
return False
3160+
31343161
def is_periph_fw(self):
3162+
if not self.processed_hwdefs:
3163+
return self.is_periph_fw_unprocessed()
31353164
return int(self.env_vars.get('AP_PERIPH', 0)) != 0
31363165

31373166
def is_normal_fw(self):
@@ -3178,11 +3207,14 @@ def write_default_parameters(self):
31783207

31793208
self.romfs_add('defaults.parm', filepath)
31803209

3181-
def run(self):
3182-
3183-
# process input file
3210+
def process_hwdefs(self):
31843211
for fname in self.hwdef:
31853212
self.process_file(fname)
3213+
self.processed_hwdefs = True
3214+
3215+
def run(self):
3216+
# process input file
3217+
self.process_hwdefs()
31863218

31873219
if "MCU" not in self.config:
31883220
self.error("Missing MCU type in config")

0 commit comments

Comments
 (0)