Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Sherry Zhang | f58f2bd | 2022-01-10 17:21:11 +0800 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
Chris Brand | 0d37310 | 2021-10-29 12:39:01 -0700 | [diff] [blame] | 3 | # Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved. |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | #------------------------------------------------------------------------------- |
| 8 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 9 | cmake_minimum_required(VERSION 3.15) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 10 | |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 11 | add_executable(tfm_s) |
| 12 | add_library(secure_fw INTERFACE) |
Summer Qin | 5a212ec | 2020-11-19 15:48:57 +0800 | [diff] [blame] | 13 | add_library(tfm_secure_api INTERFACE) |
David Hu | 857bfa5 | 2019-05-21 13:54:50 +0800 | [diff] [blame] | 14 | |
Kevin Peng | 33d0394 | 2021-06-08 11:28:41 +0800 | [diff] [blame] | 15 | add_subdirectory(spm) |
David Hu | 057ba65 | 2021-12-07 13:50:15 +0800 | [diff] [blame] | 16 | add_subdirectory(partitions) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 17 | |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 18 | target_include_directories(secure_fw |
| 19 | INTERFACE |
| 20 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 21 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/partitions> |
| 22 | ) |
Ken Liu | e40f9a2 | 2019-06-03 16:42:47 +0800 | [diff] [blame] | 23 | |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 24 | target_link_libraries(secure_fw |
| 25 | INTERFACE |
| 26 | tfm_spm |
| 27 | tfm_partitions |
| 28 | ) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 29 | |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 30 | target_link_libraries(tfm_s |
| 31 | PRIVATE |
| 32 | secure_fw |
| 33 | platform_s |
| 34 | psa_interface |
| 35 | tfm_sprt |
| 36 | ) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 37 | |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 38 | set_target_properties(tfm_s |
| 39 | PROPERTIES |
| 40 | SUFFIX ".axf" |
| 41 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" |
| 42 | ) |
Gyorgy Szing | d9c57fb | 2019-09-02 17:08:18 +0200 | [diff] [blame] | 43 | |
Feder Liang | d4dbaa9 | 2021-09-07 15:34:46 +0800 | [diff] [blame] | 44 | target_compile_options(tfm_s |
| 45 | PUBLIC |
| 46 | ${COMPILER_CP_FLAG} |
| 47 | ) |
| 48 | |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 49 | target_link_options(tfm_s |
| 50 | PRIVATE |
| 51 | --entry=Reset_Handler |
| 52 | $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_s.map> |
| 53 | $<$<C_COMPILER_ID:ARMClang>:--map> |
TTornblom | af19ae9 | 2020-09-29 13:26:29 +0200 | [diff] [blame] | 54 | $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_s.map> |
Feder Liang | d4dbaa9 | 2021-09-07 15:34:46 +0800 | [diff] [blame] | 55 | PUBLIC |
| 56 | ${LINKER_CP_OPTION} |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 57 | ) |
| 58 | |
| 59 | add_convert_to_bin_target(tfm_s) |
| 60 | |
| 61 | ############################ Secure API ######################################## |
| 62 | |
| 63 | target_include_directories(tfm_secure_api |
Summer Qin | 5a212ec | 2020-11-19 15:48:57 +0800 | [diff] [blame] | 64 | INTERFACE |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 65 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 66 | ) |
| 67 | |
| 68 | target_link_libraries(tfm_secure_api |
Summer Qin | 5a212ec | 2020-11-19 15:48:57 +0800 | [diff] [blame] | 69 | INTERFACE |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 70 | tfm_arch |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 71 | ) |
| 72 | |
| 73 | set_source_files_properties( |
Ken Liu | 82e3eac | 2021-10-14 16:19:13 +0800 | [diff] [blame] | 74 | ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c |
Xinyu Zhang | a7ba50b | 2021-12-27 17:32:53 +0800 | [diff] [blame] | 75 | ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c |
Ken Liu | f39d8eb | 2021-10-07 12:55:33 +0800 | [diff] [blame] | 76 | ${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 77 | PROPERTIES |
Raef Coles | 5e8ea84 | 2020-09-25 10:36:16 +0100 | [diff] [blame] | 78 | COMPILE_FLAGS $<$<C_COMPILER_ID:GNU>:-Wno-unused-parameter> |
| 79 | COMPILE_FLAGS $<$<C_COMPILER_ID:ARMClang>:-Wno-unused-parameter> |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 80 | ) |
| 81 | |
Ken Liu | 82e3eac | 2021-10-14 16:19:13 +0800 | [diff] [blame] | 82 | # Secure component relies on 'tfm_secure_api', append headers/sources |
| 83 | # into this target, also the SPE build indicator. |
| 84 | target_sources(tfm_secure_api |
| 85 | INTERFACE |
Sherry Zhang | f58f2bd | 2022-01-10 17:21:11 +0800 | [diff] [blame] | 86 | $<$<BOOL:${CONFIG_TFM_PSA_API_SUPERVISOR_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_svc.c> |
| 87 | $<$<BOOL:${CONFIG_TFM_PSA_API_CROSS_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_cross.c> |
| 88 | $<$<BOOL:${CONFIG_TFM_PSA_API_SFN_CALL}>:${CMAKE_SOURCE_DIR}/secure_fw/spm/cmsis_psa/psa_interface_sfn.c> |
Ken Liu | 82e3eac | 2021-10-14 16:19:13 +0800 | [diff] [blame] | 89 | ) |
| 90 | |
| 91 | target_compile_definitions(tfm_secure_api |
| 92 | INTERFACE |
| 93 | CONFIG_TFM_BUILDING_SPE=1 |
Kevin Peng | 613b417 | 2022-02-15 14:41:44 +0800 | [diff] [blame] | 94 | $<$<BOOL:${CONFIG_TFM_DOORBELL_API}>:CONFIG_TFM_DOORBELL_API=1> |
Ken Liu | 82e3eac | 2021-10-14 16:19:13 +0800 | [diff] [blame] | 95 | ) |
| 96 | |
Raef Coles | abfe81a | 2020-07-10 09:52:34 +0100 | [diff] [blame] | 97 | ############################# Secure veneers ################################### |
| 98 | |
| 99 | if(NOT (TFM_PSA_API AND TFM_MULTI_CORE_TOPOLOGY)) |
| 100 | add_library(tfm_s_veneers STATIC) |
| 101 | |
| 102 | target_sources(tfm_s_veneers |
| 103 | PRIVATE |
| 104 | ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o |
| 105 | ) |
| 106 | |
| 107 | # Since s_veneers.o doesn't exist when this is evaluated by cmake we need to |
| 108 | # explicity specify what language it will use. |
| 109 | set_target_properties(tfm_s_veneers |
| 110 | PROPERTIES |
| 111 | LINKER_LANGUAGE C |
| 112 | ) |
| 113 | |
| 114 | # Pretend we have a command to generate the veneers, when in reality all |
| 115 | # that's needed is the dependency on tfm_s. This is required for the ninja |
| 116 | # build system |
| 117 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o |
| 118 | COMMAND |
| 119 | DEPENDS tfm_s |
| 120 | ) |
| 121 | |
| 122 | target_link_options(tfm_s |
| 123 | PRIVATE |
| 124 | ${LINKER_VENEER_OUTPUT_FLAG}${CMAKE_CURRENT_BINARY_DIR}/s_veneers.o |
| 125 | ) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 126 | endif() |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 127 | |
| 128 | ############################### CODE SHARING ################################### |
| 129 | if (TFM_CODE_SHARING) |
Raef Coles | 4351ec2 | 2021-04-26 09:20:50 +0100 | [diff] [blame^] | 130 | target_link_shared_code(tfm_s |
| 131 | bl2 |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 132 | ) |
Raef Coles | 4351ec2 | 2021-04-26 09:20:50 +0100 | [diff] [blame^] | 133 | |
| 134 | # mbedtls is build outside of tree, so we have to use the _from_dependency |
| 135 | # version of this function to attach the custom_command to the tfm_s target. |
| 136 | # It's also picky about stripping the symbols, so we just make them weak |
| 137 | # instead. |
| 138 | target_weaken_symbols_from_dependency(tfm_s crypto_service_mbedcrypto |
| 139 | mbedtls_asn1* |
| 140 | mbedtls_mpi* |
| 141 | mbedtls_platform* |
| 142 | mbedtls_rsa* |
| 143 | |
| 144 | #This group is only relevant if BL2 image encryption is on |
| 145 | mbedtls_md* |
| 146 | |
| 147 | #This group has two functions that cause runtime errors when shared, so the |
| 148 | #error-free ones are listed piece by piece |
| 149 | mbedtls_internal_sha256* |
| 150 | mbedtls_sha256_free |
| 151 | mbedtls_sha256_init |
| 152 | mbedtls_sha256_finish |
| 153 | mbedtls_sha256_starts |
| 154 | |
| 155 | #Symbols necessary to make sharing additional functions possible |
| 156 | mbedtls_calloc* |
| 157 | mbedtls_free* |
| 158 | |
| 159 | #Miscellaneous functions |
| 160 | mbedtls_exit* |
| 161 | memset_func* |
| 162 | ) |
| 163 | |
Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 164 | endif() |