xtensa-build-zephyr.py: parse new versions.json instead of generated .h

For rimage parameters, parse new, static versions.json file instead of
generated sof_versions.h file. This will make possible to configure
rimage before west build.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2023-05-03 22:38:43 +00:00 committed by Kai Vehmanen
parent ead25e82a2
commit 494d174b6e
2 changed files with 12 additions and 12 deletions

View File

@ -87,6 +87,7 @@ string(JSON SOF_MICRO ERROR_VARIABLE micro_error
if(NOT "${micro_error}" STREQUAL "NOTFOUND") if(NOT "${micro_error}" STREQUAL "NOTFOUND")
message(STATUS "versions.json: ${micro_error}, defaulting to 0") message(STATUS "versions.json: ${micro_error}, defaulting to 0")
# TODO: default this to .99 on the main, never released branch like zephyr does # TODO: default this to .99 on the main, never released branch like zephyr does
# Keep this default SOF_MICRO the same as the one in xtensa-build-zephyr.py
set(SOF_MICRO 0) set(SOF_MICRO 0)
endif() endif()

View File

@ -35,6 +35,7 @@ import os
import warnings import warnings
import fnmatch import fnmatch
import hashlib import hashlib
import json
import gzip import gzip
import dataclasses import dataclasses
import concurrent.futures as concurrent import concurrent.futures as concurrent
@ -443,11 +444,11 @@ def west_update():
execute_command(["west", "update"], check=True, timeout=3000, cwd=west_top) execute_command(["west", "update"], check=True, timeout=3000, cwd=west_top)
def get_sof_version(abs_build_dir): def get_sof_version():
"""[summary] Get version string major.minor.micro of SOF """[summary] Get version string major.minor.micro of SOF
firmware file. When building multiple platforms from the same SOF firmware file. When building multiple platforms from the same SOF
commit, all platforms share the same version. So for the 1st platform, commit, all platforms share the same version. So for the 1st platform,
generate the version string from sof_version.h and later platforms will extract the version information from sof/versions.json and later platforms will
reuse it. reuse it.
""" """
global sof_fw_version global sof_fw_version
@ -455,15 +456,13 @@ def get_sof_version(abs_build_dir):
return sof_fw_version return sof_fw_version
versions = {} versions = {}
with open(pathlib.Path(abs_build_dir, with open(SOF_TOP / "versions.json") as versions_file:
"zephyr/include/generated/sof_versions.h"), encoding="utf8") as hfile: versions = json.load(versions_file)
for hline in hfile: # Keep this default value the same as the default SOF_MICRO in version.cmake
words = hline.split() sof_micro = versions['SOF'].get('MICRO', "0")
if words[0] == '#define': sof_fw_version = (
versions[words[1]] = words[2] f"{versions['SOF']['MAJOR']}.{versions['SOF']['MINOR']}.{sof_micro}"
sof_fw_version = versions['SOF_MAJOR'] + '.' + versions['SOF_MINOR'] + '.' + \ )
versions['SOF_MICRO']
return sof_fw_version return sof_fw_version
def rmtree_if_exists(directory): def rmtree_if_exists(directory):
@ -671,7 +670,7 @@ def build_platforms():
sign_cmd += ["--tool-data", str(rimage_config), "--", "-k", str(signing_key)] sign_cmd += ["--tool-data", str(rimage_config), "--", "-k", str(signing_key)]
sof_fw_vers = get_sof_version(abs_build_dir) sof_fw_vers = get_sof_version()
sign_cmd += ["-f", sof_fw_vers] sign_cmd += ["-f", sof_fw_vers]