project_include.cmake
1 # This is for tracking the top level project path 2 if(BOOTLOADER_BUILD) 3 set(main_project_path "${CMAKE_BINARY_DIR}/../..") 4 else() 5 set(main_project_path "${IDF_PROJECT_PATH}") 6 endif() 7 8 get_filename_component(secure_boot_signing_key 9 "${CONFIG_SECURE_BOOT_SIGNING_KEY}" 10 ABSOLUTE BASE_DIR "${main_project_path}") 11 if(NOT EXISTS ${secure_boot_signing_key}) 12 # If the signing key is not found, create a phony gen_secure_boot_signing_key target that 13 # fails the build. fail_at_build_time also touches CMakeCache.txt to cause a cmake run next time 14 # (to pick up a new signing key if one exists, etc.) 15 fail_at_build_time(gen_secure_boot_signing_key 16 "Secure Boot Signing Key ${CONFIG_SECURE_BOOT_SIGNING_KEY} does not exist. Generate using:" 17 "\tespsecure.py generate_signing_key ${CONFIG_SECURE_BOOT_SIGNING_KEY}") 18 else() 19 add_custom_target(gen_secure_boot_signing_key) 20 endif() 21 22 if(BOOTLOADER_BUILD OR NOT IDF_BUILD_ARTIFACTS) 23 return() # don't keep recursing, generate on project builds 24 endif() 25 26 # Glue to build the bootloader subproject binary as an external 27 # cmake project under this one 28 # 29 # 30 set(bootloader_build_dir "${IDF_BUILD_ARTIFACTS_DIR}/bootloader") 31 set(bootloader_binary_files 32 "${bootloader_build_dir}/bootloader.elf" 33 "${bootloader_build_dir}/bootloader.bin" 34 "${bootloader_build_dir}/bootloader.map" 35 ) 36 37 # These additional files may get generated 38 if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE) 39 set(bootloader_binary_files 40 ${bootloader_binary_files} 41 "${bootloader_build_dir}/bootloader-reflash-digest.bin" 42 "${bootloader_build_dir}/secure-bootloader-key-192.bin" 43 "${bootloader_build_dir}/secure-bootloader-key-256.bin" 44 ) 45 endif() 46 47 if((NOT CONFIG_SECURE_BOOT_ENABLED) OR 48 CONFIG_SECURE_BOOTLOADER_REFLASHABLE OR 49 CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH) 50 externalproject_add(bootloader 51 # TODO: support overriding the bootloader in COMPONENT_PATHS 52 SOURCE_DIR "${IDF_PATH}/components/bootloader/subproject" 53 BINARY_DIR "${bootloader_build_dir}" 54 CMAKE_ARGS -DSDKCONFIG=${SDKCONFIG} -DIDF_PATH=${IDF_PATH} 55 -DSECURE_BOOT_SIGNING_KEY=${secure_boot_signing_key} 56 INSTALL_COMMAND "" 57 BUILD_ALWAYS 1 # no easy way around this... 58 BUILD_BYPRODUCTS ${bootloader_binary_files} 59 DEPENDS gen_secure_boot_signing_key 60 ) 61 else() 62 fail_at_build_time(bootloader "Invalid bootloader target: bad sdkconfig?") 63 endif() 64 65 # this is a hack due to an (annoying) shortcoming in cmake, it can't 66 # extend the 'clean' target to the external project 67 # see thread: https://cmake.org/pipermail/cmake/2016-December/064660.html 68 # 69 # So for now we just have the top-level build remove the final build products... 70 set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY 71 ADDITIONAL_MAKE_CLEAN_FILES 72 ${bootloader_binary_files})