Platform: Repartition RAM area in Musca A1

This patch increases the secure RAM memory size (96KB) for the secure
environment and decreases it for the non-secure one (32KB) in order
to accommodate them to the memory requirements of regression tests in
Musca A1.
When it is not required to run the regression tests, the RAM memory
partition is the original one which is 64KB of RAM for each execution
environment.

Change-Id: I19336c875f740bb86cdf734d8f8779fa944f6710
Signed-off-by: Marc Moreno <marc.morenoberengue@arm.com>
diff --git a/CommonConfig.cmake b/CommonConfig.cmake
index 3fb96d4..58df306 100644
--- a/CommonConfig.cmake
+++ b/CommonConfig.cmake
@@ -99,6 +99,8 @@
 set (REFERENCE_PLATFORM OFF)
 set (TFM_PARTITION_TEST_SECURE_SERVICES OFF)
 set (SERVICES_TEST_ENABLED OFF)
+set (TEST_FRAMEWORK_S  OFF)
+set (TEST_FRAMEWORK_NS OFF)
 
 if(${TARGET_PLATFORM} STREQUAL "AN521" OR ${TARGET_PLATFORM} STREQUAL "AN519")
 	set (REFERENCE_PLATFORM ON)
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index f0fa6f1..b02a2af 100755
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -198,6 +198,18 @@
 		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
 	endif()
 
+	if (NOT DEFINED TEST_FRAMEWORK_S)
+		message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.")
+	elseif (TEST_FRAMEWORK_S)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S")
+	endif()
+
+	if (NOT DEFINED TEST_FRAMEWORK_NS)
+		message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.")
+	elseif (TEST_FRAMEWORK_NS)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS")
+	endif()
+
 	#Set BL2 specific settings.
 	if (BL2)
 		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "BL2")
diff --git a/bl2/ext/mcuboot/CMakeLists.txt b/bl2/ext/mcuboot/CMakeLists.txt
index a661fbd..1713580 100644
--- a/bl2/ext/mcuboot/CMakeLists.txt
+++ b/bl2/ext/mcuboot/CMakeLists.txt
@@ -116,6 +116,18 @@
 #Add BL2 define to linker to resolve symbols in region_defs.h
 embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "BL2")
 
+if(NOT DEFINED TEST_FRAMEWORK_S)
+	message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.")
+elseif(TEST_FRAMEWORK_S)
+	embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TEST_FRAMEWORK_S")
+endif()
+
+if(NOT DEFINED TEST_FRAMEWORK_NS)
+	message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.")
+elseif(TEST_FRAMEWORK_NS)
+	embedded_set_target_link_defines(TARGET ${PROJECT_NAME} DEFINES "TEST_FRAMEWORK_NS")
+endif()
+
 #Link mbedcrypto library to project
 target_link_libraries(${PROJECT_NAME} "${MBEDTLS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX_C}mbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX_C}")
 add_dependencies(${PROJECT_NAME} ${MBEDTLS_TARGET_NAME}_install)
diff --git a/platform/ext/target/musca_a/partition/region_defs.h b/platform/ext/target/musca_a/partition/region_defs.h
index c8ad0b0..1770311 100755
--- a/platform/ext/target/musca_a/partition/region_defs.h
+++ b/platform/ext/target/musca_a/partition/region_defs.h
@@ -83,7 +83,14 @@
 #define S_CODE_LIMIT    (S_CODE_START + S_CODE_SIZE - 1)
 
 #define S_DATA_START    (S_RAM_ALIAS(0x0))
+
+#if defined(TEST_FRAMEWORK_S) || defined(TEST_FRAMEWORK_NS)
+/* Increase secure DATA area to run the regression tests on Musca A1 */
+#define S_DATA_SIZE     ((TOTAL_RAM_SIZE / 4) * 3)
+#else
 #define S_DATA_SIZE     (TOTAL_RAM_SIZE / 2)
+#endif
+
 #define S_DATA_LIMIT    (S_DATA_START + S_DATA_SIZE - 1)
 
 /* CMSE Veneers region */
@@ -96,8 +103,9 @@
 #define NS_CODE_SIZE    (IMAGE_CODE_SIZE - FLASH_AREA_BL2_SIZE)
 #define NS_CODE_LIMIT   (NS_CODE_START + NS_CODE_SIZE - 1)
 
-#define NS_DATA_START   (NS_RAM_ALIAS(TOTAL_RAM_SIZE / 2))
-#define NS_DATA_SIZE    (TOTAL_RAM_SIZE / 2)
+#define NS_DATA_START   (NS_RAM_ALIAS(S_DATA_SIZE))
+#define NS_DATA_SIZE    (TOTAL_RAM_SIZE - S_DATA_SIZE)
+
 #define NS_DATA_LIMIT   (NS_DATA_START + NS_DATA_SIZE - 1)
 
 /* NS partition information is used for MPC and SAU configuration */
diff --git a/platform/ext/target/musca_a/target_cfg.c b/platform/ext/target/musca_a/target_cfg.c
index 29fa48c..ed2a5a3 100755
--- a/platform/ext/target/musca_a/target_cfg.c
+++ b/platform/ext/target/musca_a/target_cfg.c
@@ -187,9 +187,23 @@
                                    ARM_MPC_ATTR_SECURE);
 
     mpc_data_region2->Initialize();
+
+#if defined(TEST_FRAMEWORK_S) || defined(TEST_FRAMEWORK_NS)
+    /* To run the regression tests on Musca A1, it is required to assign more
+     * RAM memory in the secure execution environment.
+     * So, the secure RAM memory size is 96KB and the non-secure one is 32 KB.
+     * When it is not required to run the regression tests, the RAM memory
+     * partition is the original one which is 64KB of the RAM memory for each
+     * execution environment.
+     */
+    mpc_data_region2->ConfigRegion(MPC_ISRAM2_RANGE_BASE_S,
+                                   MPC_ISRAM2_RANGE_LIMIT_S,
+                                   ARM_MPC_ATTR_SECURE);
+#else
     mpc_data_region2->ConfigRegion(MPC_ISRAM2_RANGE_BASE_NS,
                                    MPC_ISRAM2_RANGE_LIMIT_NS,
                                    ARM_MPC_ATTR_NONSECURE);
+#endif
 
     mpc_data_region3->Initialize();
     mpc_data_region3->ConfigRegion(MPC_ISRAM3_RANGE_BASE_NS,
diff --git a/secure_fw/CMakeLists.txt b/secure_fw/CMakeLists.txt
index 39b1897..03bdc3e 100644
--- a/secure_fw/CMakeLists.txt
+++ b/secure_fw/CMakeLists.txt
@@ -164,6 +164,18 @@
 		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TFM_PARTITION_TEST_SECURE_SERVICES")
 	endif()
 
+	if (NOT DEFINED TEST_FRAMEWORK_S)
+		message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_S is undefined.")
+	elseif (TEST_FRAMEWORK_S)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_S")
+	endif()
+
+	if (NOT DEFINED TEST_FRAMEWORK_NS)
+		message(FATAL_ERROR "Incomplete build configuration: TEST_FRAMEWORK_NS is undefined.")
+	elseif (TEST_FRAMEWORK_NS)
+		embedded_set_target_link_defines(TARGET ${EXE_NAME} DEFINES "TEST_FRAMEWORK_NS")
+	endif()
+
 	if (NOT DEFINED BL2)
 		message(FATAL_ERROR "Incomplete build configuration: BL2 is undefined. ")
 	elseif (BL2)