CMakeLists.txt 4.8 KB

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