blob: 67d161755c120afdfdf5e799419a5c6315590aa0 [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
David Hu73f259b2020-12-07 10:58:41 +080020# In actual NS integration, NS side build should include the source files
21# exported by TF-M build.
22# Directly include interface folder to simplify the NS build in this demo, since
23# install always occurs at the end of build.
24set(INTERFACE_SRC_DIR ${CMAKE_SOURCE_DIR}/interface/src)
25set(INTERFACE_INC_DIR ${CMAKE_SOURCE_DIR}/interface/include)
26
27#################### TF-M NS interface (header only) ###########################
28
29add_library(tfm_ns_interface INTERFACE)
30
31target_include_directories(tfm_ns_interface
32 INTERFACE
33 ${INTERFACE_INC_DIR}
34 ${CMAKE_BINARY_DIR}/generated/interface/include
35 ${INTERFACE_INC_DIR}/os_wrapper
36)
37
38# PSA interface files are generated from a template
39add_dependencies(tfm_ns_interface
40 tfm_generated_files
41)
42
43# Include selection of Secure Partitions from TF-M build.
44# It can be replaced by NS side configurations later.
45target_link_libraries(tfm_ns_interface
46 INTERFACE
47 tfm_partition_defs
48)
49
50target_compile_definitions(tfm_ns_interface
51 INTERFACE
52 $<$<BOOL:${TFM_PSA_API}>:TFM_PSA_API>
53 $<$<STREQUAL:${TEST_PSA_API},IPC>:PSA_API_TEST_IPC>
54 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:TFM_NS_CLIENT_IDENTIFICATION>
55 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:TFM_MULTI_CORE_TOPOLOGY>
56 $<$<BOOL:${TFM_MULTI_CORE_MULTI_CLIENT_CALL}>:TFM_MULTI_CORE_MULTI_CLIENT_CALL>
57 $<$<BOOL:${FORWARD_PROT_MSG}>:FORWARD_PROT_MSG>
58)
59
60###################### TF-M NS interface api (NS lib) ##########################
61
62add_library(tfm_api_ns STATIC)
63
64target_sources(tfm_api_ns
65 PRIVATE
66 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:${INTERFACE_SRC_DIR}/tfm_nspm_svc_handler.c>
67 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:${INTERFACE_SRC_DIR}/tfm_nspm_api.c>
68)
69
70if (${TFM_PSA_API})
71 target_sources(tfm_api_ns PRIVATE
72 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PLATFORM}>>:${INTERFACE_SRC_DIR}/tfm_platform_ipc_api.c>
73 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_ps_ipc_api.c>
74 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_its_ipc_api.c>
75 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_CRYPTO}>>:${INTERFACE_SRC_DIR}/tfm_crypto_ipc_api.c>
76 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_ipc_api.c>
77 )
78
79 if (TFM_MULTI_CORE_TOPOLOGY)
80 target_sources(tfm_api_ns PRIVATE
81 ${INTERFACE_SRC_DIR}/tfm_ns_mailbox.c
82 ${INTERFACE_SRC_DIR}/tfm_multi_core_api.c
83 ${INTERFACE_SRC_DIR}/tfm_multi_core_psa_ns_api.c
84 )
85 else()
86 target_sources(tfm_api_ns PRIVATE
87 ${INTERFACE_SRC_DIR}/tfm_ns_interface.c
88 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
89 )
90 endif()
91else()
92 target_sources(tfm_api_ns PRIVATE
93 $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_func_api.c>
94 $<$<BOOL:${TFM_PARTITION_AUDIT_LOG}>:${INTERFACE_SRC_DIR}/tfm_audit_func_api.c>
95 $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_func_api.c>
96 $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_func_api.c>
97 $<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_func_api.c>
98 $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_func_api.c>
99 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
100 ${INTERFACE_SRC_DIR}/tfm_ns_interface.c
101 )
102endif()
103
104target_link_libraries(tfm_api_ns
105 PUBLIC
106 tfm_ns_interface
107 PRIVATE
108 platform_ns
109 # CMSIS is currently only required to provide the NS client IDs. In
110 # future, this should probably be made more OS agnostic
111 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:CMSIS_5_tfm_ns>
112)
113
Raef Coles5ee45ed2020-09-24 11:25:44 +0100114############################# PSA test integration #############################
115
Raef Colesc922f252020-10-05 10:49:30 +0100116if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH)
117 if(NOT SUITE)
118 set(SUITE ${TEST_PSA_API})
119 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100120
Øyvind Rønningstad205a34a2020-10-02 10:31:23 +0200121 if (NOT DEFINED PSA_API_TEST_TARGET)
122 string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
123 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100124
Raef Colesc922f252020-10-05 10:49:30 +0100125 if(NOT TARGET)
126 if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
127 set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
128 else()
129 set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
130 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100131 endif()
132
Raef Coles5ee45ed2020-09-24 11:25:44 +0100133
Raef Colesc922f252020-10-05 10:49:30 +0100134 if(NOT PSA_INCLUDE_PATHS)
David Hu73f259b2020-12-07 10:58:41 +0800135 set(PSA_INCLUDE_PATHS ${EXPORT_INC_DIR}/
Raef Coles23d6a192020-10-22 15:43:38 +0100136 ${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/
Raef Colesc922f252020-10-05 10:49:30 +0100137 ${CMAKE_BINARY_DIR}/generated/interface/include
138 )
Raef Coles5ee45ed2020-09-24 11:25:44 +0100139 endif()
140
Raef Colesc922f252020-10-05 10:49:30 +0100141 if(NOT SP_HEAP_MEM_SUPP)
Raef Coles06e6f652020-10-20 16:10:38 +0100142 set(SP_HEAP_MEM_SUPP 0)
Raef Colesc922f252020-10-05 10:49:30 +0100143 endif()
144 if(NOT PLATFORM_PSA_ISOLATION_LEVEL)
145 set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
146 endif()
147
148 if (NOT TOOLCHAIN)
149 if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
150 set(TOOLCHAIN GNUARM)
151 elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
152 set(TOOLCHAIN ARMCLANG)
153 endif()
154 endif()
155
156 if (NOT CPU_ARCH)
157 if (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
158 set(CPU_ARCH armv8m_ml)
159 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
160 set(CPU_ARCH armv8m_bl)
161 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
162 set(CPU_ARCH armv7m)
163 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100164 endif()
165
166 add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
Kevin Peng62a87112020-07-07 15:07:46 +0800167endif()
168
Raef Coles5ee45ed2020-09-24 11:25:44 +0100169############################# Test integration #################################
Kevin Peng62a87112020-07-07 15:07:46 +0800170
Raef Coles5ee45ed2020-09-24 11:25:44 +0100171add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
Kevin Peng62a87112020-07-07 15:07:46 +0800172
Raef Coles5ee45ed2020-09-24 11:25:44 +0100173target_sources(tfm_ns_integration_test
174 PRIVATE
175 tfm_integ_test.c
176)
Kevin Peng62a87112020-07-07 15:07:46 +0800177
Raef Coles5ee45ed2020-09-24 11:25:44 +0100178target_include_directories(tfm_ns_integration_test
179 PUBLIC
180 .
181)
Kevin Peng62a87112020-07-07 15:07:46 +0800182
Raef Coles5ee45ed2020-09-24 11:25:44 +0100183target_link_libraries(tfm_ns_integration_test
184 PUBLIC
185 $<$<BOOL:${TEST_NS}>:tfm_ns_tests>
David Hu73f259b2020-12-07 10:58:41 +0800186 tfm_test_framework_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100187 PRIVATE
David Hu73f259b2020-12-07 10:58:41 +0800188 tfm_ns_interface
189 tfm_api_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100190 CMSIS_5_tfm_ns
191)
Kevin Peng62a87112020-07-07 15:07:46 +0800192
Raef Coles5ee45ed2020-09-24 11:25:44 +0100193target_compile_definitions(tfm_ns_integration_test
194 PUBLIC
195 $<$<BOOL:${TEST_NS}>:TEST_FRAMEWORK_NS>
196 $<$<BOOL:${TEST_S}>:TEST_FRAMEWORK_S>
197)
Kevin Peng62a87112020-07-07 15:07:46 +0800198
Raef Coles5ee45ed2020-09-24 11:25:44 +0100199############################# TFM NS app #######################################
Kevin Peng62a87112020-07-07 15:07:46 +0800200
Raef Coles5ee45ed2020-09-24 11:25:44 +0100201add_executable(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800202
Raef Coles5ee45ed2020-09-24 11:25:44 +0100203target_sources(tfm_ns
204 PRIVATE
205 main_ns.c
Kevin Peng0d3a3812020-12-23 02:17:57 +0000206 $<$<BOOL:${TEST_PSA_API}>:psa_api_test.c>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100207)
Kevin Peng62a87112020-07-07 15:07:46 +0800208
Raef Coles5ee45ed2020-09-24 11:25:44 +0100209target_link_libraries(tfm_ns
210 PRIVATE
211 platform_ns
212 CMSIS_5_tfm_ns
213 $<$<OR:$<BOOL:${TEST_NS}>,$<BOOL:${TEST_S}>>:tfm_ns_integration_test>
Kevin Peng0d3a3812020-12-23 02:17:57 +0000214 $<$<BOOL:${TEST_PSA_API}>:val_nspe>
215 $<$<BOOL:${TEST_PSA_API}>:pal_nspe>
216 $<$<BOOL:${TEST_PSA_API}>:test_combine>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100217 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:tfm_s_veneers>
David Hu73f259b2020-12-07 10:58:41 +0800218 tfm_api_ns
Kevin Pengaf602292020-10-20 17:49:52 +0800219 tfm_ns_log
Raef Coles5ee45ed2020-09-24 11:25:44 +0100220)
Kevin Peng62a87112020-07-07 15:07:46 +0800221
Kevin Peng0d3a3812020-12-23 02:17:57 +0000222target_compile_definitions(tfm_ns
223 PUBLIC
224 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
225)
226
Raef Coles5ee45ed2020-09-24 11:25:44 +0100227set_target_properties(tfm_ns PROPERTIES
228 SUFFIX ".axf"
229 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
230)
Kevin Peng62a87112020-07-07 15:07:46 +0800231
Raef Coles5ee45ed2020-09-24 11:25:44 +0100232target_link_options(tfm_ns
233 PRIVATE
234 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
235 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomd35ffa02020-09-29 13:31:31 +0200236 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100237)
Kevin Peng62a87112020-07-07 15:07:46 +0800238
Raef Coles5ee45ed2020-09-24 11:25:44 +0100239add_convert_to_bin_target(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800240
Raef Coles5ee45ed2020-09-24 11:25:44 +0100241############################# CMSIS ############################################
Kevin Peng62a87112020-07-07 15:07:46 +0800242
Raef Coles5ee45ed2020-09-24 11:25:44 +0100243include(FetchContent)
Kevin Peng62a87112020-07-07 15:07:46 +0800244
Raef Coles5ee45ed2020-09-24 11:25:44 +0100245set(FETCHCONTENT_QUIET FALSE)
246cmake_policy(SET CMP0079 NEW)
Kevin Peng62a87112020-07-07 15:07:46 +0800247
Raef Coles5ee45ed2020-09-24 11:25:44 +0100248add_library(CMSIS_5_tfm_ns INTERFACE)
Kevin Peng62a87112020-07-07 15:07:46 +0800249
Raef Coles5ee45ed2020-09-24 11:25:44 +0100250target_sources(CMSIS_5_tfm_ns
251 INTERFACE
252 ${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
253 ${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
254 ${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
255)
Kevin Peng62a87112020-07-07 15:07:46 +0800256
Raef Coles5ee45ed2020-09-24 11:25:44 +0100257target_include_directories(CMSIS_5_tfm_ns
258 INTERFACE
259 ${CMSIS_5_PATH}/Core/Include
260 ${CMSIS_5_PATH}/RTOS2/Include
261 ${CMSIS_5_PATH}/RTOS2/RTX/Include
262 ${CMSIS_5_PATH}/RTOS2/RTX/Config
263)
Kevin Peng62a87112020-07-07 15:07:46 +0800264
Raef Coles5ee45ed2020-09-24 11:25:44 +0100265target_link_libraries(CMSIS_5_tfm_ns
266 INTERFACE
267 platform_ns
268)