diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a0cadd57fd4f5..4d688a463fb19d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1339,6 +1339,7 @@ list(APPEND ${extra_post_build_commands} ) + add_custom_command( TARGET ${logical_target_for_zephyr_elf} POST_BUILD diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index 3696f5adf50163..d84319f3af8a32 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory_ifdef(CONFIG_NET_BUF net) add_subdirectory_ifdef(CONFIG_USB usb) add_subdirectory(random) add_subdirectory(storage) +add_subdirectory(boot) add_subdirectory_ifdef(CONFIG_SETTINGS settings) add_subdirectory(fb) add_subdirectory(power) diff --git a/subsys/Kconfig b/subsys/Kconfig index df133c082ee018..fa2ceec7820074 100644 --- a/subsys/Kconfig +++ b/subsys/Kconfig @@ -23,6 +23,8 @@ source "subsys/mgmt/Kconfig" source "subsys/net/Kconfig" +source "subsys/boot/Kconfig" + source "subsys/shell/Kconfig" source "subsys/usb/Kconfig" diff --git a/subsys/boot/CMakeLists.txt b/subsys/boot/CMakeLists.txt new file mode 100644 index 00000000000000..9e9daec69d4cf7 --- /dev/null +++ b/subsys/boot/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory_ifdef(CONFIG_BOOTLOADER_MCUBOOT mcuboot) diff --git a/subsys/boot/Kconfig b/subsys/boot/Kconfig new file mode 100644 index 00000000000000..a8315068304bd0 --- /dev/null +++ b/subsys/boot/Kconfig @@ -0,0 +1 @@ +rsource "mcuboot/Kconfig" diff --git a/subsys/boot/mcuboot/CMakeLists.txt b/subsys/boot/mcuboot/CMakeLists.txt new file mode 100644 index 00000000000000..38b721810786e8 --- /dev/null +++ b/subsys/boot/mcuboot/CMakeLists.txt @@ -0,0 +1,36 @@ +# Build a second bootloader image + +# TODO: Make configurable like OT until west is supported. +set(MCUBOOT_BASE "${ZEPHYR_BASE}/../mcuboot") +assert_exists(MCUBOOT_BASE) + +zephyr_add_executable(mcuboot) +add_subdirectory("${MCUBOOT_BASE}/boot/zephyr" ${CMAKE_CURRENT_BINARY_DIR}/mcuboot) + +# TODO: Assert that the bootloader and image use the same key. + +set(SIGNED_IMAGE signed.hex) + +set_property(GLOBAL APPEND PROPERTY + extra_post_build_commands + COMMAND + ${PYTHON_EXECUTABLE} + ${MCUBOOT_BASE}/scripts/imgtool.py + sign + --key ${MCUBOOT_BASE}/${CONFIG_BOOT_SIGNATURE_KEY_FILE} + --header-size ${CONFIG_TEXT_SECTION_OFFSET} + --align 8 # TODO: Configurable? + --version 1.0 # TODO: Configurable? + --slot-size 0x32000 # TODO: Configurable? + ${KERNEL_HEX_NAME} # TODO: Enforce that this will be present through Kconfig + ${SIGNED_IMAGE} + ) + +set_property(GLOBAL APPEND PROPERTY + HEX_FILES_TO_MERGE + ${SIGNED_IMAGE} + ) +set_property(GLOBAL APPEND PROPERTY + HEX_FILES_TO_MERGE_TARGET + ${logical_target_for_zephyr_elf} + ) diff --git a/subsys/boot/mcuboot/Kconfig b/subsys/boot/mcuboot/Kconfig new file mode 100644 index 00000000000000..dc0d5842504e4e --- /dev/null +++ b/subsys/boot/mcuboot/Kconfig @@ -0,0 +1,19 @@ +if BOOTLOADER_MCUBOOT + +config MCUBOOT_CMAKELISTS_DIR + string "Path to the directory of the MCUBoot CMakeLists.txt file" + default "$MCUBOOT_BASE/boot/zephyr/" + +endif # BOOTLOADER_MCUBOOT + +if MCUBOOT || BOOTLOADER_MCUBOOT +# TODO: Support sharing Kconfig configuration between images +config BOOT_SIGNATURE_KEY_FILE + string "PEM key file" + default "root-rsa-2048.pem" + help + The key file will be parsed by imgtool's getpub command and a .c source + with the public key information will be written in a format expected by + MCUboot. + +endif # MCUBOOT || BOOTLOADER_MCUBOOT