Skip to content
Merged
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
84 changes: 61 additions & 23 deletions scripts/xtensa-build-zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import dataclasses
import concurrent.futures as concurrent

from west import configuration as west_config

# anytree module is defined in Zephyr build requirements
from anytree import AnyNode, RenderTree, render
from packaging import version
Expand Down Expand Up @@ -383,6 +385,8 @@ def west_reinitialize(west_root_dir: pathlib.Path, west_manifest_path: pathlib.P
shutil.rmtree(dot_west_directory)
execute_command(["west", "init", "-l", f"{SOF_TOP}"], cwd=west_top)


# TODO: use west APIs directly instead of all these indirect subprocess.run("west", ...) processes
def west_init_if_needed():
"""[summary] Validates whether west workspace had been initialized and points to SOF manifest.
Peforms west initialization if needed.
Expand Down Expand Up @@ -501,6 +505,53 @@ def clean_staging(platform):
# detailed comments in west.yml
RIMAGE_SOURCE_DIR = west_top / "sof" / "rimage"


def rimage_west_configuration(platform_dict, dest_dir):
"""Configure rimage in a new file `dest_dir/westconfig.ini`, starting
from the workspace .west/config.
Returns the pathlib.Path to the new file.
"""

saved_local_var = os.environ.get('WEST_CONFIG_LOCAL')
workspace_west_config_path = os.environ.get('WEST_CONFIG_LOCAL',
str(west_top / ".west" / "config"))
platform_west_config_path = dest_dir / "westconfig.ini"
dest_dir.mkdir(parents=True, exist_ok=True)
shutil.copyfile(workspace_west_config_path, platform_west_config_path)

# Create `platform_wconfig` object pointing at our copy
os.environ['WEST_CONFIG_LOCAL'] = str(platform_west_config_path)
platform_wconfig = west_config.Configuration()
if saved_local_var is None:
del os.environ['WEST_CONFIG_LOCAL']
else:
os.environ['WEST_CONFIG_LOCAL'] = saved_local_var

# By default, run rimage directly from the rimage build directory
if platform_wconfig.get("rimage.path") is None:
rimage_executable = shutil.which("rimage", path=RIMAGE_BUILD_DIR)
assert pathlib.Path(str(rimage_executable)).exists()
platform_wconfig.set("rimage.path", shlex.quote(rimage_executable),
west_config.ConfigFile.LOCAL)

_ws_args = platform_wconfig.get("rimage.extra-args")
workspace_extra_args = [] if _ws_args is None else shlex.split(_ws_args)

# Flatten default rimage options while giving precedence to the workspace =
# the user input. We could just append and leave duplicates but that would be
# at best confusing and at worst relying on undocumented rimage precedence.
extra_args = []
for default_opt in rimage_options(platform_dict):
if not default_opt[0] in workspace_extra_args:
extra_args += default_opt

extra_args += workspace_extra_args

platform_wconfig.set("rimage.extra-args", shlex.join(extra_args))

return platform_west_config_path


def build_rimage():

# Detect non-west rimage duplicates, example: git submdule
Expand All @@ -526,28 +577,16 @@ def build_rimage():
execute_command(rimage_build_cmd, cwd=west_top)


def rimage_configuration(platform_dict):

sign_cmd = []

rimage_executable = shutil.which("rimage", path=RIMAGE_BUILD_DIR)

sign_cmd += ["--tool-path", rimage_executable, "--"]

# Flatten the list of [ ( "-o", "value" ), ...] tuples
for t in rimage_options(platform_dict):
sign_cmd += t

return sign_cmd


def rimage_options(platform_dict):
"""Return a list of default rimage options as a list of tuples,
example: [ (-f, 2.5.0), (-b, 1), (-k, key.pem),... ]

"""
opts = []

if args.verbose > 0:
opts.append(("-v",) * args.verbose)

signing_key = ""
if args.key:
signing_key = args.key
Expand Down Expand Up @@ -693,13 +732,15 @@ def build_platforms():
see https://docs.zephyrproject.org/latest/guides/west/build-flash-debug.html#one-time-cmake-arguments
Try "west config build.cmake-args -- ..." instead.""")

sign_cmd = ["west"]
sign_cmd += ["-v"] * args.verbose
sign_cmd += ["sign", "--build-dir", platform_build_dir_name, "--tool", "rimage"]
sign_cmd += rimage_configuration(platform_dict)
platf_build_environ['WEST_CONFIG_LOCAL'] = str(rimage_west_configuration(
platform_dict,
STAGING_DIR / "sof-info" / platform
))

# Make sure the build logs don't leave anything hidden
execute_command(['west', 'config', '-l'], cwd=west_top)
execute_command(['west', 'config', '-l'], cwd=west_top,
env=platf_build_environ, sof_log_env=True)
print()

# Build
try:
Expand All @@ -718,9 +759,6 @@ def build_platforms():
# Extract metadata
execute_command([str(smex_executable), "-l", str(fw_ldc_file), str(input_elf_file)])

# Sign firmware
execute_command(sign_cmd, cwd=west_top)

if platform not in RI_INFO_UNSUPPORTED:
reproducible_checksum(platform, west_top / platform_build_dir_name / "zephyr" / "zephyr.ri")

Expand Down
2 changes: 1 addition & 1 deletion zephyr/scripts/clean-expected-release-differences.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fix_dir()
die 'No %s/build-sof-staging directory\n' "$bd"

# config files have absolute paths
find "$bd" -name 'config.gz' -exec rm '{}' \;
find "$bd" \( -name 'config.gz' -o -name 'westconfig.ini' \) -exec rm '{}' \;

# In case of a compression timestamp. Also gives better messages.
find "$bd" -name '*.gz' -print0 | xargs -r -0 gunzip
Expand Down