blob: a2102190beee3f16d1f585b2360cf46c25130195 [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>
Sherry Zhang92c499a2021-03-08 18:14:15 +080083 $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_firmware_update_ipc_api.c>
84 )
David Hu73f259b2020-12-07 10:58:41 +080085
86 if (TFM_MULTI_CORE_TOPOLOGY)
87 target_sources(tfm_api_ns PRIVATE
David Hu8e683252020-12-17 18:02:32 +080088 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c
89 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c
David Hu402a2982020-12-17 22:31:04 +080090 $<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c>
David Hu98adf322020-09-01 16:18:46 +080091 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox.c>
92 $<$<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>
93 $<$<BOOL:${TEST_NS}>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox_test.c>
David Hu73f259b2020-12-07 10:58:41 +080094 )
95 else()
96 target_sources(tfm_api_ns PRIVATE
97 ${INTERFACE_SRC_DIR}/tfm_ns_interface.c
98 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
99 )
100 endif()
101else()
102 target_sources(tfm_api_ns PRIVATE
103 $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_func_api.c>
104 $<$<BOOL:${TFM_PARTITION_AUDIT_LOG}>:${INTERFACE_SRC_DIR}/tfm_audit_func_api.c>
105 $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_func_api.c>
106 $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_func_api.c>
107 $<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_func_api.c>
108 $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_func_api.c>
Sherry Zhang92c499a2021-03-08 18:14:15 +0800109 $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_firmware_update_func_api.c>
David Hu73f259b2020-12-07 10:58:41 +0800110 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
111 ${INTERFACE_SRC_DIR}/tfm_ns_interface.c
112 )
113endif()
114
115target_link_libraries(tfm_api_ns
116 PUBLIC
117 tfm_ns_interface
118 PRIVATE
119 platform_ns
120 # CMSIS is currently only required to provide the NS client IDs. In
121 # future, this should probably be made more OS agnostic
122 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:CMSIS_5_tfm_ns>
123)
124
Raef Coles5ee45ed2020-09-24 11:25:44 +0100125############################# PSA test integration #############################
126
Raef Colesc922f252020-10-05 10:49:30 +0100127if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH)
128 if(NOT SUITE)
129 set(SUITE ${TEST_PSA_API})
130 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100131
Øyvind Rønningstad205a34a2020-10-02 10:31:23 +0200132 if (NOT DEFINED PSA_API_TEST_TARGET)
133 string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
134 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100135
Raef Colesc922f252020-10-05 10:49:30 +0100136 if(NOT TARGET)
137 if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
138 set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
139 else()
140 set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
141 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100142 endif()
143
Raef Coles5ee45ed2020-09-24 11:25:44 +0100144
Raef Colesc922f252020-10-05 10:49:30 +0100145 if(NOT PSA_INCLUDE_PATHS)
David Hua1fee3d2020-12-30 11:06:37 +0800146 set(PSA_INCLUDE_PATHS ${INTERFACE_INC_DIR}/
Raef Coles23d6a192020-10-22 15:43:38 +0100147 ${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/
Raef Colesc922f252020-10-05 10:49:30 +0100148 ${CMAKE_BINARY_DIR}/generated/interface/include
149 )
Raef Coles5ee45ed2020-09-24 11:25:44 +0100150 endif()
151
Raef Colesc922f252020-10-05 10:49:30 +0100152 if(NOT SP_HEAP_MEM_SUPP)
Raef Coles06e6f652020-10-20 16:10:38 +0100153 set(SP_HEAP_MEM_SUPP 0)
Raef Colesc922f252020-10-05 10:49:30 +0100154 endif()
155 if(NOT PLATFORM_PSA_ISOLATION_LEVEL)
156 set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
157 endif()
158
159 if (NOT TOOLCHAIN)
160 if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
161 set(TOOLCHAIN GNUARM)
162 elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
163 set(TOOLCHAIN ARMCLANG)
164 endif()
165 endif()
166
167 if (NOT CPU_ARCH)
168 if (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
169 set(CPU_ARCH armv8m_ml)
170 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
171 set(CPU_ARCH armv8m_bl)
172 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
173 set(CPU_ARCH armv7m)
174 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100175 endif()
176
177 add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
Kevin Peng62a87112020-07-07 15:07:46 +0800178endif()
179
Raef Coles5ee45ed2020-09-24 11:25:44 +0100180############################# Test integration #################################
Kevin Peng62a87112020-07-07 15:07:46 +0800181
Raef Coles5ee45ed2020-09-24 11:25:44 +0100182add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
Kevin Peng62a87112020-07-07 15:07:46 +0800183
Raef Coles5ee45ed2020-09-24 11:25:44 +0100184target_sources(tfm_ns_integration_test
185 PRIVATE
186 tfm_integ_test.c
187)
Kevin Peng62a87112020-07-07 15:07:46 +0800188
Raef Coles5ee45ed2020-09-24 11:25:44 +0100189target_include_directories(tfm_ns_integration_test
190 PUBLIC
191 .
192)
Kevin Peng62a87112020-07-07 15:07:46 +0800193
Raef Coles5ee45ed2020-09-24 11:25:44 +0100194target_link_libraries(tfm_ns_integration_test
195 PUBLIC
196 $<$<BOOL:${TEST_NS}>:tfm_ns_tests>
David Hu73f259b2020-12-07 10:58:41 +0800197 tfm_test_framework_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100198 PRIVATE
David Hu73f259b2020-12-07 10:58:41 +0800199 tfm_ns_interface
200 tfm_api_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100201 CMSIS_5_tfm_ns
202)
Kevin Peng62a87112020-07-07 15:07:46 +0800203
Raef Coles5ee45ed2020-09-24 11:25:44 +0100204target_compile_definitions(tfm_ns_integration_test
205 PUBLIC
206 $<$<BOOL:${TEST_NS}>:TEST_FRAMEWORK_NS>
207 $<$<BOOL:${TEST_S}>:TEST_FRAMEWORK_S>
208)
Kevin Peng62a87112020-07-07 15:07:46 +0800209
Raef Coles5ee45ed2020-09-24 11:25:44 +0100210############################# TFM NS app #######################################
Kevin Peng62a87112020-07-07 15:07:46 +0800211
Raef Coles5ee45ed2020-09-24 11:25:44 +0100212add_executable(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800213
Raef Coles5ee45ed2020-09-24 11:25:44 +0100214target_sources(tfm_ns
215 PRIVATE
216 main_ns.c
Kevin Peng0d3a3812020-12-23 02:17:57 +0000217 $<$<BOOL:${TEST_PSA_API}>:psa_api_test.c>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100218)
Kevin Peng62a87112020-07-07 15:07:46 +0800219
Raef Coles5ee45ed2020-09-24 11:25:44 +0100220target_link_libraries(tfm_ns
221 PRIVATE
222 platform_ns
223 CMSIS_5_tfm_ns
224 $<$<OR:$<BOOL:${TEST_NS}>,$<BOOL:${TEST_S}>>:tfm_ns_integration_test>
Kevin Peng0d3a3812020-12-23 02:17:57 +0000225 $<$<BOOL:${TEST_PSA_API}>:val_nspe>
226 $<$<BOOL:${TEST_PSA_API}>:pal_nspe>
227 $<$<BOOL:${TEST_PSA_API}>:test_combine>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100228 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:tfm_s_veneers>
David Hu73f259b2020-12-07 10:58:41 +0800229 tfm_api_ns
Kevin Pengaf602292020-10-20 17:49:52 +0800230 tfm_ns_log
Raef Coles5ee45ed2020-09-24 11:25:44 +0100231)
Kevin Peng62a87112020-07-07 15:07:46 +0800232
Kevin Peng0d3a3812020-12-23 02:17:57 +0000233target_compile_definitions(tfm_ns
234 PUBLIC
235 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
236)
237
Raef Coles5ee45ed2020-09-24 11:25:44 +0100238set_target_properties(tfm_ns PROPERTIES
239 SUFFIX ".axf"
240 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
241)
Kevin Peng62a87112020-07-07 15:07:46 +0800242
Raef Coles5ee45ed2020-09-24 11:25:44 +0100243target_link_options(tfm_ns
244 PRIVATE
245 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
246 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomd35ffa02020-09-29 13:31:31 +0200247 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100248)
Kevin Peng62a87112020-07-07 15:07:46 +0800249
Raef Coles5ee45ed2020-09-24 11:25:44 +0100250add_convert_to_bin_target(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800251
Raef Coles5ee45ed2020-09-24 11:25:44 +0100252############################# CMSIS ############################################
Kevin Peng62a87112020-07-07 15:07:46 +0800253
Raef Coles5ee45ed2020-09-24 11:25:44 +0100254include(FetchContent)
Kevin Peng62a87112020-07-07 15:07:46 +0800255
Raef Coles5ee45ed2020-09-24 11:25:44 +0100256set(FETCHCONTENT_QUIET FALSE)
257cmake_policy(SET CMP0079 NEW)
Kevin Peng62a87112020-07-07 15:07:46 +0800258
Raef Coles5ee45ed2020-09-24 11:25:44 +0100259add_library(CMSIS_5_tfm_ns INTERFACE)
Kevin Peng62a87112020-07-07 15:07:46 +0800260
Raef Coles5ee45ed2020-09-24 11:25:44 +0100261target_sources(CMSIS_5_tfm_ns
262 INTERFACE
263 ${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
264 ${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
265 ${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
266)
Kevin Peng62a87112020-07-07 15:07:46 +0800267
Raef Coles5ee45ed2020-09-24 11:25:44 +0100268target_include_directories(CMSIS_5_tfm_ns
269 INTERFACE
270 ${CMSIS_5_PATH}/Core/Include
271 ${CMSIS_5_PATH}/RTOS2/Include
272 ${CMSIS_5_PATH}/RTOS2/RTX/Include
273 ${CMSIS_5_PATH}/RTOS2/RTX/Config
274)
Kevin Peng62a87112020-07-07 15:07:46 +0800275
Raef Coles5ee45ed2020-09-24 11:25:44 +0100276target_link_libraries(CMSIS_5_tfm_ns
277 INTERFACE
278 platform_ns
279)