Examples: Fix split build

Signed-off-by: Gergely Korcsák <gergely.korcsak@arm.com>
Change-Id: Iaee666cf02b3ee784c129dc5ec1410e29a3f91ec
diff --git a/examples/corstone310_fvp_dma/clcd_example/CMakeLists.txt b/examples/corstone310_fvp_dma/clcd_example/CMakeLists.txt
index 4f765d0..8452ca7 100644
--- a/examples/corstone310_fvp_dma/clcd_example/CMakeLists.txt
+++ b/examples/corstone310_fvp_dma/clcd_example/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2021-2023, Arm Limited. All rights reserved.
+# Copyright (c) 2021-2024, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -9,46 +9,42 @@
 
 ############################# External Dependencies ############################################
 
+if (NOT DEFINED CONFIG_SPE_PATH OR NOT EXISTS ${CONFIG_SPE_PATH})
+    message(FATAL_ERROR "CONFIG_SPE_PATH = ${CONFIG_SPE_PATH} is not defined or incorrect. Please provide full path to TF-M build artifacts using -DCONFIG_SPE_PATH=")
+endif()
+
+list(APPEND CMAKE_MODULE_PATH ${CONFIG_SPE_PATH}/cmake)
+
+# A platform specific MCPU and architecture flags for NS side
+include(${CONFIG_SPE_PATH}/platform/cpuarch.cmake)
+# Include common configs exported from TF-M
+include(${CONFIG_SPE_PATH}/cmake/spe_config.cmake)
+
+# Select toolchain file if it is not specified via command line or the absolute path
+# is unavailable.
+if (NOT DEFINED TFM_TOOLCHAIN_FILE)
+    if (NOT DEFINED TFM_TOOLCHAIN)
+        set(TFM_TOOLCHAIN "GNUARM")
+        message(WARNING "TFM_TOOLCHAIN or TFM_TOOLCHAIN_FILE is not defined")
+        message(WARNING "TFM_TOOLCHAIN is set to ${TFM_TOOLCHAIN}")
+    endif()
+    set(TFM_TOOLCHAIN_FILE    ${CONFIG_SPE_PATH}/cmake/toolchain_ns_${TFM_TOOLCHAIN}.cmake)
+endif()
+
+include(${TFM_TOOLCHAIN_FILE})
+project("TF-M Example"  LANGUAGES C)
+tfm_toolchain_reload_compiler()
+
 set(FREERTOS_SRC_PATH     "DOWNLOAD"  CACHE PATH  "Path to FreeRTOS kernel (or DOWNLOAD to fetch automatically")
 
 add_subdirectory(ext/freertos-kernel freertos-kernel)
 
-############################# Common variables ############################################
-
-# In actual NS integration, NS side build should include the source files
-# exported by TF-M build.
-# Directly include interface folder to simplify the NS build in this demo, since
-# install always occurs at the end of build.
-set(INTERFACE_SRC_DIR    ${CMAKE_SOURCE_DIR}/interface/src)
-set(INTERFACE_INC_DIR    ${CMAKE_SOURCE_DIR}/interface/include)
-set(TFM_SRC_DIR          ${CMAKE_SOURCE_DIR})
-
-#################### TF-M NS interface (header only) ###########################
-
-add_library(tfm_ns_interface INTERFACE)
-
-# Include interface headers exported by TF-M
-target_include_directories(tfm_ns_interface
-    INTERFACE
-        ${INTERFACE_INC_DIR}
-        ${CMAKE_BINARY_DIR}/generated/interface/include
-)
-
-# Include selection of Secure Partitions from TF-M build.
-# It can be replaced by NS side configurations later.
-target_link_libraries(tfm_ns_interface
-    INTERFACE
-        tfm_config
-)
-
 ############################# TFM NS app #######################################
 
 add_executable(tfm_ns)
 
-target_add_scatter_file(tfm_ns
-    $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/freertos-demo/corstone310_freertos.sct>
-    $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/corstone310_freertos.ld>
-)
+# The exported TF-M interfaces
+add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
 
 target_sources(tfm_ns
     PRIVATE
@@ -66,18 +62,18 @@
         # CLCD files
         clcd_lib/clcd_mps3_lib.c
         clcd_lib/clcd_mps3_drv.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/drivers/timer/armv8m/systimer_armv8-m_drv.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/timer/armv8m/systimer_armv8-m_drv.c
 
         # DMA350 unprivileged-specific files
         dma350_lib/dma350_lib_unprivileged.c
 
         # DMA350 files
         device_definition.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/native_drivers/dma350_ch_drv.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/native_drivers/dma350_drv.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/libraries/dma350_lib.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/libraries/dma350_checker_layer.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/device/source/dma350_address_remap.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_checker_layer.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_ch_drv.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_drv.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_lib.c
+        ${CONFIG_SPE_PATH}/platform/device/source/dma350_address_remap.c
 
         # freeRTOS kernel files
         ${FREERTOS_SRC_PATH}/portable/Common/mpu_wrappers.c
@@ -91,6 +87,12 @@
         ${FREERTOS_SRC_PATH}/event_groups.c
         ${FREERTOS_SRC_PATH}/portable/MemMang/heap_4.c
         ${FREERTOS_SRC_PATH}/portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c
+
+        # GNU Arm compiler version greater equal than *11.3.Rel1*
+        # has a linker issue that required system calls are missing,
+        # such as _read and _write. Add stub functions of required
+        # system calls to solve this issue.
+        $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:syscalls_stub.c>
 )
 
 target_include_directories(tfm_ns
@@ -100,29 +102,27 @@
         dma350_lib/
         freertos-config/
         amazon-freertos/
-        ${INTERFACE_INC_DIR}/
-        ${TFM_SRC_DIR}/platform/ext/target/arm/drivers/timer/armv8m/
+        ${CONFIG_SPE_PATH}/interface/include/
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/timer/armv8m/
         # freeRTOS kernel
         ${FREERTOS_SRC_PATH}/include/
         ${FREERTOS_SRC_PATH}/portable/GCC/ARM_CM85_NTZ/non_secure/
 
         # DMA350
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/native_drivers
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/libraries
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350
 )
 
 target_compile_definitions(tfm_ns
     PRIVATE
-        MBEDTLS_CONFIG_FILE="aws_mbedtls_config.h"
         # Needed for DMA-350 library
-        CMSIS_device_header=<corstone310.h>
+        CMSIS_device_header=<cmsis.h>
 )
 
 target_link_libraries(tfm_ns
     PRIVATE
         platform_ns
         tfm_api_ns
-        tfm_s_veneers
+        $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:tfm_api_ns_tz>
 )
 
 set_target_properties(tfm_ns PROPERTIES
@@ -130,6 +130,17 @@
     RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
 )
 
+if(${CMAKE_C_COMPILER_ID} STREQUAL "ARMClang")
+set_property(TARGET platform_ns PROPERTY INTERFACE_LINK_DEPENDS
+    ${CMAKE_CURRENT_SOURCE_DIR}/freertos-demo/corstone310_freertos.sct
+)
+elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
+set_property(TARGET platform_ns PROPERTY INTERFACE_LINK_DEPENDS
+    ${CMAKE_CURRENT_SOURCE_DIR}/corstone310_freertos.ld
+)
+endif()
+target_add_scatter_file(tfm_ns)
+
 target_link_options(tfm_ns
     PRIVATE
         $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
@@ -141,30 +152,6 @@
 
 ###################### TF-M NS interface api (NS lib) ##########################
 
-add_library(tfm_api_ns STATIC)
-
 target_sources(tfm_api_ns PRIVATE
-    $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_api.c>
-
+    ${CONFIG_SPE_PATH}/interface/src/os_wrapper/tfm_ns_interface_rtos.c
 )
-
-target_sources(tfm_api_ns PRIVATE
-    ${INTERFACE_SRC_DIR}/tfm_tz_psa_ns_api.c
-    ${INTERFACE_SRC_DIR}/os_wrapper/tfm_ns_interface_rtos.c
-)
-
-target_include_directories(tfm_api_ns PUBLIC
-    ${TFM_TEST_REPO_PATH}/ns_interface
-)
-
-target_link_libraries(tfm_api_ns
-    PUBLIC
-        tfm_ns_interface
-    PRIVATE
-        platform_ns
-)
-
-############################# CMSIS ############################################
-
-# Platform cmake config adds sources to CMSIS_5_tfm_ns, so we need to define it, but it is unused.
-add_library(CMSIS_5_tfm_ns INTERFACE)
diff --git a/examples/corstone310_fvp_dma/clcd_example/RTE_Components.h b/examples/corstone310_fvp_dma/clcd_example/RTE_Components.h
new file mode 100644
index 0000000..2772267
--- /dev/null
+++ b/examples/corstone310_fvp_dma/clcd_example/RTE_Components.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
+ *
+ * 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.
+ */
+
+//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
+
+#ifndef __RTE_DEVICE_H
+#define __RTE_DEVICE_H
+
+// <q> USART (Universal synchronous - asynchronous receiver transmitter) [Driver_USART0]
+// <i> Configuration settings for Driver_USART0 in component ::Drivers:USART
+#define   RTE_USART0                                1
+
+#endif  /* __RTE_DEVICE_H */
diff --git a/examples/corstone310_fvp_dma/clcd_example/corstone310_freertos.ld b/examples/corstone310_fvp_dma/clcd_example/corstone310_freertos.ld
index a3c7615..09b7328 100644
--- a/examples/corstone310_fvp_dma/clcd_example/corstone310_freertos.ld
+++ b/examples/corstone310_fvp_dma/clcd_example/corstone310_freertos.ld
@@ -1,6 +1,6 @@
 
 ;/*
-; * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
+; * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -39,6 +39,30 @@
         __Vectors_End = .;
         __Vectors_Size = __Vectors_End - __Vectors;
         __end__ = .;
+
+    /* To copy multiple ROM to RAM sections,
+     * define etext2/data2_start/data2_end and
+     * define __STARTUP_COPY_MULTIPLE in startup_cmsdk_mps3_an524_ns.S */
+        . = ALIGN(4);
+        __copy_table_start__ = .;
+        LONG (__etext)
+        LONG (__data_start__)
+        LONG ((__data_end__ - __data_start__) / 4)
+        LONG (DEFINED(__etext2) ? __etext2 : 0)
+        LONG (DEFINED(__data2_start__) ? __data2_start__ : 0)
+        LONG (DEFINED(__data2_start__) ? ((__data2_end__ - __data2_start__) / 4) : 0)
+        __copy_table_end__ = .;
+
+    /* To clear multiple BSS sections,
+     * uncomment .zero.table section and,
+     * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_cmsdk_mps3_an524_ns.S */
+        . = ALIGN(4);
+        __zero_table_start__ = .;
+        LONG (__bss_start__)
+        LONG ((__bss_end__ - __bss_start__) / 4)
+        LONG (DEFINED(__bss2_start__) ? __bss2_start__ : 0)
+        LONG (DEFINED(__bss2_start__) ? ((__bss2_end__ - __bss2_start__) / 4) : 0)
+        __zero_table_end__ = .;
     } > FLASH
     /* Privileged functions - Section needs to be 32 byte aligned to satisfy MPU requirements. */
     .privileged_functions : ALIGN(32)
@@ -95,35 +119,6 @@
         *(.ARM.exidx* .gnu.linkonce.armexidx.*)
     } > FLASH
     __exidx_end = .;
-    /* To copy multiple ROM to RAM sections,
-     * define etext2/data2_start/data2_end and
-     * define __STARTUP_COPY_MULTIPLE in startup_cmsdk_mps3_an524_ns.S */
-    .copy.table :
-    {
-        . = ALIGN(4);
-        __copy_table_start__ = .;
-        LONG (__etext)
-        LONG (__data_start__)
-        LONG ((__data_end__ - __data_start__) / 4)
-        LONG (DEFINED(__etext2) ? __etext2 : 0)
-        LONG (DEFINED(__data2_start__) ? __data2_start__ : 0)
-        LONG (DEFINED(__data2_start__) ? ((__data2_end__ - __data2_start__) / 4) : 0)
-        __copy_table_end__ = .;
-    } > FLASH
-
-    /* To clear multiple BSS sections,
-     * uncomment .zero.table section and,
-     * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_cmsdk_mps3_an524_ns.S */
-    .zero.table :
-    {
-        . = ALIGN(4);
-        __zero_table_start__ = .;
-        LONG (__bss_start__)
-        LONG ((__bss_end__ - __bss_start__) / 4)
-        LONG (DEFINED(__bss2_start__) ? __bss2_start__ : 0)
-        LONG (DEFINED(__bss2_start__) ? ((__bss2_end__ - __bss2_start__) / 4) : 0)
-        __zero_table_end__ = .;
-    } > FLASH
 
     __etext = ALIGN(4);
 
diff --git a/examples/corstone310_fvp_dma/clcd_example/freertos-demo/section_limits.c b/examples/corstone310_fvp_dma/clcd_example/freertos-demo/section_limits.c
index c72e357..f809a84 100644
--- a/examples/corstone310_fvp_dma/clcd_example/freertos-demo/section_limits.c
+++ b/examples/corstone310_fvp_dma/clcd_example/freertos-demo/section_limits.c
@@ -1,16 +1,45 @@
+/*
+ * FreeRTOS Kernel V10.4.1
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
+ * Copyright (c) 2024, Arm Limited. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://www.FreeRTOS.org
+ * http://aws.amazon.com/freertos
+ *
+ * 1 tab == 4 spaces!
+ */
+
 #include "stdint.h"
+#include "region.h"
 
-extern uint32_t Image$$ER_IROM_NS_FREERTOS_SYSTEM_CALLS$$Base;
-extern uint32_t Image$$ER_IROM_NS_FREERTOS_SYSTEM_CALLS_ALIGN$$Limit;
-extern uint32_t Image$$ER_IROM_NS_PRIVILEGED$$Base;
-extern uint32_t Image$$ER_IROM_NS_PRIVILEGED_ALIGN$$Limit;
-extern uint32_t Image$$ER_IROM_NS_UNPRIVILEGED$$Base;
-extern uint32_t Image$$ER_IROM_NS_UNPRIVILEGED_ALIGN$$Limit;
+REGION_DECLARE(Image$$, ER_IROM_NS_FREERTOS_SYSTEM_CALLS, $$Base);
+REGION_DECLARE(Image$$, ER_IROM_NS_FREERTOS_SYSTEM_CALLS_ALIGN, $$Limit);
+REGION_DECLARE(Image$$, ER_IROM_NS_PRIVILEGED, $$Base);
+REGION_DECLARE(Image$$, ER_IROM_NS_PRIVILEGED_ALIGN, $$Limit);
+REGION_DECLARE(Image$$, ER_IROM_NS_UNPRIVILEGED, $$Base);
+REGION_DECLARE(Image$$, ER_IROM_NS_UNPRIVILEGED_ALIGN, $$Limit);
 
-extern uint32_t Image$$ER_IRAM_NS_PRIVILEGED$$Base;
-extern uint32_t Image$$ER_IRAM_NS_PRIVILEGED_ALIGN$$Limit;
-extern uint32_t Image$$ER_IRAM_NS_UNPRIVILEGED$$Base;
-extern uint32_t Image$$ER_IRAM_NS_UNPRIVILEGED_ALIGN$$Limit;
+REGION_DECLARE(Image$$, ER_IRAM_NS_PRIVILEGED, $$Base);
+REGION_DECLARE(Image$$, ER_IRAM_NS_PRIVILEGED_ALIGN, $$Limit);
+REGION_DECLARE(Image$$, ER_IRAM_NS_UNPRIVILEGED, $$Base);
+REGION_DECLARE(Image$$, ER_IRAM_NS_UNPRIVILEGED_ALIGN, $$Limit);
 
 /* Privileged flash. */
 const uint32_t * __privileged_functions_start__		= ( uint32_t * ) &( Image$$ER_IROM_NS_PRIVILEGED$$Base );
diff --git a/examples/corstone310_fvp_dma/clcd_example/syscalls_stub.c b/examples/corstone310_fvp_dma/clcd_example/syscalls_stub.c
new file mode 100644
index 0000000..9ebe78e
--- /dev/null
+++ b/examples/corstone310_fvp_dma/clcd_example/syscalls_stub.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * NOTE: When GNU Arm compiler version greater equal than *11.3.Rel1*, there is a linker issue that
+ * some system calls are not implemented, such as _close, _fstat and _getpid etc. So add this file
+ * including stub functions of system calls to avoid the above linker issue.
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+
+__attribute__((weak))
+void _close(void)
+{
+}
+
+__attribute__((weak))
+void _fstat(void)
+{
+}
+
+__attribute__((weak))
+void _getpid(void)
+{
+}
+
+__attribute__((weak))
+void _isatty(void)
+{
+}
+
+__attribute__((weak))
+void _kill(void)
+{
+}
+
+__attribute__((weak))
+void _lseek(void)
+{
+}
+
+__attribute__((weak))
+void _read(void)
+{
+}
+
+__attribute__((weak))
+void _write(void)
+{
+}
diff --git a/examples/corstone310_fvp_dma/dma350_ns/CMakeLists.txt b/examples/corstone310_fvp_dma/dma350_ns/CMakeLists.txt
index 4a16186..d7f287f 100644
--- a/examples/corstone310_fvp_dma/dma350_ns/CMakeLists.txt
+++ b/examples/corstone310_fvp_dma/dma350_ns/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2023, Arm Limited. All rights reserved.
+# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -12,17 +12,16 @@
 target_sources(tfm_test_suite_extra_ns
     PRIVATE
         ${CMAKE_CURRENT_SOURCE_DIR}/dma350_ns_test.c
-        ${CONFIG_SPE_PATH}/platform/native_drivers/dma350_ch_drv.c
-        ${CONFIG_SPE_PATH}/platform/native_drivers/dma350_drv.c
-        ${CONFIG_SPE_PATH}/platform/libraries/dma350_lib.c
-        ${CONFIG_SPE_PATH}/platform/libraries/dma350_checker_layer.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_ch_drv.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_drv.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_lib.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_checker_layer.c
         ${CONFIG_SPE_PATH}/platform/device/source/dma350_address_remap.c
 )
 
 target_include_directories(tfm_test_suite_extra_ns
     PRIVATE
-        ${CONFIG_SPE_PATH}/platform/native_drivers
-        ${CONFIG_SPE_PATH}/platform/libraries
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350
 )
 
 target_compile_definitions(tfm_test_suite_extra_ns
@@ -34,4 +33,6 @@
 target_link_libraries(tfm_test_suite_extra_ns
     PRIVATE
         platform_ns
+        tfm_api_ns
+        $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:tfm_api_ns_tz>
 )
diff --git a/examples/corstone310_fvp_dma/triggering_example/CMakeLists.txt b/examples/corstone310_fvp_dma/triggering_example/CMakeLists.txt
index 21eb9ac..6c90ae5 100644
--- a/examples/corstone310_fvp_dma/triggering_example/CMakeLists.txt
+++ b/examples/corstone310_fvp_dma/triggering_example/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
+# Copyright (c) 2022-2024, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -7,66 +7,77 @@
 
 ############################# Configuration ############################################
 
+############################# External Dependencies ############################################
 
-############################# Common variables ############################################
-set(TFM_SRC_DIR          ${CMAKE_SOURCE_DIR})
+if (NOT DEFINED CONFIG_SPE_PATH OR NOT EXISTS ${CONFIG_SPE_PATH})
+    message(FATAL_ERROR "CONFIG_SPE_PATH = ${CONFIG_SPE_PATH} is not defined or incorrect. Please provide full path to TF-M build artifacts using -DCONFIG_SPE_PATH=")
+endif()
 
-#################### TF-M NS interface (header only) ###########################
+list(APPEND CMAKE_MODULE_PATH ${CONFIG_SPE_PATH}/cmake)
 
-add_library(tfm_ns_interface INTERFACE)
+# A platform specific MCPU and architecture flags for NS side
+include(${CONFIG_SPE_PATH}/platform/cpuarch.cmake)
+# Include common configs exported from TF-M
+include(${CONFIG_SPE_PATH}/cmake/spe_config.cmake)
 
-# Include interface headers exported by TF-M
-target_include_directories(tfm_ns_interface
-    INTERFACE
-        ${INTERFACE_INC_DIR}
-        ${CMAKE_BINARY_DIR}/generated/interface/include
-)
+# Select toolchain file if it is not specified via command line or the absolute path
+# is unavailable.
+if (NOT DEFINED TFM_TOOLCHAIN_FILE)
+    if (NOT DEFINED TFM_TOOLCHAIN)
+        set(TFM_TOOLCHAIN "GNUARM")
+        message(WARNING "TFM_TOOLCHAIN or TFM_TOOLCHAIN_FILE is not defined")
+        message(WARNING "TFM_TOOLCHAIN is set to ${TFM_TOOLCHAIN}")
+    endif()
+    set(TFM_TOOLCHAIN_FILE    ${CONFIG_SPE_PATH}/cmake/toolchain_ns_${TFM_TOOLCHAIN}.cmake)
+endif()
 
-# Include selection of Secure Partitions from TF-M build.
-# It can be replaced by NS side configurations later.
-target_link_libraries(tfm_ns_interface
-    INTERFACE
-        tfm_config
-)
-
-###################### TF-M NS interface api (NS lib) ##########################
-# TF-M NS interface api is needed even if there's no communication
-# between the S and NS sides.
-add_library(tfm_api_ns INTERFACE)
+include(${TFM_TOOLCHAIN_FILE})
+project("TF-M Example"  LANGUAGES C)
+tfm_toolchain_reload_compiler()
 
 ############################# TFM NS app #######################################
 
 add_executable(tfm_ns)
 
+# The exported TF-M interfaces
+add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
+
 target_include_directories(tfm_ns
     PRIVATE
-        ${TFM_SRC_DIR}/platform/ext/target/arm/drivers/usart/cmsdk
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/usart/cmsdk
 
         # DMA350
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/native_drivers
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/libraries
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350
 )
 
 target_sources(tfm_ns
     PRIVATE
         main_ns.c
+        ${CONFIG_SPE_PATH}/interface/src/os_wrapper/tfm_ns_interface_bare_metal.c
         # DMA350 files
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/native_drivers/dma350_ch_drv.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/native_drivers/dma350_drv.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/libraries/dma350_lib.c
-        ${TFM_SRC_DIR}/platform/ext/target/arm/mps3/corstone310/fvp/device/source/dma350_address_remap.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_ch_drv.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_drv.c
+        ${CONFIG_SPE_PATH}/platform/ext/target/arm/drivers/dma/dma350/dma350_lib.c
+        ${CONFIG_SPE_PATH}/platform/device/source/dma350_address_remap.c
+
+        # GNU Arm compiler version greater equal than *11.3.Rel1*
+        # has a linker issue that required system calls are missing,
+        # such as _read and _write. Add stub functions of required
+        # system calls to solve this issue.
+        $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:syscalls_stub.c>
 )
 
 target_compile_definitions(tfm_ns
     PRIVATE
         # Needed for DMA-350 library
-        CMSIS_device_header=<corstone310.h>
+        CMSIS_device_header=<cmsis.h>
 )
 
 target_link_libraries(tfm_ns
     PRIVATE
         platform_ns
-        tfm_s_veneers
+        tfm_api_ns
+        $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:tfm_api_ns_tz>
 )
 
 set_target_properties(tfm_ns PROPERTIES
@@ -74,6 +85,8 @@
     RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
 )
 
+target_add_scatter_file(tfm_ns ${CONFIG_SPE_PATH}/platform/linker_scripts)
+
 target_link_options(tfm_ns
     PRIVATE
         $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
@@ -82,8 +95,3 @@
 )
 
 add_convert_to_bin_target(tfm_ns)
-
-############################# CMSIS ############################################
-
-# Platform cmake config adds sources to CMSIS_5_tfm_ns, so we need to define it, but it is unused.
-add_library(CMSIS_5_tfm_ns INTERFACE)
diff --git a/examples/corstone310_fvp_dma/triggering_example/syscalls_stub.c b/examples/corstone310_fvp_dma/triggering_example/syscalls_stub.c
new file mode 100644
index 0000000..9ebe78e
--- /dev/null
+++ b/examples/corstone310_fvp_dma/triggering_example/syscalls_stub.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * NOTE: When GNU Arm compiler version greater equal than *11.3.Rel1*, there is a linker issue that
+ * some system calls are not implemented, such as _close, _fstat and _getpid etc. So add this file
+ * including stub functions of system calls to avoid the above linker issue.
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+
+__attribute__((weak))
+void _close(void)
+{
+}
+
+__attribute__((weak))
+void _fstat(void)
+{
+}
+
+__attribute__((weak))
+void _getpid(void)
+{
+}
+
+__attribute__((weak))
+void _isatty(void)
+{
+}
+
+__attribute__((weak))
+void _kill(void)
+{
+}
+
+__attribute__((weak))
+void _lseek(void)
+{
+}
+
+__attribute__((weak))
+void _read(void)
+{
+}
+
+__attribute__((weak))
+void _write(void)
+{
+}
diff --git a/examples/tf-m-example-ns-app/CMakeLists.txt b/examples/tf-m-example-ns-app/CMakeLists.txt
index 1e93790..1586ecf 100644
--- a/examples/tf-m-example-ns-app/CMakeLists.txt
+++ b/examples/tf-m-example-ns-app/CMakeLists.txt
@@ -1,10 +1,10 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2023, Arm Limited. All rights reserved.
+# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 #-------------------------------------------------------------------------------
-cmake_minimum_required(VERSION 3.15)
+cmake_minimum_required(VERSION 3.22)
 
 if (NOT DEFINED CONFIG_SPE_PATH OR NOT EXISTS ${CONFIG_SPE_PATH})
     message(FATAL_ERROR "CONFIG_SPE_PATH = ${CONFIG_SPE_PATH} is not defined or incorrect. Please provide full path to TF-M build artifacts using -DCONFIG_SPE_PATH=")
@@ -17,33 +17,35 @@
 # Include common configs exported from TF-M
 include(${CONFIG_SPE_PATH}/cmake/spe_config.cmake)
 
-# Select toolchain file if it is not specified via command line or the absolutate path
+# Select toolchain file if it is not specified via command line or the absolute path
 # is unavailable.
 if (NOT DEFINED TFM_TOOLCHAIN_FILE)
-    set(TFM_TOOLCHAIN_FILE    ${CONFIG_SPE_PATH}/cmake/toolchain_ns_GNUARM.cmake)
-endif()
-
-if(NOT EXISTS ${TFM_TOOLCHAIN_FILE})
-    message(FATAL_ERROR "TFM_TOOLCHAIN_FILE ${TFM_TOOLCHAIN_FILE} doesn't exist."
-                        "If it's relative path then please change to absolute path.")
+    if (NOT DEFINED TFM_TOOLCHAIN)
+        set(TFM_TOOLCHAIN "GNUARM")
+        message(WARNING "TFM_TOOLCHAIN or TFM_TOOLCHAIN_FILE is not defined")
+        message(WARNING "TFM_TOOLCHAIN is set to ${TFM_TOOLCHAIN}")
+    endif()
+    set(TFM_TOOLCHAIN_FILE    ${CONFIG_SPE_PATH}/cmake/toolchain_ns_${TFM_TOOLCHAIN}.cmake)
 endif()
 
 include(${TFM_TOOLCHAIN_FILE})
-
 project("TF-M Example"  LANGUAGES C)
 tfm_toolchain_reload_compiler()
 
+add_executable(tfm_ns)
+
 # The exported TF-M interfaces
 add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
 
-add_executable(tfm_ns
-    main.c
-    ${CONFIG_SPE_PATH}/interface/src/os_wrapper/tfm_ns_interface_bare_metal.c
-    # GNU Arm compiler version greater equal than *11.3.Rel1*
-    # has a linker issue that required system calls are missing,
-    # such as _read and _write. Add stub functions of required
-    # system calls to solve this issue.
-    $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:syscalls_stub.c>
+target_sources(tfm_ns
+    PRIVATE
+        main.c
+        ${CONFIG_SPE_PATH}/interface/src/os_wrapper/tfm_ns_interface_bare_metal.c
+        # GNU Arm compiler version greater equal than *11.3.Rel1*
+        # has a linker issue that required system calls are missing,
+        # such as _read and _write. Add stub functions of required
+        # system calls to solve this issue.
+        $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:syscalls_stub.c>
 )
 
 target_link_libraries(tfm_ns