Skip to content

Commit 33bde05

Browse files
SebastianBoehakonfam
authored andcommitted
cmake: build mcuboot using multi image build
Leverage multi image functionality to allow mcuboot being built from zephyr app build dir. Signed-off-by: Sebastian Bøe <[email protected]> Signed-off-by: Håkon Øye Amundsen <[email protected]>
1 parent ea4d33a commit 33bde05

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ list(APPEND
13391339
${extra_post_build_commands}
13401340
)
13411341

1342+
13421343
add_custom_command(
13431344
TARGET ${logical_target_for_zephyr_elf}
13441345
POST_BUILD

subsys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_subdirectory_ifdef(CONFIG_NET_BUF net)
1313
add_subdirectory_ifdef(CONFIG_USB usb)
1414
add_subdirectory(random)
1515
add_subdirectory(storage)
16+
add_subdirectory(boot)
1617
add_subdirectory_ifdef(CONFIG_SETTINGS settings)
1718
add_subdirectory(fb)
1819
add_subdirectory(power)

subsys/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ source "subsys/mgmt/Kconfig"
2323

2424
source "subsys/net/Kconfig"
2525

26+
source "subsys/boot/Kconfig"
27+
2628
source "subsys/shell/Kconfig"
2729

2830
source "subsys/usb/Kconfig"

subsys/boot/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory_ifdef(CONFIG_BOOTLOADER_MCUBOOT mcuboot)

subsys/boot/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rsource "mcuboot/Kconfig"

subsys/boot/mcuboot/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Build a second bootloader image
2+
3+
# TODO: Make configurable like OT until west is supported.
4+
set(MCUBOOT_BASE "${ZEPHYR_BASE}/../mcuboot")
5+
assert_exists(MCUBOOT_BASE)
6+
7+
zephyr_add_executable(mcuboot)
8+
add_subdirectory("${MCUBOOT_BASE}/boot/zephyr" ${CMAKE_CURRENT_BINARY_DIR}/mcuboot)
9+
10+
# TODO: Assert that the bootloader and image use the same key.
11+
12+
set(SIGNED_IMAGE signed.hex)
13+
14+
set_property(GLOBAL APPEND PROPERTY
15+
extra_post_build_commands
16+
COMMAND
17+
${PYTHON_EXECUTABLE}
18+
${MCUBOOT_BASE}/scripts/imgtool.py
19+
sign
20+
--key ${MCUBOOT_BASE}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}
21+
--header-size ${CONFIG_TEXT_SECTION_OFFSET}
22+
--align 8 # TODO: Configurable?
23+
--version 1.0 # TODO: Configurable?
24+
--slot-size 0x32000 # TODO: Configurable?
25+
${KERNEL_HEX_NAME} # TODO: Enforce that this will be present through Kconfig
26+
${SIGNED_IMAGE}
27+
)
28+
29+
set_property(GLOBAL APPEND PROPERTY
30+
HEX_FILES_TO_MERGE
31+
${SIGNED_IMAGE}
32+
)
33+
set_property(GLOBAL APPEND PROPERTY
34+
HEX_FILES_TO_MERGE_TARGET
35+
${logical_target_for_zephyr_elf}
36+
)

subsys/boot/mcuboot/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
if BOOTLOADER_MCUBOOT
2+
3+
config MCUBOOT_CMAKELISTS_DIR
4+
string "Path to the directory of the MCUBoot CMakeLists.txt file"
5+
default "$MCUBOOT_BASE/boot/zephyr/"
6+
7+
endif # BOOTLOADER_MCUBOOT
8+
9+
if MCUBOOT || BOOTLOADER_MCUBOOT
10+
# TODO: Support sharing Kconfig configuration between images
11+
config BOOT_SIGNATURE_KEY_FILE
12+
string "PEM key file"
13+
default "root-rsa-2048.pem"
14+
help
15+
The key file will be parsed by imgtool's getpub command and a .c source
16+
with the public key information will be written in a format expected by
17+
MCUboot.
18+
19+
endif # MCUBOOT || BOOTLOADER_MCUBOOT

0 commit comments

Comments
 (0)