Skip to content

Commit

Permalink
west: sign.py: generate platf.toml from platf.toml.h with cc -E
Browse files Browse the repository at this point in the history
Allow using the C pre-processor to generate a
`rimage/config/platform.toml` file from a "source"
`rimage/config/platform.toml.h` file.

This is optional and fully backwards compatible.

To use, do not use `-c` and point west sign at a configuration directory
instead or let it use the default `rimage/config/` directory and change
the files there.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
  • Loading branch information
marc-hb authored and carlescufi committed Dec 15, 2023
1 parent a65b8d4 commit 1533604
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion scripts/west_commands/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,18 @@ def rimage_config_dir(self):
self.command.dbg(f'rimage config directory={conf_dir}')
return conf_dir

def preprocess_toml(self, config_dir, toml_basename, subdir):
'Runs the C pre-processor on config_dir/toml_basename.h'

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 += ['-imacros',
str(pathlib.Path('zephyr') / 'include' / 'generated' / 'autoconf.h')]
preproc_cmd += ['-o', str(subdir / toml_basename)]
self.command.inf(quote_sh_list(preproc_cmd))
subprocess.run(preproc_cmd, check=True, cwd=self.build_dir)

def sign(self, command, build_dir, build_conf, formats):
self.command = command
args = command.args
Expand Down Expand Up @@ -555,7 +567,19 @@ 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()
extra_ri_args += ['-c', str(conf_dir / (target + '.toml'))]
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}")

if (conf_dir / (toml_basename + '.h')).exists():
toml_subdir = pathlib.Path('zephyr') / 'misc' / 'generated'
self.preprocess_toml(conf_dir, toml_basename, toml_subdir)
toml_dir = b / toml_subdir
else:
toml_dir = conf_dir

extra_ri_args += ['-c', str(toml_dir / toml_basename)]

# Warning: while not officially supported (yet?), the rimage --option that is last
# on the command line currently wins in case of duplicate options. So pay
Expand Down

0 comments on commit 1533604

Please sign in to comment.