Skip to content

Commit e574f2d

Browse files
committed
boot: Introduce direct execute-in-place (XIP) mode
This patch introduces the direct execute-in-place (XIP) mode in addition to the other upgrade modes (swap strategies, overwrite-only). When direct-XIP is enabled with the MCUBOOT_DIRECT_XIP option, mcuboot selects the newest valid image based on the image version numbers from the image header, thereafter the selected image runs directly from its flash partition (slot) instead of moving it. Therefore the images must be linked to be executed from the given image slot. It means that in direct-XIP mode either of the primary and the secondary slots can hold the active image. This patch is based on the NO_SWAP upgrade strategy which was first introduced in the Trusted Firmware-M project. Source TF-M version: TF-Mv1.0. Change-Id: If584cf01ae5aa7208845f6a6fa206f0595e0e61e Signed-off-by: David Vincze <[email protected]>
1 parent 8b0b637 commit e574f2d

File tree

6 files changed

+340
-96
lines changed

6 files changed

+340
-96
lines changed

boot/bootutil/src/bootutil_priv.h

+29-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2017-2020 Linaro LTD
55
* Copyright (c) 2017-2019 JUUL Labs
6-
* Copyright (c) 2019 Arm Limited
6+
* Copyright (c) 2019-2020 Arm Limited
77
*
88
* Original license:
99
*
@@ -66,11 +66,15 @@ struct flash_area;
6666
/** Number of image slots in flash; currently limited to two. */
6767
#define BOOT_NUM_SLOTS 2
6868

69-
#if defined(MCUBOOT_OVERWRITE_ONLY) && defined(MCUBOOT_SWAP_USING_MOVE)
70-
#error "Please enable only one of MCUBOOT_OVERWRITE_ONLY or MCUBOOT_SWAP_USING_MOVE"
69+
#if (defined(MCUBOOT_OVERWRITE_ONLY) + \
70+
defined(MCUBOOT_SWAP_USING_MOVE) + \
71+
defined(MCUBOOT_DIRECT_XIP)) > 1
72+
#error "Please enable only one of MCUBOOT_OVERWRITE_ONLY, MCUBOOT_SWAP_USING_MOVE or MCUBOOT_DIRECT_XIP"
7173
#endif
7274

73-
#if !defined(MCUBOOT_OVERWRITE_ONLY) && !defined(MCUBOOT_SWAP_USING_MOVE)
75+
#if !defined(MCUBOOT_OVERWRITE_ONLY) && \
76+
!defined(MCUBOOT_SWAP_USING_MOVE) && \
77+
!defined(MCUBOOT_DIRECT_XIP)
7478
#define MCUBOOT_SWAP_USING_SCRATCH 1
7579
#endif
7680

@@ -166,6 +170,19 @@ struct boot_swap_state {
166170

167171
_Static_assert(BOOT_IMAGE_NUMBER > 0, "Invalid value for BOOT_IMAGE_NUMBER");
168172

173+
#if !defined(MCUBOOT_DIRECT_XIP)
174+
#define IS_IN_XIP_MODE() 0
175+
#else
176+
#define IS_IN_XIP_MODE() 1
177+
178+
#if (BOOT_IMAGE_NUMBER != 1)
179+
#error "The MCUBOOT_DIRECT_XIP mode only supports single-image boot (MCUBOOT_IMAGE_NUMBER=1)."
180+
#endif
181+
#ifdef MCUBOOT_ENC_IMAGES
182+
#error "Image encryption (MCUBOOT_ENC_IMAGES) is not supported when MCUBOOT_DIRECT_XIP mode is selected."
183+
#endif
184+
#endif /* MCUBOOT_DIRECT_XIP */
185+
169186
#define BOOT_MAX_IMG_SECTORS MCUBOOT_MAX_IMG_SECTORS
170187

171188
/*
@@ -183,6 +200,14 @@ _Static_assert(BOOT_IMAGE_NUMBER > 0, "Invalid value for BOOT_IMAGE_NUMBER");
183200
| (type); \
184201
}
185202

203+
#define BOOT_LOG_IMAGE_INFO(slot, hdr) \
204+
BOOT_LOG_INF("%-9s slot: version=%u.%u.%u+%u", \
205+
((slot) == BOOT_PRIMARY_SLOT) ? "Primary" : "Secondary", \
206+
(hdr)->ih_ver.iv_major, \
207+
(hdr)->ih_ver.iv_minor, \
208+
(hdr)->ih_ver.iv_revision, \
209+
(hdr)->ih_ver.iv_build_num)
210+
186211
/*
187212
* The current flashmap API does not check the amount of space allocated when
188213
* loading sector data from the flash device, allowing for smaller counts here

0 commit comments

Comments
 (0)