blob: 14f61454108c2652a5bfe33f56d3159f9d078c78 [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.
Gyorgy Szing30fa9872017-12-05 01:08:47 +00003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
Raef Coles69817322020-10-19 14:14:14 +01008cmake_minimum_required(VERSION 3.15)
Gyorgy Szing30fa9872017-12-05 01:08:47 +00009
Raef Colesabfe81a2020-07-10 09:52:34 +010010add_executable(tfm_s)
11add_library(secure_fw INTERFACE)
Summer Qin5a212ec2020-11-19 15:48:57 +080012add_library(tfm_secure_api INTERFACE)
Raef Colesabfe81a2020-07-10 09:52:34 +010013add_library(tfm_partitions INTERFACE)
14# Lots of seperate things need to know which partitions are enabled, so this
15# meta-target is provided so the related compile definitions can be collected in
16# such a way that they don't cause issues with linking to the full spm (which is
17# the other place these could be collected) Actual definitions are placed in the
18# directories of the partitions
19add_library(tfm_partition_defs INTERFACE)
David Hu857bfa52019-05-21 13:54:50 +080020
Kevin Peng33d03942021-06-08 11:28:41 +080021add_subdirectory(spm)
Raef Colesabfe81a2020-07-10 09:52:34 +010022add_subdirectory(partitions/lib/sprt)
23add_subdirectory(partitions/audit_logging)
24add_subdirectory(partitions/crypto)
25add_subdirectory(partitions/initial_attestation)
26add_subdirectory(partitions/protected_storage)
27add_subdirectory(partitions/internal_trusted_storage)
28add_subdirectory(partitions/platform)
Mark Horvath652b9002020-09-08 20:42:05 +020029add_subdirectory(partitions/psa_proxy)
Sherry Zhang07b42412021-01-07 14:19:41 +080030add_subdirectory(partitions/firmware_update)
Ken Liu49d1a512021-08-10 11:31:03 +080031add_subdirectory(partitions/ns_agent)
Kevin Peng33d03942021-06-08 11:28:41 +080032add_subdirectory(partitions/idle_partition)
David Hub2694202021-07-15 14:58:39 +080033if (TFM_EXTRA_PARTITION_PATHS)
34 set(POSTFIX 1)
35
36 foreach(EXTRA_PARTITION IN LISTS TFM_EXTRA_PARTITION_PATHS)
37 get_filename_component(EXTRA_PARTITION_NAME ${EXTRA_PARTITION} NAME_WLE)
38 set(TEMP_BINARY_EXTRA_PARTITION
39 ${CMAKE_CURRENT_BINARY_DIR}/partitions/${EXTRA_PARTITION_NAME}_${POSTFIX})
40 add_subdirectory(${EXTRA_PARTITION} ${TEMP_BINARY_EXTRA_PARTITION})
41
42 math(EXPR POSTFIX "${POSTFIX} + 1")
43 endforeach()
44endif()
Gyorgy Szing30fa9872017-12-05 01:08:47 +000045
Raef Colesabfe81a2020-07-10 09:52:34 +010046target_include_directories(secure_fw
47 INTERFACE
48 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
49 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/partitions>
50)
Ken Liue40f9a22019-06-03 16:42:47 +080051
Raef Colesabfe81a2020-07-10 09:52:34 +010052target_link_libraries(secure_fw
53 INTERFACE
54 tfm_spm
55 tfm_partitions
56)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000057
Raef Colesabfe81a2020-07-10 09:52:34 +010058target_link_libraries(tfm_s
59 PRIVATE
60 secure_fw
61 platform_s
62 psa_interface
63 tfm_sprt
64)
Gyorgy Szing30fa9872017-12-05 01:08:47 +000065
Raef Colesabfe81a2020-07-10 09:52:34 +010066set_target_properties(tfm_s
67 PROPERTIES
68 SUFFIX ".axf"
69 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
70)
Gyorgy Szingd9c57fb2019-09-02 17:08:18 +020071
Feder Liangd4dbaa92021-09-07 15:34:46 +080072target_compile_options(tfm_s
73 PUBLIC
74 ${COMPILER_CP_FLAG}
75)
76
Raef Colesabfe81a2020-07-10 09:52:34 +010077target_link_options(tfm_s
78 PRIVATE
79 --entry=Reset_Handler
80 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_s.map>
81 $<$<C_COMPILER_ID:ARMClang>:--map>
TTornblomaf19ae92020-09-29 13:26:29 +020082 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_s.map>
Feder Liangd4dbaa92021-09-07 15:34:46 +080083 PUBLIC
84 ${LINKER_CP_OPTION}
Raef Colesabfe81a2020-07-10 09:52:34 +010085)
86
87add_convert_to_bin_target(tfm_s)
88
89############################ Secure API ########################################
90
91target_include_directories(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +080092 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +010093 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
94)
95
96target_link_libraries(tfm_secure_api
Summer Qin5a212ec2020-11-19 15:48:57 +080097 INTERFACE
Raef Colesabfe81a2020-07-10 09:52:34 +010098 tfm_arch
Raef Colesabfe81a2020-07-10 09:52:34 +010099)
100
101set_source_files_properties(
Ken Liu82e3eac2021-10-14 16:19:13 +0800102 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c
Ken Liue07c3b72021-10-14 16:19:13 +0800103 ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_thread.c
Raef Colesabfe81a2020-07-10 09:52:34 +0100104 PROPERTIES
Raef Coles5e8ea842020-09-25 10:36:16 +0100105 COMPILE_FLAGS $<$<C_COMPILER_ID:GNU>:-Wno-unused-parameter>
106 COMPILE_FLAGS $<$<C_COMPILER_ID:ARMClang>:-Wno-unused-parameter>
Raef Colesabfe81a2020-07-10 09:52:34 +0100107)
108
Ken Liu82e3eac2021-10-14 16:19:13 +0800109# Secure component relies on 'tfm_secure_api', append headers/sources
110# into this target, also the SPE build indicator.
111target_sources(tfm_secure_api
112 INTERFACE
113 $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c>
Ken Liue07c3b72021-10-14 16:19:13 +0800114 $<$<BOOL:${TFM_PSA_API}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_thread.c>
Ken Liu82e3eac2021-10-14 16:19:13 +0800115)
116
117target_compile_definitions(tfm_secure_api
118 INTERFACE
119 CONFIG_TFM_BUILDING_SPE=1
120)
121
Raef Colesabfe81a2020-07-10 09:52:34 +0100122############################# Secure veneers ###################################
123
124if(NOT (TFM_PSA_API AND TFM_MULTI_CORE_TOPOLOGY))
125 add_library(tfm_s_veneers STATIC)
126
127 target_sources(tfm_s_veneers
128 PRIVATE
129 ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
130 )
131
132 # Since s_veneers.o doesn't exist when this is evaluated by cmake we need to
133 # explicity specify what language it will use.
134 set_target_properties(tfm_s_veneers
135 PROPERTIES
136 LINKER_LANGUAGE C
137 )
138
139 # Pretend we have a command to generate the veneers, when in reality all
140 # that's needed is the dependency on tfm_s. This is required for the ninja
141 # build system
142 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
143 COMMAND
144 DEPENDS tfm_s
145 )
146
147 target_link_options(tfm_s
148 PRIVATE
149 ${LINKER_VENEER_OUTPUT_FLAG}${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o
150 )
Gyorgy Szing30fa9872017-12-05 01:08:47 +0000151endif()
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000152
153############################### CODE SHARING ###################################
154if (TFM_CODE_SHARING)
155 set(LIB_LIST mbedcrypto
156 crypto_service_cc312
157 platform_s
Raef Colesdfe519b2021-01-07 12:52:47 +0000158 tfm_psa_rot_partition_crypto
159 tfm_psa_rot_partition_audit
160 tfm_psa_rot_partition_attestation
161 tfm_app_rot_partition_ps
162 tfm_psa_rot_partition_its
163 tfm_psa_rot_partition_platform
Tamas Banf8b0b2d2020-10-26 13:03:13 +0000164 platform_s
165 tfm_sprt
166 tfm_spm
167 )
168 if (TFM_CODE_SHARING_PATH)
169 compiler_link_shared_code(tfm_s
170 ${TFM_CODE_SHARING_PATH} # Path to shared code
171 EXTERNAL_TARGET # Not produced by tf-m build
172 "${LIB_LIST}"
173 )
174 else()
175 compiler_link_shared_code(tfm_s
176 ${CMAKE_CURRENT_BINARY_DIR}/../bl2
177 bl2
178 "${LIB_LIST}"
179 )
180 endif()
181endif()