-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
executable file
·360 lines (301 loc) · 12.5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#-------------------------------------------------------------------------------
# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
# Copyright (c) 2022-2023 Cypress Semiconductor Corporation (an Infineon company)
# or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
#-------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.13)
project(tfm_ns LANGUAGES ASM C)
# For multi-core projects, the NS app can be run on a different CPU to the
# Secure code. To facilitate this, we once again reload the compiler to load the
# setting for the NS CPU. Cmake settings are directory scoped so this affects
# anything loaded from or declared in this dir.
if (EXISTS ${TARGET_PLATFORM_PATH}/preload_ns.cmake)
include(${TARGET_PLATFORM_PATH}/preload_ns.cmake)
tfm_toolchain_reload_compiler()
endif()
if (TFM_MULTI_CORE_TOPOLOGY)
# Enable TFM_MULTI_CORE_NS_OS when building with tf-m-tests NS App.
set(TFM_MULTI_CORE_NS_OS ON CACHE BOOL "Enable NS RTOS support in NS mailbox")
endif()
# In actual NS integration, NS side build should include the source files
# exported by TF-M build.
# Directly include interface folder to simplify the NS build in this demo, since
# install always occurs at the end of build.
set(INTERFACE_SRC_DIR ${CMAKE_SOURCE_DIR}/interface/src)
set(INTERFACE_INC_DIR ${CMAKE_SOURCE_DIR}/interface/include)
# NS interface implemented by NSPE
set(NS_INTERFACE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../ns_interface)
# nsid_manager
set(NSID_MGR_DIR ${NS_INTERFACE_DIR}/ns_client_ext)
#################### TF-M NS interface (header only) ###########################
add_library(tfm_ns_interface INTERFACE)
# Include interface headers exported by TF-M
target_include_directories(tfm_ns_interface
INTERFACE
${INTERFACE_INC_DIR}
${CMAKE_BINARY_DIR}/generated/interface/include
$<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:${INTERFACE_INC_DIR}/multi_core>
)
# Include NS local interface headers
target_include_directories(tfm_ns_interface
INTERFACE
${NS_INTERFACE_DIR}
${NSID_MGR_DIR}
)
# Include selection of Secure Partitions from TF-M build.
# It can be replaced by NS side configurations later.
target_link_libraries(tfm_ns_interface
INTERFACE
tfm_partition_defs
)
target_compile_definitions(tfm_ns_interface
INTERFACE
$<$<STREQUAL:${TEST_PSA_API},IPC>:PSA_API_TEST_IPC>
$<$<BOOL:${TFM_NS_MANAGE_NSID}>:TFM_NS_MANAGE_NSID>
$<$<BOOL:${TEST_NS_MANAGE_NSID}>:TEST_NS_MANAGE_NSID>
$<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:CONFIG_TFM_USE_TRUSTZONE>
$<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:TFM_MULTI_CORE_TOPOLOGY>
$<$<BOOL:${TFM_PARTITION_NS_AGENT_MAILBOX}>:TFM_PARTITION_NS_AGENT_MAILBOX>
$<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:TFM_MULTI_CORE_NS_OS>
$<$<AND:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>,$<BOOL:${TFM_MULTI_CORE_NS_OS}>>:TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD>
)
target_compile_options(tfm_ns_interface
INTERFACE
${COMPILER_CP_FLAG}
)
###################### TF-M NS interface api (NS lib) ##########################
add_library(tfm_api_ns STATIC)
target_sources(tfm_api_ns
PRIVATE
$<$<BOOL:${TFM_NS_MANAGE_NSID}>:${NSID_MGR_DIR}/tfm_nsid_manager.c>
)
target_sources(tfm_api_ns PRIVATE
$<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_api.c>
$<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_api.c>
$<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_api.c>
$<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_api.c>
$<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_attest_api.c>
$<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_fwu_api.c>
)
if (TFM_PARTITION_NS_AGENT_MAILBOX)
target_sources(tfm_api_ns PRIVATE
${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c
${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c
$<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox.c>
$<$<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>
)
# NS RTOS specific implementation of NS mailbox
target_sources(tfm_api_ns PRIVATE
$<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:${NS_INTERFACE_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c>
$<$<BOOL:${TEST_NS_MULTI_CORE}>:${NS_INTERFACE_DIR}/multi_core/tfm_ns_mailbox_test.c>
)
endif()
target_sources(tfm_api_ns PRIVATE
$<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c>
# NS specific implementation of NS interface dispatcher
$<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${INTERFACE_SRC_DIR}/os_wrapper/tfm_ns_interface_rtos.c>
)
target_link_libraries(tfm_api_ns
PUBLIC
tfm_ns_interface
PRIVATE
$<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:tfm_s_veneers>
platform_ns
)
############################# PSA test integration #############################
if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH)
if(NOT SUITE)
set(SUITE ${TEST_PSA_API})
endif()
if (NOT DEFINED PSA_API_TEST_TARGET OR PSA_API_TEST_TARGET STREQUAL "")
string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
endif()
if(NOT TARGET)
if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
else()
set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
endif()
endif()
if(NOT PSA_INCLUDE_PATHS)
set(PSA_INCLUDE_PATHS ${INTERFACE_INC_DIR}/
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/
${CMAKE_BINARY_DIR}/generated/interface/include
)
endif()
if(NOT SP_HEAP_MEM_SUPP)
set(SP_HEAP_MEM_SUPP 0)
endif()
if(NOT PLATFORM_PSA_ISOLATION_LEVEL)
set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
endif()
if (NOT TOOLCHAIN)
if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
set(TOOLCHAIN GNUARM)
elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
set(TOOLCHAIN ARMCLANG)
endif()
endif()
if (NOT CPU_ARCH)
if (${TFM_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
set(CPU_ARCH armv8m_ml)
elseif (${TFM_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
set(CPU_ARCH armv8m_bl)
elseif (${TFM_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
set(CPU_ARCH armv7m)
endif()
endif()
add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
if (TEST_PSA_API STREQUAL IPC)
target_include_directories(tfm_partitions
INTERFACE
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests
)
target_sources(tfm_psa_rot_partition_driver_partition
PRIVATE
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/auto_generated/intermedia_driver_partition_psa.c
)
target_link_libraries(tfm_psa_rot_partition_driver_partition
PRIVATE
psa_interface
platform_s
)
target_compile_definitions(tfm_psa_rot_partition_driver_partition
PRIVATE
CONFIG_TFM_BUILDING_SPE=1
TFM_LVL=${TFM_ISOLATION_LEVEL}
)
target_sources(tfm_app_rot_partition_client_partition
PRIVATE
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/auto_generated/intermedia_client_partition_psa.c
)
target_link_libraries(tfm_app_rot_partition_client_partition
PRIVATE
psa_interface
platform_s
)
target_compile_definitions(tfm_app_rot_partition_client_partition
PRIVATE
CONFIG_TFM_BUILDING_SPE=1
TFM_LVL=${TFM_ISOLATION_LEVEL}
)
target_sources(tfm_app_rot_partition_server_partition
PRIVATE
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/auto_generated/intermedia_server_partition_psa.c
)
target_link_libraries(tfm_app_rot_partition_server_partition
PRIVATE
psa_interface
platform_s
)
target_compile_definitions(tfm_app_rot_partition_server_partition
PRIVATE
CONFIG_TFM_BUILDING_SPE=1
TFM_LVL=${TFM_ISOLATION_LEVEL}
)
target_sources(tfm_partitions
INTERFACE
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/auto_generated/load_info_driver_partition_psa.c
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/auto_generated/load_info_client_partition_psa.c
${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/auto_generated/load_info_server_partition_psa.c
)
target_link_libraries(tfm_partitions
INTERFACE
tfm_psa_rot_partition_driver_partition
tfm_app_rot_partition_client_partition
tfm_app_rot_partition_server_partition
)
endif()
endif()
############################# Test integration #################################
if (CONFIG_TFM_ERPC_TEST_FRAMEWORK)
set(CONFIG_ENABLE_NS_UART_TX_RX_CONTROL ON CACHE BOOL "Whether to enable UART TX RX")
set(ERPC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../erpc)
add_subdirectory(${ERPC_DIR}/server ${CMAKE_CURRENT_BINARY_DIR}/erpc/server)
endif()
add_library(tfm_test_app STATIC EXCLUDE_FROM_ALL)
target_sources(tfm_test_app
PRIVATE
$<$<NOT:$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>>:test_app.c>
$<$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>:erpc_app.c>
$<$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>:${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_uart_cmsis.cpp>
$<$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>:${ERPC_REPO_PATH}/erpc_c/transports/erpc_uart_cmsis_transport.cpp>
)
target_include_directories(tfm_test_app
PUBLIC
.
$<$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>:${ERPC_DIR}/server>
$<$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>:${ERPC_REPO_PATH}/erpc_c/transports>
)
target_link_libraries(tfm_test_app
PRIVATE
$<$<BOOL:${TEST_FRAMEWORK_NS}>:tfm_ns_tests>
$<$<BOOL:${TEST_PSA_API}>:val_nspe>
$<$<BOOL:${TEST_PSA_API}>:pal_nspe>
$<$<BOOL:${TEST_PSA_API}>:test_combine>
$<$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>:erpc_server>
tfm_api_ns
tfm_log
)
target_compile_definitions(tfm_test_app
PRIVATE
$<$<BOOL:${TEST_FRAMEWORK_NS}>:TEST_FRAMEWORK_NS>
$<$<BOOL:${TEST_FRAMEWORK_S}>:TEST_FRAMEWORK_S>
$<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
)
############################# TFM NS app #######################################
add_executable(tfm_ns)
target_sources(tfm_ns
PRIVATE
main_ns.c
)
target_link_libraries(tfm_ns
PRIVATE
platform_ns
CMSIS_5_tfm_ns
tfm_test_app
tfm_log
)
set_target_properties(tfm_ns PROPERTIES
SUFFIX ".axf"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
target_link_options(tfm_ns
PRIVATE
$<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
$<$<C_COMPILER_ID:ARMClang>:--map>
$<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
)
add_convert_to_bin_target(tfm_ns)
############################# CMSIS ############################################
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)
cmake_policy(SET CMP0079 NEW)
add_library(CMSIS_5_tfm_ns INTERFACE)
target_sources(CMSIS_5_tfm_ns
INTERFACE
${NSID_MGR_DIR}/tz_shim_layer.c
${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
$<$<BOOL:${TFM_NS_MANAGE_NSID}>:${CMAKE_CURRENT_SOURCE_DIR}/tfm_nsid_map_table.c>
)
target_include_directories(CMSIS_5_tfm_ns
INTERFACE
${CMSIS_5_PATH}/Core/Include
${CMSIS_5_PATH}/RTOS2/Include
${CMSIS_5_PATH}/RTOS2/RTX/Include
${CMSIS_5_PATH}/RTOS2/RTX/Config
$<$<BOOL:${TFM_NS_MANAGE_NSID}>:${CMAKE_CURRENT_SOURCE_DIR}>
)
target_link_libraries(CMSIS_5_tfm_ns
INTERFACE
platform_ns
)
target_compile_definitions(CMSIS_5_tfm_ns
INTERFACE
$<$<BOOL:${TFM_NS_MANAGE_NSID}>:TFM_NS_MANAGE_NSID>
)