Boot: Consider both image slots for shared data
When saving shared data, look for the supplied image flash area in both
the primary and secondary slots instead of only the primary slot. In
ram-load and direct-xip modes, the selected image may be in the
secondary slot.
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
Change-Id: Ia4374a46a2c92c392909d3d54e2fad8232001fe4
diff --git a/bl2/src/shared_data.c b/bl2/src/shared_data.c
index 73d0f73..fd2fb7b 100644
--- a/bl2/src/shared_data.c
+++ b/bl2/src/shared_data.c
@@ -193,15 +193,18 @@
/* Look for the given flash area to determine the image ID. */
for (i = 0; i < MCUBOOT_IMAGE_NUMBER; i++) {
- if (flash_area_open(FLASH_AREA_IMAGE_PRIMARY(i),
- &temp_fap) != 0) {
- return -1;
- }
-
- if (fap == temp_fap) {
+ if (flash_area_open(FLASH_AREA_IMAGE_PRIMARY(i), &temp_fap) == 0 &&
+ fap == temp_fap) {
mcuboot_image_id = i;
break;
}
+#if defined(MCUBOOT_DIRECT_XIP) || defined(MCUBOOT_RAM_LOAD)
+ else if (flash_area_open(FLASH_AREA_IMAGE_SECONDARY(i), &temp_fap) == 0 &&
+ fap == temp_fap) {
+ mcuboot_image_id = i;
+ break;
+ }
+#endif
}
if (i == MCUBOOT_IMAGE_NUMBER) {