Skip to content

Commit 9566aa5

Browse files
nordicjmcarlescufi
authored andcommitted
sysbuild: Add MCUboot operating mode
Adds a sysbuild Kconfig to select the operating mode of MCUboot which is then propagated to the MCUboot and application images Signed-off-by: Jamie McCrae <[email protected]>
1 parent 206f2fd commit 9566aa5

File tree

3 files changed

+139
-2
lines changed

3 files changed

+139
-2
lines changed

share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
1-
# Copyright (c) 2023 Nordic Semiconductor
1+
# Copyright (c) 2023-2024 Nordic Semiconductor
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

55
# This sysbuild CMake file sets the sysbuild controlled settings as properties
66
# on Zephyr MCUboot / bootloader image.
77

8+
set(bootmodes CONFIG_SINGLE_APPLICATION_SLOT
9+
CONFIG_BOOT_SWAP_USING_SCRATCH
10+
CONFIG_BOOT_UPGRADE_ONLY
11+
CONFIG_BOOT_SWAP_USING_MOVE
12+
CONFIG_BOOT_DIRECT_XIP
13+
CONFIG_BOOT_RAM_LOAD
14+
CONFIG_BOOT_FIRMWARE_LOADER)
15+
16+
if(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP)
17+
set(bootmode CONFIG_SINGLE_APPLICATION_SLOT)
18+
elseif(SB_CONFIG_MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH)
19+
set(bootmode CONFIG_BOOT_SWAP_USING_MOVE)
20+
elseif(SB_CONFIG_MCUBOOT_MODE_SWAP_SCRATCH)
21+
set(bootmode CONFIG_BOOT_SWAP_USING_SCRATCH)
22+
elseif(SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY)
23+
set(bootmode CONFIG_BOOT_UPGRADE_ONLY)
24+
elseif(SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP OR SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT)
25+
set(bootmode CONFIG_BOOT_DIRECT_XIP)
26+
elseif(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD)
27+
set(bootmode CONFIG_BOOT_RAM_LOAD)
28+
elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER)
29+
set(bootmode CONFIG_BOOT_FIRMWARE_LOADER)
30+
endif()
31+
32+
foreach(loopbootmode ${bootmodes})
33+
if("${loopbootmode}" STREQUAL "${bootmode}")
34+
set_config_bool(${ZCMAKE_APPLICATION} ${loopbootmode} y)
35+
else()
36+
set_config_bool(${ZCMAKE_APPLICATION} ${loopbootmode} n)
37+
endif()
38+
endforeach()
39+
40+
if(SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT)
41+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_DIRECT_XIP_REVERT y)
42+
else()
43+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_DIRECT_XIP_REVERT n)
44+
endif()
45+
846
set(keytypes CONFIG_BOOT_SIGNATURE_TYPE_NONE
947
CONFIG_BOOT_SIGNATURE_TYPE_RSA
1048
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256

share/sysbuild/image_configurations/MAIN_image_default.cmake

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023 Nordic Semiconductor
1+
# Copyright (c) 2023-2024 Nordic Semiconductor
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

@@ -19,4 +19,22 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT)
1919
else()
2020
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n)
2121
endif()
22+
23+
if(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP)
24+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP y)
25+
elseif(SB_CONFIG_MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH)
26+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH y)
27+
elseif(SB_CONFIG_MCUBOOT_MODE_SWAP_SCRATCH)
28+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH y)
29+
elseif(SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY)
30+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY y)
31+
elseif(SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP)
32+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP y)
33+
elseif(SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT)
34+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT y)
35+
elseif(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD)
36+
# Not yet supported in zephyr code
37+
elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER)
38+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER y)
39+
endif()
2240
endif()

share/sysbuild/images/bootloader/Kconfig

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,87 @@ endchoice
3030

3131
if BOOTLOADER_MCUBOOT
3232

33+
choice MCUBOOT_MODE
34+
prompt "Mode of operation"
35+
default MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH
36+
help
37+
The operating mode of MCUboot (which will also be propagated to the application).
38+
39+
config MCUBOOT_MODE_SINGLE_APP
40+
bool "Single slot"
41+
help
42+
MCUboot will only boot slot0_partition placed application and does not care about other
43+
slots. In this mode application is not able to DFU its own update to secondary slot and
44+
all updates need to be performed using MCUboot serial recovery.
45+
46+
config MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH
47+
bool "Swap without scratch (swap using move)"
48+
help
49+
MCUboot expects slot0_partition and slot1_partition to be present in DT and application
50+
will boot from slot0_partition. MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected
51+
in main application if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION.
52+
53+
config MCUBOOT_MODE_SWAP_SCRATCH
54+
bool "Swap using scratch"
55+
help
56+
MCUboot expects slot0_partition, slot1_partition and scratch_partition to be present in
57+
DT, and application will boot from slot0_partition. In this mode scratch_partition is
58+
used as temporary storage when MCUboot swaps application from the secondary slot to the
59+
primary slot.
60+
MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected in main application if MCUboot
61+
has been built with MCUBOOT_DOWNGRADE_PREVENTION.
62+
63+
config MCUBOOT_MODE_OVERWRITE_ONLY
64+
bool "Overwrite"
65+
help
66+
MCUboot will take contents of secondary slot of an image and will overwrite primary slot
67+
with it. In this mode it is not possible to revert back to previous version as it is not
68+
stored in the secondary slot.
69+
This mode supports MCUBOOT_BOOTLOADER_NO_DOWNGRADE which means that the overwrite will
70+
not happen unless the version of secondary slot is higher than the version in primary
71+
slot.
72+
73+
config MCUBOOT_MODE_DIRECT_XIP
74+
bool "DirectXIP"
75+
help
76+
MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode MCUboot
77+
can boot from either partition and will select one with higher application image version,
78+
which usually means major.minor.patch triple, unless BOOT_VERSION_CMP_USE_BUILD_NUMBER is
79+
also selected in MCUboot that enables comparison of build number.
80+
This option automatically selectes MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible
81+
to swap back to older version of application.
82+
83+
config MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT
84+
bool "DirectXIP with revert"
85+
help
86+
MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode MCUboot
87+
will boot the application with the higher version from either slot, as long as it has
88+
been marked to be boot next time for test or permanently. In case when application is
89+
marked for test it needs to confirm itself, on the first boot, or it will be removed and
90+
MCUboot will revert to booting previously approved application.
91+
This mode does not allow freely switching between application versions, as, once higher
92+
version application is approved, it is not possible to select lower version for boot.
93+
This mode selects MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible to downgrade
94+
running application, but note that MCUboot may do that if application with higher
95+
version will not get confirmed.
96+
97+
config MCUBOOT_MODE_RAM_LOAD
98+
bool "RAM load"
99+
help
100+
MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode, MCUboot
101+
will select the image with the higher version number, copy it to RAM and begin execution
102+
from there. The image must be linked to execute from RAM, the address that it is copied
103+
to is specified using the load-addr argument when running imgtool.
104+
105+
config MCUBOOT_MODE_FIRMWARE_UPDATER
106+
bool "Firmware updater"
107+
help
108+
MCUboot will only boot slot0_partition for the main application but has an entrance
109+
mechanism defined for entering the slot1_partition which is a dedicated firmware updater
110+
application used to update the slot0_partition application.
111+
112+
endchoice
113+
33114
config SIGNATURE_TYPE
34115
string
35116
default NONE if BOOT_SIGNATURE_TYPE_NONE

0 commit comments

Comments
 (0)