espressif:esp32: Add multi image support
Changes on configuration and flash area organization for supporting
multi image and implementation for booting on different processors
on esp32
Signed-off-by: Almir Okato <almir.okato@espressif.com>
diff --git a/boot/espressif/include/sysflash/sysflash.h b/boot/espressif/include/sysflash/sysflash.h
index 7f0fb28..5419853 100644
--- a/boot/espressif/include/sysflash/sysflash.h
+++ b/boot/espressif/include/sysflash/sysflash.h
@@ -4,6 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
+#pragma once
+
+#include <mcuboot_config/mcuboot_config.h>
+
//! A user-defined identifier for different storage mediums
//! (i.e internal flash, external NOR flash, eMMC, etc)
#define FLASH_DEVICE_INTERNAL_FLASH 0
@@ -12,14 +16,35 @@
//! there is not slot
#define FLASH_SLOT_DOES_NOT_EXIST 255
-//! NB: MCUboot expects this define to exist but it's only used
-//! if MCUBOOT_SWAP_USING_SCRATCH=1 is set
-#define FLASH_AREA_IMAGE_SCRATCH FLASH_SLOT_DOES_NOT_EXIST
-
//! The slot we will use to track the bootloader allocation
#define FLASH_AREA_BOOTLOADER 0
-//! A mapping to primary and secondary/upgrade slot
-//! given an image_index. We'll plan to use
-#define FLASH_AREA_IMAGE_PRIMARY(i) ((i == 0) ? 1 : 255)
-#define FLASH_AREA_IMAGE_SECONDARY(i) ((i == 0) ? 2 : 255)
+#define FLASH_AREA_IMAGE_0_PRIMARY 1
+#define FLASH_AREA_IMAGE_0_SECONDARY 2
+#define FLASH_AREA_IMAGE_SCRATCH 3
+#define FLASH_AREA_IMAGE_1_PRIMARY 4
+#define FLASH_AREA_IMAGE_1_SECONDARY 5
+
+#if (MCUBOOT_IMAGE_NUMBER == 1)
+#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
+ FLASH_AREA_IMAGE_0_PRIMARY : \
+ FLASH_SLOT_DOES_NOT_EXIST)
+#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
+ FLASH_AREA_IMAGE_0_SECONDARY : \
+ FLASH_SLOT_DOES_NOT_EXIST)
+
+#elif (MCUBOOT_IMAGE_NUMBER == 2)
+#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
+ FLASH_AREA_IMAGE_0_PRIMARY : \
+ ((x) == 1) ? \
+ FLASH_AREA_IMAGE_1_PRIMARY : \
+ FLASH_SLOT_DOES_NOT_EXIST)
+#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
+ FLASH_AREA_IMAGE_0_SECONDARY : \
+ ((x) == 1) ? \
+ FLASH_AREA_IMAGE_1_SECONDARY : \
+ FLASH_SLOT_DOES_NOT_EXIST)
+
+#else
+#warning "Image slot and flash area mapping is not defined"
+#endif