1#------------------------------------------------------------------------------- 2# Copyright (c) 2023-2024, Arm Limited. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6#------------------------------------------------------------------------------- 7 8 9find_package(Python3) 10 11add_executable(provisioning_bundle) 12 13if(${TFM_DUMMY_PROVISIONING}) 14 include(${CMAKE_SOURCE_DIR}/platform/ext/common/provisioning_bundle/provisioning_config.cmake) 15else() 16 include("${PROVISIONING_KEYS_CONFIG}" OPTIONAL RESULT_VARIABLE PROVISIONING_KEYS_CONFIG_PATH) 17 if(NOT PROVISIONING_KEYS_CONFIG_PATH) 18 message(WARNING "The PROVISIONING_KEYS_CONFIG is not set. If the keys are not passed via the command line then \ 19 random numbers will be used for HUK/IAK etc. \ 20 To create and use a PROVISIONING_KEYS_CONFIG file, \ 21 see the example in: tf-m/platform/ext/common/provisioning_bundle/provisioning_config.cmake") 22 endif() 23endif() 24 25set_target_properties(provisioning_bundle 26 PROPERTIES 27 SUFFIX ".axf" 28 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" 29) 30 31if(${PLATFORM_DEFAULT_PROV_LINKER_SCRIPT}) 32 target_add_scatter_file(provisioning_bundle 33 $<$<C_COMPILER_ID:ARMClang>:${CMAKE_CURRENT_SOURCE_DIR}/provisioning_bundle.sct> 34 $<$<C_COMPILER_ID:GNU>:${CMAKE_CURRENT_SOURCE_DIR}/provisioning_bundle.ld> 35 $<$<C_COMPILER_ID:IAR>:${CMAKE_CURRENT_SOURCE_DIR}/provisioning_bundle.icf> 36 ) 37endif() 38 39target_link_options(provisioning_bundle 40 PRIVATE 41 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/provisioning_bundle.map> 42 $<$<C_COMPILER_ID:ARMClang>:--map> 43 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/provisioning_bundle.map> 44) 45 46target_link_options(provisioning_bundle 47 PRIVATE 48 --entry=do_provision 49) 50 51target_sources(provisioning_bundle 52 PRIVATE 53 ./provisioning_code.c 54 ./provisioning_data.c 55 $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c> 56) 57 58target_include_directories(provisioning_bundle 59 PRIVATE 60 . 61) 62 63target_link_libraries(provisioning_bundle 64 platform_s 65 psa_interface 66) 67 68target_compile_definitions(provisioning_bundle 69 PRIVATE 70 $<$<BOOL:${PLATFORM_DEFAULT_CRYPTO_KEYS}>:PLATFORM_DEFAULT_CRYPTO_KEYS> 71 $<$<BOOL:${PLATFORM_DEFAULT_OTP}>:PLATFORM_DEFAULT_OTP> 72 $<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:SYMMETRIC_INITIAL_ATTESTATION> 73 $<$<BOOL:${TFM_DUMMY_PROVISIONING}>:TFM_DUMMY_PROVISIONING> 74 $<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:PLATFORM_DEFAULT_NV_COUNTERS> 75 $<$<BOOL:${PLATFORM_DEFAULT_OTP_WRITEABLE}>:OTP_WRITEABLE> 76 MBEDTLS_CONFIG_FILE="${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/mbedcrypto_config/tfm_mbedcrypto_config_default.h" 77 MBEDTLS_PSA_CRYPTO_CONFIG_FILE="${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/mbedcrypto_config/crypto_config_default.h" 78) 79 80add_custom_target(provisioning_bundle_bin 81 ALL 82 SOURCES provisioning_bundle.bin 83) 84 85add_custom_command(OUTPUT provisioning_bundle.bin 86 DEPENDS $<TARGET_FILE_DIR:provisioning_bundle>/provisioning_bundle.axf 87 DEPENDS provisioning_bundle 88 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/create_provisioning_bundle.py 89 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/create_provisioning_bundle.py 90 --provisioning_bundle_axf ${CMAKE_BINARY_DIR}/bin/provisioning_bundle.axf 91 --bundle_output_file provisioning_bundle.bin 92 --code_pad_size ${PROVISIONING_CODE_PADDED_SIZE} 93 --data_pad_size ${PROVISIONING_DATA_PADDED_SIZE} 94 --values_pad_size ${PROVISIONING_VALUES_PADDED_SIZE} 95 --magic "0xC0DEFEED" 96 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/provisioning_bundle.bin ${CMAKE_BINARY_DIR}/bin/provisioning_bundle.bin 97) 98 99target_sources(platform_s 100 PRIVATE 101 ./runtime_stub_provisioning.c 102) 103 104target_sources(platform_bl2 105 PRIVATE 106 ./bl2_provisioning.c 107) 108 109target_include_directories(platform_bl2 110 INTERFACE 111 . 112) 113 114add_custom_target(provisioning_data 115 SOURCES 116 provisioning_data.c 117) 118 119add_custom_command(OUTPUT provisioning_data.c 120 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,${MCUBOOT_KEY_S}> 121 DEPENDS $<IF:$<BOOL:${MCUBOOT_GENERATE_SIGNING_KEYPAIR}>,generated_private_key,${MCUBOOT_KEY_NS}> 122 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/provisioning_data_template.jinja2 123 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/create_provisioning_data.py 124 WORKING_DIRECTORY ${MCUBOOT_PATH}/scripts 125 COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/create_provisioning_data.py 126 ${CMAKE_CURRENT_BINARY_DIR}/provisioning_data.c 127 --bl2_rot_priv_key_0=${MCUBOOT_KEY_S} 128 --bl2_rot_priv_key_1=${MCUBOOT_KEY_NS} 129 --bl2_mcuboot_hw_key=${MCUBOOT_HW_KEY} 130 --template_path=${CMAKE_CURRENT_SOURCE_DIR} 131 --secure_debug_pk=${SECURE_DEBUG_PK} 132 --huk=${HUK} 133 --iak=${IAK} 134 --boot_seed=${BOOT_SEED} 135 --implementation_id=${IMPLEMENTATION_ID} 136 --certification_reference=${CERTIFICATION_REFERENCE} 137 --verification_service_url=${VERIFICATION_SERVICE_URL} 138 --entropy_seed=${ENTROPY_SEED} 139 140) 141