Boot: Extend flash layout for multiple images

This patch extends the flash layout of supported platforms, and also
introduces the BOOT_IMAGE_NUMBER macro and the current_image variable
in MCUBoot to support multiple updatable images.

The FLASH_AREA_IMAGE_PRIMARY/SECONDARY 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: Ic4425c9034f877fe2b83d80a3df211232f14a09f
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/bl2/ext/mcuboot/bootutil/src/loader.c b/bl2/ext/mcuboot/bootutil/src/loader.c
index 80789e5..c7c7173 100644
--- a/bl2/ext/mcuboot/bootutil/src/loader.c
+++ b/bl2/ext/mcuboot/bootutil/src/loader.c
@@ -47,6 +47,7 @@
 #include "bootutil/bootutil_log.h"
 
 static struct boot_loader_state boot_data;
+uint8_t current_image = 0;
 
 #if !defined(MCUBOOT_NO_SWAP) && !defined(MCUBOOT_RAM_LOADING)
 
@@ -977,18 +978,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;
     }