blob: c0399297a2c2d8eebc42e70f47b20d22c0144fac [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)
David Hu857bfa52019-05-21 13:54:50 +080014
Kevin Peng33d03942021-06-08 11:28:41 +080015add_subdirectory(spm)
David Hu057ba652021-12-07 13:50:15 +080016add_subdirectory(partitions)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000017
Raef Colesabfe81a2020-07-10 09:52:34 +010018target_include_directories(secure_fw
19 INTERFACE
20 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
21 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/partitions>
22)
Ken Liue40f9a22019-06-03 16:42:47 +080023
Raef Colesabfe81a2020-07-10 09:52:34 +010024target_link_libraries(secure_fw
25 INTERFACE
26 tfm_spm
27 tfm_partitions
28)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000029
Raef Colesabfe81a2020-07-10 09:52:34 +010030target_link_libraries(tfm_s
31 PRIVATE
32 secure_fw
33 platform_s
34 psa_interface
35 tfm_sprt
Jianliang Shen25feac92022-03-21 16:47:46 +080036 tfm_secure_api
Raef Colesabfe81a2020-07-10 09:52:34 +010037)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000038
Raef Colesabfe81a2020-07-10 09:52:34 +010039set_target_properties(tfm_s
40 PROPERTIES
41 SUFFIX ".axf"
42 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
43)
Gyorgy Szingd9c57fb2019-09-02 17:08:18 +020044
Feder Liangd4dbaa92021-09-07 15:34:46 +080045target_compile_options(tfm_s
46 PUBLIC
47 ${COMPILER_CP_FLAG}
48)
49
Raef Colesabfe81a2020-07-10 09:52:34 +010050target_link_options(tfm_s
51 PRIVATE
52 --entry=Reset_Handler
53 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_s.map>
54 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomaf19ae92020-09-29 13:26:29 +020055 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_s.map>
Feder Liangd4dbaa92021-09-07 15:34:46 +080056 PUBLIC
57 ${LINKER_CP_OPTION}
Raef Colesabfe81a2020-07-10 09:52:34 +010058)
59
60add_convert_to_bin_target(tfm_s)
61
62############################ Secure API ########################################
63
64target_include_directories(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +080065 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +010066 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
67)
68
69target_link_libraries(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +080070 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +010071 tfm_arch
Raef Colesabfe81a2020-07-10 09:52:34 +010072)
73
74set_source_files_properties(
Ken Liu82e3eac2021-10-14 16:19:13 +080075 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c
Xinyu Zhanga7ba50b2021-12-27 17:32:53 +080076 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c
Ken Liuf39d8eb2021-10-07 12:55:33 +080077 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c
Raef Colesabfe81a2020-07-10 09:52:34 +010078 PROPERTIES
Raef Coles5e8ea842020-09-25 10:36:16 +010079 COMPILE_FLAGS $<$<C_COMPILER_ID:GNU>:-Wno-unused-parameter>
80 COMPILE_FLAGS $<$<C_COMPILER_ID:ARMClang>:-Wno-unused-parameter>
Raef Colesabfe81a2020-07-10 09:52:34 +010081)
82
Ken Liu82e3eac2021-10-14 16:19:13 +080083# Secure component relies on 'tfm_secure_api', append headers/sources
84# into this target, also the SPE build indicator.
85target_sources(tfm_secure_api
86 INTERFACE
Sherry Zhangf58f2bd2022-01-10 17:21:11 +080087 $<$<BOOL:${CONFIG_TFM_PSA_API_SUPERVISOR_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c>
88 $<$<BOOL:${CONFIG_TFM_PSA_API_CROSS_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c>
89 $<$<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 +080090)
91
92target_compile_definitions(tfm_secure_api
93 INTERFACE
94 CONFIG_TFM_BUILDING_SPE=1
Kevin Peng613b4172022-02-15 14:41:44 +080095 $<$<BOOL:${CONFIG_TFM_DOORBELL_API}>:CONFIG_TFM_DOORBELL_API=1>
Ken Liu82e3eac2021-10-14 16:19:13 +080096)
97
Raef Colesabfe81a2020-07-10 09:52:34 +010098############################# Secure veneers ###################################
99
100if(NOT (TFM_PSA_API AND TFM_MULTI_CORE_TOPOLOGY))
101 add_library(tfm_s_veneers STATIC)
102
103 target_sources(tfm_s_veneers
104 PRIVATE
105 ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
106 )
107
108 # Since s_veneers.o doesn't exist when this is evaluated by cmake we need to
109 # explicity specify what language it will use.
110 set_target_properties(tfm_s_veneers
111 PROPERTIES
112 LINKER_LANGUAGE C
113 )
114
115 # Pretend we have a command to generate the veneers, when in reality all
116 # that's needed is the dependency on tfm_s. This is required for the ninja
117 # build system
118 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
119 COMMAND
120 DEPENDS tfm_s
121 )
122
123 target_link_options(tfm_s
124 PRIVATE
125 ${LINKER_VENEER_OUTPUT_FLAG}${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
126 )
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000127endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000128
129############################### CODE SHARING ###################################
130if (TFM_CODE_SHARING)
Raef Coles4351ec22021-04-26 09:20:50 +0100131 target_link_shared_code(tfm_s
132 bl2
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000133 )
Raef Coles4351ec22021-04-26 09:20:50 +0100134
135 # mbedtls is build outside of tree, so we have to use the _from_dependency
136 # version of this function to attach the custom_command to the tfm_s target.
137 # It's also picky about stripping the symbols, so we just make them weak
138 # instead.
139 target_weaken_symbols_from_dependency(tfm_s crypto_service_mbedcrypto
140 mbedtls_asn1*
141 mbedtls_mpi*
142 mbedtls_platform*
143 mbedtls_rsa*
144
145 #This group is only relevant if BL2 image encryption is on
146 mbedtls_md*
147
148 #This group has two functions that cause runtime errors when shared, so the
149 #error-free ones are listed piece by piece
150 mbedtls_internal_sha256*
151 mbedtls_sha256_free
152 mbedtls_sha256_init
153 mbedtls_sha256_finish
154 mbedtls_sha256_starts
155
156 #Symbols necessary to make sharing additional functions possible
157 mbedtls_calloc*
158 mbedtls_free*
159
160 #Miscellaneous functions
161 mbedtls_exit*
162 memset_func*
163 )
164
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000165endif()