HAL_ChibiOS: fixed a bug in processing STORAGE_FLASH_PAGE

when we look in hwdef.dat for STORAGE_FLASH_PAGE we need to recurse
into includes, or we may miss it
This commit is contained in:
Andrew Tridgell 2022-12-04 15:01:59 +11:00 committed by Randy Mackay
parent 341b0632af
commit 2a40e85356
1 changed files with 15 additions and 1 deletions

View File

@ -785,6 +785,20 @@ def get_flash_page_offset_kb(sector):
offset += pages[i] offset += pages[i]
return offset return offset
def load_file_with_include(fname):
'''load a file as an array of lines, processing any include lines'''
lines = open(fname,'r').readlines()
ret = []
for line in lines:
if line.startswith("include"):
a = shlex.split(line)
if len(a) > 1 and a[0] == "include":
fname2 = os.path.relpath(os.path.join(os.path.dirname(fname), a[1]))
ret.extend(load_file_with_include(fname2))
continue
ret.append(line)
return ret
def get_storage_flash_page(): def get_storage_flash_page():
'''get STORAGE_FLASH_PAGE either from this hwdef or from hwdef.dat '''get STORAGE_FLASH_PAGE either from this hwdef or from hwdef.dat
in the same directory if this is a bootloader in the same directory if this is a bootloader
@ -796,7 +810,7 @@ def get_storage_flash_page():
hwdefdat = args.hwdef[0].replace("-bl", "") hwdefdat = args.hwdef[0].replace("-bl", "")
if os.path.exists(hwdefdat): if os.path.exists(hwdefdat):
ret = None ret = None
lines = open(hwdefdat,'r').readlines() lines = load_file_with_include(hwdefdat)
for line in lines: for line in lines:
result = re.match(r'STORAGE_FLASH_PAGE\s*([0-9]+)', line) result = re.match(r'STORAGE_FLASH_PAGE\s*([0-9]+)', line)
if result: if result: