project_include.cmake 3.2 KB

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