@@ -128,6 +128,9 @@ def __init__(self, quiet=False, bootloader=False, signed_fw=False, outdir=None,
128
128
# list of shared up timers
129
129
self .shared_up = []
130
130
131
+ # boolean indicating whether we have read and processed self.hwdef
132
+ self .processed_hwdefs = False
133
+
131
134
def is_int (self , str ):
132
135
'''check if a string is an integer'''
133
136
try :
@@ -3131,7 +3134,33 @@ def add_iomcu_firmware_defaults(self, f):
3131
3134
3132
3135
self .add_firmware_defaults_from_file (f , "defaults_iofirmware.h" , "IOMCU Firmware" )
3133
3136
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
+
3134
3161
def is_periph_fw (self ):
3162
+ if not self .processed_hwdefs :
3163
+ return self .is_periph_fw_unprocessed ()
3135
3164
return int (self .env_vars .get ('AP_PERIPH' , 0 )) != 0
3136
3165
3137
3166
def is_normal_fw (self ):
@@ -3178,11 +3207,14 @@ def write_default_parameters(self):
3178
3207
3179
3208
self .romfs_add ('defaults.parm' , filepath )
3180
3209
3181
- def run (self ):
3182
-
3183
- # process input file
3210
+ def process_hwdefs (self ):
3184
3211
for fname in self .hwdef :
3185
3212
self .process_file (fname )
3213
+ self .processed_hwdefs = True
3214
+
3215
+ def run (self ):
3216
+ # process input file
3217
+ self .process_hwdefs ()
3186
3218
3187
3219
if "MCU" not in self .config :
3188
3220
self .error ("Missing MCU type in config" )
0 commit comments