Skip to content

Commit

Permalink
boot: zephyr: add config for swap without scratch
Browse files Browse the repository at this point in the history
Add Zephyr option to enable building a bootloader that uses an
alternative swap algorithm, that first moves up all sectors in slot1 and
then directly swaps between slot0 and slot1.

Signed-off-by: Fabio Utzig <utzig@apache.org>
  • Loading branch information
utzig committed Nov 27, 2019
1 parent e354a4a commit a4149a3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions boot/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ endif()
zephyr_library_include_directories(${BOOT_DIR}/bootutil/include)
zephyr_library_sources(
${BOOT_DIR}/bootutil/src/loader.c
${BOOT_DIR}/bootutil/src/swap_scratch.c
${BOOT_DIR}/bootutil/src/swap_move.c
${BOOT_DIR}/bootutil/src/bootutil_misc.c
${BOOT_DIR}/bootutil/src/image_validate.c
${BOOT_DIR}/bootutil/src/encrypted.c
Expand Down
13 changes: 13 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ config BOOT_UPGRADE_ONLY
of swapping them. This prevents the fallback recovery, but
uses a much simpler code path.

config BOOT_SWAP_MOVE
bool "Swap mode that can run without a scratch partition"
default n
help
If y, the swap upgrade is done in two steps, where first every
sector of the secondary slot is moved up one sector, then for
each sector X in the primary slot, it is moved to index X in
the secondary slot, then the sector at X+1 in the secondary is
moved to index X in the primary.
This allows a swap upgrade without using a scratch partition,
but is currently limited to all sectors in both slots being of
the same size.

config BOOT_BOOTSTRAP
bool "Bootstrap erased the primary slot from the secondary slot"
default n
Expand Down
2 changes: 2 additions & 0 deletions boot/zephyr/flash_map_extended.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ int flash_area_id_from_multi_image_slot(int image_index, int slot)
switch (slot) {
case 0: return FLASH_AREA_IMAGE_PRIMARY(image_index);
case 1: return FLASH_AREA_IMAGE_SECONDARY(image_index);
#if !defined(CONFIG_BOOT_SWAP_MOVE)
case 2: return FLASH_AREA_IMAGE_SCRATCH;
#endif
}

return -EINVAL; /* flash_area_open will fail on that */
Expand Down
4 changes: 4 additions & 0 deletions boot/zephyr/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
#define MCUBOOT_OVERWRITE_ONLY_FAST
#endif

#ifdef CONFIG_BOOT_SWAP_MOVE
#define MCUBOOT_SWAP_MOVE 1
#endif

#ifdef CONFIG_LOG
#define MCUBOOT_HAVE_LOGGING 1
#endif
Expand Down
2 changes: 2 additions & 0 deletions boot/zephyr/include/sysflash/sysflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#error "Image slot and flash area mapping is not defined"
#endif

#if !defined(CONFIG_BOOT_SWAP_MOVE)
#define FLASH_AREA_IMAGE_SCRATCH DT_FLASH_AREA_IMAGE_SCRATCH_ID
#endif

#endif /* __SYSFLASH_H__ */
4 changes: 2 additions & 2 deletions boot/zephyr/include/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
!defined(FLASH_AREA_IMAGE_0_SIZE) || \
!defined(FLASH_AREA_IMAGE_1_OFFSET) || \
!defined(FLASH_AREA_IMAGE_1_SIZE) || \
!defined(FLASH_AREA_IMAGE_SCRATCH_OFFSET) || \
!defined(FLASH_AREA_IMAGE_SCRATCH_SIZE)
(!defined(CONFIG_BOOT_SWAP_MOVE) && !defined(FLASH_AREA_IMAGE_SCRATCH_OFFSET)) || \
(!defined(CONFIG_BOOT_SWAP_MOVE) && !defined(FLASH_AREA_IMAGE_SCRATCH_SIZE))
#error "Target support is incomplete; cannot build mcuboot."
#endif

Expand Down
2 changes: 2 additions & 0 deletions boot/zephyr/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"
CONFIG_BOOT_ENCRYPT_RSA=n
CONFIG_BOOT_ENCRYPT_EC256=n

CONFIG_BOOT_UPGRADE_ONLY=n
CONFIG_BOOT_SWAP_MOVE=n
CONFIG_BOOT_BOOTSTRAP=n

### Default to RSA
Expand Down

0 comments on commit a4149a3

Please sign in to comment.