Skip to content

Commit a736efa

Browse files
danieldegrassed3zd3z
authored andcommitted
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 <ddegrasse@tenstorrent.com>
1 parent 61c5547 commit a736efa

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
@@ -285,7 +285,8 @@ struct boot_loader_state {
285285
/* Image destination and size for the active slot */
286286
uint32_t img_dst;
287287
uint32_t img_sz;
288-
#elif defined(MCUBOOT_DIRECT_XIP_REVERT)
288+
#endif
289+
#if defined(MCUBOOT_DIRECT_XIP_REVERT) || defined(MCUBOOT_RAM_LOAD_REVERT)
289290
/* Swap status for the active slot */
290291
struct boot_swap_state swap_state;
291292
#endif

boot/bootutil/src/loader.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,8 @@ print_loaded_images(struct boot_loader_state *state)
26052605
}
26062606
#endif
26072607

2608-
#if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)
2608+
#if (defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)) || \
2609+
(defined(MCUBOOT_RAM_LOAD) && defined(MCUBOOT_RAM_LOAD_REVERT))
26092610
/**
26102611
* Checks whether the active slot of the current image was previously selected
26112612
* to run. Erases the image if it was selected but its execution failed,
@@ -2724,17 +2725,17 @@ boot_load_and_validate_images(struct boot_loader_state *state)
27242725
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
27252726
continue;
27262727
}
2728+
#endif /* MCUBOOT_DIRECT_XIP */
27272729

2728-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
2730+
#if defined(MCUBOOT_DIRECT_XIP_REVERT) || defined(MCUBOOT_RAM_LOAD_REVERT)
27292731
rc = boot_select_or_erase(state);
27302732
if (rc != 0) {
27312733
/* The selected image slot has been erased. */
27322734
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
27332735
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
27342736
continue;
27352737
}
2736-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
2737-
#endif /* MCUBOOT_DIRECT_XIP */
2738+
#endif /* MCUBOOT_DIRECT_XIP_REVERT || MCUBOOT_RAM_LOAD_REVERT */
27382739

27392740
#ifdef MCUBOOT_RAM_LOAD
27402741
/* 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
@@ -504,6 +504,17 @@ config BOOT_DIRECT_XIP_REVERT
504504
attempt to boot the previous image. The images can also be made permanent
505505
(marked as confirmed in advance) just like in swap mode.
506506

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