Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 2 | # Copyright (c) 2020-2021, 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) |
| 8 | include(../../deployment.cmake REQUIRED) |
| 9 | |
| 10 | #------------------------------------------------------------------------------- |
| 11 | # The CMakeLists.txt for building the crypto deployment for opteesp |
| 12 | # |
| 13 | # Builds the Crypto service provider for running in an SEL0 secure partition |
| 14 | # hosted by OPTEE in the role of SPM. |
| 15 | #------------------------------------------------------------------------------- |
| 16 | include(${TS_ROOT}/environments/opteesp/env.cmake) |
| 17 | project(trusted-services LANGUAGES C ASM) |
| 18 | add_executable(crypto-sp) |
| 19 | target_include_directories(crypto-sp PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}") |
| 20 | set(SP_UUID "d9df52d5-16a2-4bb2-9aa4-d26d3b84e8c0") |
| 21 | |
| 22 | |
| 23 | # Include SP DEV KIT interface |
| 24 | set(SP_DEV_KIT_INC_DIR ${CMAKE_CURRENT_LIST_DIR}) |
| 25 | list(APPEND CMAKE_MODULE_PATH "${TS_ROOT}/external/Spdevkit") |
| 26 | find_package(Spdevkit REQUIRED) |
| 27 | sp_dev_kit_configure_linking(TARGET crypto-sp DEFINES ARM64=1) |
| 28 | target_link_libraries(crypto-sp PRIVATE ${SP_DEV_KIT_LIBRARIES}) |
| 29 | |
julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 30 | #------------------------------------------------------------------------------- |
| 31 | # Components that are specific to deployment in the opteesp environment. |
| 32 | # |
| 33 | #------------------------------------------------------------------------------- |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 34 | add_components(TARGET "crypto-sp" |
| 35 | BASE_DIR ${TS_ROOT} |
| 36 | COMPONENTS |
julhal01 | 734dbad | 2020-12-21 10:27:41 +0000 | [diff] [blame] | 37 | "components/common/tlv" |
julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame^] | 38 | "components/config/ramstore" |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 39 | "components/messaging/ffa/libsp" |
| 40 | "components/rpc/ffarpc/endpoint" |
| 41 | "components/rpc/ffarpc/caller/sp" |
| 42 | "components/rpc/common/caller" |
| 43 | "components/rpc/common/interface" |
| 44 | "components/rpc/dummy" |
| 45 | "components/service/common" |
| 46 | "components/service/common/serializer/protobuf" |
| 47 | "components/service/common/provider" |
| 48 | "components/service/crypto/provider/mbedcrypto" |
julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame^] | 49 | "components/service/crypto/provider/mbedcrypto/trng_adapter/platform" |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 50 | "components/service/crypto/provider/serializer/protobuf" |
julhal01 | 734dbad | 2020-12-21 10:27:41 +0000 | [diff] [blame] | 51 | "components/service/crypto/provider/serializer/packed-c" |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 52 | "components/service/secure_storage/client/psa" |
| 53 | "protocols/rpc/common/packed-c" |
| 54 | "protocols/service/secure_storage/packed-c" |
| 55 | "protocols/service/crypto/protobuf" |
| 56 | "environments/opteesp" |
| 57 | ) |
| 58 | |
| 59 | target_sources(crypto-sp PRIVATE |
| 60 | crypto_sp.c |
| 61 | ) |
| 62 | |
julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 63 | #------------------------------------------------------------------------------- |
| 64 | # Use the selected platform to provide drivers needed by the deployment |
| 65 | # |
| 66 | #------------------------------------------------------------------------------- |
| 67 | # temporarily force platform - with this change, the build interface to |
| 68 | # an external builder such as a Yocto recipe is unchanged. Should remove |
| 69 | # once the build interface is published. |
julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame^] | 70 | set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Overridden" FORCE) |
julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 71 | |
| 72 | add_platform(TARGET "crypto-sp") |
| 73 | |
| 74 | #------------------------------------------------------------------------------- |
| 75 | # Components used from external projects |
| 76 | # |
| 77 | #------------------------------------------------------------------------------- |
| 78 | |
| 79 | # Nanopb |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 80 | include(../../../external/nanopb/nanopb.cmake) |
| 81 | target_link_libraries(crypto-sp PRIVATE nanopb::protobuf-nanopb-static) |
| 82 | protobuf_generate_all(TGT "crypto-sp" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols") |
| 83 | |
julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame] | 84 | # Mbedcrypto |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 85 | include(../../../external/mbed-crypto/mbedcrypto.cmake) |
| 86 | target_link_libraries(crypto-sp PRIVATE mbedcrypto) |
| 87 | |
| 88 | if(CMAKE_CROSSCOMPILING) |
| 89 | target_link_libraries(crypto-sp PRIVATE stdc++ gcc m) |
| 90 | endif() |
| 91 | |
| 92 | ################################################################# |
| 93 | |
| 94 | target_compile_definitions(crypto-sp PRIVATE |
| 95 | ARM64=1 |
| 96 | ) |
| 97 | |
| 98 | target_include_directories(crypto-sp PRIVATE |
| 99 | ${TS_ROOT} |
| 100 | ${TS_ROOT}/components |
| 101 | ${TS_ROOT}/deployments/crypto/opteesp |
| 102 | ) |
| 103 | |
| 104 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 105 | target_compile_options(crypto-sp PRIVATE |
| 106 | -fdiagnostics-show-option |
| 107 | -fpic |
| 108 | -gdwarf-2 |
| 109 | -mstrict-align |
| 110 | -O0 |
| 111 | -std=gnu99 |
| 112 | ) |
| 113 | |
| 114 | # Options for GCC that control linking |
| 115 | target_link_options(crypto-sp PRIVATE |
| 116 | -e __sp_entry |
| 117 | -fno-lto |
| 118 | -nostdlib |
| 119 | -pie |
| 120 | -zmax-page-size=4096 |
| 121 | ) |
| 122 | # Options directly for LD, these are not understood by GCC |
| 123 | target_link_options(crypto-sp PRIVATE |
| 124 | -Wl,--as-needed |
| 125 | -Wl,--sort-section=alignment |
| 126 | # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list |
| 127 | ) |
| 128 | endif() |
| 129 | |
| 130 | compiler_generate_stripped_elf(TARGET crypto-sp NAME "${SP_UUID}.stripped.elf" RES STRIPPED_ELF) |
| 131 | |
| 132 | ######################################## install |
| 133 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 134 | set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE) |
| 135 | endif() |
| 136 | #TODO: api headers |
Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 137 | |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 138 | install(TARGETS crypto-sp |
Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 139 | PUBLIC_HEADER DESTINATION ${TS_ENV}/include |
| 140 | RUNTIME DESTINATION ${TS_ENV}/bin |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 141 | ) |
Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 142 | install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin) |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 143 | |
| 144 | get_property(_PROTO_FILES TARGET crypto-sp PROPERTY PROTOBUF_FILES) |
Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 145 | install(FILES ${_PROTO_FILES} DESTINATION ${TS_ENV}/lib/protobuf) |
Julian Hall | 4061ed6 | 2020-11-23 18:24:06 +0100 | [diff] [blame] | 146 | |
| 147 | |
| 148 | set(EXPORT_SP_NAME "crypto") |
| 149 | set(EXPORT_SP_UUID ${SP_UUID}) |
| 150 | include(${TS_ROOT}/environments/opteesp/ExportSp.cmake) |