Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions boards/intel/adsp/doc/intel_adsp_generic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,26 @@ Signing Tool
As firmware binary signing is mandatory on Intel products from Skylake onwards,
you will also need to set up the SOF rimage signing tool and key.

.. code-block:: shell

cd zephyrproject
west config manifest.project-filter -- +sof
west update
cd modules/audio/sof/tools/rimage
Clone the SOF repository and follow the instructions in the rimage :file:`README.md`
to build the tool on your system.

Follow the instructions in the rimage :file:`README.md` to build the tool on
your system. You can either copy the executable to a directory in your PATH or
You can either copy the executable to a directory in your PATH or
use ``west config rimage.path /path/to/rimage-build/rimage``; see more details
in the output of ``west sign -h``. Running directly from the build directory
makes you less likely to use an obsolete rimage version by mistake.

Platform-specific configuration files are located in the ``rimage/config/``
subdirectory. For a different configuration directory you can use:
``west config build.cmake-args -- -DRIMAGE_CONFIG_PATH=/path/to/my/rimage/config``.
The west signing script will also need to know the path to the SOF directory.
Depending on whether you need to use twister:

* If you only need to build with ``west build``:

* Platform-specific configuration files are located in the ``rimage/config/``
subdirectory. For a different configuration directory you can use:
``west config build.cmake-args -- -DRIMAGE_CONFIG_PATH=/path/to/my/rimage/config``.

* If you also need to use twister to build and run on hardware:

* Environment variable ``SOF_SRC_DIR`` must be set to point to the SOF directory.


Xtensa Toolchain (Optional)
Expand Down
89 changes: 80 additions & 9 deletions scripts/west_commands/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,75 @@ def edt_flash_params(cmd, flash):

class RimageSigner(Signer):

def check_if_sof_dir(self, maybe_sof_dir):
'''
Check if a pathlib.Path() object is the root of the SOF tree.

Returns a Path object if it is indeed the SOF tree, or None if not.

This checks if the file "versions.json" exists under the path, as
this file contains the SOF versioning information.
'''
versions_json_file = maybe_sof_dir / 'versions.json'
if versions_json_file.exists():
return maybe_sof_dir

return None

def get_sof_src_dir(self):
'''
Find the SOF tree.

Returns a Path object if SOF tree is found, or None if not.
'''
sof_src_dir = None

# Try to find SOF directory via path to rimage config files pointed to
# via CMake cached variable "RIMAGE_CONFIG_PATH" if it exists.
# The config files are inside <sof top>/tools/tools/rimage/config in
# the SOF tree.
conf_dir = self.cmake_cache.get('RIMAGE_CONFIG_PATH')
if conf_dir:
# Config path is <sof top>/tools/rimage/config/
# So need to go up 3 levels to get SOF directory.
maybe_sof_dir = pathlib.Path(conf_dir).parent.parent.parent

# Make sure this is the actual SOF directory as
# RIMAGE_CONFIG_PATH may point to somewhere else.
sof_src_dir = self.check_if_sof_dir(maybe_sof_dir)

# Try to find SOF if it is included via manifest as a project
# under the main manifest (e.g. included via a sub-manifest).
if not sof_src_dir:
try:
sof_proj = self.command.manifest.get_projects(['sof'], allow_paths=False)
sof_src_dir = pathlib.Path(sof_proj[0].abspath)

# Since SOF is pulled in as a project, we assume it is
# the correct one as the manifest has to be modified
# manually.
except ValueError:
pass

# Try to find SOF as SOF is the top level manifest via west init.
if not sof_src_dir:
maybe_sof_dir = pathlib.Path(manifest.manifest_path()).parent

# Make sure this is the actual SOF directory
# as the top level manifest may not be SOF.
sof_src_dir = self.check_if_sof_dir(maybe_sof_dir)

# If the above all failed to find the SOF tree, see if the path is specified
# via environment variable "SOF_SRC_DIR" as last resort.
if not sof_src_dir and os.getenv("SOF_SRC_DIR"):
maybe_sof_dir = pathlib.Path(os.getenv("SOF_SRC_DIR"))

# Make sure this is the actual SOF directory
# as the top level manifest may not be SOF.
sof_src_dir = self.check_if_sof_dir(maybe_sof_dir)

return sof_src_dir

def rimage_config_dir(self):
'Returns the rimage/config/ directory with the highest precedence'
args = self.command.args
Expand All @@ -438,7 +507,11 @@ def rimage_config_dir(self):
def generate_uuid_registry(self):
'Runs the uuid-registry.h generator script'

generate_cmd = [sys.executable, str(self.sof_src_dir / 'scripts' / 'gen-uuid-reg.py'),
uuid_script_path = self.sof_src_dir / 'scripts' / 'gen-uuid-reg.py'
if not uuid_script_path.exists():
self.command.die(f"{uuid_script_path} does not exists.")

generate_cmd = [sys.executable, str(uuid_script_path),
str(self.sof_src_dir / 'uuid-registry.txt'),
str(pathlib.Path('zephyr') / 'include' / 'generated' / 'uuid-registry.h')
]
Expand Down Expand Up @@ -554,13 +627,11 @@ def sign(self, command, build_dir, build_conf, formats):
if not args.quiet:
command.inf('Signing with tool {}'.format(tool_path))

try:
sof_proj = command.manifest.get_projects(['sof'], allow_paths=False)
sof_src_dir = pathlib.Path(sof_proj[0].abspath)
except ValueError: # sof is the manifest
sof_src_dir = pathlib.Path(manifest.manifest_path()).parent

self.sof_src_dir = sof_src_dir
self.sof_src_dir = self.get_sof_src_dir()
if self.sof_src_dir:
command.inf(f"SOF directory: {self.sof_src_dir}")
else:
command.die("Cannot find SOF directory.")


command.inf('Signing for SOC target ' + target)
Expand Down Expand Up @@ -605,7 +676,7 @@ def sign(self, command, build_dir, build_conf, formats):
if '-k' not in sign_config_extra_args + args.tool_args:
# rimage requires a key argument even when it does not sign
cmake_default_key = cache.get('RIMAGE_SIGN_KEY', 'key placeholder from sign.py')
extra_ri_args += [ '-k', str(sof_src_dir / 'keys' / cmake_default_key) ]
extra_ri_args += [ '-k', str(self.sof_src_dir / 'keys' / cmake_default_key) ]

if args.tool_data and '-c' in args.tool_args:
command.wrn('--tool-data ' + args.tool_data + ' ignored! Overridden by: -- -c ... ')
Expand Down
Loading