From 63024baa126684fc18def098b1f74fc448786b25 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 15 Dec 2023 16:34:00 +0100 Subject: [PATCH] llext: add support for signing additional binaries This allows the use of "west sign" command for signing of additional binaries with rimage, specifically this is used to sign llext extensions for SOF. Example: west sign -d build-mtl -t rimage -p build-rimage/rimage -- \ -k key.pem -c modules/audio/sof/src/samples/audio/smart_amp_test.toml \ -r build-mtl/zephyr/smart_amp_llext/libsmart_amp_test_out.so Signed-off-by: Guennadi Liakhovetski --- scripts/west_commands/sign.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/west_commands/sign.py b/scripts/west_commands/sign.py index 8d961004adb057..702913f669ebba 100644 --- a/scripts/west_commands/sign.py +++ b/scripts/west_commands/sign.py @@ -440,6 +440,7 @@ def preprocess_toml(self, config_dir, toml_basename, subdir): compiler_path = self.cmake_cache.get("CMAKE_C_COMPILER") preproc_cmd = [compiler_path, '-P', '-E', str(config_dir / (toml_basename + '.h'))] preproc_cmd += ['-I', str(self.sof_src_dir / 'src')] + preproc_cmd += ['-I', str(self.sof_src_dir)] preproc_cmd += ['-imacros', str(pathlib.Path('zephyr') / 'include' / 'generated' / 'autoconf.h')] preproc_cmd += ['-o', str(subdir / toml_basename)] @@ -467,7 +468,14 @@ def sign(self, command, build_dir, build_conf, formats): else: log.die(msg) - kernel_name = build_conf.get('CONFIG_KERNEL_BIN_NAME', 'zephyr') + sign_config_extra_args = config_get_words(command.config, 'rimage.extra-args', []) + + is_llext = '-r' in sign_config_extra_args + args.tool_args + + if is_llext: + kernel_name = 'llext' + else: + kernel_name = build_conf.get('CONFIG_KERNEL_BIN_NAME', 'zephyr') # TODO: make this a new sign.py --bootloader option. if target in ('imx8', 'imx8m', 'imx8ulp'): @@ -552,10 +560,11 @@ def sign(self, command, build_dir, build_conf, formats): if not args.quiet and args.verbose: sign_base += ['-v'] * args.verbose - components = [ ] if bootloader is None else [ bootloader ] - components += [ kernel ] - - sign_config_extra_args = config_get_words(command.config, 'rimage.extra-args', []) + components = [ ] + if not is_llext: + if bootloader is not None: + components += [ bootloader ] + components += [ kernel ] if '-k' not in sign_config_extra_args + args.tool_args: # rimage requires a key argument even when it does not sign @@ -567,7 +576,10 @@ def sign(self, command, build_dir, build_conf, formats): if '-c' not in sign_config_extra_args + args.tool_args: conf_dir = self.rimage_config_dir() - toml_basename = target + '.toml' + if is_llext: + toml_basename = 'llext.toml' + else: + toml_basename = target + '.toml' if ((conf_dir / toml_basename).exists() and (conf_dir / (toml_basename + '.h')).exists()): command.die(f"Cannot have both {toml_basename + '.h'} and {toml_basename} in {conf_dir}")