Skip to content

Commit 78b1b9c

Browse files
committed
west: sign/rimage: use rimage config to find SOF directory
After removal of SOF from manifest, if rimage is in path, the build would fail because the gen-uuid-reg.py cannot be found anymore. To fix this, use the rimage config path to find the SOF directory since the rimage config path is a directory under SOF. This would allow rimage to again sign images to run on hardware. Signed-off-by: Daniel Leung <[email protected]>
1 parent d14a547 commit 78b1b9c

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

scripts/west_commands/sign.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ def rimage_config_dir(self):
438438
def generate_uuid_registry(self):
439439
'Runs the uuid-registry.h generator script'
440440

441-
generate_cmd = [sys.executable, str(self.sof_src_dir / 'scripts' / 'gen-uuid-reg.py'),
441+
uuid_script_path = self.sof_src_dir / 'scripts' / 'gen-uuid-reg.py'
442+
if not uuid_script_path.exists():
443+
self.command.die(f"{uuid_script_path} does not exists.")
444+
445+
generate_cmd = [sys.executable, str(uuid_script_path),
442446
str(self.sof_src_dir / 'uuid-registry.txt'),
443447
str(pathlib.Path('zephyr') / 'include' / 'generated' / 'uuid-registry.h')
444448
]
@@ -554,13 +558,46 @@ def sign(self, command, build_dir, build_conf, formats):
554558
if not args.quiet:
555559
command.inf('Signing with tool {}'.format(tool_path))
556560

557-
try:
558-
sof_proj = command.manifest.get_projects(['sof'], allow_paths=False)
559-
sof_src_dir = pathlib.Path(sof_proj[0].abspath)
560-
except ValueError: # sof is the manifest
561-
sof_src_dir = pathlib.Path(manifest.manifest_path()).parent
561+
sof_src_dir = None
562+
563+
# Try to find SOF directory via path to rimage config files
564+
conf_dir = self.cmake_cache.get('RIMAGE_CONFIG_PATH')
565+
if conf_dir:
566+
# Config path is <sof top>/tools/rimage/config/
567+
# So need to go up 3 levels to get SOF directory.
568+
maybe_sof_dir = pathlib.Path(conf_dir).parent.parent.parent
569+
570+
# Make sure this is the actual SOF directory as
571+
# RIMAGE_CONFIG_PATH may point to somewhere else.
572+
versions_json_file = maybe_sof_dir / 'versions.json'
573+
if versions_json_file.exists():
574+
sof_src_dir = maybe_sof_dir
575+
576+
# Try to find SOF if it is included via manifest
577+
if not sof_src_dir:
578+
try:
579+
sof_proj = command.manifest.get_projects(['sof'], allow_paths=False)
580+
sof_src_dir = pathlib.Path(sof_proj[0].abspath)
581+
582+
# Since SOF is pulled in as a project, we assume it is
583+
# the correct one as the manifest has to be modified
584+
# manually.
585+
except ValueError:
586+
pass
587+
588+
# If SOF is the top level manifest via west init
589+
if not sof_src_dir:
590+
maybe_sof_dir = pathlib.Path(manifest.manifest_path()).parent
591+
592+
# Make sure this is the actual SOF directory
593+
# as the top level manifest may not be SOF.
594+
versions_json_file = maybe_sof_dir / 'versions.json'
595+
if versions_json_file.exists():
596+
sof_src_dir = maybe_sof_dir
562597

563598
self.sof_src_dir = sof_src_dir
599+
if not self.sof_src_dir:
600+
command.die("Cannot find SOF directory.")
564601

565602

566603
command.inf('Signing for SOC target ' + target)

0 commit comments

Comments
 (0)