From e78341079228b135bee65deb8e0d4e2b4385cf94 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 6 Apr 2025 17:27:49 +0200 Subject: tools: Add directory and move scripts here This allows to re-use these scripts. Since they are currently used to build Zephyr builds and three are intended (application, bootloader and application as native_sim build) this makes sense. --- tools/configure_zephyr.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 tools/configure_zephyr.py (limited to 'tools/configure_zephyr.py') diff --git a/tools/configure_zephyr.py b/tools/configure_zephyr.py new file mode 100755 index 0000000..fa1fc5d --- /dev/null +++ b/tools/configure_zephyr.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + + +# This Source Code Form is subject to the terms of the Mozilla Public License, +# v. 2.0. If a copy of the MPL was not distributed with this file, You can +# obtain one at https://mozilla.org/MPL/2.0/. + + +import subprocess +import sys + + +source_tree = sys.argv[1] +build_tree = sys.argv[2] +board = sys.argv[3] +zephyr_base = sys.argv[4] +zephyr_modules = sys.argv[5] +extra_conf_file = sys.argv[6] +signing_key_file = sys.argv[7] + + +subprocess.run( + [ + "cmake", + f"-S{source_tree}", + f"-B{build_tree}", + f"-DBOARD={board}", + f"-DZEPHYR_BASE={zephyr_base}", + f"-DZEPHYR_MODULES={zephyr_modules}", + f"-DEXTRA_CONF_FILE={extra_conf_file}", + f"-DCONFIG_BOOT_SIGNATURE_KEY_FILE=\"{signing_key_file}\"" + ], + shell=False, + check=True, +) -- cgit v1.2.3-70-g09d2 From 867755129e5c50f4e35bc34d5818c2397f3f09db Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 6 Apr 2025 17:59:06 +0200 Subject: tools: Use argparse for build scripts This makes them re-usable for the application and native_sim firmwares. --- fw/btl/meson.build | 17 +++++++------- tools/build_zephyr.py | 47 +++++++++++++++++++++++-------------- tools/configure_zephyr.py | 59 ++++++++++++++++++++++++++++++----------------- 3 files changed, 77 insertions(+), 46 deletions(-) (limited to 'tools/configure_zephyr.py') diff --git a/fw/btl/meson.build b/fw/btl/meson.build index cedd11d..b64fd40 100644 --- a/fw/btl/meson.build +++ b/fw/btl/meson.build @@ -3,13 +3,13 @@ external_project = import('unstable-external_project') external_project.add_project( configure_zephyr, configure_options: [ - bootloader_firmware, - meson.current_build_dir() / 'build', - board, - zephyr, - ';'.join(zephyr_modules), - meson.current_source_dir() / 'bootloader.conf', - signing_key, + '--source-tree', bootloader_firmware, + '--build-tree', meson.current_build_dir() / 'build', + '--board', board, + '--zephyr-base', zephyr, + '--zephyr-modules', ';'.join(zephyr_modules), + '--extra-config', meson.current_source_dir() / 'bootloader.conf', + '--signing-key', signing_key, ], verbose: true, ) @@ -18,7 +18,8 @@ bootloader = custom_target('bootloader', output: ['bootloader.bin'], command: [ build_zephyr, - meson.current_build_dir() / 'build', + '--build-tree', meson.current_build_dir() / 'build', + '--target-name', 'bootloader.bin', ], build_by_default: true, install: true, diff --git a/tools/build_zephyr.py b/tools/build_zephyr.py index c99727e..e201bac 100755 --- a/tools/build_zephyr.py +++ b/tools/build_zephyr.py @@ -6,29 +6,42 @@ # obtain one at https://mozilla.org/MPL/2.0/. +import argparse import multiprocessing import shutil import subprocess -import sys import pathlib -build_tree = pathlib.Path(sys.argv[1]) -output_dir = build_tree.parent +def main() -> None: + parser = argparse.ArgumentParser( + description="Build a Zephyr GNU Make build", + ) + parser.add_argument("-B", "--build-tree", required=True) + parser.add_argument("-n", "--target-name", required=True) -subprocess.run( - [ - "make", - f"-j{multiprocessing.cpu_count()}", - "-C", - f"{str(build_tree)}", - ], - shell=False, - check=True, -) + args = parser.parse_args() -shutil.copy( - build_tree / "zephyr" / "zephyr.bin", - output_dir / "bootloader.bin" -) + build_tree = pathlib.Path(args.build_tree) + output_dir = build_tree.parent + + subprocess.run( + [ + "make", + f"-j{multiprocessing.cpu_count()}", + "-C", + f"{str(build_tree)}", + ], + shell=False, + check=True, + ) + + shutil.copy( + build_tree / "zephyr" / "zephyr.bin", + output_dir / args.target_name + ) + + +if __name__ == "__main__": + main() diff --git a/tools/configure_zephyr.py b/tools/configure_zephyr.py index fa1fc5d..e709063 100755 --- a/tools/configure_zephyr.py +++ b/tools/configure_zephyr.py @@ -6,30 +6,47 @@ # obtain one at https://mozilla.org/MPL/2.0/. +import argparse import subprocess -import sys -source_tree = sys.argv[1] -build_tree = sys.argv[2] -board = sys.argv[3] -zephyr_base = sys.argv[4] -zephyr_modules = sys.argv[5] -extra_conf_file = sys.argv[6] -signing_key_file = sys.argv[7] +def main() -> None: + parser = argparse.ArgumentParser( + description="Configure a Zephyr CMake build", + ) + parser.add_argument("-S", "--source-tree", required=True) + parser.add_argument("-B", "--build-tree", required=True) + parser.add_argument("-b", "--board", required=True) + parser.add_argument("-z", "--zephyr-base", required=True) + parser.add_argument("-m", "--zephyr-modules", required=False) + parser.add_argument("-c", "--extra-config", required=False) + parser.add_argument("-k", "--signing-key", required=False) + parser.add_argument("--prefix", required=False) + parser.add_argument("--libdir", required=False) + parser.add_argument("--bindir", required=False) -subprocess.run( - [ + args = parser.parse_args() + + command = [ "cmake", - f"-S{source_tree}", - f"-B{build_tree}", - f"-DBOARD={board}", - f"-DZEPHYR_BASE={zephyr_base}", - f"-DZEPHYR_MODULES={zephyr_modules}", - f"-DEXTRA_CONF_FILE={extra_conf_file}", - f"-DCONFIG_BOOT_SIGNATURE_KEY_FILE=\"{signing_key_file}\"" - ], - shell=False, - check=True, -) + f"-S{args.source_tree}", + f"-B{args.build_tree}", + f"-DBOARD={args.board}", + f"-DZEPHYR_BASE={args.zephyr_base}", + ] + + if args.zephyr_modules is not None: + command.append(f"-DZEPHYR_MODULES={args.zephyr_modules}") + + if args.extra_config is not None: + command.append(f"-DEXTRA_CONF_FILE={args.extra_config}") + + if args.signing_key is not None: + command.append(f"-DCONFIG_BOOT_SIGNATURE_KEY_FILE=\"{args.signing_key}\"") + + subprocess.run(command, shell=False, check=True) + + +if __name__ == "__main__": + main() -- cgit v1.2.3-70-g09d2