Skip to content

Commit

Permalink
xtensa-build-zephyr.py: create /lib/firmware tarball
Browse files Browse the repository at this point in the history
With addition of loadable modules, SOF firmware installation depends
much more on symbolic links. Add a step to build script to create a
tarball of the installed firmware binaries in the build-staging-sof
tree. The created tarball (e.g. build-sof-staging/sof/sof.tar.gz)
provides a ready structure that can be unpacked to e.g. /lib/firmware on
Linux target machines.

Signed-off-by: Kai Vehmanen <[email protected]>
  • Loading branch information
kv2019i committed Aug 14, 2024
1 parent 118cf46 commit 8c1b8a2
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion scripts/xtensa-build-zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import gzip
import dataclasses
import concurrent.futures as concurrent
import tarfile

from west import configuration as west_config

Expand Down Expand Up @@ -329,7 +330,12 @@ def parse_args():
│ └── sof-PLAT.ri
└── sof-PLAT.ri\n
""")

tarball_args = parser.add_mutually_exclusive_group()
# argparse.BooleanOptionalAction requires Python 3.9
parser.set_defaults(tarball=True)
tarball_args.add_argument("--no-tarball", dest='tarball', action='store_false')
tarball_args.add_argument("--tarball", dest='tarball', action='store_true',
help="""Create a tar file of the installed firmware files under build-sof-staging.""")
parser.add_argument("--version", required=False, action="store_true",
help="Prints version of this script.")

Expand Down Expand Up @@ -1169,6 +1175,36 @@ def reproducible_checksum(platform, ri_file):
chk256 = sof_ri_info.EraseVariables(ri_file, parsed_ri, west_top / repro_output)
print('sha256sum {0}\n{1} {0}'.format(repro_output, chk256))

def create_tarball():
# vendor directories (typically under /lib/firmware) to include
# in the tarball
vendor_dirs = [ 'intel']

build_top = west_top / 'build-sof-staging' / 'sof'

# Some CI/build usages incrementally call this script to create
# a staging area with multiple targets. Support this mode
# of use by naming the tarball with target name in case only a single
# target is built. In other cases, use a generic tarball name.
if len(args.platforms) == 1:
tarball_name = f'sof-%s.tgz' % args.platforms[0]
else:
tarball_name = 'sof.tgz'

prev_cwd = os.getcwd()
os.chdir(build_top)

tarball_path = build_top / tarball_name
with tarfile.open(tarball_path, 'w:gz') as tarball:
for vendor_dir in vendor_dirs:
vendor_dir_path = build_top / vendor_dir
if not vendor_dir_path.exists():
continue
tarball.add(vendor_dir, recursive=True)
print(f"Tarball %s created" % tarball_path)
tarball.close()

os.chdir(prev_cwd)

def main():
parse_args()
Expand All @@ -1190,6 +1226,8 @@ def main():

build_rimage()
build_platforms()
if args.tarball:
create_tarball()
show_installed_files()

if __name__ == "__main__":
Expand Down

0 comments on commit 8c1b8a2

Please sign in to comment.