From 2a40e8535663f71ee685e58983b67717edee11ca Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 4 Dec 2022 15:01:59 +1100 Subject: [PATCH] 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 --- .../hwdef/scripts/chibios_hwdef.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index 98c0d5383b..f3acfb703b 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -785,6 +785,20 @@ def get_flash_page_offset_kb(sector): offset += pages[i] 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(): '''get STORAGE_FLASH_PAGE either from this hwdef or from hwdef.dat in the same directory if this is a bootloader @@ -796,7 +810,7 @@ def get_storage_flash_page(): hwdefdat = args.hwdef[0].replace("-bl", "") if os.path.exists(hwdefdat): ret = None - lines = open(hwdefdat,'r').readlines() + lines = load_file_with_include(hwdefdat) for line in lines: result = re.match(r'STORAGE_FLASH_PAGE\s*([0-9]+)', line) if result: