diff options
author | xengineering <me@xengineering.eu> | 2025-05-24 11:31:11 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2025-05-24 11:31:11 +0200 |
commit | a82bdbbec681cec0c6f5304318b6010f1752dbf6 (patch) | |
tree | 539d4610508c1bb3069c5f11ee63977e534b2a68 /tools | |
parent | f38300b15627e5234f0f0a07c31c32135901dee7 (diff) | |
parent | bf8d20fe4d8d3369dd7f63e95f53613dbbfa3603 (diff) | |
download | iot-contact-a82bdbbec681cec0c6f5304318b6010f1752dbf6.tar iot-contact-a82bdbbec681cec0c6f5304318b6010f1752dbf6.tar.zst iot-contact-a82bdbbec681cec0c6f5304318b6010f1752dbf6.zip |
Merge build system improvements
- remove flash targets (replaced by easy to flash `factory-image.bin`)
- replaced installation step by copy targets
- provide `factory-image.bin` and `update-image.bin`
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/build_zephyr.py | 5 | ||||
-rwxr-xr-x | tools/configure_zephyr.py | 2 | ||||
-rwxr-xr-x | tools/make_factory_image.py | 95 | ||||
-rw-r--r-- | tools/meson.build | 1 |
4 files changed, 98 insertions, 5 deletions
diff --git a/tools/build_zephyr.py b/tools/build_zephyr.py index 1d9e783..5dd9e47 100755 --- a/tools/build_zephyr.py +++ b/tools/build_zephyr.py @@ -38,10 +38,7 @@ def main() -> None: check=True, ) - shutil.copy( - build_tree / "zephyr" / args.binary_name, - output_dir / args.target_name - ) + shutil.copy(build_tree / "zephyr" / args.binary_name, output_dir / args.target_name) if __name__ == "__main__": diff --git a/tools/configure_zephyr.py b/tools/configure_zephyr.py index e709063..f4707c6 100755 --- a/tools/configure_zephyr.py +++ b/tools/configure_zephyr.py @@ -43,7 +43,7 @@ def main() -> 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}\"") + command.append(f'-DCONFIG_BOOT_SIGNATURE_KEY_FILE="{args.signing_key}"') subprocess.run(command, shell=False, check=True) diff --git a/tools/make_factory_image.py b/tools/make_factory_image.py new file mode 100755 index 0000000..735f657 --- /dev/null +++ b/tools/make_factory_image.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 + + +import argparse +import dataclasses +import pathlib + + +PADDING_BYTE: bytes = b"\xff" + + +def main() -> None: + args = Arguments.from_cli() + print(args) + + factory_image: bytes = join( + bootloader=args.bootloader.read_bytes(), + application=args.application.read_bytes(), + offset=args.offset, + ) + + args.factory_image.write_bytes(factory_image) + + +def join(bootloader: bytes, application: bytes, offset: int) -> bytes: + padding = PADDING_BYTE * (offset - len(bootloader)) + + return bootloader + padding + application + + +@dataclasses.dataclass +class Arguments: + bootloader: pathlib.Path + offset: int + application: pathlib.Path + factory_image: pathlib.Path + + def __post_init__(self) -> None: + assert isinstance(self.bootloader, pathlib.Path) + + assert isinstance(self.offset, int) + assert self.offset >= 0 + + assert isinstance(self.application, pathlib.Path) + + assert isinstance(self.factory_image, pathlib.Path) + + def __str__(self) -> str: + return f"""{__file__} \\ + --bootloader {self.bootloader} \\ + --offset 0x{self.offset:X} \\ + --application {self.application} \\ + --factory_image {self.factory_image}""" + + @staticmethod + def from_cli() -> "Arguments": + parser = argparse.ArgumentParser( + description="Join bootloader and application firmware to a factory image" + ) + + parser.add_argument( + "-b", "--bootloader", required=True, help="path to bootloader firmware" + ) + + default_offset = 0x40000 + parser.add_argument( + "-o", + "--offset", + default=default_offset, + help=f"offset in bytes between bootloader and application (default: 0x{default_offset:X})", + ) + + parser.add_argument( + "-a", "--application", required=True, help="path to application firmware" + ) + + parser.add_argument( + "-f", + "--factory-image", + default=pathlib.Path("factory-image.bin"), + help="path to output factory image file", + ) + + args = parser.parse_args() + + return Arguments( + bootloader=pathlib.Path(args.bootloader), + offset=int(args.offset), + application=pathlib.Path(args.application), + factory_image=pathlib.Path(args.factory_image), + ) + + +if __name__ == "__main__": + main() diff --git a/tools/meson.build b/tools/meson.build index 85ddbb3..f58c54b 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -1,2 +1,3 @@ configure_zephyr = meson.current_source_dir() / 'configure_zephyr.py' build_zephyr = meson.current_source_dir() / 'build_zephyr.py' +make_factory_image = meson.current_source_dir() / 'make_factory_image.py' |