Tests: The "split build" adaptation
This code builds TEST_NS_ITS test using split build.
cd ./trusted-firmware-m
cmake -S . -B ../tf-m-tests/build-tfm -DTFM_PLATFORM=arm/mps2/an521
-DCONFIG_TFM_BUILD_SPLIT=ON
-DCMAKE_INSTALL_PREFIX=../tf-m-tests/build-tfm/api_ns
-DTFM_TOOLCHAINE=toolchain_GNUARM.cmake
-DTFM_PROFILE=profile_small
-DNS=OFF -DTEST_S=OFF -DPLATFORM_DEFAULT_IMAGE_SIGNING=ON
cmake --build build -- install
cd ../tf-m-tests/app_ns_test
cmake -S . -B build -DTEST_NS_ITS=OFF
-DCONFIG_SPE_PATH=../build-tfm/api_ns
cmake --build build -- tfm_app_binaries
Check the binary in ./build/tfm_s_ns_signed.bin
Signed-off-by: Anton Komlev <anton.komlev@arm.com>
Change-Id: Icaf38d844fe38d444b973776af2616d16c5439b1
diff --git a/CMSIS/CMakeLists.txt b/CMSIS/CMakeLists.txt
new file mode 100644
index 0000000..0d603ed
--- /dev/null
+++ b/CMSIS/CMakeLists.txt
@@ -0,0 +1,64 @@
+#-------------------------------------------------------------------------------
+# 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)
+cmake_policy(SET CMP0079 NEW)
+
+add_library(CMSIS_5_RTX_V8MMN STATIC IMPORTED GLOBAL)
+add_library(CMSIS_5_RTX_V8MMFN STATIC IMPORTED GLOBAL)
+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)
+
+if ("${CMAKE_C_COMPILER_ID}" STREQUAL GNU)
+ set_target_properties(CMSIS_5_RTX_V8MMN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/GCC/libRTX_V8MMN.a)
+ set_target_properties(CMSIS_5_RTX_V8MMFN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/GCC/libRTX_V8MMFN.a)
+ set_target_properties(CMSIS_5_RTX_V8MBN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/GCC/libRTX_V8MBN.a)
+ set_target_properties(CMSIS_5_RTX_CM3 PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/GCC/libRTX_CM3.a)
+elseif("${CMAKE_C_COMPILER_ID}" STREQUAL ARMClang)
+ set_target_properties(CMSIS_5_RTX_V8MMN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/ARM/RTX_V8MMN.lib)
+ set_target_properties(CMSIS_5_RTX_V8MMFN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/ARM/RTX_V8MMFN.lib)
+ set_target_properties(CMSIS_5_RTX_V8MBN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/ARM/RTX_V8MBN.lib)
+ set_target_properties(CMSIS_5_RTX_CM3 PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/ARM/RTX_CM3.lib)
+elseif("${CMAKE_C_COMPILER_ID}" STREQUAL IAR)
+ add_library(CMSIS_5_RTX_V81MMN STATIC IMPORTED GLOBAL)
+ set_target_properties(CMSIS_5_RTX_V8MMN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/IAR/RTX_V8MMN.a)
+ set_target_properties(CMSIS_5_RTX_V81MMN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/IAR/RTX_V81MMN.a)
+ set_target_properties(CMSIS_5_RTX_V8MMFN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/IAR/RTX_V8MMFN.a)
+ set_target_properties(CMSIS_5_RTX_V8MBN PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/IAR/RTX_V8MBN.a)
+ set_target_properties(CMSIS_5_RTX_CM3 PROPERTIES IMPORTED_LOCATION ${CMSIS_LIBS_DIR}/IAR/RTX_CM3.a)
+else()
+ message(FATAL_ERROR "${CMAKE_C_COMPILER_ID} does not have CMSIS RTX static libraries set up")
+endif()
+
+add_library(RTX_OS STATIC)
+
+target_sources(RTX_OS
+ PUBLIC
+ RTOS2/RTX/Config/RTX_Config.c
+ RTOS2/RTX/Source/rtx_lib.c
+)
+
+target_include_directories(RTX_OS
+ PUBLIC
+ Core/Include
+ RTOS2/Include
+ RTOS2/RTX/Include
+ RTOS2/RTX/Config
+)
+
+target_link_libraries(RTX_OS
+ PRIVATE
+ CMSIS_5_RTX_V8MMN
+ tfm_test_broker
+ platform_ns # for cmsis_compiler.h
+ psa_interface # for os_wrapper/common.h
+)
diff --git a/CMSIS/README b/CMSIS/README
index 369c323..307528f 100644
--- a/CMSIS/README
+++ b/CMSIS/README
@@ -1,5 +1,6 @@
The source codes under this folder are copied from:
https://github.com/ARM-software/CMSIS_5.git, tag 5.5.0, without modifications.
+Only CMakeLists.txt file is added for TF-M test build purpose.
The prebuilt libraries have two versions:
- v5.5.0 for ARMCLANG and GCC compilers
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0f09d25..ebac5f3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,6 +5,12 @@
#
#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.15)
+
+# This is a legacy root CMake script, kept for backward compatibility.
+# In a new, split build please go to a dedicated test's subdirectory.
+# For example: ./app_ns_test for building NS regression tests.
+
add_subdirectory(log)
add_subdirectory(lib/ext)
diff --git a/app_ns_test/CMakeLists.txt b/app_ns_test/CMakeLists.txt
new file mode 100644
index 0000000..d66ece8
--- /dev/null
+++ b/app_ns_test/CMakeLists.txt
@@ -0,0 +1,56 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.15)
+
+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()
+
+if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+ set(CROSS_COMPILE arm-none-eabi)
+ set(CMAKE_TOOLCHAIN_FILE ${CONFIG_SPE_PATH}/cmake/toolchain_ns_GNUARM.cmake)
+endif()
+
+if (NOT DEFINED TFM_TEST_PATH)
+ set(TFM_TEST_PATH ${CMAKE_SOURCE_DIR}/../test)
+endif()
+
+set(TFM_NS_REG_TEST ON)
+set(NS ON)
+set(TEST_NS ON)
+#------------------------------------------------------------------------------
+
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../cmake)
+list(APPEND CMAKE_MODULE_PATH ${CONFIG_SPE_PATH}/cmake)
+
+project(tfm_ns LANGUAGES C)
+
+add_executable(tfm_ns)
+
+add_subdirectory(../ns_interface ${CMAKE_BINARY_DIR}/ns_interface)
+add_subdirectory(../test ${CMAKE_BINARY_DIR}/tests)
+
+include(../test/config/set_config.cmake)
+
+############################# TFM NS main app ##################################
+
+target_sources(tfm_ns
+ PRIVATE
+ test_app.c
+)
+
+target_link_libraries(tfm_ns
+ PRIVATE
+ tfm_test_broker
+ tfm_ns_tests
+ tfm_test_framework_common
+)
+
+set_target_properties(tfm_ns PROPERTIES
+ SUFFIX ".axf"
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
+)
diff --git a/app_ns_test/test_app.c b/app_ns_test/test_app.c
new file mode 100644
index 0000000..bd45b38
--- /dev/null
+++ b/app_ns_test/test_app.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "test_app.h"
+#include "tfm_log.h"
+#include "test_framework_integ_test.h"
+
+/**
+ * \brief Services test thread
+ *
+ */
+__attribute__((noreturn))
+void test_app(void *argument)
+{
+ UNUSED_VARIABLE(argument);
+
+ tfm_non_secure_client_run_tests();
+
+ /* Output EOT char for test environments like FVP. */
+ LOG_MSG("\x04");
+
+ /* End of test */
+ for (;;) {
+ }
+}
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
new file mode 100644
index 0000000..2717293
--- /dev/null
+++ b/cmake/utils.cmake
@@ -0,0 +1,56 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+# A string calibrating routine to the specified length by
+# appending to an input string a specified character.
+#
+# output - variable to return the calibrated string
+
+function(format_string output input size filler)
+ string(LENGTH ${input} length)
+ foreach(i RANGE ${length} ${size})
+ string(CONCAT input ${input} ${filler})
+ endforeach()
+ set(${output} ${input} PARENT_SCOPE)
+endfunction()
+
+# Prints formatted list of options with a title
+#
+# title - will be printed in a header
+# options - list of CMake options to print (semicolon separated)
+#
+# Example:
+# dump_options("Partitions" "TFM_PARTITION_CRYPTO; TFM_PARTITION_FIRMWARE_UPDATE ")
+# will produce:
+# -- -------- Partitions ---------------------
+# -- TFM_PARTITION_CRYPTO ON
+# -- TFM_PARTITION_FIRMWARE_UPDATE OFF
+# -- -----------------------------------------
+
+function(dump_options title options)
+
+ if (CONFIG_TFM_PARTITION_QUIET)
+ return()
+ endif()
+
+ format_string(header "-------- ${title} " 50 "-")
+ message(STATUS )
+ message(STATUS "${header}")
+
+ foreach (option ${options})
+ string(STRIP ${option} option)
+ # avoid errors on empty strings to tolerate ';' at the end of list
+ if((DEFINED ${option}) AND NOT ${option} STREQUAL "")
+ format_string(option_name ${option} 40 " ")
+ message(STATUS "${option_name} ${${option}}")
+ endif()
+ endforeach()
+
+ format_string(footer "-" 50 "-")
+ message(STATUS "${footer}")
+endfunction()
+
diff --git a/log/CMakeLists.txt b/log/CMakeLists.txt
index 9860934..2ac6ceb 100644
--- a/log/CMakeLists.txt
+++ b/log/CMakeLists.txt
@@ -6,11 +6,11 @@
#-------------------------------------------------------------------------------
############################# Ns Log ###########################################
-add_library(tfm_log INTERFACE)
+add_library(tfm_log STATIC)
add_library(tfm_log_interface INTERFACE)
target_sources(tfm_log
- INTERFACE
+ PRIVATE
tfm_log_raw.c
)
@@ -23,4 +23,6 @@
INTERFACE
tfm_log_interface
platform_common_interface
+ PUBLIC
+ platform_ns
)
diff --git a/ns_interface/CMakeLists.txt b/ns_interface/CMakeLists.txt
new file mode 100644
index 0000000..0c6990b
--- /dev/null
+++ b/ns_interface/CMakeLists.txt
@@ -0,0 +1,77 @@
+#-------------------------------------------------------------------------------
+# 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)
+
+# This is important to add this SPE subdirectory at first as it
+# brings configuration from TF-M build
+add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
+
+add_subdirectory(../log ${CMAKE_BINARY_DIR}/log)
+add_subdirectory(../CMSIS ${CMAKE_BINARY_DIR}/CMSIS)
+
+add_library(tfm_test_broker STATIC)
+
+target_sources(tfm_test_broker
+ PUBLIC
+ ../app/main_ns.c
+ ../app/os_wrapper_cmsis_rtos_v2.c
+ ns_client_ext/tz_shim_layer.c
+)
+
+target_include_directories(tfm_test_broker
+ PUBLIC
+ .
+ ../app
+)
+
+target_link_libraries(tfm_test_broker
+ PUBLIC
+ RTX_OS
+ tfm_api_ns
+ tfm_log
+)
+
+add_subdirectory(ns_client_ext)
+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()
+
+################################################################################
+########### Patches and stubs to the existing (single) build process to leave
+# legacy code untouched for backwrd compatibility.
+# TODO: Sort it out after single build deprecation and code restructuring
+
+# platform_common_interface target is linked to the log target only
+add_library(platform_common_interface INTERFACE)
+
+# platform_region_defs needed by PS tests
+add_library(platform_region_defs INTERFACE)
+
+# stub the tfm_partition target.
+add_library(tfm_partitions INTERFACE)
+
+target_link_libraries(platform_common_interface
+ INTERFACE
+ platform_ns
+)
+
+target_include_directories(tfm_test_broker
+ PUBLIC
+ ns_client_ext # TODO: It shall be in tfm_nsid_manager. Need to sort out dependencies
+)
+
+target_include_directories(tfm_config
+ INTERFACE
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
diff --git a/ns_interface/multi_core/CMakeLists.txt b/ns_interface/multi_core/CMakeLists.txt
new file mode 100644
index 0000000..5780624
--- /dev/null
+++ b/ns_interface/multi_core/CMakeLists.txt
@@ -0,0 +1,28 @@
+#-------------------------------------------------------------------------------
+# 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/ns_interface/ns_client_ext/CMakeLists.txt b/ns_interface/ns_client_ext/CMakeLists.txt
new file mode 100644
index 0000000..24a0971
--- /dev/null
+++ b/ns_interface/ns_client_ext/CMakeLists.txt
@@ -0,0 +1,26 @@
+#-------------------------------------------------------------------------------
+# 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)
+
+if (TFM_NS_MANAGE_NSID)
+ add_library(tfm_nsid_manager STATIC
+ tfm_nsid_manager.c
+ ../../app/tfm_nsid_map_table.c
+ )
+
+ target_compile_definitions(tfm_nsid_manager
+ PUBLIC
+ TFM_NS_MANAGE_NSID
+ $<$<BOOL:${TEST_NS_MANAGE_NSID}>:TEST_NS_MANAGE_NSID>
+ )
+else()
+ add_library(tfm_nsid_manager INTERFACE)
+endif()
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
old mode 100755
new mode 100644
index a0a018b..15053d7
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -7,22 +7,22 @@
cmake_minimum_required(VERSION 3.13)
-add_library(tfm_test_framework_common INTERFACE)
+add_library(tfm_test_framework_common STATIC)
target_sources(tfm_test_framework_common
- INTERFACE
+ PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/framework/test_framework.c
${CMAKE_CURRENT_SOURCE_DIR}/framework/test_framework_helpers.c
${CMAKE_CURRENT_SOURCE_DIR}/framework/test_framework_integ_test_helper.c
)
target_include_directories(tfm_test_framework_common
- INTERFACE
+ PUBLIC
framework
)
target_link_libraries(tfm_test_framework_common
- INTERFACE
+ PUBLIC
tfm_log_interface
)
diff --git a/test/secure_fw/suites/CMakeLists.txt b/test/secure_fw/suites/CMakeLists.txt
index c44541e..cda6e6d 100644
--- a/test/secure_fw/suites/CMakeLists.txt
+++ b/test/secure_fw/suites/CMakeLists.txt
@@ -70,9 +70,9 @@
add_subdirectory(crypto)
add_subdirectory(extra)
add_subdirectory(its)
-add_subdirectory(qcbor)
+# add_subdirectory(qcbor)
add_subdirectory(ps)
-add_subdirectory(t_cose)
+# add_subdirectory(t_cose)
add_subdirectory(platform)
add_subdirectory(fwu)
add_subdirectory(multi_core/non_secure)
diff --git a/test/secure_fw/suites/nsid/CMakeLists.txt b/test/secure_fw/suites/nsid/CMakeLists.txt
index b3b6262..3dd41eb 100644
--- a/test/secure_fw/suites/nsid/CMakeLists.txt
+++ b/test/secure_fw/suites/nsid/CMakeLists.txt
@@ -35,6 +35,7 @@
PRIVATE
tfm_test_framework_ns
platform_ns
+ tfm_test_broker
)
target_link_libraries(tfm_ns_tests