blob: ace61845e89a1e23088f5517cf5e41eb878bd5ce [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
David Hucdc51fb2021-04-06 18:10:46 +080030# NS interface implemented by NSPE
31set(NS_INTERFACE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../ns_interface)
32
David Hu73f259b2020-12-07 10:58:41 +080033#################### TF-M NS interface (header only) ###########################
34
35add_library(tfm_ns_interface INTERFACE)
36
David Hucdc51fb2021-04-06 18:10:46 +080037# Include interface headers exported by TF-M
David Hu73f259b2020-12-07 10:58:41 +080038target_include_directories(tfm_ns_interface
39 INTERFACE
40 ${INTERFACE_INC_DIR}
41 ${CMAKE_BINARY_DIR}/generated/interface/include
David Hu8e683252020-12-17 18:02:32 +080042 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:${INTERFACE_INC_DIR}/multi_core>
David Hu98adf322020-09-01 16:18:46 +080043 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:${CMAKE_SOURCE_DIR}/platform/ext/cmsis>
David Hu73f259b2020-12-07 10:58:41 +080044)
45
David Hucdc51fb2021-04-06 18:10:46 +080046# Include NS local interface headers
47target_include_directories(tfm_ns_interface
48 INTERFACE
49 ${NS_INTERFACE_DIR}
50)
51
David Hu73f259b2020-12-07 10:58:41 +080052# PSA interface files are generated from a template
53add_dependencies(tfm_ns_interface
54 tfm_generated_files
55)
56
57# Include selection of Secure Partitions from TF-M build.
58# It can be replaced by NS side configurations later.
59target_link_libraries(tfm_ns_interface
60 INTERFACE
61 tfm_partition_defs
62)
63
64target_compile_definitions(tfm_ns_interface
65 INTERFACE
66 $<$<BOOL:${TFM_PSA_API}>:TFM_PSA_API>
67 $<$<STREQUAL:${TEST_PSA_API},IPC>:PSA_API_TEST_IPC>
68 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:TFM_NS_CLIENT_IDENTIFICATION>
69 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:TFM_MULTI_CORE_TOPOLOGY>
David Hu402a2982020-12-17 22:31:04 +080070 $<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:TFM_MULTI_CORE_NS_OS>
David Hu98adf322020-09-01 16:18:46 +080071 $<$<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 +080072 $<$<BOOL:${FORWARD_PROT_MSG}>:FORWARD_PROT_MSG>
73)
74
75###################### TF-M NS interface api (NS lib) ##########################
76
77add_library(tfm_api_ns STATIC)
78
David Hu73f259b2020-12-07 10:58:41 +080079if (${TFM_PSA_API})
80 target_sources(tfm_api_ns PRIVATE
Jianliang Shen7a814e42021-10-18 15:25:39 +080081 $<$<OR:$<BOOL:${FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PLATFORM}>>:${INTERFACE_SRC_DIR}/tfm_platform_ipc_api.c>
82 $<$<OR:$<BOOL:${FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_ps_ipc_api.c>
83 $<$<OR:$<BOOL:${FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_its_ipc_api.c>
84 $<$<OR:$<BOOL:${FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_CRYPTO}>>:${INTERFACE_SRC_DIR}/tfm_crypto_ipc_api.c>
85 $<$<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 +080086 $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_firmware_update_ipc_api.c>
87 )
David Hu73f259b2020-12-07 10:58:41 +080088
89 if (TFM_MULTI_CORE_TOPOLOGY)
90 target_sources(tfm_api_ns PRIVATE
David Hu8e683252020-12-17 18:02:32 +080091 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c
92 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c
David Hu98adf322020-09-01 16:18:46 +080093 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox.c>
94 $<$<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>
David Hu73f259b2020-12-07 10:58:41 +080095 )
David Hucdc51fb2021-04-06 18:10:46 +080096
97 # NS RTOS specific implementation of NS mailbox
98 target_sources(tfm_api_ns PRIVATE
99 $<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:${NS_INTERFACE_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c>
shejia01e0dd80a2021-07-12 17:47:50 +0800100 $<$<BOOL:${TEST_NS_MULTI_CORE}>:${NS_INTERFACE_DIR}/multi_core/tfm_ns_mailbox_test.c>
David Hucdc51fb2021-04-06 18:10:46 +0800101 )
David Hu73f259b2020-12-07 10:58:41 +0800102 else()
103 target_sources(tfm_api_ns PRIVATE
David Hu73f259b2020-12-07 10:58:41 +0800104 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
105 )
David Hucdc51fb2021-04-06 18:10:46 +0800106
107 # NS specific implementation of NS interface dispacther
108 target_sources(tfm_api_ns PRIVATE
109 ${CMAKE_CURRENT_SOURCE_DIR}/tfm_ns_interface.c
110 )
David Hu73f259b2020-12-07 10:58:41 +0800111 endif()
112else()
113 target_sources(tfm_api_ns PRIVATE
114 $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_func_api.c>
115 $<$<BOOL:${TFM_PARTITION_AUDIT_LOG}>:${INTERFACE_SRC_DIR}/tfm_audit_func_api.c>
116 $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_func_api.c>
117 $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_func_api.c>
118 $<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_func_api.c>
119 $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_func_api.c>
Sherry Zhang92c499a2021-03-08 18:14:15 +0800120 $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_firmware_update_func_api.c>
David Hucdc51fb2021-04-06 18:10:46 +0800121 )
122
123 # NS specific implementation of NS interface dispacther
124 target_sources(tfm_api_ns PRIVATE
125 ${CMAKE_CURRENT_SOURCE_DIR}/tfm_ns_interface.c
David Hu73f259b2020-12-07 10:58:41 +0800126 )
127endif()
128
129target_link_libraries(tfm_api_ns
130 PUBLIC
131 tfm_ns_interface
132 PRIVATE
Sherry Zhang8342d7d2021-10-14 17:57:26 +0800133 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:tfm_s_veneers>
David Hu73f259b2020-12-07 10:58:41 +0800134 platform_ns
David Hu73f259b2020-12-07 10:58:41 +0800135)
136
Raef Coles5ee45ed2020-09-24 11:25:44 +0100137############################# PSA test integration #############################
138
Raef Colesc922f252020-10-05 10:49:30 +0100139if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH)
140 if(NOT SUITE)
141 set(SUITE ${TEST_PSA_API})
142 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100143
Øyvind Rønningstad205a34a2020-10-02 10:31:23 +0200144 if (NOT DEFINED PSA_API_TEST_TARGET)
145 string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
146 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100147
Raef Colesc922f252020-10-05 10:49:30 +0100148 if(NOT TARGET)
149 if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
150 set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
151 else()
152 set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
153 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100154 endif()
155
Raef Coles5ee45ed2020-09-24 11:25:44 +0100156
Raef Colesc922f252020-10-05 10:49:30 +0100157 if(NOT PSA_INCLUDE_PATHS)
David Hua1fee3d2020-12-30 11:06:37 +0800158 set(PSA_INCLUDE_PATHS ${INTERFACE_INC_DIR}/
Raef Coles23d6a192020-10-22 15:43:38 +0100159 ${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/
Raef Colesc922f252020-10-05 10:49:30 +0100160 ${CMAKE_BINARY_DIR}/generated/interface/include
161 )
Raef Coles5ee45ed2020-09-24 11:25:44 +0100162 endif()
163
Raef Colesc922f252020-10-05 10:49:30 +0100164 if(NOT SP_HEAP_MEM_SUPP)
Raef Coles06e6f652020-10-20 16:10:38 +0100165 set(SP_HEAP_MEM_SUPP 0)
Raef Colesc922f252020-10-05 10:49:30 +0100166 endif()
167 if(NOT PLATFORM_PSA_ISOLATION_LEVEL)
168 set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
169 endif()
170
171 if (NOT TOOLCHAIN)
172 if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
173 set(TOOLCHAIN GNUARM)
174 elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
175 set(TOOLCHAIN ARMCLANG)
176 endif()
177 endif()
178
179 if (NOT CPU_ARCH)
180 if (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
181 set(CPU_ARCH armv8m_ml)
182 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
183 set(CPU_ARCH armv8m_bl)
184 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
185 set(CPU_ARCH armv7m)
186 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100187 endif()
188
189 add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
Kevin Peng62a87112020-07-07 15:07:46 +0800190endif()
191
Raef Coles5ee45ed2020-09-24 11:25:44 +0100192############################# Test integration #################################
Kevin Peng62a87112020-07-07 15:07:46 +0800193
Raef Coles5ee45ed2020-09-24 11:25:44 +0100194add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
Kevin Peng62a87112020-07-07 15:07:46 +0800195
Raef Coles5ee45ed2020-09-24 11:25:44 +0100196target_sources(tfm_ns_integration_test
197 PRIVATE
198 tfm_integ_test.c
199)
Kevin Peng62a87112020-07-07 15:07:46 +0800200
Raef Coles5ee45ed2020-09-24 11:25:44 +0100201target_include_directories(tfm_ns_integration_test
202 PUBLIC
203 .
204)
Kevin Peng62a87112020-07-07 15:07:46 +0800205
Raef Coles5ee45ed2020-09-24 11:25:44 +0100206target_link_libraries(tfm_ns_integration_test
Raef Coles5ee45ed2020-09-24 11:25:44 +0100207 PRIVATE
David Huacba69e2021-09-10 15:36:48 +0800208 $<$<BOOL:${TEST_FRAMEWORK_NS}>:tfm_ns_tests>
209 $<$<BOOL:${TEST_FRAMEWORK_S}>:tfm_ns_interface>
210 $<$<BOOL:${TEST_FRAMEWORK_S}>:tfm_api_ns>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100211)
Kevin Peng62a87112020-07-07 15:07:46 +0800212
Raef Coles5ee45ed2020-09-24 11:25:44 +0100213target_compile_definitions(tfm_ns_integration_test
214 PUBLIC
shejia01e0dd80a2021-07-12 17:47:50 +0800215 $<$<BOOL:${TEST_FRAMEWORK_NS}>:TEST_FRAMEWORK_NS>
216 $<$<BOOL:${TEST_FRAMEWORK_S}>:TEST_FRAMEWORK_S>
shejia0126b2d782021-08-19 17:08:24 +0800217 $<$<BOOL:${TFM_LIB_MODEL}>:TFM_LIB_MODEL>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100218)
Kevin Peng62a87112020-07-07 15:07:46 +0800219
Raef Coles5ee45ed2020-09-24 11:25:44 +0100220############################# TFM NS app #######################################
Kevin Peng62a87112020-07-07 15:07:46 +0800221
Raef Coles5ee45ed2020-09-24 11:25:44 +0100222add_executable(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800223
Raef Coles5ee45ed2020-09-24 11:25:44 +0100224target_sources(tfm_ns
225 PRIVATE
226 main_ns.c
Kevin Peng0d3a3812020-12-23 02:17:57 +0000227 $<$<BOOL:${TEST_PSA_API}>:psa_api_test.c>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100228)
Kevin Peng62a87112020-07-07 15:07:46 +0800229
Raef Coles5ee45ed2020-09-24 11:25:44 +0100230target_link_libraries(tfm_ns
231 PRIVATE
232 platform_ns
233 CMSIS_5_tfm_ns
shejia01e0dd80a2021-07-12 17:47:50 +0800234 $<$<OR:$<BOOL:${TEST_FRAMEWORK_NS}>,$<BOOL:${TEST_FRAMEWORK_S}>>:tfm_ns_integration_test>
Kevin Peng0d3a3812020-12-23 02:17:57 +0000235 $<$<BOOL:${TEST_PSA_API}>:val_nspe>
236 $<$<BOOL:${TEST_PSA_API}>:pal_nspe>
237 $<$<BOOL:${TEST_PSA_API}>:test_combine>
David Hu73f259b2020-12-07 10:58:41 +0800238 tfm_api_ns
Kevin Pengaf602292020-10-20 17:49:52 +0800239 tfm_ns_log
Raef Coles5ee45ed2020-09-24 11:25:44 +0100240)
Kevin Peng62a87112020-07-07 15:07:46 +0800241
Kevin Peng0d3a3812020-12-23 02:17:57 +0000242target_compile_definitions(tfm_ns
243 PUBLIC
244 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
245)
246
Raef Coles5ee45ed2020-09-24 11:25:44 +0100247set_target_properties(tfm_ns PROPERTIES
248 SUFFIX ".axf"
249 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
250)
Kevin Peng62a87112020-07-07 15:07:46 +0800251
Raef Coles5ee45ed2020-09-24 11:25:44 +0100252target_link_options(tfm_ns
253 PRIVATE
254 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
255 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomd35ffa02020-09-29 13:31:31 +0200256 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100257)
Kevin Peng62a87112020-07-07 15:07:46 +0800258
Raef Coles5ee45ed2020-09-24 11:25:44 +0100259add_convert_to_bin_target(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800260
Raef Coles5ee45ed2020-09-24 11:25:44 +0100261############################# CMSIS ############################################
Kevin Peng62a87112020-07-07 15:07:46 +0800262
Raef Coles5ee45ed2020-09-24 11:25:44 +0100263include(FetchContent)
Kevin Peng62a87112020-07-07 15:07:46 +0800264
Raef Coles5ee45ed2020-09-24 11:25:44 +0100265set(FETCHCONTENT_QUIET FALSE)
266cmake_policy(SET CMP0079 NEW)
Kevin Peng62a87112020-07-07 15:07:46 +0800267
Raef Coles5ee45ed2020-09-24 11:25:44 +0100268add_library(CMSIS_5_tfm_ns INTERFACE)
Kevin Peng62a87112020-07-07 15:07:46 +0800269
Raef Coles5ee45ed2020-09-24 11:25:44 +0100270target_sources(CMSIS_5_tfm_ns
271 INTERFACE
272 ${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
273 ${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
274 ${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
275)
Kevin Peng62a87112020-07-07 15:07:46 +0800276
Raef Coles5ee45ed2020-09-24 11:25:44 +0100277target_include_directories(CMSIS_5_tfm_ns
278 INTERFACE
279 ${CMSIS_5_PATH}/Core/Include
280 ${CMSIS_5_PATH}/RTOS2/Include
281 ${CMSIS_5_PATH}/RTOS2/RTX/Include
282 ${CMSIS_5_PATH}/RTOS2/RTX/Config
283)
Kevin Peng62a87112020-07-07 15:07:46 +0800284
Raef Coles5ee45ed2020-09-24 11:25:44 +0100285target_link_libraries(CMSIS_5_tfm_ns
286 INTERFACE
287 platform_ns
288)