Build: Update app_broker build

Update app_broker build to make dependencies more stable.

  - Sort NS library folder structure.
    Move common library folders out of app_broker. Place them under lib
    folder. Move CMSIS to lib/ext.
    It is expected that users can re-use those library in other NS
    integration with TF-M.
  - NS libraries depend on each other and therefore the dependencies are
    complicated. Build those NS libraries under app_broker to more
    easily sort out dependencies. Remove build files from library
    folders.

Signed-off-by: David Hu <david.hu@arm.com>
Change-Id: I8c2ff7bbec6c03738b9cbe49fd286a5147293ba5
diff --git a/app_broker/CMakeLists.txt b/app_broker/CMakeLists.txt
index cc6622c..2933833 100644
--- a/app_broker/CMakeLists.txt
+++ b/app_broker/CMakeLists.txt
@@ -14,27 +14,158 @@
 # brings configuration from TF-M build
 add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
 
-add_subdirectory(log)
-add_subdirectory(CMSIS)
-add_subdirectory(os_wrapper)
+####################### NS application libraries #######################
 
-add_library(tfm_test_broker STATIC
-    main_ns.c
+# Build all the NS application libraries here under app_broker
+# Those NS libraries depend on each other. It is more convenient to sort out the dependencies here.
+#
+# Those NS libraries also link to libraries exported from TF-M secure build. Specify all the
+# dependencies on TF-M exported libraries here, rather than under each NS library folder.
+# Therefore, NS library can be shared and re-used in other downstream projects, without specially
+# handling the differences of dependencies and paths in NS builds.
+
+# Interface files exported from TF-M secure build
+set(SPE_INSTALL_INTERFACE_SRC    ${CONFIG_SPE_PATH}/interface/src)
+set(SPE_INSTALL_INTERFACE_INC    ${CONFIG_SPE_PATH}/interface/include)
+# lib parth
+set(APP_LIB_DIR                  ${CMAKE_CURRENT_LIST_DIR}/../lib)
+
+# TF-M logging
+add_subdirectory(${APP_LIB_DIR}/log    ${CMAKE_CURRENT_BINARY_DIR}/lib/log)
+
+# OS wrapper library consists of the wrapper layer of RTOSes, such as RTX
+add_library(os_wrapper STATIC)
+
+target_sources(os_wrapper
+    PRIVATE
+        ${CMAKE_CURRENT_LIST_DIR}/os_wrapper_cmsis_rtos_v2.c
 )
 
-target_include_directories(tfm_test_broker PUBLIC .)
+target_include_directories(os_wrapper
+    PUBLIC
+        ${CMAKE_CURRENT_LIST_DIR}/../lib/os_wrapper
+        # Some NS files include "os_wrapper/xxx.h" instead
+        ${CMAKE_CURRENT_LIST_DIR}/../lib
+        # Some OS wrapper header files are exported from TF-M secure build
+        ${SPE_INSTALL_INTERFACE_INC}
+)
+
+target_link_libraries(os_wrapper
+    PRIVATE
+        RTX_OS
+        tfm_nsid_manager
+)
+
+# NSID manager
+add_library(tfm_nsid_manager INTERFACE)
+
+target_include_directories(tfm_nsid_manager
+    INTERFACE
+        ${APP_LIB_DIR}/nsid_manager
+)
+
+target_sources(tfm_nsid_manager
+    INTERFACE
+        $<$<BOOL:${TFM_NS_MANAGE_NSID}>:${APP_LIB_DIR}/nsid_manager/tfm_nsid_manager.c>
+)
+
+target_compile_definitions(tfm_nsid_manager
+    INTERFACE
+        $<$<BOOL:${TFM_NS_MANAGE_NSID}>:TFM_NS_MANAGE_NSID>
+        $<$<BOOL:${TEST_NS_MANAGE_NSID}>:TEST_NS_MANAGE_NSID>
+)
+
+# Provide TZ context management stub to RTOS if protected by Trustzone
+target_sources(RTX_OS
+    INTERFACE
+        $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${APP_LIB_DIR}/nsid_manager/tz_shim_layer.c>
+)
+
+target_link_libraries(RTX_OS
+    INTERFACE
+        tfm_nsid_manager
+)
+
+# Multi-core library
+if(TFM_PARTITION_NS_AGENT_MAILBOX)
+    add_library(ns_multi_core STATIC)
+
+    target_sources(ns_multi_core
+        PRIVATE
+            $<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${SPE_INSTALL_INTERFACE_SRC}/multi_core/tfm_ns_mailbox.c>
+            $<$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>:${SPE_INSTALL_INTERFACE_SRC}/multi_core/tfm_ns_mailbox_thread.c>
+            # NS RTOS specific implementation of NS mailbox
+            ${APP_LIB_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c
+            $<$<BOOL:${TEST_NS_MULTI_CORE}>:${APP_LIB_DIR}/multi_core/tfm_ns_mailbox_test.c>
+    )
+
+    target_compile_definitions(ns_multi_core
+        PUBLIC
+            $<$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>:TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD>
+            TFM_MULTI_CORE_NS_OS
+    )
+
+    target_link_libraries(ns_multi_core
+        PRIVATE
+            platform_ns
+            tfm_api_ns
+            os_wrapper
+    )
+endif()
+
+################## Update plaform_ns with NS settings #################
+
+target_include_directories(platform_ns
+    PUBLIC
+        $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:${SPE_INSTALL_INTERFACE_INC}/multi_core>
+        ${SPE_INSTALL_INTERFACE_INC}
+)
+
+target_compile_definitions(platform_ns
+    PUBLIC
+        $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:TFM_MULTI_CORE_NS_OS>
+)
+
+################# Update NS interface with NS settings ################
+
+target_sources(tfm_api_ns
+    PRIVATE
+        # NS specific implementation of NS interface dispatcher
+        $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${SPE_INSTALL_INTERFACE_SRC}/os_wrapper/tfm_ns_interface_rtos.c>
+)
+
+target_compile_definitions(tfm_api_ns
+    PUBLIC
+        $<$<BOOL:${TEST_NS_MULTI_CORE}>:TFM_MULTI_CORE_TEST>
+)
+
+target_link_libraries(tfm_api_ns
+    PRIVATE
+        $<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:os_wrapper>
+)
+
+######################## NS application broker ########################
+
+add_library(tfm_test_broker STATIC)
+
+target_sources(tfm_test_broker
+    PRIVATE
+        main_ns.c
+        $<$<BOOL:${TFM_NS_MANAGE_NSID}>:${CMAKE_CURRENT_LIST_DIR}/tfm_nsid_map_table.c>
+)
+
+target_include_directories(tfm_test_broker
+    PUBLIC
+        .
+)
 
 target_link_libraries(tfm_test_broker
+    PRIVATE
+        os_wrapper
+        tfm_nsid_manager
     PUBLIC
+        RTX_OS
         tfm_api_ns
         tfm_log
-        os_wrapper
+        $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:ns_multi_core>
 )
-
-add_subdirectory(nsid_manager)
-target_link_libraries(tfm_test_broker PUBLIC tfm_nsid_manager)
-
-if (TFM_PARTITION_NS_AGENT_MAILBOX)
-    add_subdirectory(multi_core)
-    target_link_libraries(tfm_test_broker PUBLIC ns_multi_core)
-endif()
diff --git a/app_broker/multi_core/CMakeLists.txt b/app_broker/multi_core/CMakeLists.txt
deleted file mode 100644
index 5780624..0000000
--- a/app_broker/multi_core/CMakeLists.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2023, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-#
-# This CMake script used in a split build only. In the legacy 'sinlge' build
-# this file is ignoed. Please don't be confused.
-#
-cmake_minimum_required(VERSION 3.15)
-
-add_library(ns_multi_core STATIC
-    PRIVATE
-        tfm_multi_core_ns_api.c
-        tfm_multi_core_psa_ns_api.c
-        $<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:tfm_ns_mailbox.c>
-        $<$<AND:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>,$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:tfm_ns_mailbox_thread.c>
-        # NS RTOS specific implementation of NS mailbox
-        $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:tfm_ns_mailbox_rtos_api.c>
-        $<$<BOOL:${TEST_NS_MULTI_CORE}>:tfm_ns_mailbox_test.c>
-)
-
-target_compile_definitions(ns_multi_core
-    PUBLIC
-        $<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:TFM_PARTITION_NS_AGENT_MAILBOX>
-        $<$<AND:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>,$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD>
-)
diff --git a/app_broker/nsid_manager/CMakeLists.txt b/app_broker/nsid_manager/CMakeLists.txt
deleted file mode 100644
index 24c5d9e..0000000
--- a/app_broker/nsid_manager/CMakeLists.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2023, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-
-cmake_minimum_required(VERSION 3.15)
-
-add_library(tfm_nsid_manager STATIC)
-
-target_include_directories(tfm_nsid_manager PUBLIC .)
-
-target_link_libraries(tfm_nsid_manager PRIVATE RTX_OS)
-
-if(TFM_NS_MANAGE_NSID)
-    target_sources(tfm_nsid_manager
-        PUBLIC
-            tfm_nsid_manager.c
-            tfm_nsid_map_table.c
-            tz_shim_layer.c
-    )
-
-    target_compile_definitions(tfm_nsid_manager
-        PUBLIC
-            TFM_NS_MANAGE_NSID
-            $<$<BOOL:${TEST_NS_MANAGE_NSID}>:TEST_NS_MANAGE_NSID>
-    )
-else()
-    target_sources(tfm_nsid_manager
-        PUBLIC
-            tz_stub.c
-    )
-endif()
diff --git a/app_broker/nsid_manager/tz_stub.c b/app_broker/nsid_manager/tz_stub.c
deleted file mode 100644
index 306112d..0000000
--- a/app_broker/nsid_manager/tz_stub.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2023, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-/*
- * This is a stub functoins for TF-M shim layer of TZ APIs
- *
- */
-
-#include "tz_context.h"
-/*
- * TF-M shim layer of the CMSIS TZ RTOS thread context management API
- */
-
-/*
- * Initialize token-nsid map table in tfm nsid manager
- * Return execution status (1: success, 0: error)
- */
-uint32_t TZ_InitContextSystem_S(void)
-{
-    return 1U;    /* Success */
-}
-
-/*
- * Allocate context memory from Secure side
- * Param: TZ_ModuleId_t (NSID if TFM_NS_MANAGE_NSID is enabled)
- * Return token if TFM_NS_MANAGE_NSID is enabled
- * Return 0 if no memory available or internal error
- */
-TZ_MemoryId_t TZ_AllocModuleContext_S(TZ_ModuleId_t module)
-{
-    return 1U;    /* Success */
-}
-
-/*
- * Free context memory that was previously allocated with TZ_AllocModuleContext_S
- * Param: TZ_MemoryId_t (token if TFM_NS_MANAGE_NSID is enabled)
- * Return execution status (1: success, 0: error)
- */
-uint32_t TZ_FreeModuleContext_S(TZ_MemoryId_t id)
-{
-    return 1U;    /* Success */
-}
-
-/*
- * Load secure context (called on RTOS thread context switch)
- * Param: TZ_MemoryId_t (token if TFM_NS_MANAGE_NSID is enabled)
- * Return execution status (1: success, 0: error)
- */
-uint32_t TZ_LoadContext_S(TZ_MemoryId_t id)
-{
-    return 1U;    /* Success */
-}
-
-/*
- * Store secure context (called on RTOS thread context switch)
- * Param: TZ_MemoryId_t (token if TFM_NS_MANAGE_NSID is enabled)
- * Return execution status (1: success, 0: error)
- */
-uint32_t TZ_StoreContext_S(TZ_MemoryId_t id)
-{
-    return 1U;    /* Success */
-}
diff --git a/app_broker/os_wrapper/CMakeLists.txt b/app_broker/os_wrapper/CMakeLists.txt
deleted file mode 100644
index d7f043e..0000000
--- a/app_broker/os_wrapper/CMakeLists.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-
-cmake_minimum_required(VERSION 3.13)
-
-add_library(os_wrapper STATIC)
-
-target_sources(os_wrapper
-    PUBLIC
-        os_wrapper_cmsis_rtos_v2.c
-)
-
-target_include_directories(os_wrapper PUBLIC .)
-
-target_link_libraries(os_wrapper
-    PRIVATE
-        psa_interface
-    PUBLIC
-        tfm_nsid_manager
-        RTX_OS
-)
diff --git a/app_broker/os_wrapper/os_wrapper_cmsis_rtos_v2.c b/app_broker/os_wrapper_cmsis_rtos_v2.c
similarity index 100%
rename from app_broker/os_wrapper/os_wrapper_cmsis_rtos_v2.c
rename to app_broker/os_wrapper_cmsis_rtos_v2.c
diff --git a/app_broker/test_app.h b/app_broker/test_app.h
index d60827c..35728ba 100644
--- a/app_broker/test_app.h
+++ b/app_broker/test_app.h
@@ -8,6 +8,8 @@
 #ifndef __TFM_TEST_APP_H__
 #define __TFM_TEST_APP_H__
 
+#include <stdint.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/app_broker/nsid_manager/tfm_nsid_map_table.c b/app_broker/tfm_nsid_map_table.c
similarity index 100%
rename from app_broker/nsid_manager/tfm_nsid_map_table.c
rename to app_broker/tfm_nsid_map_table.c
diff --git a/app_broker/nsid_manager/tfm_nsid_map_table.h b/app_broker/tfm_nsid_map_table.h
similarity index 100%
rename from app_broker/nsid_manager/tfm_nsid_map_table.h
rename to app_broker/tfm_nsid_map_table.h
diff --git a/app_broker/CMSIS/CMakeLists.txt b/lib/ext/CMSIS/CMakeLists.txt
similarity index 92%
rename from app_broker/CMSIS/CMakeLists.txt
rename to lib/ext/CMSIS/CMakeLists.txt
index 3a20f9c..f994d55 100644
--- a/app_broker/CMSIS/CMakeLists.txt
+++ b/lib/ext/CMSIS/CMakeLists.txt
@@ -16,7 +16,7 @@
 add_library(CMSIS_5_RTX_V8MBN STATIC IMPORTED GLOBAL)
 add_library(CMSIS_5_RTX_CM3 STATIC IMPORTED GLOBAL)
 
-set(CMSIS_LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/RTOS2/RTX/Library)
+set(CMSIS_LIBS_DIR ${CMAKE_CURRENT_LIST_DIR}/RTOS2/RTX/Library)
 
 if ("${CMAKE_C_COMPILER_ID}" STREQUAL GNU)
     set_target_properties(CMSIS_5_RTX_V8MMN  PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/GCC/libRTX_V8MMN.a)
@@ -39,16 +39,16 @@
     message(FATAL_ERROR "${CMAKE_C_COMPILER_ID} does not have CMSIS RTX static libraries set up")
 endif()
 
-add_library(RTX_OS STATIC)
+add_library(RTX_OS INTERFACE)
 
 target_sources(RTX_OS
-    PUBLIC
+    INTERFACE
         RTOS2/RTX/Config/RTX_Config.c
         RTOS2/RTX/Source/rtx_lib.c
 )
 
 target_include_directories(RTX_OS
-    PUBLIC
+    INTERFACE
         Core/Include
         RTOS2/Include
         RTOS2/RTX/Include
@@ -56,10 +56,7 @@
 )
 
 target_link_libraries(RTX_OS
-    PRIVATE
+    INTERFACE
         CMSIS_5_RTX_V8MMN
-        tfm_test_broker
-    PUBLIC
         platform_ns         # for cmsis_compiler.h
-        psa_interface       # for os_wrapper/common.h
 )
diff --git a/app_broker/CMSIS/LICENSE.txt b/lib/ext/CMSIS/LICENSE.txt
similarity index 100%
rename from app_broker/CMSIS/LICENSE.txt
rename to lib/ext/CMSIS/LICENSE.txt
diff --git a/app_broker/CMSIS/README b/lib/ext/CMSIS/README
similarity index 100%
rename from app_broker/CMSIS/README
rename to lib/ext/CMSIS/README
diff --git a/app_broker/CMSIS/RTOS2/Include/cmsis_os2.h b/lib/ext/CMSIS/RTOS2/Include/cmsis_os2.h
similarity index 100%
rename from app_broker/CMSIS/RTOS2/Include/cmsis_os2.h
rename to lib/ext/CMSIS/RTOS2/Include/cmsis_os2.h
diff --git a/app_broker/CMSIS/RTOS2/RTX/Config/RTX_Config.c b/lib/ext/CMSIS/RTOS2/RTX/Config/RTX_Config.c
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Config/RTX_Config.c
rename to lib/ext/CMSIS/RTOS2/RTX/Config/RTX_Config.c
diff --git a/app_broker/CMSIS/RTOS2/RTX/Config/RTX_Config.h b/lib/ext/CMSIS/RTOS2/RTX/Config/RTX_Config.h
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Config/RTX_Config.h
rename to lib/ext/CMSIS/RTOS2/RTX/Config/RTX_Config.h
diff --git a/app_broker/CMSIS/RTOS2/RTX/Include/rtx_evr.h b/lib/ext/CMSIS/RTOS2/RTX/Include/rtx_evr.h
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Include/rtx_evr.h
rename to lib/ext/CMSIS/RTOS2/RTX/Include/rtx_evr.h
diff --git a/app_broker/CMSIS/RTOS2/RTX/Include/rtx_os.h b/lib/ext/CMSIS/RTOS2/RTX/Include/rtx_os.h
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Include/rtx_os.h
rename to lib/ext/CMSIS/RTOS2/RTX/Include/rtx_os.h
diff --git a/app_broker/CMSIS/RTOS2/RTX/Include/tz_context.h b/lib/ext/CMSIS/RTOS2/RTX/Include/tz_context.h
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Include/tz_context.h
rename to lib/ext/CMSIS/RTOS2/RTX/Include/tz_context.h
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM0.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM0.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM0.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM0.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM3.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM3.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM3.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM3.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM4F.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM4F.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM4F.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_CM4F.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MB.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MB.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MB.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MB.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MBN.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MBN.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MBN.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MBN.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MM.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MM.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MM.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MM.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMF.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMF.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMF.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMF.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMFN.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMFN.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMFN.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMFN.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib b/lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib
rename to lib/ext/CMSIS/RTOS2/RTX/Library/ARM/RTX_V8MMN.lib
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM0.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM0.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM0.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM0.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM3.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM3.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM3.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM3.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM4F.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM4F.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM4F.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_CM4F.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MB.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MB.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MB.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MB.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MBN.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MBN.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MBN.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MBN.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MM.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MM.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MM.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MM.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMF.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMF.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMF.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMF.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMFN.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMFN.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMFN.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMFN.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMN.a b/lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMN.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMN.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/GCC/libRTX_V8MMN.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM0.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM0.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM0.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM0.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM3.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM3.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM3.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM3.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM4F.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM4F.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM4F.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_CM4F.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V81MMN.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V81MMN.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V81MMN.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V81MMN.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MB.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MB.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MB.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MB.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MBN.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MBN.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MBN.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MBN.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MM.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MM.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MM.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MM.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMF.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMF.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMF.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMF.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMFN.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMFN.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMFN.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMFN.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMN.a b/lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMN.a
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMN.a
rename to lib/ext/CMSIS/RTOS2/RTX/Library/IAR/RTX_V8MMN.a
Binary files differ
diff --git a/app_broker/CMSIS/RTOS2/RTX/Source/rtx_lib.c b/lib/ext/CMSIS/RTOS2/RTX/Source/rtx_lib.c
similarity index 100%
rename from app_broker/CMSIS/RTOS2/RTX/Source/rtx_lib.c
rename to lib/ext/CMSIS/RTOS2/RTX/Source/rtx_lib.c
diff --git a/lib/ext/CMakeLists.txt b/lib/ext/CMakeLists.txt
index d6da886..c9155fe 100644
--- a/lib/ext/CMakeLists.txt
+++ b/lib/ext/CMakeLists.txt
@@ -13,3 +13,4 @@
     add_subdirectory(qcbor)
 endif()
 
+add_subdirectory(CMSIS)
diff --git a/app_broker/log/CMakeLists.txt b/lib/log/CMakeLists.txt
similarity index 83%
rename from app_broker/log/CMakeLists.txt
rename to lib/log/CMakeLists.txt
index 3612435..a843b41 100644
--- a/app_broker/log/CMakeLists.txt
+++ b/lib/log/CMakeLists.txt
@@ -6,19 +6,20 @@
 #-------------------------------------------------------------------------------
 
 ############################# Ns Log ###########################################
-add_library(tfm_log STATIC)
+
+add_library(tfm_log INTERFACE)
 
 target_sources(tfm_log
-    PRIVATE
+    INTERFACE
         tfm_log_raw.c
 )
 
 target_include_directories(tfm_log
-    PUBLIC
-        ${CMAKE_CURRENT_SOURCE_DIR}
+    INTERFACE
+        .
 )
 
 target_link_libraries(tfm_log
-    PUBLIC
+    INTERFACE
         platform_ns
 )
diff --git a/app_broker/log/tfm_log.h b/lib/log/tfm_log.h
similarity index 100%
rename from app_broker/log/tfm_log.h
rename to lib/log/tfm_log.h
diff --git a/app_broker/log/tfm_log_raw.c b/lib/log/tfm_log_raw.c
similarity index 100%
rename from app_broker/log/tfm_log_raw.c
rename to lib/log/tfm_log_raw.c
diff --git a/app_broker/log/tfm_log_raw.h b/lib/log/tfm_log_raw.h
similarity index 100%
rename from app_broker/log/tfm_log_raw.h
rename to lib/log/tfm_log_raw.h
diff --git a/app_broker/multi_core/tfm_ns_mailbox_rtos_api.c b/lib/multi_core/tfm_ns_mailbox_rtos_api.c
similarity index 100%
rename from app_broker/multi_core/tfm_ns_mailbox_rtos_api.c
rename to lib/multi_core/tfm_ns_mailbox_rtos_api.c
diff --git a/app_broker/multi_core/tfm_ns_mailbox_test.c b/lib/multi_core/tfm_ns_mailbox_test.c
similarity index 100%
rename from app_broker/multi_core/tfm_ns_mailbox_test.c
rename to lib/multi_core/tfm_ns_mailbox_test.c
diff --git a/app_broker/nsid_manager/tfm_nsid_manager.c b/lib/nsid_manager/tfm_nsid_manager.c
similarity index 100%
rename from app_broker/nsid_manager/tfm_nsid_manager.c
rename to lib/nsid_manager/tfm_nsid_manager.c
diff --git a/app_broker/nsid_manager/tfm_nsid_manager.h b/lib/nsid_manager/tfm_nsid_manager.h
similarity index 100%
rename from app_broker/nsid_manager/tfm_nsid_manager.h
rename to lib/nsid_manager/tfm_nsid_manager.h
diff --git a/app_broker/nsid_manager/tz_shim_layer.c b/lib/nsid_manager/tz_shim_layer.c
similarity index 100%
rename from app_broker/nsid_manager/tz_shim_layer.c
rename to lib/nsid_manager/tz_shim_layer.c
diff --git a/app_broker/os_wrapper/delay.h b/lib/os_wrapper/delay.h
similarity index 100%
rename from app_broker/os_wrapper/delay.h
rename to lib/os_wrapper/delay.h
diff --git a/app_broker/os_wrapper/msg_queue.h b/lib/os_wrapper/msg_queue.h
similarity index 100%
rename from app_broker/os_wrapper/msg_queue.h
rename to lib/os_wrapper/msg_queue.h
diff --git a/app_broker/os_wrapper/semaphore.h b/lib/os_wrapper/semaphore.h
similarity index 100%
rename from app_broker/os_wrapper/semaphore.h
rename to lib/os_wrapper/semaphore.h
diff --git a/app_broker/os_wrapper/thread.h b/lib/os_wrapper/thread.h
similarity index 100%
rename from app_broker/os_wrapper/thread.h
rename to lib/os_wrapper/thread.h
diff --git a/app_broker/os_wrapper/tick.h b/lib/os_wrapper/tick.h
similarity index 100%
rename from app_broker/os_wrapper/tick.h
rename to lib/os_wrapper/tick.h
diff --git a/tests_reg/CMakeLists.txt b/tests_reg/CMakeLists.txt
index ef95cca..a60f744 100644
--- a/tests_reg/CMakeLists.txt
+++ b/tests_reg/CMakeLists.txt
@@ -38,14 +38,13 @@
 # Test configurations
 include(${CMAKE_CURRENT_LIST_DIR}/test/config/default_test_config.cmake)
 
-add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../lib/ext ${CMAKE_BINARY_DIR}/lib/ext)
-
 include(${TFM_TOOLCHAIN_FILE})
 project(tfm_ns LANGUAGES C ASM)
 tfm_toolchain_reload_compiler()
 
 add_executable(tfm_ns)
 
+add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../lib/ext ${CMAKE_BINARY_DIR}/lib/ext)
 add_subdirectory(../app_broker ${CMAKE_BINARY_DIR}/app_broker)
 add_subdirectory(test)
 
diff --git a/tests_reg/test/CMakeLists.txt b/tests_reg/test/CMakeLists.txt
index a9558a5..aa2025f 100644
--- a/tests_reg/test/CMakeLists.txt
+++ b/tests_reg/test/CMakeLists.txt
@@ -19,7 +19,6 @@
 target_include_directories(tfm_test_framework_common
     INTERFACE
         framework
-        ${CMAKE_CURRENT_LIST_DIR}/../../app_broker/log
 )
 
 add_subdirectory(secure_fw)
diff --git a/tests_reg/test/bl2/mcuboot/CMakeLists.txt b/tests_reg/test/bl2/mcuboot/CMakeLists.txt
index fa83278..4dd1028 100644
--- a/tests_reg/test/bl2/mcuboot/CMakeLists.txt
+++ b/tests_reg/test/bl2/mcuboot/CMakeLists.txt
@@ -11,7 +11,7 @@
 # So a dedicated library is duplicated here, and it links the platform_s instead of platform_ns.
 
 # TO-DO: find a better approach to reference the directory
-set(LOG_SOURCE_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../../app_broker/log)
+set(LOG_SOURCE_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../../lib/log)
 
 add_library(mcuboot_test_log INTERFACE)
 add_library(mcuboot_test_log_interface INTERFACE)
diff --git a/tests_reg/test/secure_fw/suites/multi_core/non_secure/CMakeLists.txt b/tests_reg/test/secure_fw/suites/multi_core/non_secure/CMakeLists.txt
index 9b15af1..9f65ff2 100644
--- a/tests_reg/test/secure_fw/suites/multi_core/non_secure/CMakeLists.txt
+++ b/tests_reg/test/secure_fw/suites/multi_core/non_secure/CMakeLists.txt
@@ -33,14 +33,11 @@
 target_link_libraries(tfm_test_suite_multi_core_ns
     PRIVATE
         tfm_test_framework_ns
+        ns_multi_core
+        os_wrapper
 )
 
 target_link_libraries(tfm_ns_tests
     INTERFACE
         tfm_test_suite_multi_core_ns
 )
-
-target_compile_definitions(tfm_api_ns
-    PUBLIC
-        TFM_MULTI_CORE_TEST
-)