Boot: Extend flash layout for multiple images
This patch introduces the BOOT_IMAGE_NUMBER macro and current_image
variable to support multiple updatable images and the associated
extended flash layout.
The FLASH_AREA_IMAGE_* object-like macros are replaced with
function-like ones and therefore some functions have been updated,
because the labels of a switch statement and the initialization
values of objects with static storage duration have to be constant
expressions.
Change-Id: Ib7b26ec3c94233e52db4f97825ddb6a3e55bb1d3
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index fcbf082..a843d73 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -47,6 +47,7 @@
MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
static struct boot_loader_state boot_data;
+uint8_t current_image = 0;
#if defined(MCUBOOT_VALIDATE_PRIMARY_SLOT) && !defined(MCUBOOT_OVERWRITE_ONLY)
static int boot_status_fails = 0;
@@ -1021,18 +1022,20 @@
uint32_t total_sz;
uint32_t off;
uint32_t sz;
+ int fa_id_primary;
+ int fa_id_secondary;
int rc;
BOOT_LOG_DBG("erasing trailer; fa_id=%d", fap->fa_id);
- switch (fap->fa_id) {
- case FLASH_AREA_IMAGE_PRIMARY:
+ fa_id_primary = flash_area_id_from_image_slot(BOOT_PRIMARY_SLOT);
+ fa_id_secondary = flash_area_id_from_image_slot(BOOT_SECONDARY_SLOT);
+
+ if (fap->fa_id == fa_id_primary) {
slot = BOOT_PRIMARY_SLOT;
- break;
- case FLASH_AREA_IMAGE_SECONDARY:
+ } else if (fap->fa_id == fa_id_secondary) {
slot = BOOT_SECONDARY_SLOT;
- break;
- default:
+ } else {
return BOOT_EFLASH;
}