Skip to content

Commit 936d247

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 93398ca commit 936d247

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

boot/bootutil/src/bootutil_priv.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ struct boot_loader_state {
259259
/* Image destination and size for the active slot */
260260
uint32_t img_dst;
261261
uint32_t img_sz;
262-
#elif defined(MCUBOOT_DIRECT_XIP_REVERT)
262+
#endif
263+
#if defined(MCUBOOT_DIRECT_XIP_REVERT) || defined(MCUBOOT_RAM_LOAD_REVERT)
263264
/* Swap status for the active slot */
264265
struct boot_swap_state swap_state;
265266
#endif

boot/bootutil/src/loader.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,8 @@ print_loaded_images(struct boot_loader_state *state)
26342634
}
26352635
#endif
26362636

2637-
#if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)
2637+
#if (defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)) || \
2638+
(defined(MCUBOOT_RAM_LOAD) && defined(MCUBOOT_RAM_LOAD_REVERT))
26382639
/**
26392640
* Checks whether the active slot of the current image was previously selected
26402641
* to run. Erases the image if it was selected but its execution failed,
@@ -2758,17 +2759,17 @@ boot_load_and_validate_images(struct boot_loader_state *state)
27582759
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
27592760
continue;
27602761
}
2762+
#endif /* MCUBOOT_DIRECT_XIP */
27612763

2762-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
2764+
#if defined(MCUBOOT_DIRECT_XIP_REVERT) || defined(MCUBOOT_RAM_LOAD_REVERT)
27632765
rc = boot_select_or_erase(state);
27642766
if (rc != 0) {
27652767
/* The selected image slot has been erased. */
27662768
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
27672769
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
27682770
continue;
27692771
}
2770-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
2771-
#endif /* MCUBOOT_DIRECT_XIP */
2772+
#endif /* MCUBOOT_DIRECT_XIP_REVERT || MCUBOOT_RAM_LOAD_REVERT */
27722773

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

boot/zephyr/Kconfig

+11
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ config BOOT_DIRECT_XIP_REVERT
344344
attempt to boot the previous image. The images can also be made permanent
345345
(marked as confirmed in advance) just like in swap mode.
346346

347+
config BOOT_RAM_LOAD_REVERT
348+
bool "Enable the revert mechanism in ramload mode"
349+
depends on BOOT_RAM_LOAD
350+
help
351+
If y, enables the revert mechanism in ramload similar to the one in
352+
swap mode. It requires the trailer magic to be added to the signed image.
353+
When a reboot happens without the image being confirmed at runtime, the
354+
bootloader considers the image faulty and erases it. After this it will
355+
attempt to boot the previous image. The images can also be made permanent
356+
(marked as confirmed in advance) just like in swap mode.
357+
347358
config BOOT_BOOTSTRAP
348359
bool "Bootstrap erased the primary slot from the secondary slot"
349360
default n

boot/zephyr/include/mcuboot_config/mcuboot_config.h

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
#define MCUBOOT_DIRECT_XIP_REVERT
9393
#endif
9494

95+
#ifdef CONFIG_BOOT_RAM_LOAD_REVERT
96+
#define MCUBOOT_RAM_LOAD_REVERT
97+
#endif
98+
9599
#ifdef CONFIG_BOOT_RAM_LOAD
96100
#define MCUBOOT_RAM_LOAD 1
97101
#define IMAGE_EXECUTABLE_RAM_START CONFIG_BOOT_IMAGE_EXECUTABLE_RAM_START

0 commit comments

Comments
 (0)