blob: 63f4fb2371371a10c88f4e89249a8f551010172b [file] [log] [blame]
Gyorgy Szing30fa9872017-12-05 01:08:47 +00001#-------------------------------------------------------------------------------
Raef Colesdfe519b2021-01-07 12:52:47 +00002# Copyright (c) 2020-2021, 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)
Kevin Peng33d03942021-06-08 11:28:41 +080034add_subdirectory(partitions/idle_partition)
David Hub2694202021-07-15 14:58:39 +080035if (TFM_EXTRA_PARTITION_PATHS)
36 set(POSTFIX 1)
37
38 foreach(EXTRA_PARTITION IN LISTS TFM_EXTRA_PARTITION_PATHS)
39 get_filename_component(EXTRA_PARTITION_NAME ${EXTRA_PARTITION} NAME_WLE)
40 set(TEMP_BINARY_EXTRA_PARTITION
41 ${CMAKE_CURRENT_BINARY_DIR}/partitions/${EXTRA_PARTITION_NAME}_${POSTFIX})
42 add_subdirectory(${EXTRA_PARTITION} ${TEMP_BINARY_EXTRA_PARTITION})
43
44 math(EXPR POSTFIX "${POSTFIX} + 1")
45 endforeach()
46endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000047
Raef Colesabfe81a2020-07-10 09:52:34 +010048target_include_directories(secure_fw
49 INTERFACE
50 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
51 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/partitions>
52)
Ken Liue40f9a22019-06-03 16:42:47 +080053
Raef Colesabfe81a2020-07-10 09:52:34 +010054target_link_libraries(secure_fw
55 INTERFACE
56 tfm_spm
57 tfm_partitions
58)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000059
Raef Colesabfe81a2020-07-10 09:52:34 +010060target_link_libraries(tfm_s
61 PRIVATE
62 secure_fw
63 platform_s
64 psa_interface
65 tfm_sprt
66)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000067
Raef Colesabfe81a2020-07-10 09:52:34 +010068set_target_properties(tfm_s
69 PROPERTIES
70 SUFFIX ".axf"
71 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
72)
Gyorgy Szingd9c57fb2019-09-02 17:08:18 +020073
Feder Liangd4dbaa92021-09-07 15:34:46 +080074target_compile_options(tfm_s
75 PUBLIC
76 ${COMPILER_CP_FLAG}
77)
78
Raef Colesabfe81a2020-07-10 09:52:34 +010079target_link_options(tfm_s
80 PRIVATE
81 --entry=Reset_Handler
82 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_s.map>
83 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomaf19ae92020-09-29 13:26:29 +020084 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_s.map>
Feder Liangd4dbaa92021-09-07 15:34:46 +080085 PUBLIC
86 ${LINKER_CP_OPTION}
Raef Colesabfe81a2020-07-10 09:52:34 +010087)
88
89add_convert_to_bin_target(tfm_s)
90
91############################ Secure API ########################################
92
93target_include_directories(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +080094 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +010095 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
96)
97
98target_link_libraries(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +080099 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +0100100 tfm_arch
Raef Colesabfe81a2020-07-10 09:52:34 +0100101)
102
103set_source_files_properties(
Ken Liu82e3eac2021-10-14 16:19:13 +0800104 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c
Ken Liue07c3b72021-10-14 16:19:13 +0800105 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_thread.c
Ken Liuf39d8eb2021-10-07 12:55:33 +0800106 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c
Raef Colesabfe81a2020-07-10 09:52:34 +0100107 PROPERTIES
Raef Coles5e8ea842020-09-25 10:36:16 +0100108 COMPILE_FLAGS $<$<C_COMPILER_ID:GNU>:-Wno-unused-parameter>
109 COMPILE_FLAGS $<$<C_COMPILER_ID:ARMClang>:-Wno-unused-parameter>
Raef Colesabfe81a2020-07-10 09:52:34 +0100110)
111
Ken Liu82e3eac2021-10-14 16:19:13 +0800112# Secure component relies on 'tfm_secure_api', append headers/sources
113# into this target, also the SPE build indicator.
114target_sources(tfm_secure_api
115 INTERFACE
116 $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c>
Ken Liue07c3b72021-10-14 16:19:13 +0800117 $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_thread.c>
Ken Liuf39d8eb2021-10-07 12:55:33 +0800118 $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c>
Ken Liu82e3eac2021-10-14 16:19:13 +0800119)
120
121target_compile_definitions(tfm_secure_api
122 INTERFACE
123 CONFIG_TFM_BUILDING_SPE=1
124)
125
Raef Colesabfe81a2020-07-10 09:52:34 +0100126############################# Secure veneers ###################################
127
128if(NOT (TFM_PSA_API AND TFM_MULTI_CORE_TOPOLOGY))
129 add_library(tfm_s_veneers STATIC)
130
131 target_sources(tfm_s_veneers
132 PRIVATE
133 ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
134 )
135
136 # Since s_veneers.o doesn't exist when this is evaluated by cmake we need to
137 # explicity specify what language it will use.
138 set_target_properties(tfm_s_veneers
139 PROPERTIES
140 LINKER_LANGUAGE C
141 )
142
143 # Pretend we have a command to generate the veneers, when in reality all
144 # that's needed is the dependency on tfm_s. This is required for the ninja
145 # build system
146 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
147 COMMAND
148 DEPENDS tfm_s
149 )
150
151 target_link_options(tfm_s
152 PRIVATE
153 ${LINKER_VENEER_OUTPUT_FLAG}${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
154 )
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000155endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000156
157############################### CODE SHARING ###################################
158if (TFM_CODE_SHARING)
159 set(LIB_LIST mbedcrypto
160 crypto_service_cc312
161 platform_s
Raef Colesdfe519b2021-01-07 12:52:47 +0000162 tfm_psa_rot_partition_crypto
163 tfm_psa_rot_partition_audit
164 tfm_psa_rot_partition_attestation
165 tfm_app_rot_partition_ps
166 tfm_psa_rot_partition_its
167 tfm_psa_rot_partition_platform
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000168 platform_s
169 tfm_sprt
170 tfm_spm
171 )
172 if (TFM_CODE_SHARING_PATH)
173 compiler_link_shared_code(tfm_s
174 ${TFM_CODE_SHARING_PATH} # Path to shared code
175 EXTERNAL_TARGET # Not produced by tf-m build
176 "${LIB_LIST}"
177 )
178 else()
179 compiler_link_shared_code(tfm_s
180 ${CMAKE_CURRENT_BINARY_DIR}/../bl2
181 bl2
182 "${LIB_LIST}"
183 )
184 endif()
185endif()