From 0ea9bc3442b7142a5b7ecdb176ac733b57332981 Mon Sep 17 00:00:00 2001 From: James O'Shannessy <12959316+joshanne@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:04:50 +1000 Subject: [PATCH 1/3] hwdef: Parse parameters and detect defined defaults correctly --- .../AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index 935db8536f8bb..2dcb411e85d45 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -2891,12 +2891,14 @@ def get_processed_defaults_file(self, defaults_filepath, depth=0): def write_processed_defaults_file(self, filepath): # see if board has a defaults.parm file or a --default-parameters file was specified defaults_filename = os.path.join(os.path.dirname(self.hwdef[0]), 'defaults.parm') - defaults_path = os.path.join(os.path.dirname(self.hwdef[0]), args.params) - defaults_abspath = None - if os.path.exists(defaults_path): - defaults_abspath = os.path.abspath(self.default_params_filepath) - self.progress("Default parameters path from command line: %s" % self.default_params_filepath) + if isinstance(self.default_params_filepath, str): + defaults_path = os.path.join(os.path.dirname(self.hwdef[0]), self.default_params_filepath) + if not os.path.exists(defaults_path): + self.error(f"Specified defaults file not found at path {defaults_path}") + + defaults_abspath = os.path.abspath(defaults_path) + self.progress("Default parameters path from command line: %s" % defaults_path) elif os.path.exists(defaults_filename): defaults_abspath = os.path.abspath(defaults_filename) self.progress("Default parameters path from hwdef: %s" % defaults_filename) From b5a19838f9fd302c6f4fdd6b58e8676a0a1652ff Mon Sep 17 00:00:00 2001 From: James O'Shannessy <12959316+joshanne@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:05:33 +1000 Subject: [PATCH 2/3] Tools: call the chibios hwdef generator rather than subcall it --- Tools/ardupilotwaf/chibios.py | 47 +++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Tools/ardupilotwaf/chibios.py b/Tools/ardupilotwaf/chibios.py index 785bce15bcee5..ea0ebab4477e0 100644 --- a/Tools/ardupilotwaf/chibios.py +++ b/Tools/ardupilotwaf/chibios.py @@ -16,6 +16,10 @@ import base64 import subprocess +# modify our search path: +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts')) +import chibios_hwdef + _dynamic_env_data = {} def _load_dynamic_env_data(bld): bldnode = bld.bldnode.make_node('modules/ChibiOS') @@ -638,17 +642,27 @@ def generate_hwdef_h(env): print(env.BOOTLOADER_OPTION) env.BOOTLOADER_OPTION += " --signed-fw" print(env.BOOTLOADER_OPTION) - hwdef_script = os.path.join(env.SRCROOT, 'libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py') hwdef_out = env.BUILDROOT if not os.path.exists(hwdef_out): os.mkdir(hwdef_out) - python = sys.executable - cmd = "{0} '{1}' -D '{2}' --params '{3}' '{4}'".format(python, hwdef_script, hwdef_out, env.DEFAULT_PARAMETERS, env.HWDEF) + + # Build a list of the hardware definitions + hwdef_arr = [env.HWDEF] if env.HWDEF_EXTRA: - cmd += " '{0}'".format(env.HWDEF_EXTRA) - if env.BOOTLOADER_OPTION: - cmd += " " + env.BOOTLOADER_OPTION - return subprocess.call(cmd, shell=True) + # Add any extra hwdefs that may be defined + hwdef_arr.append(env.HWDEF_EXTRA) + ch = chibios_hwdef.ChibiOSHWDef(outdir=hwdef_out, + bootloader=env.BOOTLOADER, + signed_fw=env.AP_SIGNED_FIRMWARE, + default_params_filepath=env.DEFAULT_PARAMETERS, + hwdef=hwdef_arr) + try: + ch.run() + # Return success for subprocess call + return 0 + except SystemExit: + # The run failed, so return the error code + return 1 def pre_build(bld): '''pre-build hook to change dynamic sources''' @@ -668,21 +682,18 @@ def pre_build(bld): def build(bld): - - hwdef_rule="%s '%s/hwdef/scripts/chibios_hwdef.py' -D '%s' --params '%s' '%s'" % ( - bld.env.get_flat('PYTHON'), - bld.env.AP_HAL_ROOT, - bld.env.BUILDROOT, - bld.env.default_parameters, - bld.env.HWDEF) + hwdef_arr = [bld.env.HWDEF] if bld.env.HWDEF_EXTRA: - hwdef_rule += " " + bld.env.HWDEF_EXTRA - if bld.env.BOOTLOADER_OPTION: - hwdef_rule += " " + bld.env.BOOTLOADER_OPTION + hwdef_arr.append(bld.env.HWDEF_EXTRA) + ch = chibios_hwdef.ChibiOSHWDef(outdir=bld.env.BUILDROOT, + bootloader=bld.env.BOOTLOADER, + signed_fw=bld.env.AP_SIGNED_FIRMWARE, + default_params_filepath=bld.env.DEFAULT_PARAMETERS, + hwdef=hwdef_arr) bld( # build hwdef.h from hwdef.dat. This is needed after a waf clean source=bld.path.ant_glob(bld.env.HWDEF), - rule=hwdef_rule, + rule=ch.run, group='dynamic_sources', target=[bld.bldnode.find_or_declare('hwdef.h'), bld.bldnode.find_or_declare('ldscript.ld'), From b002b6b06cbcced00fb8df8ba0c4f7c0886fe193 Mon Sep 17 00:00:00 2001 From: James O'Shannessy <12959316+joshanne@users.noreply.github.com> Date: Wed, 4 Sep 2024 07:17:30 +1000 Subject: [PATCH 3/3] wscript: Fix AP_SIGNED_FIRMWARE only defined as bool if flag is provided If is not provided at build time, then AP_SIGNED_FIRMWARE results in empty list. If is provided at build time, then AP_SIGNED_FIRMWARE results in . --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index f400c74cdb7ee..18ef844f6d8a2 100644 --- a/wscript +++ b/wscript @@ -491,8 +491,8 @@ def configure(cfg): _set_build_context_variant(cfg.env.BOARD) cfg.setenv(cfg.env.BOARD) + cfg.env.AP_SIGNED_FIRMWARE = cfg.options.signed_fw if cfg.options.signed_fw: - cfg.env.AP_SIGNED_FIRMWARE = True cfg.options.enable_check_firmware = True cfg.env.BOARD = cfg.options.board