CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. idf_component_register(PRIV_REQUIRES esptool_py)
  2. if(BOOTLOADER_BUILD)
  3. return()
  4. endif()
  5. set(partition_csv "${PARTITION_CSV_PATH}")
  6. if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES AND CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
  7. set(unsigned_partition_bin "partition-table-unsigned.bin")
  8. set(final_partition_bin "partition-table.bin")
  9. set(final_partition_target "sign_partition_table")
  10. else()
  11. set(unsigned_partition_bin "partition-table.bin")
  12. set(final_partition_bin "partition-table.bin")
  13. set(final_partition_target "build_partition_table")
  14. endif()
  15. if(NOT CONFIG_PARTITION_TABLE_MD5)
  16. set(md5_opt --disable-md5sum)
  17. endif()
  18. if(CONFIG_ESPTOOLPY_FLASHSIZE)
  19. set(flashsize_opt --flash-size ${CONFIG_ESPTOOLPY_FLASHSIZE})
  20. endif()
  21. if(CONFIG_SECURE_BOOT AND NOT CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION)
  22. set(partition_secure_opt --secure)
  23. else()
  24. set(partition_secure_opt "")
  25. endif()
  26. idf_build_get_property(build_dir BUILD_DIR)
  27. idf_build_get_property(python PYTHON)
  28. set(gen_partition_table "${python}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py" "-q"
  29. "--offset" "${PARTITION_TABLE_OFFSET}" "${md5_opt}" "${flashsize_opt}"
  30. "${partition_secure_opt}")
  31. set(partition_table_display
  32. COMMAND ${CMAKE_COMMAND} -E echo "Partition table binary generated. Contents:"
  33. COMMAND ${CMAKE_COMMAND} -E echo "*******************************************************************************"
  34. COMMAND ${gen_partition_table} "${build_dir}/partition_table/${unsigned_partition_bin}"
  35. COMMAND ${CMAKE_COMMAND} -E echo "*******************************************************************************"
  36. )
  37. add_custom_command(OUTPUT "${build_dir}/partition_table/${unsigned_partition_bin}"
  38. COMMAND ${gen_partition_table} "${partition_csv}" "${build_dir}/partition_table/${unsigned_partition_bin}"
  39. ${partition_table_display}
  40. DEPENDS ${partition_csv} "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py"
  41. VERBATIM)
  42. add_custom_target(partition_table_bin DEPENDS "${build_dir}/partition_table/${unsigned_partition_bin}"
  43. "${build_dir}/partition_table/${final_partition_bin}")
  44. if(EXISTS ${partition_csv})
  45. add_custom_target(partition-table
  46. DEPENDS partition_table_bin
  47. ${partition_table_display}
  48. VERBATIM)
  49. add_deprecated_target_alias(partition_table partition-table)
  50. else()
  51. # If the partition input CSV is not found, create a phony partition_table target that
  52. # fails the build. fail_at_build_time also touches CMakeCache.txt to cause a cmake run next time
  53. # (to pick up a new CSV if one exists, etc.)
  54. fail_at_build_time(partition-table
  55. "Partition table CSV ${partition_csv} does not exist."
  56. "Either change partition table in menuconfig or create this input file.")
  57. endif()
  58. # Add signing steps
  59. if(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
  60. if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
  61. add_custom_target(gen_unsigned_partition_bin ALL DEPENDS
  62. "${build_dir}/partition_table/${unsigned_partition_bin}")
  63. add_custom_command(OUTPUT "${build_dir}/partition_table/${final_partition_bin}"
  64. COMMAND ${ESPSECUREPY} sign_data --version 1 --keyfile "${SECURE_BOOT_SIGNING_KEY}"
  65. -o "${build_dir}/partition_table/${final_partition_bin}"
  66. "${build_dir}/partition_table/${unsigned_partition_bin}"
  67. DEPENDS "${build_dir}/partition_table/${unsigned_partition_bin}"
  68. VERBATIM)
  69. else()
  70. string(REPLACE ";" " " espsecurepy "${ESPSECUREPY}")
  71. add_custom_command(TARGET partition-table POST_BUILD
  72. COMMAND ${CMAKE_COMMAND} -E echo
  73. "Partition table built but not signed. Sign partition data before flashing:"
  74. COMMAND ${CMAKE_COMMAND} -E echo
  75. "\t${espsecurepy} sign_data --keyfile KEYFILE ${build_dir}/partition_table/${final_partition_bin}"
  76. VERBATIM)
  77. endif()
  78. elseif(CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME)
  79. add_custom_command(TARGET partition-table POST_BUILD
  80. COMMAND ${CMAKE_COMMAND} -E echo "Partition table built:"
  81. VERBATIM)
  82. endif()
  83. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  84. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  85. if(CONFIG_APP_BUILD_GENERATE_BINARIES)
  86. esptool_py_flash_target(partition-table-flash "${main_args}" "${sub_args}")
  87. esptool_py_flash_target_image(partition-table-flash partition-table "${PARTITION_TABLE_OFFSET}"
  88. "${build_dir}/partition_table/${final_partition_bin}")
  89. esptool_py_flash_target_image(flash partition-table "${PARTITION_TABLE_OFFSET}"
  90. "${build_dir}/partition_table/${final_partition_bin}")
  91. add_deprecated_target_alias(partition_table-flash partition-table-flash)
  92. endif()