From 083b3310767ac01fd03427ab79ec64736b9ae753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Wed, 12 Dec 2018 08:59:47 +0100 Subject: [PATCH 1/2] cmake: Migrate to support multi-image building MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate to support multi-image building. Must be applied simultaneously with zephyrproject-rtos/zephyr#13672 See the Zephyr PR for details. Signed-off-by: Sebastian Bøe --- boot/zephyr/CMakeLists.txt | 20 ++++++++++++++++- boot/zephyr/Kconfig | 8 ------- zephyr/CMakeLists.txt | 39 ++++++++++++++++++++++++++++++++ zephyr/Kconfig | 46 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 zephyr/CMakeLists.txt create mode 100644 zephyr/Kconfig diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index 76e26cc84..6b6958280 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -134,7 +134,7 @@ if(CONFIG_MCUBOOT_SERIAL) zephyr_link_libraries_ifdef( CONFIG_TINYCBOR - TINYCBOR + ${IMAGE}TINYCBOR ) zephyr_include_directories_ifdef( @@ -149,6 +149,14 @@ if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "") else() set(KEY_FILE ${MCUBOOT_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}) endif() + + set_property( + GLOBAL + PROPERTY + KEY_FILE + ${KEY_FILE} + ) + set(GENERATED_PUBKEY ${ZEPHYR_BINARY_DIR}/autogen-pubkey.c) add_custom_command( OUTPUT ${GENERATED_PUBKEY} @@ -163,3 +171,13 @@ if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "") ) zephyr_library_sources(${GENERATED_PUBKEY}) endif() + +# TODO: Configurable? +set_property(GLOBAL APPEND PROPERTY + HEX_FILES_TO_MERGE + ${PROJECT_BINARY_DIR}/zephyr/${KERNEL_HEX_NAME} + ) +set_property(GLOBAL APPEND PROPERTY + HEX_FILES_TO_MERGE_TARGET + ${logical_target_for_zephyr_elf} + ) diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig index 4e75cef72..a87a59f2e 100644 --- a/boot/zephyr/Kconfig +++ b/boot/zephyr/Kconfig @@ -60,14 +60,6 @@ config BOOT_SIGNATURE_TYPE_ECDSA_P256 endchoice -config BOOT_SIGNATURE_KEY_FILE - string "PEM key file" - default "" - 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. - config MBEDTLS_CFG_FILE default "mcuboot-mbedtls-cfg.h" diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt new file mode 100644 index 000000000..1cf48f0c0 --- /dev/null +++ b/zephyr/CMakeLists.txt @@ -0,0 +1,39 @@ +if(CONFIG_BOOTLOADER_MCUBOOT) + # Build a second bootloader image + + set(MCUBOOT_BASE ${CMAKE_CURRENT_LIST_DIR}/..) + + zephyr_add_executable(mcuboot require_build) + + if (${require_build}) + 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 ${DT_FLASH_WRITE_BLOCK_SIZE} + --version 0.1 # 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} + ) + endif() # ${require_build} +endif() diff --git a/zephyr/Kconfig b/zephyr/Kconfig new file mode 100644 index 000000000..ae4c50414 --- /dev/null +++ b/zephyr/Kconfig @@ -0,0 +1,46 @@ +if BOOTLOADER_MCUBOOT + +config MCUBOOT_CMAKELISTS_DIR + string "Path to the directory of the MCUBoot CMakeLists.txt file" + default "$MCUBOOT_BASE/boot/zephyr/" + + +choice + prompt "MCUBoot build strategy" + default MCUBOOT_BUILD_STRATEGY_FROM_SOURCE + +config MCUBOOT_BUILD_STRATEGY_USE_HEX_FILE + # Mandatory option when being built through 'zephyr_add_executable' + bool "Use hex file instead of building MCUBoot" + +if MCUBOOT_BUILD_STRATEGY_USE_HEX_FILE + +config MCUBOOT_HEX_FILE + # Mandatory option when being built through 'zephyr_add_executable' + string "MCUBoot hex file" + +endif # MCUBOOT_USE_HEX_FILE + +config MCUBOOT_BUILD_STRATEGY_SKIP_BUILD + # Mandatory option when being built through 'zephyr_add_executable' + bool "Skip building MCUBoot" + +config MCUBOOT_BUILD_STRATEGY_FROM_SOURCE + # Mandatory option when being built through 'zephyr_add_executable' + bool "Build from source" + +endchoice + +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 From 49d5af704a54fd715fcad4fde60c5dad9fff3fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20=C3=98ye=20Amundsen?= Date: Wed, 15 May 2019 11:22:47 +0000 Subject: [PATCH 2/2] Prefix dtc overlay with image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Øye Amundsen --- boot/zephyr/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index 6b6958280..e7f2c51f6 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -13,16 +13,16 @@ set(BOARD qemu_x86) # and fits inside, the boot partition. (If the user specified a # DTC_OVERLAY_FILE on the CMake command line, we need to append onto # the list). -if(DTC_OVERLAY_FILE) - set(DTC_OVERLAY_FILE - "${DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/dts.overlay") +if(${IMAGE}DTC_OVERLAY_FILE) + set(${IMAGE}DTC_OVERLAY_FILE + "${${IMAGE}DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/dts.overlay") else() - set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/dts.overlay) + set(${IMAGE}DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/dts.overlay) endif() if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}.overlay) - set(DTC_OVERLAY_FILE - "${DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}.overlay") + set(${IMAGE}DTC_OVERLAY_FILE + "${${IMAGE}DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}.overlay") endif() # Enable Zephyr runner options which request mass erase if so