Skip to content

Commit 42aff4d

Browse files
modules: mcuboot: add Kconfigs for RAMLOAD_WITH_REVERT mode
Add Kconfigs for RAMLOAD_WITH_REVERT mode in MCUBoot. This mode works in a manner similar to DIRECT_XIP_WITH_REVERT- namely, mcuboot will only boot an image that is either confirmed or marked as pending. If both images are confirmed, mcuboot will still select the one with the higher version, so downgrading is not possible using this mode. Signed-off-by: Daniel DeGrasse <ddegrasse@tenstorrent.com>
1 parent 5e26130 commit 42aff4d

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

cmake/mcuboot.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function(zephyr_mcuboot_tasks)
127127
if(CONFIG_MCUBOOT_IMGTOOL_OVERWRITE_ONLY)
128128
# Use overwrite-only instead of swap upgrades.
129129
set(imgtool_args --overwrite-only --align 1 ${imgtool_args})
130-
elseif(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD)
130+
elseif(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD OR CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT)
131131
# RAM load requires setting the location of where to load the image to
132132
dt_chosen(chosen_ram PROPERTY "zephyr,sram")
133133
dt_reg_addr(chosen_ram_address PATH ${chosen_ram})
@@ -189,7 +189,7 @@ function(zephyr_mcuboot_tasks)
189189
${output}.signed.encrypted.bin)
190190
endif()
191191

192-
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD)
192+
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD OR CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT)
193193
list(APPEND byproducts ${output}.slot1.signed.encrypted.bin)
194194
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
195195
${imgtool_sign} ${imgtool_args_alt_slot} ${output}.bin
@@ -252,7 +252,7 @@ function(zephyr_mcuboot_tasks)
252252
${output}.signed.encrypted.hex)
253253
endif()
254254

255-
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD)
255+
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD OR CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT)
256256
list(APPEND byproducts ${output}.slot1.signed.hex)
257257
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
258258
${imgtool_sign} ${imgtool_args_alt_slot} ${output}.hex

modules/Kconfig.mcuboot

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,26 @@ config MCUBOOT_BOOTLOADER_MODE_RAM_LOAD
211211
This option automatically selectes MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible
212212
to swap back to older version of the application.
213213

214+
config MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT
215+
bool "MCUboot has been configured for RAM LOAD with revert"
216+
select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE
217+
select MCUBOOT_BOOTLOADER_NO_DOWNGRADE
218+
help
219+
MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode, MCUboot
220+
will select the image with the higher version number, copy it to RAM and begin execution
221+
from there. The image must be linked to execute from RAM, the address that it is copied
222+
to is specified using the load-addr argument when running imgtool.
223+
This option automatically selectes MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible
224+
to swap back to older version of the application.
225+
In this mode MCUboot will boot the application with the higher
226+
version from either slot, as long as it has been marked to be boot
227+
next time for test or permanently. In case when application is marked
228+
for test it needs to confirm itself, on the first boot, or it will be
229+
removed and MCUboot will revert to booting previously approved
230+
application. Note that in this mode MCUboot will not boot an
231+
application if it does not have an image header, so if an application
232+
is flashed manually it should be marked as confirmed
233+
214234
config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP
215235
bool "MCUboot has been configured for DirectXIP operation"
216236
select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE

share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ elseif(SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY)
2727
set(bootmode CONFIG_BOOT_UPGRADE_ONLY)
2828
elseif(SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP OR SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT)
2929
set(bootmode CONFIG_BOOT_DIRECT_XIP)
30-
elseif(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD)
30+
elseif(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD OR SB_CONFIG_MCUBOOT_MODE_RAM_LOAD_WITH_REVERT)
3131
set(bootmode CONFIG_BOOT_RAM_LOAD)
3232
elseif(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP_RAM_LOAD)
3333
set(bootmode CONFIG_SINGLE_APPLICATION_SLOT_RAM_LOAD)
@@ -56,6 +56,12 @@ else()
5656
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_DIRECT_XIP_REVERT n)
5757
endif()
5858

59+
if(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD_WITH_REVERT)
60+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_RAM_LOAD_REVERT y)
61+
else()
62+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_RAM_LOAD_REVERT n)
63+
endif()
64+
5965
set(keytypes CONFIG_BOOT_SIGNATURE_TYPE_NONE
6066
CONFIG_BOOT_SIGNATURE_TYPE_RSA
6167
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256

share/sysbuild/image_configurations/MAIN_image_default.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT)
3939
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD y)
4040
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_XIP n)
4141
set_config_int(${ZCMAKE_APPLICATION} CONFIG_FLASH_SIZE 0)
42+
elseif(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD_WITH_REVERT)
43+
# RAM load mode requires XIP be disabled and flash size be set to 0
44+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT y)
45+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_XIP n)
46+
set_config_int(${ZCMAKE_APPLICATION} CONFIG_FLASH_SIZE 0)
4247
elseif(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP_RAM_LOAD)
4348
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP_RAM_LOAD y)
4449
elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER)

share/sysbuild/images/bootloader/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ config MCUBOOT_MODE_RAM_LOAD
119119
Note: RAM must be assigned to the bootloader that is not used by the application in this
120120
mode so that the bootloader is able to function until the application has booted.
121121

122+
config MCUBOOT_MODE_RAM_LOAD_WITH_REVERT
123+
bool "RAM load with revert"
124+
help
125+
MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode, MCUboot
126+
will select the image with the higher version number, copy it to RAM and begin execution
127+
from there. MCUBoot will only boot an image if it has been marked to be boot next time
128+
for test or permanently. In case when application is marked for test it needs to confirm
129+
itself, on the first boot, or it will be removed and MCUboot will revert to booting
130+
previously approved application. The image must be linked to execute from RAM, the address
131+
that it is copied to is specified using the load-addr argument when running imgtool.
132+
133+
Note: RAM must be assigned to the bootloader that is not used by the application in this
134+
mode so that the bootloader is able to function until the application has booted.
135+
122136
config MCUBOOT_MODE_FIRMWARE_UPDATER
123137
bool "Firmware updater"
124138
help

0 commit comments

Comments
 (0)