Skip to content

Commit 0b035cc

Browse files
boot: zephyr: add support for revert mode with ramload
Add support for revert mode when using ramloading. This includes the same restrictions as revert mode with direct-xip, namely that an image must have a valid BOOT_MAGIC value in order for mcuboot to attempt to load it. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 5cf2a5f commit 0b035cc

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

boot/bootutil/src/bootutil_priv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ struct boot_loader_state {
275275
/* Image destination and size for the active slot */
276276
uint32_t img_dst;
277277
uint32_t img_sz;
278-
#elif defined(MCUBOOT_DIRECT_XIP_REVERT)
278+
#endif
279+
#if defined(MCUBOOT_DIRECT_XIP_REVERT) || defined(MCUBOOT_RAM_LOAD_REVERT)
279280
/* Swap status for the active slot */
280281
struct boot_swap_state swap_state;
281282
#endif

boot/bootutil/src/loader.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,8 @@ print_loaded_images(struct boot_loader_state *state)
28982898
}
28992899
#endif
29002900

2901-
#if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)
2901+
#if (defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)) || \
2902+
(defined(MCUBOOT_RAM_LOAD) && defined(MCUBOOT_RAM_LOAD_REVERT))
29022903
/**
29032904
* Checks whether the active slot of the current image was previously selected
29042905
* to run. Erases the image if it was selected but its execution failed,
@@ -3018,17 +3019,17 @@ boot_load_and_validate_images(struct boot_loader_state *state)
30183019
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
30193020
continue;
30203021
}
3022+
#endif /* MCUBOOT_DIRECT_XIP */
30213023

3022-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
3024+
#if defined(MCUBOOT_DIRECT_XIP_REVERT) || defined(MCUBOOT_RAM_LOAD_REVERT)
30233025
rc = boot_select_or_erase(state);
30243026
if (rc != 0) {
30253027
/* The selected image slot has been erased. */
30263028
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
30273029
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
30283030
continue;
30293031
}
3030-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
3031-
#endif /* MCUBOOT_DIRECT_XIP */
3032+
#endif /* MCUBOOT_DIRECT_XIP_REVERT || MCUBOOT_RAM_LOAD_REVERT */
30323033

30333034
#ifdef MCUBOOT_RAM_LOAD
30343035
/* Image is first loaded to RAM and authenticated there in order to

boot/zephyr/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ config BOOT_DIRECT_XIP_REVERT
500500
attempt to boot the previous image. The images can also be made permanent
501501
(marked as confirmed in advance) just like in swap mode.
502502

503+
config BOOT_RAM_LOAD_REVERT
504+
bool "Enable the revert mechanism in ram-load mode"
505+
depends on BOOT_RAM_LOAD
506+
help
507+
If y, enables the revert mechanism in ram-load similar to the one in
508+
swap mode. It requires the trailer magic to be added to the signed image.
509+
When a reboot happens without the image being confirmed at runtime, the
510+
bootloader considers the image faulty and erases it. After this it will
511+
attempt to boot the previous image. The images can also be made permanent
512+
(marked as confirmed in advance) just like in swap mode.
513+
503514
config BOOT_BOOTSTRAP
504515
bool "Bootstrap erased the primary slot from the secondary slot"
505516
help

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
#define MCUBOOT_DIRECT_XIP_REVERT
101101
#endif
102102

103+
#ifdef CONFIG_BOOT_RAM_LOAD_REVERT
104+
#define MCUBOOT_RAM_LOAD_REVERT
105+
#endif
106+
103107
#ifdef CONFIG_BOOT_RAM_LOAD
104108
#define MCUBOOT_RAM_LOAD 1
105109
#define IMAGE_EXECUTABLE_RAM_START CONFIG_BOOT_IMAGE_EXECUTABLE_RAM_START

0 commit comments

Comments
 (0)