project_include.cmake 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # LEGACY_INCLUDE_COMMON_HEADERS has to be passed in via cache variable since
  60. # the bootloader common component requirements depends on this and
  61. # config variables are not available before project() call.
  62. -DLEGACY_INCLUDE_COMMON_HEADERS=${CONFIG_LEGACY_INCLUDE_COMMON_HEADERS}
  63. INSTALL_COMMAND ""
  64. BUILD_ALWAYS 1 # no easy way around this...
  65. BUILD_BYPRODUCTS ${bootloader_binary_files}
  66. DEPENDS gen_secure_boot_signing_key
  67. )
  68. else()
  69. fail_at_build_time(bootloader "Invalid bootloader target: bad sdkconfig?")
  70. endif()
  71. # this is a hack due to an (annoying) shortcoming in cmake, it can't
  72. # extend the 'clean' target to the external project
  73. # see thread: https://cmake.org/pipermail/cmake/2016-December/064660.html
  74. #
  75. # So for now we just have the top-level build remove the final build products...
  76. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  77. ADDITIONAL_MAKE_CLEAN_FILES
  78. ${bootloader_binary_files})