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