blob: a668639a557235fcfbf049f99d929e9c6a691a0c [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}
David Hud2c78e72021-04-07 16:08:03 +080050 ${NS_INTERFACE_DIR}/ns_client_id
David Hucdc51fb2021-04-06 18:10:46 +080051)
52
David Hu73f259b2020-12-07 10:58:41 +080053# PSA interface files are generated from a template
54add_dependencies(tfm_ns_interface
55 tfm_generated_files
56)
57
58# Include selection of Secure Partitions from TF-M build.
59# It can be replaced by NS side configurations later.
60target_link_libraries(tfm_ns_interface
61 INTERFACE
62 tfm_partition_defs
63)
64
65target_compile_definitions(tfm_ns_interface
66 INTERFACE
67 $<$<BOOL:${TFM_PSA_API}>:TFM_PSA_API>
68 $<$<STREQUAL:${TEST_PSA_API},IPC>:PSA_API_TEST_IPC>
69 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:TFM_NS_CLIENT_IDENTIFICATION>
70 $<$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>:TFM_MULTI_CORE_TOPOLOGY>
David Hu402a2982020-12-17 22:31:04 +080071 $<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:TFM_MULTI_CORE_NS_OS>
David Hu98adf322020-09-01 16:18:46 +080072 $<$<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 +080073 $<$<BOOL:${FORWARD_PROT_MSG}>:FORWARD_PROT_MSG>
74)
75
76###################### TF-M NS interface api (NS lib) ##########################
77
78add_library(tfm_api_ns STATIC)
79
80target_sources(tfm_api_ns
81 PRIVATE
David Hud2c78e72021-04-07 16:08:03 +080082 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:${NS_INTERFACE_DIR}/ns_client_id/tfm_nspm_svc_handler.c>
83 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:${NS_INTERFACE_DIR}/ns_client_id/tfm_nspm_api.c>
David Hu73f259b2020-12-07 10:58:41 +080084)
85
86if (${TFM_PSA_API})
87 target_sources(tfm_api_ns PRIVATE
88 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PLATFORM}>>:${INTERFACE_SRC_DIR}/tfm_platform_ipc_api.c>
89 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_ps_ipc_api.c>
90 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>>:${INTERFACE_SRC_DIR}/tfm_its_ipc_api.c>
91 $<$<OR:$<BOOL:{$FORWARD_PROT_MSG}>,$<BOOL:${TFM_PARTITION_CRYPTO}>>:${INTERFACE_SRC_DIR}/tfm_crypto_ipc_api.c>
92 $<$<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 +080093 $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_firmware_update_ipc_api.c>
94 )
David Hu73f259b2020-12-07 10:58:41 +080095
96 if (TFM_MULTI_CORE_TOPOLOGY)
97 target_sources(tfm_api_ns PRIVATE
David Hu8e683252020-12-17 18:02:32 +080098 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_ns_api.c
99 ${INTERFACE_SRC_DIR}/multi_core/tfm_multi_core_psa_ns_api.c
David Hu98adf322020-09-01 16:18:46 +0800100 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD}>>:${INTERFACE_SRC_DIR}/multi_core/tfm_ns_mailbox.c>
101 $<$<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 +0800102 )
David Hucdc51fb2021-04-06 18:10:46 +0800103
104 # NS RTOS specific implementation of NS mailbox
105 target_sources(tfm_api_ns PRIVATE
106 $<$<BOOL:${TFM_MULTI_CORE_NS_OS}>:${NS_INTERFACE_DIR}/multi_core/tfm_ns_mailbox_rtos_api.c>
David Hud2c78e72021-04-07 16:08:03 +0800107 $<$<BOOL:${TEST_NS}>:${NS_INTERFACE_DIR}/multi_core/tfm_ns_mailbox_test.c>
David Hucdc51fb2021-04-06 18:10:46 +0800108 )
David Hu73f259b2020-12-07 10:58:41 +0800109 else()
110 target_sources(tfm_api_ns PRIVATE
David Hu73f259b2020-12-07 10:58:41 +0800111 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
112 )
David Hucdc51fb2021-04-06 18:10:46 +0800113
114 # NS specific implementation of NS interface dispacther
115 target_sources(tfm_api_ns PRIVATE
116 ${CMAKE_CURRENT_SOURCE_DIR}/tfm_ns_interface.c
117 )
David Hu73f259b2020-12-07 10:58:41 +0800118 endif()
119else()
120 target_sources(tfm_api_ns PRIVATE
121 $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_func_api.c>
122 $<$<BOOL:${TFM_PARTITION_AUDIT_LOG}>:${INTERFACE_SRC_DIR}/tfm_audit_func_api.c>
123 $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_func_api.c>
124 $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_func_api.c>
125 $<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_func_api.c>
126 $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_func_api.c>
Sherry Zhang92c499a2021-03-08 18:14:15 +0800127 $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_firmware_update_func_api.c>
David Hu73f259b2020-12-07 10:58:41 +0800128 ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
David Hucdc51fb2021-04-06 18:10:46 +0800129 )
130
131 # NS specific implementation of NS interface dispacther
132 target_sources(tfm_api_ns PRIVATE
133 ${CMAKE_CURRENT_SOURCE_DIR}/tfm_ns_interface.c
David Hu73f259b2020-12-07 10:58:41 +0800134 )
135endif()
136
137target_link_libraries(tfm_api_ns
138 PUBLIC
139 tfm_ns_interface
140 PRIVATE
141 platform_ns
142 # CMSIS is currently only required to provide the NS client IDs. In
143 # future, this should probably be made more OS agnostic
144 $<$<BOOL:${TFM_NS_CLIENT_IDENTIFICATION}>:CMSIS_5_tfm_ns>
145)
146
Raef Coles5ee45ed2020-09-24 11:25:44 +0100147############################# PSA test integration #############################
148
Raef Colesc922f252020-10-05 10:49:30 +0100149if(TEST_PSA_API AND NOT PSA_ARCH_TESTS_BINARY_PATH)
150 if(NOT SUITE)
151 set(SUITE ${TEST_PSA_API})
152 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100153
Øyvind Rønningstad205a34a2020-10-02 10:31:23 +0200154 if (NOT DEFINED PSA_API_TEST_TARGET)
155 string(REGEX REPLACE ".*/" "" PSA_API_TEST_TARGET ${TFM_PLATFORM})
156 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100157
Raef Colesc922f252020-10-05 10:49:30 +0100158 if(NOT TARGET)
159 if (NOT "${TEST_PSA_API}" STREQUAL "IPC")
160 set(TARGET tgt_dev_apis_tfm_${PSA_API_TEST_TARGET})
161 else()
162 set(TARGET tgt_ff_tfm_${PSA_API_TEST_TARGET})
163 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100164 endif()
165
Raef Coles5ee45ed2020-09-24 11:25:44 +0100166
Raef Colesc922f252020-10-05 10:49:30 +0100167 if(NOT PSA_INCLUDE_PATHS)
David Hua1fee3d2020-12-30 11:06:37 +0800168 set(PSA_INCLUDE_PATHS ${INTERFACE_INC_DIR}/
Raef Coles23d6a192020-10-22 15:43:38 +0100169 ${CMAKE_BINARY_DIR}/generated/api-tests/platform/manifests/
Raef Colesc922f252020-10-05 10:49:30 +0100170 ${CMAKE_BINARY_DIR}/generated/interface/include
171 )
Raef Coles5ee45ed2020-09-24 11:25:44 +0100172 endif()
173
Raef Colesc922f252020-10-05 10:49:30 +0100174 if(NOT SP_HEAP_MEM_SUPP)
Raef Coles06e6f652020-10-20 16:10:38 +0100175 set(SP_HEAP_MEM_SUPP 0)
Raef Colesc922f252020-10-05 10:49:30 +0100176 endif()
177 if(NOT PLATFORM_PSA_ISOLATION_LEVEL)
178 set(PLATFORM_PSA_ISOLATION_LEVEL ${TFM_ISOLATION_LEVEL})
179 endif()
180
181 if (NOT TOOLCHAIN)
182 if (${CMAKE_C_COMPILER_ID} STREQUAL GNU)
183 set(TOOLCHAIN GNUARM)
184 elseif (${CMAKE_C_COMPILER_ID} STREQUAL ARMClang)
185 set(TOOLCHAIN ARMCLANG)
186 endif()
187 endif()
188
189 if (NOT CPU_ARCH)
190 if (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.main)
191 set(CPU_ARCH armv8m_ml)
192 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv8-m.base)
193 set(CPU_ARCH armv8m_bl)
194 elseif (${CMAKE_SYSTEM_ARCHITECTURE} STREQUAL armv7-m)
195 set(CPU_ARCH armv7m)
196 endif()
Raef Coles5ee45ed2020-09-24 11:25:44 +0100197 endif()
198
199 add_subdirectory(${PSA_ARCH_TESTS_PATH}/api-tests ${CMAKE_CURRENT_BINARY_DIR}/psa_api_tests)
Kevin Peng62a87112020-07-07 15:07:46 +0800200endif()
201
Raef Coles5ee45ed2020-09-24 11:25:44 +0100202############################# Test integration #################################
Kevin Peng62a87112020-07-07 15:07:46 +0800203
Raef Coles5ee45ed2020-09-24 11:25:44 +0100204add_library(tfm_ns_integration_test STATIC EXCLUDE_FROM_ALL)
Kevin Peng62a87112020-07-07 15:07:46 +0800205
Raef Coles5ee45ed2020-09-24 11:25:44 +0100206target_sources(tfm_ns_integration_test
207 PRIVATE
208 tfm_integ_test.c
209)
Kevin Peng62a87112020-07-07 15:07:46 +0800210
Raef Coles5ee45ed2020-09-24 11:25:44 +0100211target_include_directories(tfm_ns_integration_test
212 PUBLIC
213 .
214)
Kevin Peng62a87112020-07-07 15:07:46 +0800215
Raef Coles5ee45ed2020-09-24 11:25:44 +0100216target_link_libraries(tfm_ns_integration_test
217 PUBLIC
218 $<$<BOOL:${TEST_NS}>:tfm_ns_tests>
David Hu73f259b2020-12-07 10:58:41 +0800219 tfm_test_framework_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100220 PRIVATE
David Hu73f259b2020-12-07 10:58:41 +0800221 tfm_ns_interface
222 tfm_api_ns
Raef Coles5ee45ed2020-09-24 11:25:44 +0100223 CMSIS_5_tfm_ns
224)
Kevin Peng62a87112020-07-07 15:07:46 +0800225
Raef Coles5ee45ed2020-09-24 11:25:44 +0100226target_compile_definitions(tfm_ns_integration_test
227 PUBLIC
228 $<$<BOOL:${TEST_NS}>:TEST_FRAMEWORK_NS>
229 $<$<BOOL:${TEST_S}>:TEST_FRAMEWORK_S>
230)
Kevin Peng62a87112020-07-07 15:07:46 +0800231
Raef Coles5ee45ed2020-09-24 11:25:44 +0100232############################# TFM NS app #######################################
Kevin Peng62a87112020-07-07 15:07:46 +0800233
Raef Coles5ee45ed2020-09-24 11:25:44 +0100234add_executable(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800235
Raef Coles5ee45ed2020-09-24 11:25:44 +0100236target_sources(tfm_ns
237 PRIVATE
238 main_ns.c
Kevin Peng0d3a3812020-12-23 02:17:57 +0000239 $<$<BOOL:${TEST_PSA_API}>:psa_api_test.c>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100240)
Kevin Peng62a87112020-07-07 15:07:46 +0800241
Raef Coles5ee45ed2020-09-24 11:25:44 +0100242target_link_libraries(tfm_ns
243 PRIVATE
244 platform_ns
245 CMSIS_5_tfm_ns
246 $<$<OR:$<BOOL:${TEST_NS}>,$<BOOL:${TEST_S}>>:tfm_ns_integration_test>
Kevin Peng0d3a3812020-12-23 02:17:57 +0000247 $<$<BOOL:${TEST_PSA_API}>:val_nspe>
248 $<$<BOOL:${TEST_PSA_API}>:pal_nspe>
249 $<$<BOOL:${TEST_PSA_API}>:test_combine>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100250 $<$<NOT:$<BOOL:${TFM_MULTI_CORE_TOPOLOGY}>>:tfm_s_veneers>
David Hu73f259b2020-12-07 10:58:41 +0800251 tfm_api_ns
Kevin Pengaf602292020-10-20 17:49:52 +0800252 tfm_ns_log
Raef Coles5ee45ed2020-09-24 11:25:44 +0100253)
Kevin Peng62a87112020-07-07 15:07:46 +0800254
Kevin Peng0d3a3812020-12-23 02:17:57 +0000255target_compile_definitions(tfm_ns
256 PUBLIC
257 $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
258)
259
Raef Coles5ee45ed2020-09-24 11:25:44 +0100260set_target_properties(tfm_ns PROPERTIES
261 SUFFIX ".axf"
262 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
263)
Kevin Peng62a87112020-07-07 15:07:46 +0800264
Raef Coles5ee45ed2020-09-24 11:25:44 +0100265target_link_options(tfm_ns
266 PRIVATE
267 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
268 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomd35ffa02020-09-29 13:31:31 +0200269 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
Raef Coles5ee45ed2020-09-24 11:25:44 +0100270)
Kevin Peng62a87112020-07-07 15:07:46 +0800271
Raef Coles5ee45ed2020-09-24 11:25:44 +0100272add_convert_to_bin_target(tfm_ns)
Kevin Peng62a87112020-07-07 15:07:46 +0800273
Raef Coles5ee45ed2020-09-24 11:25:44 +0100274############################# CMSIS ############################################
Kevin Peng62a87112020-07-07 15:07:46 +0800275
Raef Coles5ee45ed2020-09-24 11:25:44 +0100276include(FetchContent)
Kevin Peng62a87112020-07-07 15:07:46 +0800277
Raef Coles5ee45ed2020-09-24 11:25:44 +0100278set(FETCHCONTENT_QUIET FALSE)
279cmake_policy(SET CMP0079 NEW)
Kevin Peng62a87112020-07-07 15:07:46 +0800280
Raef Coles5ee45ed2020-09-24 11:25:44 +0100281add_library(CMSIS_5_tfm_ns INTERFACE)
Kevin Peng62a87112020-07-07 15:07:46 +0800282
Raef Coles5ee45ed2020-09-24 11:25:44 +0100283target_sources(CMSIS_5_tfm_ns
284 INTERFACE
285 ${CMSIS_5_PATH}/RTOS2/RTX/Config/RTX_Config.c
286 ${CMSIS_5_PATH}/RTOS2/RTX/Source/rtx_lib.c
287 ${CMAKE_CURRENT_SOURCE_DIR}/os_wrapper_cmsis_rtos_v2.c
288)
Kevin Peng62a87112020-07-07 15:07:46 +0800289
Raef Coles5ee45ed2020-09-24 11:25:44 +0100290target_include_directories(CMSIS_5_tfm_ns
291 INTERFACE
292 ${CMSIS_5_PATH}/Core/Include
293 ${CMSIS_5_PATH}/RTOS2/Include
294 ${CMSIS_5_PATH}/RTOS2/RTX/Include
295 ${CMSIS_5_PATH}/RTOS2/RTX/Config
296)
Kevin Peng62a87112020-07-07 15:07:46 +0800297
Raef Coles5ee45ed2020-09-24 11:25:44 +0100298target_link_libraries(CMSIS_5_tfm_ns
299 INTERFACE
300 platform_ns
301)