CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. set(srcs
  2. "src/bootloader_clock.c"
  3. "src/bootloader_common.c"
  4. "src/bootloader_flash.c"
  5. "src/bootloader_random.c"
  6. "src/bootloader_utility.c"
  7. "src/esp_image_format.c"
  8. "src/flash_partitions.c"
  9. "src/flash_qio_mode.c"
  10. "src/bootloader_flash_config_${IDF_TARGET}.c"
  11. "src/bootloader_efuse_${IDF_TARGET}.c"
  12. )
  13. if(IDF_TARGET STREQUAL "esp32")
  14. # Not supported on ESP32S2Beta yet
  15. list(APPEND srcs "src/flash_encrypt.c")
  16. endif()
  17. if(BOOTLOADER_BUILD)
  18. set(include_dirs "include" "include_bootloader")
  19. # freertos is included just for the CONFIG_FREERTOS_UNICORE macro
  20. set(priv_requires micro-ecc spi_flash efuse freertos)
  21. list(APPEND srcs
  22. "src/bootloader_init.c"
  23. "src/${IDF_TARGET}/bootloader_sha.c"
  24. "src/${IDF_TARGET}/flash_encrypt.c"
  25. "src/${IDF_TARGET}/secure_boot_signatures.c"
  26. "src/${IDF_TARGET}/secure_boot.c"
  27. "src/${IDF_TARGET}/bootloader_${IDF_TARGET}.c"
  28. )
  29. else()
  30. list(APPEND srcs
  31. "src/idf/bootloader_sha.c"
  32. "src/idf/secure_boot_signatures.c")
  33. set(include_dirs "include")
  34. set(priv_include_dirs "include_bootloader")
  35. set(priv_requires spi_flash mbedtls efuse)
  36. endif()
  37. set(requires soc) #unfortunately the header directly uses SOC registers
  38. idf_component_register(SRCS "${srcs}"
  39. INCLUDE_DIRS "${include_dirs}"
  40. PRIV_INCLUDE_DIRS "${priv_include_dirs}"
  41. REQUIRES "${requires}"
  42. PRIV_REQUIRES "${priv_requires}")
  43. if(CONFIG_SECURE_SIGNED_APPS)
  44. if(BOOTLOADER_BUILD)
  45. # Whether CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES or not, we need verification key to embed
  46. # in the library.
  47. if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
  48. # We generate the key from the signing key. The signing key is passed from the main project.
  49. get_filename_component(secure_boot_signing_key
  50. "${SECURE_BOOT_SIGNING_KEY}"
  51. ABSOLUTE BASE_DIR "${project_dir}")
  52. get_filename_component(secure_boot_verification_key
  53. "signature_verification_key.bin"
  54. ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  55. add_custom_command(OUTPUT "${secure_boot_verification_key}"
  56. COMMAND ${ESPSECUREPY}
  57. extract_public_key --keyfile "${secure_boot_signing_key}"
  58. "${secure_boot_verification_key}"
  59. DEPENDS ${secure_boot_signing_key}
  60. VERBATIM)
  61. else()
  62. # We expect to 'inherit' the verification key passed from main project.
  63. get_filename_component(secure_boot_verification_key
  64. ${SECURE_BOOT_VERIFICATION_KEY}
  65. ABSOLUTE BASE_DIR "${project_dir}")
  66. endif()
  67. else() # normal app build
  68. idf_build_get_property(project_dir PROJECT_DIR)
  69. if(CONFIG_SECURE_BOOT_VERIFICATION_KEY)
  70. # verification-only build supplies verification key
  71. set(secure_boot_verification_key ${CONFIG_SECURE_BOOT_VERIFICATION_KEY})
  72. get_filename_component(secure_boot_verification_key
  73. ${secure_boot_verification_key}
  74. ABSOLUTE BASE_DIR "${project_dir}")
  75. else()
  76. # sign at build time, extracts key from signing key
  77. set(secure_boot_verification_key "${CMAKE_BINARY_DIR}/signature_verification_key.bin")
  78. get_filename_component(secure_boot_signing_key
  79. ${CONFIG_SECURE_BOOT_SIGNING_KEY}
  80. ABSOLUTE BASE_DIR "${project_dir}")
  81. add_custom_command(OUTPUT "${secure_boot_verification_key}"
  82. COMMAND ${ESPSECUREPY}
  83. extract_public_key --keyfile "${secure_boot_signing_key}"
  84. "${secure_boot_verification_key}"
  85. WORKING_DIRECTORY ${project_dir}
  86. DEPENDS ${secure_boot_signing_key}
  87. VERBATIM)
  88. endif()
  89. endif()
  90. # Embed the verification key in the binary (app & bootloader)
  91. #
  92. target_add_binary_data(${COMPONENT_LIB} "${secure_boot_verification_key}" "BINARY"
  93. RENAME_TO signature_verification_key_bin)
  94. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  95. APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
  96. "${secure_boot_verification_key}")
  97. endif()