blob: aabdaed51b3ae1547bcb7356d4194bc533ae7464 [file] [log] [blame]
Kevin Peng62a87112020-07-07 15:07:46 +08001#-------------------------------------------------------------------------------
David Hu48369db2020-12-17 17:31:54 +08002# Copyright (c) 2020-2021, 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()
David Hu402a2982020-12-17 22:31:04 +080018
19 # Enable TFM_MULTI_CORE_NS_OS when building with tf-m-tests NS App.
20 set(TFM_MULTI_CORE_NS_OS ON CACHE BOOL "Enable NS RTOS support in NS mailbox")
Kevin Peng62a87112020-07-07 15:07:46 +080021endif()
22
David Hu73f259b2020-12-07 10:58:41 +080023# In actual NS integration, NS side build should include the source files
24# exported by TF-M build.
25# Directly include interface folder to simplify the NS build in this demo, since
26# install always occurs at the end of build.
27set(INTERFACE_SRC_DIR ${CMAKE_SOURCE_DIR}/interface/src)
28set(INTERFACE_INC_DIR ${CMAKE_SOURCE_DIR}/interface/include)
29
30#################### TF-M NS interface (header only) ###########################
31
32add_library(tfm_ns_interface INTERFACE)
33
34target_include_directories(tfm_ns_interface
35 INTERFACE
36 ${INTERFACE_INC_DIR}
37 ${CMAKE_BINARY_DIR}/generated/interface/include
38 ${INTERFACE_INC_DIR}/os_wrapper
David Hu8e683252020-12-17 18:02:32 +080039 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:${INTERFACE_INC_DIR}/multi_core>
David Hu98adf322020-09-01 16:18:46 +080040 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:${CMAKE_SOURCE_DIR}/platform/ext/cmsis>
David Hu73f259b2020-12-07 10:58:41 +080041)
42
43# PSA interface files are generated from a template
44add_dependencies(tfm_ns_interface
45 tfm_generated_files
46)
47
48# Include selection of Secure Partitions from TF-M build.
49# It can be replaced by NS side configurations later.
50target_link_libraries(tfm_ns_interface
51 INTERFACE
52 tfm_partition_defs
53)
54
55target_compile_definitions(tfm_ns_interface
56 INTERFACE
57 $<$<BOOL:${TFM_PSA_API}>:TFM_PSA_API>
58 $<$<STREQUAL:${TEST_PSA_API},IPC>:PSA_API_TEST_IPC>
59 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:TFM_NS_CLIENT_IDENTIFICATION>
60 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:TFM_MULTI_CORE_TOPOLOGY>
David Hu402a2982020-12-17 22:31:04 +080061 $<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:TFM_MULTI_CORE_NS_OS>
David Hu98adf322020-09-01 16:18:46 +080062 $<$<AND:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>,$<BOOL:${TFM_MULTI_CORE_NS_OS}>>:TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD>
David Hu73f259b2020-12-07 10:58:41 +080063 $<$<BOOL:${FORWARD_PROT_MSG}>:FORWARD_PROT_MSG>
64)
65
66###################### TF-M NS interface api (NS lib) ##########################
67
68add_library(tfm_api_ns STATIC)
69
70target_sources(tfm_api_ns
71 PRIVATE
72 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:${INTERFACE_SRC_DIR}/tfm_nspm_svc_handler.c>
73 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:${INTERFACE_SRC_DIR}/tfm_nspm_api.c>
74)
75
76if (${TFM_PSA_API})
77 target_sources(tfm_api_ns PRIVATE
78 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PLATFORM}>>:${INTERFACE_SRC_DIR}/tfm_platform_ipc_api.c>
79 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_ps_ipc_api.c>
80 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_its_ipc_api.c>
81 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_CRYPTO}>>:${INTERFACE_SRC_DIR}/tfm_crypto_ipc_api.c>
82 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_ipc_api.c>
83 )
84
85 if (TFM_MULTI_CORE_TOPOLOGY)
86 target_sources(tfm_api_ns PRIVATE
David Hu8e683252020-12-17 18:02:32 +080087 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c
88 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c
David Hu402a2982020-12-17 22:31:04 +080089 $<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c>
David Hu98adf322020-09-01 16:18:46 +080090 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox.c>
91 $<$<AND:$<BOOL:${TFM_MULTI_CORE_NS_OS}>,$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_thread.c>
92 $<$<BOOL:${TEST_NS}>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_test.c>
David Hu73f259b2020-12-07 10:58:41 +080093 )
94 else()
95 target_sources(tfm_api_ns PRIVATE
96 ${INTERFACE_SRC_DIR}/tfm_ns_interface.c
97 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
98 )
99 endif()
100else()
101 target_sources(tfm_api_ns PRIVATE
102 $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_func_api.c>
103 $<$<BOOL:${TFM_PARTITION_AUDIT_LOG}>:${INTERFACE_SRC_DIR}/tfm_audit_func_api.c>
104 $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_func_api.c>
105 $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_func_api.c>
106 $<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_func_api.c>
107 $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_func_api.c>
108 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
109 ${INTERFACE_SRC_DIR}/tfm_ns_interface.c
110 )
111endif()
112
113target_link_libraries(tfm_api_ns
114 PUBLIC
115 tfm_ns_interface
116 PRIVATE
117 platform_ns
118 # CMSIS is currently only required to provide the NS client IDs. In
119 # future, this should probably be made more OS agnostic
120 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:CMSIS_5_tfm_ns>
121)
122
Raef Coles5ee45ed2020-09-24 11:25:44 +0100123############################# PSA test integration #############################
124
Raef Colesc922f252020-10-05 10:49:30 +0100125if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH)
126 if(NOT SUITE)
127 set(SUITE ${TEST_PSA_API})
128 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100129
Øyvind Rønningstad205a34a2020-10-02 10:31:23 +0200130 if (NOT DEFINED PSA_API_TEST_TARGET)
131 string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
132 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100133
Raef Colesc922f252020-10-05 10:49:30 +0100134 if(NOT TARGET)
135 if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
136 set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
137 else()
138 set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
139 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100140 endif()
141
Raef Coles5ee45ed2020-09-24 11:25:44 +0100142
Raef Colesc922f252020-10-05 10:49:30 +0100143 if(NOT PSA_INCLUDE_PATHS)
David Hua1fee3d2020-12-30 11:06:37 +0800144 set(PSA_INCLUDE_PATHS ${INTERFACE_INC_DIR}/
Raef Coles23d6a192020-10-22 15:43:38 +0100145 ${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/
Raef Colesc922f252020-10-05 10:49:30 +0100146 ${CMAKE_BINARY_DIR}/generated/interface/include
147 )
Raef Coles5ee45ed2020-09-24 11:25:44 +0100148 endif()
149
Raef Colesc922f252020-10-05 10:49:30 +0100150 if(NOT SP_HEAP_MEM_SUPP)
Raef Coles06e6f652020-10-20 16:10:38 +0100151 set(SP_HEAP_MEM_SUPP 0)
Raef Colesc922f252020-10-05 10:49:30 +0100152 endif()
153 if(NOT PLATFORM_PSA_ISOLATION_LEVEL)
154 set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
155 endif()
156
157 if (NOT TOOLCHAIN)
158 if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
159 set(TOOLCHAIN GNUARM)
160 elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
161 set(TOOLCHAIN ARMCLANG)
162 endif()
163 endif()
164
165 if (NOT CPU_ARCH)
166 if (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
167 set(CPU_ARCH armv8m_ml)
168 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
169 set(CPU_ARCH armv8m_bl)
170 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
171 set(CPU_ARCH armv7m)
172 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100173 endif()
174
175 add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
Kevin Peng62a87112020-07-07 15:07:46 +0800176endif()
177
Raef Coles5ee45ed2020-09-24 11:25:44 +0100178############################# Test integration #################################
Kevin Peng62a87112020-07-07 15:07:46 +0800179
Raef Coles5ee45ed2020-09-24 11:25:44 +0100180add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
Kevin Peng62a87112020-07-07 15:07:46 +0800181
Raef Coles5ee45ed2020-09-24 11:25:44 +0100182target_sources(tfm_ns_integration_test
183 PRIVATE
184 tfm_integ_test.c
185)
Kevin Peng62a87112020-07-07 15:07:46 +0800186
Raef Coles5ee45ed2020-09-24 11:25:44 +0100187target_include_directories(tfm_ns_integration_test
188 PUBLIC
189 .
190)
Kevin Peng62a87112020-07-07 15:07:46 +0800191
Raef Coles5ee45ed2020-09-24 11:25:44 +0100192target_link_libraries(tfm_ns_integration_test
193 PUBLIC
194 $<$<BOOL:${TEST_NS}>:tfm_ns_tests>
David Hu73f259b2020-12-07 10:58:41 +0800195 tfm_test_framework_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100196 PRIVATE
David Hu73f259b2020-12-07 10:58:41 +0800197 tfm_ns_interface
198 tfm_api_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100199 CMSIS_5_tfm_ns
200)
Kevin Peng62a87112020-07-07 15:07:46 +0800201
Raef Coles5ee45ed2020-09-24 11:25:44 +0100202target_compile_definitions(tfm_ns_integration_test
203 PUBLIC
204 $<$<BOOL:${TEST_NS}>:TEST_FRAMEWORK_NS>
205 $<$<BOOL:${TEST_S}>:TEST_FRAMEWORK_S>
206)
Kevin Peng62a87112020-07-07 15:07:46 +0800207
Raef Coles5ee45ed2020-09-24 11:25:44 +0100208############################# TFM NS app #######################################
Kevin Peng62a87112020-07-07 15:07:46 +0800209
Raef Coles5ee45ed2020-09-24 11:25:44 +0100210add_executable(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800211
Raef Coles5ee45ed2020-09-24 11:25:44 +0100212target_sources(tfm_ns
213 PRIVATE
214 main_ns.c
Kevin Peng0d3a3812020-12-23 02:17:57 +0000215 $<$<BOOL:${TEST_PSA_API}>:psa_api_test.c>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100216)
Kevin Peng62a87112020-07-07 15:07:46 +0800217
Raef Coles5ee45ed2020-09-24 11:25:44 +0100218target_link_libraries(tfm_ns
219 PRIVATE
220 platform_ns
221 CMSIS_5_tfm_ns
222 $<$<OR:$<BOOL:${TEST_NS}>,$<BOOL:${TEST_S}>>:tfm_ns_integration_test>
Kevin Peng0d3a3812020-12-23 02:17:57 +0000223 $<$<BOOL:${TEST_PSA_API}>:val_nspe>
224 $<$<BOOL:${TEST_PSA_API}>:pal_nspe>
225 $<$<BOOL:${TEST_PSA_API}>:test_combine>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100226 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:tfm_s_veneers>
David Hu73f259b2020-12-07 10:58:41 +0800227 tfm_api_ns
Kevin Pengaf602292020-10-20 17:49:52 +0800228 tfm_ns_log
Raef Coles5ee45ed2020-09-24 11:25:44 +0100229)
Kevin Peng62a87112020-07-07 15:07:46 +0800230
Kevin Peng0d3a3812020-12-23 02:17:57 +0000231target_compile_definitions(tfm_ns
232 PUBLIC
233 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
234)
235
Raef Coles5ee45ed2020-09-24 11:25:44 +0100236set_target_properties(tfm_ns PROPERTIES
237 SUFFIX ".axf"
238 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
239)
Kevin Peng62a87112020-07-07 15:07:46 +0800240
Raef Coles5ee45ed2020-09-24 11:25:44 +0100241target_link_options(tfm_ns
242 PRIVATE
243 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
244 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomd35ffa02020-09-29 13:31:31 +0200245 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100246)
Kevin Peng62a87112020-07-07 15:07:46 +0800247
Raef Coles5ee45ed2020-09-24 11:25:44 +0100248add_convert_to_bin_target(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800249
Raef Coles5ee45ed2020-09-24 11:25:44 +0100250############################# CMSIS ############################################
Kevin Peng62a87112020-07-07 15:07:46 +0800251
Raef Coles5ee45ed2020-09-24 11:25:44 +0100252include(FetchContent)
Kevin Peng62a87112020-07-07 15:07:46 +0800253
Raef Coles5ee45ed2020-09-24 11:25:44 +0100254set(FETCHCONTENT_QUIET FALSE)
255cmake_policy(SET CMP0079 NEW)
Kevin Peng62a87112020-07-07 15:07:46 +0800256
Raef Coles5ee45ed2020-09-24 11:25:44 +0100257add_library(CMSIS_5_tfm_ns INTERFACE)
Kevin Peng62a87112020-07-07 15:07:46 +0800258
Raef Coles5ee45ed2020-09-24 11:25:44 +0100259target_sources(CMSIS_5_tfm_ns
260 INTERFACE
261 ${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
262 ${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
263 ${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
264)
Kevin Peng62a87112020-07-07 15:07:46 +0800265
Raef Coles5ee45ed2020-09-24 11:25:44 +0100266target_include_directories(CMSIS_5_tfm_ns
267 INTERFACE
268 ${CMSIS_5_PATH}/Core/Include
269 ${CMSIS_5_PATH}/RTOS2/Include
270 ${CMSIS_5_PATH}/RTOS2/RTX/Include
271 ${CMSIS_5_PATH}/RTOS2/RTX/Config
272)
Kevin Peng62a87112020-07-07 15:07:46 +0800273
Raef Coles5ee45ed2020-09-24 11:25:44 +0100274target_link_libraries(CMSIS_5_tfm_ns
275 INTERFACE
276 platform_ns
277)