Skip to content

Commit 1db8404

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 0224781 commit 1db8404

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
@@ -2721,7 +2721,8 @@ print_loaded_images(struct boot_loader_state *state)
27212721
}
27222722
#endif
27232723

2724-
#if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)
2724+
#if (defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)) || \
2725+
(defined(MCUBOOT_RAM_LOAD) && defined(MCUBOOT_RAM_LOAD_REVERT))
27252726
/**
27262727
* Checks whether the active slot of the current image was previously selected
27272728
* to run. Erases the image if it was selected but its execution failed,
@@ -2841,17 +2842,17 @@ boot_load_and_validate_images(struct boot_loader_state *state)
28412842
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
28422843
continue;
28432844
}
2845+
#endif /* MCUBOOT_DIRECT_XIP */
28442846

2845-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
2847+
#if defined(MCUBOOT_DIRECT_XIP_REVERT) || defined(MCUBOOT_RAM_LOAD_REVERT)
28462848
rc = boot_select_or_erase(state);
28472849
if (rc != 0) {
28482850
/* The selected image slot has been erased. */
28492851
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
28502852
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
28512853
continue;
28522854
}
2853-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
2854-
#endif /* MCUBOOT_DIRECT_XIP */
2855+
#endif /* MCUBOOT_DIRECT_XIP_REVERT || MCUBOOT_RAM_LOAD_REVERT */
28552856

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

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

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)