From 7914ec3f96dbb8228e791d9492cfc3651cf9deca Mon Sep 17 00:00:00 2001
From: Emekcan Aras <emekcan.aras@arm.com>
Date: Wed, 5 Apr 2023 10:28:57 +0100
Subject: [PATCH] Platform: corstone1000: Fix Flash reading issue for FIP data

Fixes the flash reading issue since bl2 needs to read the data from
flash in XIP mode on FPGA (mps3).

Upstream-Status: Submitted [https://review.trustedfirmware.org/c/TF-M/trusted-firmware-m/+/20558]
Signed-off-by: Emekcan Aras <emekcan.aras@arm.com>
---
 platform/ext/target/arm/corstone1000/bl2/boot_hal_bl2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/platform/ext/target/arm/corstone1000/bl2/boot_hal_bl2.c b/platform/ext/target/arm/corstone1000/bl2/boot_hal_bl2.c
index cf6340c5a9..e4183c7a57 100644
--- a/platform/ext/target/arm/corstone1000/bl2/boot_hal_bl2.c
+++ b/platform/ext/target/arm/corstone1000/bl2/boot_hal_bl2.c
@@ -89,6 +89,7 @@ static bool fill_flash_map_with_fip_data(uint8_t boot_index) {
 
     /* parse directly from flash using XIP mode */
     /* FIP is large so its not a good idea to load it in memory */
+    Select_XIP_Mode_For_Shared_Flash();
     result = parse_fip_and_extract_tfa_info(
         FLASH_BASE_ADDRESS + fip_offset + FIP_SIGNATURE_AREA_SIZE, fip_size,
         &tfa_offset, &tfa_size);
@@ -96,7 +97,7 @@ static bool fill_flash_map_with_fip_data(uint8_t boot_index) {
         BOOT_LOG_ERR("parse_fip_and_extract_tfa_info failed");
         return false;
     }
-
+    Select_Write_Mode_For_Shared_Flash();
     flash_map[2].fa_off = fip_offset + FIP_SIGNATURE_AREA_SIZE + tfa_offset;
     flash_map[2].fa_size = tfa_size;
     flash_map[3].fa_off = flash_map[2].fa_off + flash_map[2].fa_size;
-- 
2.17.1

