blob: aba47182a933a9365f6b2b26bc943d21192d754f [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 Brandcae20262022-06-23 12:05:33 -07003# Copyright (c) 2021-2022 Cypress Semiconductor Corporation (an Infineon
4# company) or an affiliate of Cypress Semiconductor Corporation. All rights
5# reserved.
Gyorgy Szing30fa9872017-12-05 01:08:47 +00006#
7# SPDX-License-Identifier: BSD-3-Clause
8#
9#-------------------------------------------------------------------------------
10
Raef Coles69817322020-10-19 14:14:14 +010011cmake_minimum_required(VERSION 3.15)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000012
Raef Colesabfe81a2020-07-10 09:52:34 +010013add_executable(tfm_s)
14add_library(secure_fw INTERFACE)
David Hu857bfa52019-05-21 13:54:50 +080015
Kevin Peng33d03942021-06-08 11:28:41 +080016add_subdirectory(spm)
David Hu057ba652021-12-07 13:50:15 +080017add_subdirectory(partitions)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000018
Xinyu Zhanga2fab0e2022-10-24 15:37:46 +080019target_include_directories(tfm_config
20 INTERFACE
21 ${CMAKE_CURRENT_SOURCE_DIR}/include
22 ${CMAKE_CURRENT_SOURCE_DIR}/partitions/crypto
23 ${CMAKE_CURRENT_SOURCE_DIR}/partitions/firmware_update
24 ${CMAKE_CURRENT_SOURCE_DIR}/partitions/initial_attestation
25 ${CMAKE_CURRENT_SOURCE_DIR}/partitions/internal_trusted_storage
26 ${CMAKE_CURRENT_SOURCE_DIR}/partitions/platform
27 ${CMAKE_CURRENT_SOURCE_DIR}/partitions/protected_storage
28 ${CMAKE_CURRENT_SOURCE_DIR}/spm/include
29)
30
Xinyu Zhang07152702022-10-31 12:35:49 +080031target_compile_definitions(tfm_config
32 INTERFACE
33 $<$<STREQUAL:${PS_CRYPTO_AEAD_ALG},PSA_ALG_GCM>:PS_CRYPTO_AEAD_ALG_GCM>
34 $<$<STREQUAL:${PS_CRYPTO_AEAD_ALG},PSA_ALG_CCM>:PS_CRYPTO_AEAD_ALG_CCM>
35 $<$<BOOL:${PS_ENCRYPTION}>:PS_ENCRYPTION>
36)
37
Raef Colesabfe81a2020-07-10 09:52:34 +010038target_include_directories(secure_fw
39 INTERFACE
40 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
41 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/partitions>
42)
Ken Liue40f9a22019-06-03 16:42:47 +080043
Raef Colesabfe81a2020-07-10 09:52:34 +010044target_link_libraries(secure_fw
45 INTERFACE
46 tfm_spm
47 tfm_partitions
48)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000049
Raef Colesabfe81a2020-07-10 09:52:34 +010050target_link_libraries(tfm_s
51 PRIVATE
52 secure_fw
53 platform_s
54 psa_interface
55 tfm_sprt
56)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000057
Raef Colesabfe81a2020-07-10 09:52:34 +010058set_target_properties(tfm_s
59 PROPERTIES
60 SUFFIX ".axf"
61 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
62)
Gyorgy Szingd9c57fb2019-09-02 17:08:18 +020063
Feder Liangd4dbaa92021-09-07 15:34:46 +080064target_compile_options(tfm_s
65 PUBLIC
66 ${COMPILER_CP_FLAG}
67)
68
Raef Colesabfe81a2020-07-10 09:52:34 +010069target_link_options(tfm_s
70 PRIVATE
71 --entry=Reset_Handler
72 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_s.map>
73 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomaf19ae92020-09-29 13:26:29 +020074 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_s.map>
Feder Liangd4dbaa92021-09-07 15:34:46 +080075 PUBLIC
76 ${LINKER_CP_OPTION}
Raef Colesabfe81a2020-07-10 09:52:34 +010077)
78
79add_convert_to_bin_target(tfm_s)
80
81############################ Secure API ########################################
82
Raef Colesabfe81a2020-07-10 09:52:34 +010083set_source_files_properties(
Ken Liu82e3eac2021-10-14 16:19:13 +080084 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c
Xinyu Zhanga7ba50b2021-12-27 17:32:53 +080085 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c
Ken Liuf39d8eb2021-10-07 12:55:33 +080086 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c
Raef Colesabfe81a2020-07-10 09:52:34 +010087 PROPERTIES
Raef Coles5e8ea842020-09-25 10:36:16 +010088 COMPILE_FLAGS $<$<C_COMPILER_ID:GNU>:-Wno-unused-parameter>
89 COMPILE_FLAGS $<$<C_COMPILER_ID:ARMClang>:-Wno-unused-parameter>
Raef Colesabfe81a2020-07-10 09:52:34 +010090)
91
Kevin Peng8b8f7a42022-08-05 17:56:30 +080092target_sources(tfm_sprt
93 PRIVATE
Sherry Zhangf58f2bd2022-01-10 17:21:11 +080094 $<$<BOOL:${CONFIG_TFM_PSA_API_SUPERVISOR_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c>
95 $<$<BOOL:${CONFIG_TFM_PSA_API_CROSS_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c>
96 $<$<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 +080097)
98
Raef Colesabfe81a2020-07-10 09:52:34 +010099############################# Secure veneers ###################################
100
Chris Brandca819022022-07-19 09:25:15 -0700101if(CONFIG_TFM_USE_TRUSTZONE)
Raef Colesabfe81a2020-07-10 09:52:34 +0100102 add_library(tfm_s_veneers STATIC)
103
104 target_sources(tfm_s_veneers
105 PRIVATE
106 ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
107 )
108
109 # Since s_veneers.o doesn't exist when this is evaluated by cmake we need to
110 # explicity specify what language it will use.
111 set_target_properties(tfm_s_veneers
112 PROPERTIES
113 LINKER_LANGUAGE C
114 )
115
116 # Pretend we have a command to generate the veneers, when in reality all
117 # that's needed is the dependency on tfm_s. This is required for the ninja
118 # build system
119 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
120 COMMAND
121 DEPENDS tfm_s
122 )
123
124 target_link_options(tfm_s
125 PRIVATE
126 ${LINKER_VENEER_OUTPUT_FLAG}${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
127 )
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000128endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000129
130############################### CODE SHARING ###################################
131if (TFM_CODE_SHARING)
Raef Coles4351ec22021-04-26 09:20:50 +0100132 target_link_shared_code(tfm_s
133 bl2
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000134 )
Raef Coles4351ec22021-04-26 09:20:50 +0100135
136 # mbedtls is build outside of tree, so we have to use the _from_dependency
137 # version of this function to attach the custom_command to the tfm_s target.
138 # It's also picky about stripping the symbols, so we just make them weak
139 # instead.
140 target_weaken_symbols_from_dependency(tfm_s crypto_service_mbedcrypto
141 mbedtls_asn1*
142 mbedtls_mpi*
143 mbedtls_platform*
144 mbedtls_rsa*
145
146 #This group is only relevant if BL2 image encryption is on
147 mbedtls_md*
148
149 #This group has two functions that cause runtime errors when shared, so the
150 #error-free ones are listed piece by piece
151 mbedtls_internal_sha256*
152 mbedtls_sha256_free
153 mbedtls_sha256_init
154 mbedtls_sha256_finish
155 mbedtls_sha256_starts
156
157 #Symbols necessary to make sharing additional functions possible
158 mbedtls_calloc*
159 mbedtls_free*
160
161 #Miscellaneous functions
162 mbedtls_exit*
163 memset_func*
164 )
165
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000166endif()