blob: 9ac040618d46d3b90f099e6d2aeb382ca9a2d62f [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
Sherry Zhangf58f2bd2022-01-10 17:21:11 +08002# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
Chris Brand0d373102021-10-29 12:39:01 -07003# Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
Gyorgy Szing30fa9872017-12-05 01:08:47 +00004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7#-------------------------------------------------------------------------------
8
Raef Coles69817322020-10-19 14:14:14 +01009cmake_minimum_required(VERSION 3.15)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000010
Raef Colesabfe81a2020-07-10 09:52:34 +010011add_executable(tfm_s)
12add_library(secure_fw INTERFACE)
Summer Qin5a212ec2020-11-19 15:48:57 +080013add_library(tfm_secure_api INTERFACE)
Raef Colesabfe81a2020-07-10 09:52:34 +010014add_library(tfm_partitions INTERFACE)
15# Lots of seperate things need to know which partitions are enabled, so this
16# meta-target is provided so the related compile definitions can be collected in
17# such a way that they don't cause issues with linking to the full spm (which is
18# the other place these could be collected) Actual definitions are placed in the
19# directories of the partitions
20add_library(tfm_partition_defs INTERFACE)
David Hu857bfa52019-05-21 13:54:50 +080021
Kevin Peng33d03942021-06-08 11:28:41 +080022add_subdirectory(spm)
Raef Colesabfe81a2020-07-10 09:52:34 +010023add_subdirectory(partitions/lib/sprt)
24add_subdirectory(partitions/audit_logging)
25add_subdirectory(partitions/crypto)
26add_subdirectory(partitions/initial_attestation)
27add_subdirectory(partitions/protected_storage)
28add_subdirectory(partitions/internal_trusted_storage)
29add_subdirectory(partitions/platform)
Mark Horvath652b9002020-09-08 20:42:05 +020030add_subdirectory(partitions/psa_proxy)
Sherry Zhang07b42412021-01-07 14:19:41 +080031add_subdirectory(partitions/firmware_update)
Chris Brand0d373102021-10-29 12:39:01 -070032add_subdirectory(partitions/ns_agent_tz)
33add_subdirectory(partitions/ns_agent_mailbox)
Mingyang Sund3f55972022-02-11 18:16:35 +080034if (CONFIG_TFM_SPM_BACKEND_IPC)
35 add_subdirectory(partitions/idle_partition)
36endif()
37
David Hub2694202021-07-15 14:58:39 +080038if (TFM_EXTRA_PARTITION_PATHS)
39 set(POSTFIX 1)
40
41 foreach(EXTRA_PARTITION IN LISTS TFM_EXTRA_PARTITION_PATHS)
42 get_filename_component(EXTRA_PARTITION_NAME ${EXTRA_PARTITION} NAME_WLE)
43 set(TEMP_BINARY_EXTRA_PARTITION
44 ${CMAKE_CURRENT_BINARY_DIR}/partitions/${EXTRA_PARTITION_NAME}_${POSTFIX})
45 add_subdirectory(${EXTRA_PARTITION} ${TEMP_BINARY_EXTRA_PARTITION})
46
47 math(EXPR POSTFIX "${POSTFIX} + 1")
48 endforeach()
49endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000050
Raef Colesabfe81a2020-07-10 09:52:34 +010051target_include_directories(secure_fw
52 INTERFACE
53 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
54 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/partitions>
55)
Ken Liue40f9a22019-06-03 16:42:47 +080056
Raef Colesabfe81a2020-07-10 09:52:34 +010057target_link_libraries(secure_fw
58 INTERFACE
59 tfm_spm
60 tfm_partitions
61)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000062
Raef Colesabfe81a2020-07-10 09:52:34 +010063target_link_libraries(tfm_s
64 PRIVATE
65 secure_fw
66 platform_s
67 psa_interface
68 tfm_sprt
69)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000070
Raef Colesabfe81a2020-07-10 09:52:34 +010071set_target_properties(tfm_s
72 PROPERTIES
73 SUFFIX ".axf"
74 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
75)
Gyorgy Szingd9c57fb2019-09-02 17:08:18 +020076
Feder Liangd4dbaa92021-09-07 15:34:46 +080077target_compile_options(tfm_s
78 PUBLIC
79 ${COMPILER_CP_FLAG}
80)
81
Raef Colesabfe81a2020-07-10 09:52:34 +010082target_link_options(tfm_s
83 PRIVATE
84 --entry=Reset_Handler
85 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_s.map>
86 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomaf19ae92020-09-29 13:26:29 +020087 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_s.map>
Feder Liangd4dbaa92021-09-07 15:34:46 +080088 PUBLIC
89 ${LINKER_CP_OPTION}
Raef Colesabfe81a2020-07-10 09:52:34 +010090)
91
92add_convert_to_bin_target(tfm_s)
93
94############################ Secure API ########################################
95
96target_include_directories(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +080097 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +010098 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
99)
100
101target_link_libraries(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +0800102 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +0100103 tfm_arch
Raef Colesabfe81a2020-07-10 09:52:34 +0100104)
105
106set_source_files_properties(
Ken Liu82e3eac2021-10-14 16:19:13 +0800107 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c
Xinyu Zhanga7ba50b2021-12-27 17:32:53 +0800108 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c
Ken Liuf39d8eb2021-10-07 12:55:33 +0800109 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c
Raef Colesabfe81a2020-07-10 09:52:34 +0100110 PROPERTIES
Raef Coles5e8ea842020-09-25 10:36:16 +0100111 COMPILE_FLAGS $<$<C_COMPILER_ID:GNU>:-Wno-unused-parameter>
112 COMPILE_FLAGS $<$<C_COMPILER_ID:ARMClang>:-Wno-unused-parameter>
Raef Colesabfe81a2020-07-10 09:52:34 +0100113)
114
Ken Liu82e3eac2021-10-14 16:19:13 +0800115# Secure component relies on 'tfm_secure_api', append headers/sources
116# into this target, also the SPE build indicator.
117target_sources(tfm_secure_api
118 INTERFACE
Sherry Zhangf58f2bd2022-01-10 17:21:11 +0800119 $<$<BOOL:${CONFIG_TFM_PSA_API_SUPERVISOR_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c>
120 $<$<BOOL:${CONFIG_TFM_PSA_API_CROSS_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c>
121 $<$<BOOL:${CONFIG_TFM_PSA_API_SFN_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c>
Ken Liu82e3eac2021-10-14 16:19:13 +0800122)
123
124target_compile_definitions(tfm_secure_api
125 INTERFACE
126 CONFIG_TFM_BUILDING_SPE=1
127)
128
Raef Colesabfe81a2020-07-10 09:52:34 +0100129############################# Secure veneers ###################################
130
131if(NOT (TFM_PSA_API AND TFM_MULTI_CORE_TOPOLOGY))
132 add_library(tfm_s_veneers STATIC)
133
134 target_sources(tfm_s_veneers
135 PRIVATE
136 ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
137 )
138
139 # Since s_veneers.o doesn't exist when this is evaluated by cmake we need to
140 # explicity specify what language it will use.
141 set_target_properties(tfm_s_veneers
142 PROPERTIES
143 LINKER_LANGUAGE C
144 )
145
146 # Pretend we have a command to generate the veneers, when in reality all
147 # that's needed is the dependency on tfm_s. This is required for the ninja
148 # build system
149 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
150 COMMAND
151 DEPENDS tfm_s
152 )
153
154 target_link_options(tfm_s
155 PRIVATE
156 ${LINKER_VENEER_OUTPUT_FLAG}${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
157 )
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000158endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000159
160############################### CODE SHARING ###################################
161if (TFM_CODE_SHARING)
162 set(LIB_LIST mbedcrypto
163 crypto_service_cc312
164 platform_s
Raef Colesdfe519b2021-01-07 12:52:47 +0000165 tfm_psa_rot_partition_crypto
166 tfm_psa_rot_partition_audit
167 tfm_psa_rot_partition_attestation
168 tfm_app_rot_partition_ps
169 tfm_psa_rot_partition_its
170 tfm_psa_rot_partition_platform
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000171 platform_s
172 tfm_sprt
173 tfm_spm
174 )
175 if (TFM_CODE_SHARING_PATH)
176 compiler_link_shared_code(tfm_s
177 ${TFM_CODE_SHARING_PATH} # Path to shared code
178 EXTERNAL_TARGET # Not produced by tf-m build
179 "${LIB_LIST}"
180 )
181 else()
182 compiler_link_shared_code(tfm_s
183 ${CMAKE_CURRENT_BINARY_DIR}/../bl2
184 bl2
185 "${LIB_LIST}"
186 )
187 endif()
188endif()