blob: 7906a91041943dc2cdcee18fc7a5bba7bdf2a296 [file] [log] [blame]
Kevin Peng62a87112020-07-07 15:07:46 +08001#-------------------------------------------------------------------------------
Raef Coles5ee45ed2020-09-24 11:25:44 +01002# Copyright (c) 2020, Arm Limited. All rights reserved.
Kevin Peng62a87112020-07-07 15:07:46 +08003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
Raef Coles5ee45ed2020-09-24 11:25:44 +01008cmake_minimum_required(VERSION 3.13)
Kevin Peng62a87112020-07-07 15:07:46 +08009project(tfm_ns LANGUAGES ASM C)
Kevin Peng62a87112020-07-07 15:07:46 +080010
Raef Coles5ee45ed2020-09-24 11:25:44 +010011# For multi-core projects, the NS app can be run on a different CPU to the
12# Secure code. To facilitate this, we once again reload the compiler to load the
13# setting for the NS CPU. Cmake settings are directory scoped so this affects
14# anything loaded from or declared in this dir.
15if (TFM_MULTI_CORE_TOPOLOGY)
16 include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload_ns.cmake)
Raef Coles34cffa72020-10-28 10:27:19 +000017 tfm_toolchain_reload_compiler()
Kevin Peng62a87112020-07-07 15:07:46 +080018endif()
19
Raef Coles5ee45ed2020-09-24 11:25:44 +010020############################# PSA test integration #############################
21
Raef Colesc922f252020-10-05 10:49:30 +010022if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH)
23 if(NOT SUITE)
24 set(SUITE ${TEST_PSA_API})
25 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +010026
Øyvind Rønningstad205a34a2020-10-02 10:31:23 +020027 if (NOT DEFINED PSA_API_TEST_TARGET)
28 string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
29 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +010030
Raef Colesc922f252020-10-05 10:49:30 +010031 if(NOT TARGET)
32 if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
33 set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
34 else()
35 set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
36 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +010037 endif()
38
Raef Coles5ee45ed2020-09-24 11:25:44 +010039
Raef Colesc922f252020-10-05 10:49:30 +010040 if(NOT PSA_INCLUDE_PATHS)
41 set(PSA_INCLUDE_PATHS ${CMAKE_SOURCE_DIR}/interface/include/
Raef Coles23d6a192020-10-22 15:43:38 +010042 ${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/
Raef Colesc922f252020-10-05 10:49:30 +010043 ${CMAKE_BINARY_DIR}/generated/interface/include
44 )
Raef Coles5ee45ed2020-09-24 11:25:44 +010045 endif()
46
Raef Colesc922f252020-10-05 10:49:30 +010047 if(NOT SP_HEAP_MEM_SUPP)
Raef Coles06e6f652020-10-20 16:10:38 +010048 set(SP_HEAP_MEM_SUPP 0)
Raef Colesc922f252020-10-05 10:49:30 +010049 endif()
50 if(NOT PLATFORM_PSA_ISOLATION_LEVEL)
51 set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
52 endif()
53
54 if (NOT TOOLCHAIN)
55 if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
56 set(TOOLCHAIN GNUARM)
57 elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
58 set(TOOLCHAIN ARMCLANG)
59 endif()
60 endif()
61
62 if (NOT CPU_ARCH)
63 if (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
64 set(CPU_ARCH armv8m_ml)
65 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
66 set(CPU_ARCH armv8m_bl)
67 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
68 set(CPU_ARCH armv7m)
69 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +010070 endif()
71
72 add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
Kevin Peng62a87112020-07-07 15:07:46 +080073endif()
74
Raef Coles5ee45ed2020-09-24 11:25:44 +010075############################# Test integration #################################
Kevin Peng62a87112020-07-07 15:07:46 +080076
Raef Coles5ee45ed2020-09-24 11:25:44 +010077add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
Kevin Peng62a87112020-07-07 15:07:46 +080078
Raef Coles5ee45ed2020-09-24 11:25:44 +010079target_sources(tfm_ns_integration_test
80 PRIVATE
81 tfm_integ_test.c
82)
Kevin Peng62a87112020-07-07 15:07:46 +080083
Raef Coles5ee45ed2020-09-24 11:25:44 +010084target_include_directories(tfm_ns_integration_test
85 PUBLIC
86 .
87)
Kevin Peng62a87112020-07-07 15:07:46 +080088
Raef Coles5ee45ed2020-09-24 11:25:44 +010089target_link_libraries(tfm_ns_integration_test
90 PUBLIC
91 $<$<BOOL:${TEST_NS}>:tfm_ns_tests>
92 tfm_test_framework
93 PRIVATE
94 psa_interface
Raef Coles5ee45ed2020-09-24 11:25:44 +010095 psa_api_ns
96 CMSIS_5_tfm_ns
97)
Kevin Peng62a87112020-07-07 15:07:46 +080098
Raef Coles5ee45ed2020-09-24 11:25:44 +010099target_compile_definitions(tfm_ns_integration_test
100 PUBLIC
101 $<$<BOOL:${TEST_NS}>:TEST_FRAMEWORK_NS>
102 $<$<BOOL:${TEST_S}>:TEST_FRAMEWORK_S>
103)
Kevin Peng62a87112020-07-07 15:07:46 +0800104
Raef Coles5ee45ed2020-09-24 11:25:44 +0100105############################# TFM NS app #######################################
Kevin Peng62a87112020-07-07 15:07:46 +0800106
Øyvind Rønningstad93ce2f52020-11-09 18:01:35 +0100107if (TEST_PSA_API)
108 add_library(tfm_ns_psa_test STATIC)
109
110 target_sources(tfm_ns_psa_test
111 PRIVATE
112 psa_api_test.c
113 )
114
115 target_link_libraries(tfm_ns_psa_test
116 PRIVATE
117 val_nspe
118 pal_nspe
119 test_combine
120 platform_ns
121 psa_api_ns
122 )
123
124 target_include_directories(tfm_ns_psa_test
125 PUBLIC
126 .
127 )
128
129 target_compile_definitions(tfm_ns_psa_test
130 PUBLIC
131 PSA_API_TEST_NS
132 )
133endif()
134
Raef Coles5ee45ed2020-09-24 11:25:44 +0100135add_executable(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800136
Raef Coles5ee45ed2020-09-24 11:25:44 +0100137target_sources(tfm_ns
138 PRIVATE
139 main_ns.c
Raef Coles5ee45ed2020-09-24 11:25:44 +0100140)
Kevin Peng62a87112020-07-07 15:07:46 +0800141
Raef Coles5ee45ed2020-09-24 11:25:44 +0100142target_link_libraries(tfm_ns
143 PRIVATE
144 platform_ns
145 CMSIS_5_tfm_ns
146 $<$<OR:$<BOOL:${TEST_NS}>,$<BOOL:${TEST_S}>>:tfm_ns_integration_test>
Øyvind Rønningstad93ce2f52020-11-09 18:01:35 +0100147 $<$<BOOL:${TEST_PSA_API}>:tfm_ns_psa_test>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100148 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:tfm_s_veneers>
149 psa_api_ns
Kevin Pengaf602292020-10-20 17:49:52 +0800150 tfm_ns_log
Raef Coles5ee45ed2020-09-24 11:25:44 +0100151)
Kevin Peng62a87112020-07-07 15:07:46 +0800152
Raef Coles5ee45ed2020-09-24 11:25:44 +0100153set_target_properties(tfm_ns PROPERTIES
154 SUFFIX ".axf"
155 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
156)
Kevin Peng62a87112020-07-07 15:07:46 +0800157
Raef Coles5ee45ed2020-09-24 11:25:44 +0100158target_link_options(tfm_ns
159 PRIVATE
160 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
161 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomd35ffa02020-09-29 13:31:31 +0200162 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100163)
Kevin Peng62a87112020-07-07 15:07:46 +0800164
Raef Coles5ee45ed2020-09-24 11:25:44 +0100165add_convert_to_bin_target(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800166
Raef Coles5ee45ed2020-09-24 11:25:44 +0100167############################# CMSIS ############################################
Kevin Peng62a87112020-07-07 15:07:46 +0800168
Raef Coles5ee45ed2020-09-24 11:25:44 +0100169include(FetchContent)
Kevin Peng62a87112020-07-07 15:07:46 +0800170
Raef Coles5ee45ed2020-09-24 11:25:44 +0100171set(FETCHCONTENT_QUIET FALSE)
172cmake_policy(SET CMP0079 NEW)
Kevin Peng62a87112020-07-07 15:07:46 +0800173
Raef Coles5ee45ed2020-09-24 11:25:44 +0100174add_library(CMSIS_5_tfm_ns INTERFACE)
Kevin Peng62a87112020-07-07 15:07:46 +0800175
Raef Coles5ee45ed2020-09-24 11:25:44 +0100176target_sources(CMSIS_5_tfm_ns
177 INTERFACE
178 ${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
179 ${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
180 ${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
181)
Kevin Peng62a87112020-07-07 15:07:46 +0800182
Raef Coles5ee45ed2020-09-24 11:25:44 +0100183target_include_directories(CMSIS_5_tfm_ns
184 INTERFACE
185 ${CMSIS_5_PATH}/Core/Include
186 ${CMSIS_5_PATH}/RTOS2/Include
187 ${CMSIS_5_PATH}/RTOS2/RTX/Include
188 ${CMSIS_5_PATH}/RTOS2/RTX/Config
189)
Kevin Peng62a87112020-07-07 15:07:46 +0800190
Raef Coles5ee45ed2020-09-24 11:25:44 +0100191target_link_libraries(CMSIS_5_tfm_ns
192 INTERFACE
193 platform_ns
194)