| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| Imre Kis | eeee964 | 2021-12-17 13:59:46 +0100 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | cmake_minimum_required(VERSION 3.16) |
| Gyorgy Szing | a365a04 | 2021-12-02 01:48:27 +0100 | [diff] [blame] | 8 | |
| 9 | # Set default platform. |
| 10 | set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Target platform location.") |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 11 | include(../../deployment.cmake REQUIRED) |
| 12 | |
| 13 | #------------------------------------------------------------------------------- |
| 14 | # The CMakeLists.txt for building the crypto deployment for opteesp |
| 15 | # |
| 16 | # Builds the Crypto service provider for running in an SEL0 secure partition |
| 17 | # hosted by OPTEE in the role of SPM. |
| 18 | #------------------------------------------------------------------------------- |
| 19 | include(${TS_ROOT}/environments/opteesp/env.cmake) |
| 20 | project(trusted-services LANGUAGES C ASM) |
| 21 | add_executable(crypto-sp) |
| 22 | target_include_directories(crypto-sp PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}") |
| 23 | set(SP_UUID "d9df52d5-16a2-4bb2-9aa4-d26d3b84e8c0") |
| Imre Kis | eeee964 | 2021-12-17 13:59:46 +0100 | [diff] [blame] | 24 | set(SP_HEAP_SIZE "490 * 1024" CACHE STRING "SP heap size in bytes") |
| Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 25 | set(TRACE_PREFIX "CRYPTO" CACHE STRING "Trace prefix") |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 26 | |
| julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 27 | #------------------------------------------------------------------------------- |
| 28 | # Components that are specific to deployment in the opteesp environment. |
| 29 | # |
| 30 | #------------------------------------------------------------------------------- |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 31 | add_components(TARGET "crypto-sp" |
| 32 | BASE_DIR ${TS_ROOT} |
| 33 | COMPONENTS |
| Balint Dobszay | 286ff75 | 2022-03-04 15:57:19 +0100 | [diff] [blame] | 34 | "components/common/fdt" |
| julhal01 | 734dbad | 2020-12-21 10:27:41 +0000 | [diff] [blame] | 35 | "components/common/tlv" |
| Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 36 | "components/common/trace" |
| 37 | "components/common/utils" |
| julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame] | 38 | "components/config/ramstore" |
| julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 39 | "components/config/loader/sp" |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 40 | "components/messaging/ffa/libsp" |
| 41 | "components/rpc/ffarpc/endpoint" |
| 42 | "components/rpc/ffarpc/caller/sp" |
| 43 | "components/rpc/common/caller" |
| 44 | "components/rpc/common/interface" |
| Julian Hall | a7e76c8 | 2021-04-14 11:12:11 +0100 | [diff] [blame] | 45 | "components/service/common/include" |
| Julian Hall | 99a57e3 | 2021-07-28 14:18:50 +0100 | [diff] [blame] | 46 | "components/service/common/client" |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 47 | "components/service/common/serializer/protobuf" |
| 48 | "components/service/common/provider" |
| Julian Hall | 3e61454 | 2021-07-29 11:47:47 +0100 | [diff] [blame] | 49 | "components/service/discovery/provider" |
| 50 | "components/service/discovery/provider/serializer/packed-c" |
| Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame] | 51 | "components/service/crypto/provider" |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 52 | "components/service/crypto/provider/serializer/protobuf" |
| julhal01 | 734dbad | 2020-12-21 10:27:41 +0000 | [diff] [blame] | 53 | "components/service/crypto/provider/serializer/packed-c" |
| Julian Hall | 7bfb18e | 2021-07-13 15:48:13 +0100 | [diff] [blame] | 54 | "components/service/crypto/provider/extension/hash" |
| 55 | "components/service/crypto/provider/extension/hash/serializer/packed-c" |
| Julian Hall | e7bccbe | 2021-07-16 09:50:34 +0100 | [diff] [blame] | 56 | "components/service/crypto/provider/extension/cipher" |
| 57 | "components/service/crypto/provider/extension/cipher/serializer/packed-c" |
| Julian Hall | fe487b7 | 2021-07-19 10:29:59 +0100 | [diff] [blame] | 58 | "components/service/crypto/provider/extension/key_derivation" |
| 59 | "components/service/crypto/provider/extension/key_derivation/serializer/packed-c" |
| Julian Hall | a6d3cbc | 2021-07-20 10:13:21 +0100 | [diff] [blame] | 60 | "components/service/crypto/provider/extension/mac" |
| 61 | "components/service/crypto/provider/extension/mac/serializer/packed-c" |
| Julian Hall | 7bfb18e | 2021-07-13 15:48:13 +0100 | [diff] [blame] | 62 | "components/service/crypto/factory/full" |
| Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame] | 63 | "components/service/crypto/backend/mbedcrypto" |
| 64 | "components/service/crypto/backend/mbedcrypto/trng_adapter/platform" |
| Julian Hall | a7e76c8 | 2021-04-14 11:12:11 +0100 | [diff] [blame] | 65 | "components/service/secure_storage/include" |
| julhal01 | 1260f10 | 2021-02-15 17:34:08 +0000 | [diff] [blame] | 66 | "components/service/secure_storage/frontend/psa/its" |
| 67 | "components/service/secure_storage/backend/secure_storage_client" |
| julhal01 | 3a4207d | 2021-03-08 13:32:08 +0000 | [diff] [blame] | 68 | "components/service/secure_storage/backend/null_store" |
| 69 | "components/service/secure_storage/factory/sp/rot_store" |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 70 | "protocols/rpc/common/packed-c" |
| 71 | "protocols/service/secure_storage/packed-c" |
| 72 | "protocols/service/crypto/protobuf" |
| 73 | "environments/opteesp" |
| 74 | ) |
| 75 | |
| 76 | target_sources(crypto-sp PRIVATE |
| 77 | crypto_sp.c |
| 78 | ) |
| 79 | |
| julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 80 | #------------------------------------------------------------------------------- |
| Gyorgy Szing | a365a04 | 2021-12-02 01:48:27 +0100 | [diff] [blame] | 81 | # Set target platform to provide drivers needed by the deployment |
| julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 82 | # |
| 83 | #------------------------------------------------------------------------------- |
| julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 84 | add_platform(TARGET "crypto-sp") |
| 85 | |
| 86 | #------------------------------------------------------------------------------- |
| 87 | # Components used from external projects |
| 88 | # |
| 89 | #------------------------------------------------------------------------------- |
| 90 | |
| Imre Kis | 23583e3 | 2021-10-22 14:54:51 +0200 | [diff] [blame] | 91 | # Get libc include dir |
| Gyorgy Szing | 693877e | 2021-12-12 02:51:10 +0100 | [diff] [blame] | 92 | get_property(LIBC_INCLUDE_PATH TARGET stdlib::c PROPERTY INTERFACE_INCLUDE_DIRECTORIES) |
| Imre Kis | 23583e3 | 2021-10-22 14:54:51 +0200 | [diff] [blame] | 93 | |
| julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 94 | # Nanopb |
| Imre Kis | 23583e3 | 2021-10-22 14:54:51 +0200 | [diff] [blame] | 95 | list(APPEND NANOPB_EXTERNAL_INCLUDE_PATHS ${LIBC_INCLUDE_PATH}) |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 96 | include(../../../external/nanopb/nanopb.cmake) |
| 97 | target_link_libraries(crypto-sp PRIVATE nanopb::protobuf-nanopb-static) |
| 98 | protobuf_generate_all(TGT "crypto-sp" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols") |
| 99 | |
| Balint Dobszay | 3c52ce6 | 2021-05-10 16:27:18 +0200 | [diff] [blame] | 100 | # Mbed TLS provides libmbedcrypto |
| Imre Kis | 23583e3 | 2021-10-22 14:54:51 +0200 | [diff] [blame] | 101 | list(APPEND MBEDTLS_EXTRA_INCLUDES ${LIBC_INCLUDE_PATH}) |
| Balint Dobszay | 3c52ce6 | 2021-05-10 16:27:18 +0200 | [diff] [blame] | 102 | include(../../../external/MbedTLS/MbedTLS.cmake) |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 103 | target_link_libraries(crypto-sp PRIVATE mbedcrypto) |
| Gyorgy Szing | 693877e | 2021-12-12 02:51:10 +0100 | [diff] [blame] | 104 | target_link_libraries(mbedcrypto INTERFACE stdlib::c) |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 105 | |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 106 | |
| 107 | ################################################################# |
| 108 | |
| 109 | target_compile_definitions(crypto-sp PRIVATE |
| 110 | ARM64=1 |
| 111 | ) |
| 112 | |
| 113 | target_include_directories(crypto-sp PRIVATE |
| 114 | ${TS_ROOT} |
| 115 | ${TS_ROOT}/components |
| 116 | ${TS_ROOT}/deployments/crypto/opteesp |
| 117 | ) |
| 118 | |
| 119 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 120 | target_compile_options(crypto-sp PRIVATE |
| 121 | -fdiagnostics-show-option |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 122 | -gdwarf-2 |
| 123 | -mstrict-align |
| 124 | -O0 |
| Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame] | 125 | -std=c99 |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 126 | ) |
| 127 | |
| 128 | # Options for GCC that control linking |
| 129 | target_link_options(crypto-sp PRIVATE |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 130 | -zmax-page-size=4096 |
| 131 | ) |
| 132 | # Options directly for LD, these are not understood by GCC |
| 133 | target_link_options(crypto-sp PRIVATE |
| 134 | -Wl,--as-needed |
| 135 | -Wl,--sort-section=alignment |
| 136 | # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list |
| 137 | ) |
| 138 | endif() |
| 139 | |
| 140 | compiler_generate_stripped_elf(TARGET crypto-sp NAME "${SP_UUID}.stripped.elf" RES STRIPPED_ELF) |
| 141 | |
| 142 | ######################################## install |
| 143 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 144 | set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE) |
| 145 | endif() |
| 146 | #TODO: api headers |
| Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 147 | |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 148 | install(TARGETS crypto-sp |
| Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 149 | PUBLIC_HEADER DESTINATION ${TS_ENV}/include |
| 150 | RUNTIME DESTINATION ${TS_ENV}/bin |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 151 | ) |
| Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 152 | install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin) |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 153 | |
| 154 | get_property(_PROTO_FILES TARGET crypto-sp PROPERTY PROTOBUF_FILES) |
| Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 155 | install(FILES ${_PROTO_FILES} DESTINATION ${TS_ENV}/lib/protobuf) |
| Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 156 | |
| Imre Kis | a74aaf9 | 2021-12-14 17:13:06 +0100 | [diff] [blame^] | 157 | include(${TS_ROOT}/tools/cmake/common/ExportSp.cmake) |
| 158 | export_sp( |
| 159 | SP_UUID ${SP_UUID} |
| 160 | SP_NAME "crypto" |
| 161 | MK_IN ${TS_ROOT}/environments/opteesp/sp.mk.in |
| 162 | DTS_IN ${CMAKE_CURRENT_LIST_DIR}/default_crypto.dts.in |
| 163 | JSON_IN ${TS_ROOT}/environments/opteesp/sp_pkg.json.in |
| 164 | ) |