forked from nrfconnect/sdk-mcuboot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nrf noup] cmake: multi-image + partition manager
- Upstream PR#430, plus various fixes from the v1.0.0 development cycle. This added support for being built as a sub image from the downstream Nordic patch set for a zephyr multi image build system. - Downstream partition manager support, plus bug fixes from the v1.0.0 dev cycle. Partition Manager is a component which uses yaml files to resolve flash placement with a wholistic view of the device. Over time, these formerly separate downstream patch series grew increasingly intertwined after the initial rejection of the upstream multi-image patch set. This represents the results which roughly appeared in NCS v1.0. Signed-off-by: Håkon Øye Amundsen <[email protected]> Signed-off-by: Øyvind Rønningstad <[email protected]> Signed-off-by: Sebastian Bøe <[email protected]> Signed-off-by: Sigvart Hovland <[email protected]> Signed-off-by: Marti Bolivar <[email protected]> (cherry picked from commit 0e68ab4) (cherry picked from commit 6168414) (cherry picked from commit d62e189) (cherry picked from commit a4db98d) (cherry picked from commit b6d3687) (cherry picked from commit 4b91989) (cherry picked from commit edc8dc6) (cherry picked from commit 289f108) (cherry picked from commit 447495f) (cherry picked from commit 8cb0e49) (cherry picked from commit 4a61a17) (cherry picked from commit 8b0e50c) (cherry picked from commit 545e2c0) Signed-off-by: Martí Bolívar <[email protected]>
- Loading branch information
1 parent
4bcdaad
commit 0fa1f04
Showing
6 changed files
with
239 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <autoconf.h> | ||
|
||
mcuboot: | ||
size: CONFIG_PM_PARTITION_SIZE_MCUBOOT | ||
placement: | ||
before: [mcuboot_primary] | ||
|
||
mcuboot_primary_app: | ||
# All images to be placed in MCUboot's slot 0 should be placed in this | ||
# partition | ||
span: [app] | ||
|
||
mcuboot_primary: | ||
span: [mcuboot_pad, mcuboot_primary_app] | ||
|
||
mcuboot_secondary: | ||
share_size: [mcuboot_primary] | ||
placement: | ||
after: | ||
[mcuboot_primary] | ||
|
||
mcuboot_scratch: | ||
size: CONFIG_PM_PARTITION_SIZE_MCUBOOT_SCRATCH | ||
placement: | ||
after: [app] | ||
|
||
mcuboot_storage: | ||
size: CONFIG_PM_PARTITION_SIZE_MCUBOOT_STORAGE | ||
placement: | ||
after: [mcuboot_scratch] | ||
|
||
# Padding placed before image to boot | ||
mcuboot_pad: | ||
# MCUboot pad must be placed before the 'spm' partition if that is present. | ||
# If 'spm' partition is not present, it must be placed before the 'app'. | ||
size: CONFIG_PM_PARTITION_SIZE_MCUBOOT_PAD | ||
placement: | ||
before: [mcuboot_primary_app] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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_BINARY_DIR}/mcuboot) | ||
endif() # ${require_build} | ||
|
||
set(to_sign_hex ${KERNEL_HEX_NAME}) | ||
|
||
# TODO: Assert that the bootloader and image use the same key. | ||
|
||
set(signed_image_hex ${PROJECT_BINARY_DIR}/signed.hex) | ||
set(signed_image_bin ${PROJECT_BINARY_DIR}/signed.bin) | ||
set(to_sign_bin ${PROJECT_BINARY_DIR}/to_sign.bin) | ||
set(update_hex ${PROJECT_BINARY_DIR}/update.hex) | ||
set(update_bin ${PROJECT_BINARY_DIR}/update.bin) | ||
|
||
get_property(app_binary_dir GLOBAL PROPERTY PROJECT_BINARY_DIR) | ||
set(merged_hex_file | ||
${app_binary_dir}/mcuboot_primary_app.hex) | ||
set(merged_hex_file_depends | ||
mcuboot_primary_app_hex$<SEMICOLON>${PROJECT_BINARY_DIR}/mcuboot_primary_app.hex) | ||
set(sign_merged | ||
$<TARGET_EXISTS:partition_manager>) | ||
set(to_sign_hex | ||
$<IF:${sign_merged},${merged_hex_file},${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME}>) | ||
set(sign_depends | ||
$<IF:${sign_merged},${merged_hex_file_depends},zephyr_final>) | ||
set(sign_cmd | ||
${PYTHON_EXECUTABLE} | ||
${MCUBOOT_BASE}/scripts/imgtool.py | ||
sign | ||
--key ${MCUBOOT_BASE}/${CONFIG_BOOT_SIGNATURE_KEY_FILE} | ||
--header-size $<TARGET_PROPERTY:partition_manager,PM_MCUBOOT_PAD_SIZE> | ||
--align ${DT_FLASH_WRITE_BLOCK_SIZE} | ||
--version ${CONFIG_MCUBOOT_IMAGE_VERSION} | ||
--slot-size $<TARGET_PROPERTY:partition_manager,PM_MCUBOOT_PRIMARY_SIZE> | ||
--pad-header | ||
) | ||
|
||
add_custom_command( | ||
OUTPUT | ||
${signed_image_hex} | ||
${update_hex} | ||
${update_bin} | ||
COMMAND | ||
${sign_cmd} | ||
${to_sign_hex} | ||
${signed_image_hex} | ||
COMMAND | ||
${CMAKE_OBJCOPY} | ||
--input-target=ihex | ||
--output-target=binary | ||
${to_sign_hex} | ||
${to_sign_bin} | ||
COMMAND | ||
${sign_cmd} | ||
${to_sign_bin} | ||
${update_bin} | ||
COMMAND | ||
${sign_cmd} | ||
--pad # This argument is needed for MCUboot to apply the test swap. | ||
${to_sign_hex} | ||
${update_hex} | ||
COMMAND | ||
${CMAKE_OBJCOPY} | ||
--input-target=ihex | ||
--output-target=ihex | ||
--change-address $<TARGET_PROPERTY:partition_manager,PM_MCUBOOT_PRIMARY_SIZE> | ||
${update_hex} | ||
${PROJECT_BINARY_DIR}/moved_update.hex | ||
DEPENDS | ||
${sign_depends} | ||
) | ||
add_custom_target(mcuboot_sign_target DEPENDS ${signed_image_hex}) | ||
|
||
set_property(GLOBAL PROPERTY | ||
mcuboot_primary_app_PM_HEX_FILE | ||
${signed_image_hex} | ||
) | ||
set_property(GLOBAL PROPERTY | ||
mcuboot_primary_app_PM_TARGET | ||
mcuboot_sign_target | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
menu "MCUboot" | ||
|
||
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 | ||
|
||
config MCUBOOT_IMAGE_VERSION | ||
string "Image version" | ||
default "0.0.0+0" | ||
help | ||
Value to be passed as 'version' argument to 'imgtool.py' when | ||
creating signed image. Note that no semantics are connected to | ||
this variable. It does not provide downgrade prevention, and is only | ||
valuable for debugging purposes. Format: maj.min.rev+build with | ||
latter parts optional. | ||
|
||
endif # BOOTLOADER_MCUBOOT | ||
|
||
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. | ||
|
||
endmenu |