CMakeLists.txt 4.8 KB

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