Balint Dobszay | efd67b3 | 2024-11-14 17:44:02 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | set(MS_TPM_URL "https://github.com/microsoft/ms-tpm-20-ref.git" CACHE STRING "MS TPM repository URL") |
| 9 | set(MS_TPM_REFSPEC "e9fc7b89d865536c46deb63f9c7d0121a3ded49c" CACHE STRING "MS TPM git refspec") |
| 10 | set(MS_TPM_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/ms_tpm-src" CACHE PATH "MS TPM source directory") |
| 11 | set(MS_TPM_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/ms_tpm-install" CACHE PATH "MS TPM install directory") |
| 12 | set(MS_TPM_BUILD_TYPE "Debug" CACHE STRING "MS TPM build type") |
| 13 | |
| 14 | # Add Mbed TLS |
| 15 | set(MBEDTLS_CONFIG_FILE "${TS_ROOT}/external/MbedTLS/config/ms_tpm_config.h" CACHE STRING "" FORCE) |
| 16 | include(${TS_ROOT}/external/MbedTLS/MbedTLS.cmake) |
| 17 | |
| 18 | # Pass include paths to ms_tpm |
| 19 | get_target_property(_mbedcrypto_includes MbedTLS::mbedcrypto INTERFACE_INCLUDE_DIRECTORIES) |
| 20 | get_target_property(_mbedx509_includes MbedTLS::mbedx509 INTERFACE_INCLUDE_DIRECTORIES) |
| 21 | set(TPM_EXTRA_INCLUDES |
| 22 | # MbedTLS includes |
| 23 | "${_mbedcrypto_includes}" |
| 24 | "${_mbedx509_includes}" |
| 25 | # TS utilities |
| 26 | "${TS_ROOT}/components/common/trace/include" |
| 27 | "${TS_ROOT}/components/common/utils/include" |
| 28 | # PSA headers |
| 29 | "${TS_ROOT}/components/service/common/include" |
| 30 | "${TS_ROOT}/components/service/secure_storage/include" |
| 31 | CACHE STRING "" FORCE) |
| 32 | |
| 33 | set(TPM_EXTRA_DEFINITIONS |
| 34 | # TPM config |
| 35 | _ARM_ |
| 36 | GCC |
| 37 | HASH_LIB=Mbed |
| 38 | SYM_LIB=Mbed |
| 39 | MATH_LIB=Mbed |
| 40 | SIMULATION=NO |
| 41 | VTPM=NO |
| 42 | ECC_NIST_P521=YES # if not defined, the TPM internal bignum allocation won't be large enough |
| 43 | CERTIFYX509_DEBUG=NO |
| 44 | |
| 45 | # Pass MbedTLS config |
| 46 | MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}" |
| 47 | |
| 48 | # Pass TS trace config |
| 49 | TRACE_LEVEL=${TRACE_LEVEL} |
| 50 | TRACE_PREFIX="${TRACE_PREFIX}" |
| 51 | CACHE STRING "" FORCE) |
| 52 | |
| 53 | # Only pass libc settings to ms_tpm if needed. For environments where the standard library is not |
| 54 | # overridden, this is not needed. |
| 55 | if(TARGET stdlib::c) |
| 56 | include(${TS_ROOT}/tools/cmake/common/PropertyCopy.cmake) |
| 57 | # Save libc settings |
| 58 | save_interface_target_properties(TGT stdlib::c PREFIX LIBC) |
| 59 | # Translate libc settings to CMake code fragment. Will be inserted into |
| 60 | # mbedtls-init-cache.cmake.in when LazyFetch configures the file. |
| 61 | translate_interface_target_properties(PREFIX LIBC RES _cmake_fragment) |
| 62 | unset_saved_properties(LIBC) |
| 63 | endif() |
| 64 | |
| 65 | set(GIT_OPTIONS |
| 66 | GIT_REPOSITORY ${MS_TPM_URL} |
| 67 | GIT_TAG ${MS_TPM_REFSPEC} |
| 68 | GIT_SHALLOW TRUE |
| 69 | PATCH_COMMAND |
| 70 | git stash |
| 71 | COMMAND git branch -f bf-am |
| 72 | COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-Add-MbedTLS-crypto-port.patch |
| 73 | COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0002-Add-PSA-platform-port.patch |
| 74 | COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0003-Add-CMake-support.patch |
| 75 | COMMAND git reset bf-am |
| 76 | ) |
| 77 | |
| 78 | include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED) |
| 79 | LazyFetch_MakeAvailable(DEP_NAME ms_tpm |
| 80 | FETCH_OPTIONS ${GIT_OPTIONS} |
| 81 | INSTALL_DIR ${MS_TPM_INSTALL_DIR} |
| 82 | PACKAGE_DIR ${MS_TPM_INSTALL_DIR} |
| 83 | CACHE_FILE "${TS_ROOT}/external/ms_tpm/ms_tpm-init-cache.cmake.in" |
| 84 | SOURCE_DIR "${MS_TPM_SOURCE_DIR}" |
| 85 | ) |
| 86 | unset(_cmake_fragment) |
| 87 | |
| 88 | target_link_libraries(ms_tpm::tpm INTERFACE MbedTLS::mbedcrypto) |
| 89 | target_link_libraries(ms_tpm::tpm INTERFACE MbedTLS::mbedx509) |