cmake: Move platform specific parts to platform dir

Rename Config*.cmake files to reflect the target they build for.
Add target specific configuration options to CMake files, and set the
proper values in the  Config*.cmake files.
Eliminate direct inclusion of cmsis core_cm33.h
Update build instructions

Change-Id: I7f506b45e649ce3a0d31cc5784c6a01e1710935c
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/CommonConfig.cmake b/CommonConfig.cmake
index 1040b3c..f479815 100644
--- a/CommonConfig.cmake
+++ b/CommonConfig.cmake
@@ -13,6 +13,31 @@
 	message(FATAL_ERROR "ERROR: Incomplete Configuration: BL2 not defined, Include this file from a Config*.cmake")
 endif()
 
+set(BUILD_CMSIS_CORE Off)
+set(BUILD_RETARGET Off)
+set(BUILD_NATIVE_DRIVERS Off)
+set(BUILD_TIME Off)
+set(BUILD_STARTUP Off)
+set(BUILD_TARGET_CFG Off)
+set(BUILD_TARGET_HARDWARE_KEYS Off)
+set(BUILD_CMSIS_DRIVERS Off)
+set(BUILD_UART_STDOUT Off)
+set(BUILD_FLASH Off)
+if(NOT DEFINED PLATFORM_CMAKE_FILE)
+	message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
+elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
+	message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
+else()
+	include(${PLATFORM_CMAKE_FILE})
+endif()
+
+
+#Use any ARMCLANG version found on PATH. Note: Only versions supported by the
+#build system will work. A file cmake/Common/CompilerArmClangXY.cmake
+#must be present with a matching version.
+include("Common/FindArmClang")
+include("Common/${ARMCLANG_MODULE}")
+
 ##Shared compiler and linker settings.
 function(config_setting_shared_flags tgt)
 	embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C FLAGS -xc -std=c99 -fshort-enums -mfpu=none -fshort-wchar -funsigned-char -mcmse -Wall -Werror)
@@ -83,11 +108,9 @@
 
 ##Secure side
 config_setting_shared_flags(tfm_s)
-embedded_set_target_linker_file(TARGET tfm_s PATH "${CMAKE_CURRENT_LIST_DIR}/platform/ext/target/mps2/an521/armclang/mps2_an521_s.sct")
 
 ##Non secure side
 config_setting_shared_flags(tfm_ns)
-embedded_set_target_linker_file(TARGET tfm_ns PATH  "${CMAKE_CURRENT_LIST_DIR}/platform/ext/target/mps2/an521/armclang/mps2_an521_ns.sct")
 
 ##TF-M storage
 config_setting_shared_flags(tfm_storage)
diff --git a/ConfigCoreTest.cmake b/ConfigCoreTest.cmake
index 7faeafc..6118ec6 100644
--- a/ConfigCoreTest.cmake
+++ b/ConfigCoreTest.cmake
@@ -7,20 +7,15 @@
 
 #This file holds information of a specific build configuration of this project.
 
-#Select platform specific build system settings file.
-set(PLATFORM_CMAKE_FILE "${CMAKE_CURRENT_LIST_DIR}/platform/ext/Mps2AN521.cmake")
-
-#Include board specific config (CPU, etc...)
-include("Common/BoardAN521")
-
-#Use any ARMCLANG version found on PATH. Note: Only versions supported by the
-#build system will work. A file cmake/Common/CompilerArmClangXY.cmake
-#must be present with a matching version.
-include("Common/FindArmClang")
-if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/cmake/Common/${ARMCLANG_MODULE}.cmake")
-    message(FATAL_ERROR "ERROR: Unsupported ARMCLANG compiler version found on PATH.")
+#Include board specific config (CPU, etc...), select platform specific build
+#system settings file
+if(NOT DEFINED TARGET_PLATFORM)
+	message(FATAL_ERROR "ERROR: TARGET_PLATFORM is not set in command line")
+elseif(${TARGET_PLATFORM} STREQUAL "AN521")
+	set(PLATFORM_CMAKE_FILE "${CMAKE_CURRENT_LIST_DIR}/platform/ext/Mps2AN521.cmake")
+else()
+	message(FATAL_ERROR "ERROR: Target \"${TARGET_PLATFORM}\" is not supported.")
 endif()
-include("Common/${ARMCLANG_MODULE}")
 
 ##These variables select how the projects are built. Each project will set
 #various project specific settings (e.g. what files to build, macro
@@ -30,4 +25,3 @@
 set (BL2 True)
 
 include ("${CMAKE_CURRENT_LIST_DIR}/CommonConfig.cmake")
-
diff --git a/ConfigDefault.cmake b/ConfigDefault.cmake
index 7aa18e0..358b098 100644
--- a/ConfigDefault.cmake
+++ b/ConfigDefault.cmake
@@ -7,20 +7,15 @@
 
 #This file holds information of a specific build configuration of this project.
 
-#Select platform specific build system settings file.
-set(PLATFORM_CMAKE_FILE "${CMAKE_CURRENT_LIST_DIR}/platform/ext/Mps2AN521.cmake")
-
-#Include board specific config (CPU, etc...)
-include("Common/BoardAN521")
-
-#Use any ARMCLANG version found on PATH. Note: Only versions supported by the
-#build system will work. A file cmake/Common/CompilerArmClangXY.cmake
-#must be present with a matching version.
-include("Common/FindArmClang")
-if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/cmake/Common/${ARMCLANG_MODULE}.cmake")
-    message(FATAL_ERROR "ERROR: Unsupported ARMCLANG compiler version found on PATH.")
+#Include board specific config (CPU, etc...), select platform specific build
+#system settings file
+if(NOT DEFINED TARGET_PLATFORM)
+	message(FATAL_ERROR "ERROR: TARGET_PLATFORM is not set in command line")
+elseif(${TARGET_PLATFORM} STREQUAL "AN521")
+	set(PLATFORM_CMAKE_FILE "${CMAKE_CURRENT_LIST_DIR}/platform/ext/Mps2AN521.cmake")
+else()
+	message(FATAL_ERROR "ERROR: Target \"${TARGET_PLATFORM}\" is not supported.")
 endif()
-include("Common/${ARMCLANG_MODULE}")
 
 ##These variables select how the projects are built. Each project will set
 #various project specific settings (e.g. what files to build, macro
@@ -30,4 +25,3 @@
 set (BL2 True)
 
 include ("${CMAKE_CURRENT_LIST_DIR}/CommonConfig.cmake")
-
diff --git a/ConfigRegression.cmake b/ConfigRegression.cmake
index 7e65ab1..3595aa7 100644
--- a/ConfigRegression.cmake
+++ b/ConfigRegression.cmake
@@ -7,20 +7,15 @@
 
 #This file holds information of a specific build configuration of this project.
 
-#Select platform specific build system settings file.
-set(PLATFORM_CMAKE_FILE "${CMAKE_CURRENT_LIST_DIR}/platform/ext/Mps2AN521.cmake")
-
-#Include board specific config (CPU, etc...)
-include("Common/BoardAN521")
-
-#Use any ARMCLANG version found on PATH. Note: Only versions supported by the
-#build system will work. A file cmake/Common/CompilerArmClangXY.cmake
-#must be present with a matching version.
-include("Common/FindArmClang")
-if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/cmake/Common/${ARMCLANG_MODULE}.cmake")
-    message(FATAL_ERROR "ERROR: Unsupported ARMCLANG compiler version found on PATH.")
+#Include board specific config (CPU, etc...), select platform specific build
+#system settings file
+if(NOT DEFINED TARGET_PLATFORM)
+	message(FATAL_ERROR "ERROR: TARGET_PLATFORM is not set in command line")
+elseif(${TARGET_PLATFORM} STREQUAL "AN521")
+	set(PLATFORM_CMAKE_FILE "${CMAKE_CURRENT_LIST_DIR}/platform/ext/Mps2AN521.cmake")
+else()
+	message(FATAL_ERROR "ERROR: Target \"${TARGET_PLATFORM}\" is not supported.")
 endif()
-include("Common/${ARMCLANG_MODULE}")
 
 ##These variables select how the projects are built. Each project will set
 #various project specific settings (e.g. what files to build, macro
@@ -30,4 +25,3 @@
 set (BL2 True)
 
 include ("${CMAKE_CURRENT_LIST_DIR}/CommonConfig.cmake")
-
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index b1e71c3..d32bb39 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -59,6 +59,11 @@
 	include(${PLATFORM_CMAKE_FILE})
 endif()
 
+if(NOT DEFINED NS_SCATTER_FILE_NAME)
+	message(FATAL_ERROR "ERROR: Incomplete Configuration: NS_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
+endif()
+embedded_set_target_linker_file(TARGET tfm_ns PATH  "${NS_SCATTER_FILE_NAME}")
+
 #Set include directories.
 embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR}/common/sct ABSOLUTE APPEND)
 embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${INTERFACE_DIR}/include ABSOLUTE APPEND)
@@ -72,7 +77,10 @@
 #Create an executable
 add_executable(${PROJECT_NAME} ${ALL_SRC_C} ${ALL_SRC_C_NS} ${ALL_SRC_ASM_NS} ${NS_APP_SRC})
 #Add the RTX library
-target_link_libraries(${PROJECT_NAME} "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib")
+if(NOT DEFINED RTX_LIB_PATH)
+	message(FATAL_ERROR "ERROR: Incomplete Configuration: RTX_LIB_PATH is not defined.")
+endif()
+target_link_libraries(${PROJECT_NAME} "${RTX_LIB_PATH}")
 #Set macro definitions
 target_compile_definitions(${PROJECT_NAME} PRIVATE __thumb2__ __DOMAIN_NS=1 __ARM_FEATURE_CMSE=3 LOG_MSG_HANDLER_MODE_PRINTF_ENABLED)
 
@@ -90,12 +98,17 @@
 
 	set(MCUBOOT_DIR ${TFM_ROOT_DIR}/bl2/ext/mcuboot)
 
+if(NOT DEFINED FLASH_LAYOUT)
+	message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
+endif()
+
 	add_custom_command(TARGET ${PROJECT_NAME}
 						POST_BUILD
 
 						#Create concatenated binary image from tfm_ns.bin and tfm_s.bin
 						COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
-						ARGS -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
+						ARGS -l ${FLASH_LAYOUT}
+							 -s $<TARGET_FILE_DIR:tfm_s>/tfm_s.bin
 							 -n $<TARGET_FILE_DIR:tfm_ns>/tfm_ns.bin
 							 -o ${CMAKE_BINARY_DIR}/tfm_full.bin
 
diff --git a/bl2/ext/mcuboot/CMakeLists.txt b/bl2/ext/mcuboot/CMakeLists.txt
index 0b9f279..dcc63e5 100644
--- a/bl2/ext/mcuboot/CMakeLists.txt
+++ b/bl2/ext/mcuboot/CMakeLists.txt
@@ -56,7 +56,6 @@
 	include(${PLATFORM_CMAKE_FILE})
 endif()
 
-
 #Append all our source files to global lists.
 list(APPEND ALL_SRC_C "${MCUBOOT_DIR}/bl2_main.c"
 		"${MCUBOOT_DIR}/flash_map.c"
@@ -99,9 +98,12 @@
 embedded_include_directories(PATH ${MBEDTLS_INSTALL_DIR}/include ABSOLUTE APPEND)
 
 #Define linker file
-embedded_set_target_linker_file(TARGET mcuboot PATH "${TFM_ROOT_DIR}/platform/ext/target/mps2/an521/armclang/mps2_an521_bl2.sct")
+if(NOT DEFINED BL2_LINKER_CONFIG)
+	message(FATAL_ERROR "ERROR: Incomplete Configuration: BL2_LINKER_CONFIG is not defined.")
+endif()
+embedded_set_target_linker_file(TARGET mcuboot PATH "${BL2_LINKER_CONFIG}")
 
-add_executable(${PROJECT_NAME} ${MCUBOOT_SRC} ${ALL_SRC_ASM_BL2} ${ALL_SRC_C} ${ALL_SRC_CXX})
+add_executable(${PROJECT_NAME} ${ALL_SRC_ASM_BL2} ${ALL_SRC_C} ${ALL_SRC_CXX})
 
 #Add BL2 define to linker to resolve symbols in region_defs.h
 set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " --predefine=\"-DBL2\"")
diff --git a/bl2/ext/mcuboot/scripts/assemble.py b/bl2/ext/mcuboot/scripts/assemble.py
index c2c5d18..b8b60eb 100644
--- a/bl2/ext/mcuboot/scripts/assemble.py
+++ b/bl2/ext/mcuboot/scripts/assemble.py
@@ -30,22 +30,22 @@
 size_re   = re.compile(r"^#define ([0-9A-Z_]+)_IMAGE_MAX_SIZE\s+((0x)?[0-9a-fA-F]+)")
 
 class Assembly():
-    def __init__(self, output):
+    def __init__(self, layout_path, output):
+        self.output = output
+        self.layout_path = layout_path
         self.find_slots()
         try:
             os.unlink(output)
         except OSError as e:
             if e.errno != errno.ENOENT:
                 raise
-        self.output = output
 
     def find_slots(self):
         offsets = {}
         sizes = {}
 
         scriptsDir = os.path.dirname(os.path.abspath(__file__))
-        path = '../../../../platform/ext/target/mps2/an521/partition/flash_layout.h'
-        configFile = os.path.join(scriptsDir, path)
+        configFile = os.path.join(scriptsDir, self.layout_path)
 
         with open(configFile, 'r') as fd:
             for line in fd:
@@ -81,6 +81,8 @@
 def main():
     parser = argparse.ArgumentParser()
 
+    parser.add_argument('-l', '--layout', required=True,
+            help='Location of the memory layout file')
     parser.add_argument('-s', '--secure', required=True,
             help='Unsigned secure image')
     parser.add_argument('-n', '--non_secure',
@@ -89,7 +91,7 @@
             help='Filename to write full image to')
 
     args = parser.parse_args()
-    output = Assembly(args.output)
+    output = Assembly(args.layout, args.output)
 
 
     output.add_image(args.secure, "SECURE")
diff --git a/cmake/Common/BoardAN521.cmake b/cmake/Common/BoardAN521.cmake
deleted file mode 100644
index e4135e5..0000000
--- a/cmake/Common/BoardAN521.cmake
+++ /dev/null
@@ -1,11 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2017, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-
-#Set some global variables our build system uses.
-
-#This board has a Cortex M33 CPU.
-include("Common/CpuM33")
diff --git a/cmake/Common/FindArmClang.cmake b/cmake/Common/FindArmClang.cmake
index 7e02f51..08d743e 100644
--- a/cmake/Common/FindArmClang.cmake
+++ b/cmake/Common/FindArmClang.cmake
@@ -111,3 +111,6 @@
 
 STRING(REGEX REPLACE "([0-9]+)\.([0-9]+)(\.[0-9]+)*.*" "CompilerArmClang\\1\\2" ARMCLANG_MODULE "${ARMCLANG_VER}")
 
+if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${ARMCLANG_MODULE}.cmake")
+	message(FATAL_ERROR "ERROR: Unsupported ARMCLANG compiler version found on PATH.")
+endif()
diff --git a/docs/user_guides/tfm_build_instruction.md b/docs/user_guides/tfm_build_instruction.md
index ed22433..b7fba99 100644
--- a/docs/user_guides/tfm_build_instruction.md
+++ b/docs/user_guides/tfm_build_instruction.md
@@ -13,7 +13,7 @@
 
 Both need to be cloned manually in the current release.
 
-### Build steps:
+### Build steps for the AN521 FPGA:
 
 ```
 cd <TF-M base folder>
@@ -23,13 +23,28 @@
 cd trusted-firmware-m
 mkdir cmake_build
 cd cmake_build
-cmake ../ -G"Unix Makefiles"
+cmake ../ -G"Unix Makefiles" -DTARGET_PLATFORM=AN521
 make
 ```
 
-### Regression Tests
+### Concept of build config files
+The build configuration for TF-M is provided to the build system by two
+different components:
+* The way applications are built is specified by providing one of the
+`Config<APP_NAME>.cmake` files to the build system. This can be done by adding
+the `` -DPROJ_CONFIG=<absolute file path> `` i.e. on Linux:
+`` -DPROJ_CONFIG=`readlink -f ../ConfigRegression.cmake` `` parameter to the
+cmake command. (See examples below.)
+* The target platform can be specified by adding the
+`-DTARGET_PLATFORM=<target platform name>` option to the cmake command (See
+  examples below.)
+
+*Note* For all the applications we build the level 2 bootloader
+
+### Regression Tests for AN521
 The default option build doesn't include regression tests. Procedure for
-building the regression tests is below.
+building the regression tests is below. Compiling for other target hardware
+is possible by selecting a different build config file.
 
 `It is recommended that tests are built in a different directory.`
 
@@ -40,7 +55,7 @@
 cd trusted-firmware-m
 mkdir cmake_test
 cd cmake_test
-cmake -G"Unix Makefiles" -DPROJ_CONFIG=`readlink -f ../ConfigRegression.cmake` ../
+cmake -G"Unix Makefiles" -DPROJ_CONFIG=`readlink -f ../ConfigRegression.cmake` -DTARGET_PLATFORM=AN521 ../
 make
 ```
 
@@ -51,7 +66,7 @@
 cd trusted-firmware-m
 mkdir cmake_test
 cd cmake_test
-cmake -G"Unix Makefiles" -DPROJ_CONFIG=`cygpath -m ../ConfigRegression.cmake` ../
+cmake -G"Unix Makefiles" -DPROJ_CONFIG=`cygpath -m ../ConfigRegression.cmake` -DTARGET_PLATFORM=AN521 ../
 make
 ```
 
@@ -63,14 +78,14 @@
 *On Windows*
 
 ```
-cmake -G"Unix Makefiles" -DPROJ_CONFIG=`cygpath -m ../ConfigRegression.cmake` ../
+cmake -G"Unix Makefiles" -DPROJ_CONFIG=`cygpath -m ../ConfigRegression.cmake` -DTARGET_PLATFORM=AN521 ../
 make install
 ```
 
 *On Linux*
 
 ```
-cmake -G"Unix Makefiles" -DPROJ_CONFIG=`readlink -f ../ConfigRegression.cmake` ../
+cmake -G"Unix Makefiles" -DPROJ_CONFIG=`readlink -f ../ConfigRegression.cmake` -DTARGET_PLATFORM=AN521 ../
 make install
 ```
 
diff --git a/platform/ext/Mps2AN521.cmake b/platform/ext/Mps2AN521.cmake
index 80190f4..b63e9db 100644
--- a/platform/ext/Mps2AN521.cmake
+++ b/platform/ext/Mps2AN521.cmake
@@ -7,8 +7,25 @@
 
 #This file gathers all MPS2/AN521 specific files in the application.
 
+#MPS2/AN521 has a Cortex M33 CPU.
+include("Common/CpuM33")
+
 set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR})
 
+#Specify the location of platform specific build dependencies.
+set (BL2_SCATTER_FILE_NAME "${PLATFORM_DIR}/target/mps2/an521/armclang/mps2_an521_bl2.sct")
+set (S_SCATTER_FILE_NAME   "${PLATFORM_DIR}/target/mps2/an521/armclang/mps2_an521_s.sct")
+set (NS_SCATTER_FILE_NAME  "${PLATFORM_DIR}/target/mps2/an521/armclang/mps2_an521_ns.sct")
+set (FLASH_LAYOUT          "${PLATFORM_DIR}/target/mps2/an521/partition/flash_layout.h")
+if (DEFINED CMSIS_5_DIR)
+  # not all project defines CMSIS_5_DIR, only the ones that use it.
+  set (RTX_LIB_PATH "${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib")
+endif()
+
+if (BL2)
+  set (BL2_LINKER_CONFIG ${BL2_SCATTER_FILE_NAME})
+endif()
+
 embedded_include_directories(PATH "${PLATFORM_DIR}/cmsis" ABSOLUTE)
 embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2" ABSOLUTE)
 embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an521" ABSOLUTE)
@@ -33,7 +50,7 @@
 if (NOT DEFINED BUILD_UART_STDOUT)
   message(FATAL_ERROR "Configuration variable BUILD_UART_STDOUT (true|false) is undefined!")
 elseif(BUILD_UART_STDOUT)
-  LIST(APPEND ALL_SRC_C "${PLATFORM_DIR}/common/uart_stdout.c")
+  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/common/uart_stdout.c")
   embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
   set(BUILD_NATIVE_DRIVERS true)
   set(BUILD_CMSIS_DRIVERS true)
@@ -52,7 +69,7 @@
 if (NOT DEFINED BUILD_TIME)
   message(FATAL_ERROR "Configuration variable BUILD_TIME (true|false) is undefined!")
 elseif(BUILD_TIME)
-  LIST(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/mps2/an521/native_drivers/timer_cmsdk/timer_cmsdk.c")
+  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/mps2/an521/native_drivers/timer_cmsdk/timer_cmsdk.c")
   embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an521/native_drivers/timer_cmsdk" ABSOLUTE)
 endif()
 
@@ -77,15 +94,15 @@
 if (NOT DEFINED BUILD_TARGET_HARDWARE_KEYS)
   message(FATAL_ERROR "Configuration variable BUILD_TARGET_HARDWARE_KEYS (true|false) is undefined!")
 elseif(BUILD_TARGET_HARDWARE_KEYS)
-  LIST(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/mps2/an521/dummy_crypto_keys.c")
+  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/mps2/an521/dummy_crypto_keys.c")
 endif()
 
 if (NOT DEFINED BUILD_CMSIS_DRIVERS)
   message(FATAL_ERROR "Configuration variable BUILD_CMSIS_DRIVERS (true|false) is undefined!")
 elseif(BUILD_CMSIS_DRIVERS)
-  LIST(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/mps2/an521/cmsis_drivers/Driver_MPC.c"
+  list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/mps2/an521/cmsis_drivers/Driver_MPC.c"
     "${PLATFORM_DIR}/target/mps2/an521/cmsis_drivers/Driver_PPC.c")
-  LIST(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/mps2/an521/cmsis_drivers/Driver_USART.c")
+  list(APPEND ALL_SRC_C "${PLATFORM_DIR}/target/mps2/an521/cmsis_drivers/Driver_USART.c")
   embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an521/cmsis_drivers" ABSOLUTE)
   embedded_include_directories(PATH "${PLATFORM_DIR}/driver" ABSOLUTE)
 endif()
diff --git a/platform/ext/target/mps2/an521/cmsis_core/cmsis_cpu.h b/platform/ext/target/mps2/an521/cmsis_core/cmsis_cpu.h
new file mode 100644
index 0000000..b94fcd9
--- /dev/null
+++ b/platform/ext/target/mps2/an521/cmsis_core/cmsis_cpu.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016-2018 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CMSIS_CPU_H__
+#define __CMSIS_CPU_H__
+
+/* --------  Configuration of the Cortex-M33 Processor and Core Peripherals  ------ */
+#define __CM33_REV                0x0000U   /* Core revision r0p1 */
+#define __MPU_PRESENT             1U        /* MPU present */
+#define __SAUREGION_PRESENT       1U        /* SAU regions present */
+#define __VTOR_PRESENT            1U        /* VTOR present */
+#define __NVIC_PRIO_BITS          3U        /* Number of Bits used for Priority Levels */
+#define __Vendor_SysTickConfig    0U        /* Set to 1 if different SysTick Config is used */
+#define __FPU_PRESENT             0U        /* no FPU present */
+#define __DSP_PRESENT             0U        /* no DSP extension present */
+
+#include "core_cm33.h"
+
+#endif /* __CMSIS_CPU_H__ */
diff --git a/platform/ext/target/mps2/an521/cmsis_core/mps2_an521.h b/platform/ext/target/mps2/an521/cmsis_core/mps2_an521.h
index ee6581b..a42670a 100644
--- a/platform/ext/target/mps2/an521/cmsis_core/mps2_an521.h
+++ b/platform/ext/target/mps2/an521/cmsis_core/mps2_an521.h
@@ -19,17 +19,7 @@
 
 #include "platform_irq.h"         /* Platform IRQ numbers */
 
-/* --------  Configuration of the Cortex-M33 Processor and Core Peripherals  ------ */
-#define __CM33_REV                0x0000U   /* Core revision r0p1 */
-#define __MPU_PRESENT             1U        /* MPU present */
-#define __SAUREGION_PRESENT       1U        /* SAU regions present */
-#define __VTOR_PRESENT            1U        /* VTOR present */
-#define __NVIC_PRIO_BITS          3U        /* Number of Bits used for Priority Levels */
-#define __Vendor_SysTickConfig    0U        /* Set to 1 if different SysTick Config is used */
-#define __FPU_PRESENT             0U        /* no FPU present */
-#define __DSP_PRESENT             0U        /* no DSP extension present */
-
-#include <core_cm33.h>                 /* Processor and core peripherals */
+#include "cmsis_cpu.h"                 /* Processor and core peripherals */
 #include "system_cmsdk_mps2_an521.h"   /* System Header */
 
 #include "platform_regs.h"        /* Platform registers */
diff --git a/secure_fw/CMakeLists.txt b/secure_fw/CMakeLists.txt
index efc4e55..ab698c3 100644
--- a/secure_fw/CMakeLists.txt
+++ b/secure_fw/CMakeLists.txt
@@ -51,6 +51,11 @@
 	include(${PLATFORM_CMAKE_FILE})
 endif()
 
+if(NOT DEFINED S_SCATTER_FILE_NAME)
+	message(FATAL_ERROR "ERROR: Incomplete Configuration: S_SCATTER_FILE_NAME not defined, Include this file from a Config*.cmake")
+endif()
+embedded_set_target_linker_file(TARGET tfm_s PATH "${S_SCATTER_FILE_NAME}")
+
 embedded_target_include_directories(TARGET ${PROJECT_NAME} PATH ${TFM_ROOT_DIR} ABSOLUTE APPEND)
 
 #Specify what we build
diff --git a/secure_fw/spm/mpu_armv8m_drv.c b/secure_fw/spm/mpu_armv8m_drv.c
index 05f5a93..4e82e82 100644
--- a/secure_fw/spm/mpu_armv8m_drv.c
+++ b/secure_fw/spm/mpu_armv8m_drv.c
@@ -6,7 +6,7 @@
  */
 
 #include "mpu_armv8m_drv.h"
-#include "core_cm33.h"
+#include "cmsis_cpu.h"
 
 /*
  * FixMe: