project_include.cmake 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. # Set some global esptool.py variables
  2. #
  3. # Many of these are read when generating flash_app_args & flash_project_args
  4. idf_build_get_property(target IDF_TARGET)
  5. idf_build_get_property(python PYTHON)
  6. idf_build_get_property(idf_path IDF_PATH)
  7. set(chip_model ${target})
  8. # TODO: remove this if block when esp32h2 beta1 is no longer supported
  9. if(target STREQUAL "esp32h2")
  10. if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_1)
  11. set(chip_model esp32h2beta1)
  12. elseif(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2)
  13. set(chip_model esp32h2beta2)
  14. endif()
  15. endif()
  16. set(ESPTOOLPY ${python} "$ENV{ESPTOOL_WRAPPER}" "${CMAKE_CURRENT_LIST_DIR}/esptool/esptool.py" --chip ${chip_model})
  17. set(ESPSECUREPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espsecure.py")
  18. set(ESPEFUSEPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espefuse.py")
  19. set(ESPMONITOR ${python} "${idf_path}/tools/idf_monitor.py")
  20. if(CONFIG_SPI_FLASH_HPM_ENABLE)
  21. # When set flash frequency to 120M, must keep 1st bootloader work under ``DOUT`` mode
  22. # because on some flash chips, 120M will modify the status register,
  23. # which will make ROM won't work.
  24. # This change intends to be for esptool only and the bootloader should keep use
  25. # ``DOUT`` mode.
  26. set(ESPFLASHMODE "dout")
  27. message("Note: HPM is enabled for the flash, force the ROM bootloader into DOUT mode for stable boot on")
  28. else()
  29. set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
  30. endif()
  31. set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
  32. set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
  33. set(ESPTOOLPY_CHIP "${chip_model}")
  34. set(esptool_elf2image_args
  35. --flash_mode ${ESPFLASHMODE}
  36. --flash_freq ${ESPFLASHFREQ}
  37. --flash_size ${ESPFLASHSIZE}
  38. )
  39. set(MMU_PAGE_SIZE ${CONFIG_MMU_PAGE_MODE})
  40. if(NOT BOOTLOADER_BUILD)
  41. list(APPEND esptool_elf2image_args --elf-sha256-offset 0xb0)
  42. # For chips that support configurable MMU page size feature
  43. # If page size is configured to values other than the default "64KB" in menuconfig,
  44. # then we need to pass the actual size to flash-mmu-page-size arg
  45. if(NOT MMU_PAGE_SIZE STREQUAL "64KB")
  46. list(APPEND esptool_elf2image_args --flash-mmu-page-size ${MMU_PAGE_SIZE})
  47. endif()
  48. endif()
  49. if(NOT CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION AND
  50. NOT BOOTLOADER_BUILD)
  51. if(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
  52. list(APPEND esptool_elf2image_args --secure-pad)
  53. elseif(CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME OR CONFIG_SECURE_SIGNED_APPS_ECDSA_V2_SCHEME)
  54. list(APPEND esptool_elf2image_args --secure-pad-v2)
  55. endif()
  56. endif()
  57. if(CONFIG_ESP32_REV_MIN)
  58. set(min_rev ${CONFIG_ESP32_REV_MIN})
  59. endif()
  60. if(CONFIG_ESP32C3_REV_MIN)
  61. set(min_rev ${CONFIG_ESP32C3_REV_MIN})
  62. endif()
  63. if(CONFIG_IDF_TARGET_ESP32C2)
  64. set(min_rev 1)
  65. endif()
  66. if(min_rev)
  67. list(APPEND esptool_elf2image_args --min-rev ${min_rev})
  68. set(monitor_rev_args "--revision;${min_rev}")
  69. unset(min_rev)
  70. endif()
  71. if(CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE)
  72. # Set ESPFLASHSIZE to 'detect' *after* esptool_elf2image_args are generated,
  73. # as elf2image can't have 'detect' as an option...
  74. set(ESPFLASHSIZE detect)
  75. # Flash size detection updates the image header which would invalidate the appended
  76. # SHA256 digest. Therefore, a digest is not appended in that case.
  77. # This argument requires esptool>=4.1.
  78. list(APPEND esptool_elf2image_args --dont-append-digest)
  79. endif()
  80. if(CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME)
  81. set(ESPFLASHSIZE keep)
  82. endif()
  83. idf_build_get_property(build_dir BUILD_DIR)
  84. idf_build_get_property(elf_name EXECUTABLE_NAME GENERATOR_EXPRESSION)
  85. idf_build_get_property(elf EXECUTABLE GENERATOR_EXPRESSION)
  86. idf_build_get_property(elf_dir EXECUTABLE_DIR GENERATOR_EXPRESSION)
  87. if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES AND NOT BOOTLOADER_BUILD)
  88. set(unsigned_project_binary "${elf_name}-unsigned.bin")
  89. else()
  90. set(unsigned_project_binary "${elf_name}.bin")
  91. endif()
  92. set(PROJECT_BIN "${elf_name}.bin")
  93. #
  94. # Add 'app.bin' target - generates with elf2image
  95. #
  96. if(CONFIG_APP_BUILD_GENERATE_BINARIES)
  97. add_custom_command(OUTPUT "${build_dir}/.bin_timestamp"
  98. COMMAND ${ESPTOOLPY} elf2image ${esptool_elf2image_args}
  99. -o "${build_dir}/${unsigned_project_binary}" "${elf_dir}/${elf}"
  100. COMMAND ${CMAKE_COMMAND} -E echo "Generated ${build_dir}/${unsigned_project_binary}"
  101. COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/${unsigned_project_binary}" > "${build_dir}/.bin_timestamp"
  102. DEPENDS ${elf}
  103. VERBATIM
  104. WORKING_DIRECTORY ${build_dir}
  105. COMMENT "Generating binary image from built executable"
  106. )
  107. add_custom_target(gen_project_binary DEPENDS "${build_dir}/.bin_timestamp")
  108. endif()
  109. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  110. APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
  111. "${build_dir}/${unsigned_project_binary}"
  112. )
  113. if(CONFIG_APP_BUILD_GENERATE_BINARIES)
  114. add_custom_target(app ALL DEPENDS gen_project_binary)
  115. endif()
  116. if(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
  117. set(secure_boot_version "1")
  118. elseif(CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME OR CONFIG_SECURE_SIGNED_APPS_ECDSA_V2_SCHEME)
  119. set(secure_boot_version "2")
  120. endif()
  121. if(NOT BOOTLOADER_BUILD AND CONFIG_SECURE_SIGNED_APPS)
  122. if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
  123. # for locally signed secure boot image, add a signing step to get from unsigned app to signed app
  124. get_filename_component(secure_boot_signing_key "${CONFIG_SECURE_BOOT_SIGNING_KEY}"
  125. ABSOLUTE BASE_DIR "${project_dir}")
  126. add_custom_command(OUTPUT "${build_dir}/.signed_bin_timestamp"
  127. COMMAND ${ESPSECUREPY} sign_data --version ${secure_boot_version} --keyfile ${secure_boot_signing_key}
  128. -o "${build_dir}/${PROJECT_BIN}" "${build_dir}/${unsigned_project_binary}"
  129. COMMAND ${CMAKE_COMMAND} -E echo "Generated signed binary image ${build_dir}/${PROJECT_BIN}"
  130. "from ${build_dir}/${unsigned_project_binary}"
  131. COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/${PROJECT_BIN}" > "${build_dir}/.signed_bin_timestamp"
  132. DEPENDS "${build_dir}/.bin_timestamp"
  133. VERBATIM
  134. COMMENT "Generating signed binary image"
  135. )
  136. add_custom_target(gen_signed_project_binary DEPENDS "${build_dir}/.signed_bin_timestamp")
  137. add_dependencies(gen_project_binary gen_signed_project_binary)
  138. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  139. APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
  140. "${build_dir}/${PROJECT_BIN}"
  141. )
  142. else()
  143. string(REPLACE ";" " " espsecurepy "${ESPSECUREPY}")
  144. add_custom_command(TARGET app POST_BUILD
  145. COMMAND ${CMAKE_COMMAND} -E echo
  146. "App built but not signed. Sign app before flashing"
  147. COMMAND ${CMAKE_COMMAND} -E echo
  148. "\t${espsecurepy} sign_data --keyfile KEYFILE --version ${secure_boot_version} \
  149. ${build_dir}/${PROJECT_BIN}"
  150. VERBATIM)
  151. endif()
  152. endif()
  153. add_custom_target(erase_flash
  154. COMMAND ${CMAKE_COMMAND}
  155. -D "IDF_PATH=${idf_path}"
  156. -D "SERIAL_TOOL=${ESPTOOLPY}"
  157. -D "SERIAL_TOOL_ARGS=erase_flash"
  158. -P run_serial_tool.cmake
  159. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  160. USES_TERMINAL
  161. VERBATIM
  162. )
  163. add_custom_target(monitor
  164. COMMAND ${CMAKE_COMMAND}
  165. -D "IDF_PATH=${idf_path}"
  166. -D "SERIAL_TOOL=${ESPMONITOR}"
  167. -D "SERIAL_TOOL_ARGS=--target;${target};${monitor_rev_args};${elf_dir}/${elf}"
  168. -D "WORKING_DIRECTORY=${build_dir}"
  169. -P run_serial_tool.cmake
  170. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  171. USES_TERMINAL
  172. VERBATIM
  173. )
  174. set(esptool_flash_main_args "--before=${CONFIG_ESPTOOLPY_BEFORE}")
  175. if(CONFIG_SECURE_BOOT OR CONFIG_SECURE_FLASH_ENC_ENABLED)
  176. # If security enabled then override post flash option
  177. list(APPEND esptool_flash_main_args "--after=no_reset")
  178. else()
  179. list(APPEND esptool_flash_main_args "--after=${CONFIG_ESPTOOLPY_AFTER}")
  180. endif()
  181. if(CONFIG_ESPTOOLPY_NO_STUB)
  182. list(APPEND esptool_flash_main_args "--no-stub")
  183. endif()
  184. idf_component_set_property(esptool_py FLASH_ARGS "${esptool_flash_main_args}")
  185. idf_component_set_property(esptool_py FLASH_SUB_ARGS "--flash_mode ${ESPFLASHMODE} --flash_freq ${ESPFLASHFREQ} \
  186. --flash_size ${ESPFLASHSIZE}")
  187. function(esptool_py_partition_needs_encryption retencrypted partition_name)
  188. # Check if encryption is enabled
  189. if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
  190. # Encryption is enabled, get partition type, subtype and encrypted flag
  191. # to determine whether it needs encryption or not.
  192. partition_table_get_partition_info(type "--partition-name ${partition_name}" "type")
  193. partition_table_get_partition_info(subtype "--partition-name ${partition_name}" "subtype")
  194. partition_table_get_partition_info(encrypted "--partition-name ${partition_name}" "encrypted")
  195. # As defined in gen_esp32part.py file:
  196. # Types:
  197. # - APP 0x00
  198. # - DATA 0x01
  199. # Subtypes:
  200. # - ota 0x00
  201. # - nvs 0x02
  202. # If the partition is an app, an OTA or an NVS partition, then it should
  203. # be encrypted
  204. if(
  205. (${type} EQUAL 0) OR
  206. (${type} EQUAL 1 AND ${subtype} EQUAL 0) OR
  207. (${type} EQUAL 1 AND ${subtype} EQUAL 2)
  208. )
  209. set(encrypted TRUE)
  210. endif()
  211. # Return 'encrypted' value to the caller
  212. set(${retencrypted} ${encrypted} PARENT_SCOPE)
  213. else()
  214. # Encryption not enabled, return false
  215. set(${retencrypted} FALSE PARENT_SCOPE)
  216. endif()
  217. endfunction()
  218. function(esptool_py_flash_to_partition target_name partition_name binary_path)
  219. # Retrieve the offset for the partition to flash the image on
  220. partition_table_get_partition_info(offset "--partition-name ${partition_name}" "offset")
  221. if(NOT offset)
  222. message(FATAL_ERROR "Could not find offset of partition ${partition_name}")
  223. endif()
  224. # Check whether the partition needs encryption or not
  225. esptool_py_partition_needs_encryption(encrypted ${partition_name})
  226. # If the image should not be encrypted, we pass the option
  227. # ALWAYS_PLAINTEXT to the function esptool_py_flash_target_image
  228. if(NOT ${encrypted})
  229. set(option ALWAYS_PLAINTEXT)
  230. endif()
  231. # The image name is also the partition name
  232. esptool_py_flash_target_image(${target_name} ${partition_name} ${offset}
  233. ${binary_path} ${option})
  234. endfunction()
  235. # This function takes a fifth optional named parameter: "ALWAYS_PLAINTEXT". As
  236. # its name states, it marks whether the image should be flashed as plain text or
  237. # not. If build macro CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT is set and
  238. # this parameter is provided, then the image will be flahsed as plain text
  239. # (not encrypted) on the target. This parameter will be ignored if build macro
  240. # CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT is not set.
  241. function(esptool_py_flash_target_image target_name image_name offset image)
  242. set(options ALWAYS_PLAINTEXT)
  243. idf_build_get_property(build_dir BUILD_DIR)
  244. file(RELATIVE_PATH image ${build_dir} ${image})
  245. cmake_parse_arguments(arg "${options}" "" "" "${ARGN}")
  246. # Check if the image has to be plain text or not, depending on the macro
  247. # CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT and the parameter
  248. # ALWAYS_PLAINTEXT
  249. set(encrypted false)
  250. if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT AND
  251. NOT arg_ALWAYS_PLAINTEXT)
  252. set(encrypted true)
  253. endif()
  254. # In the following snippet of code, some properties are defined for our
  255. # current target. These properties will be used to generate the actual
  256. # target_name_args files using the target_name_args.in files.
  257. # Please see function esptool_py_flash_target above for more information
  258. # about these properties and how they are used.
  259. # Add the image file, with its offset, to the list of files to
  260. # flash to the target. No matter whether flash encryption is
  261. # enabled or not, plain binaries (non-encrypted) need to be
  262. # generated
  263. set_property(TARGET ${target_name} APPEND PROPERTY FLASH_FILE
  264. "\"${offset}\" : \"${image}\"")
  265. set_property(TARGET ${target_name} APPEND PROPERTY FLASH_ENTRY
  266. "\"${image_name}\" : { \"offset\" : \"${offset}\", \"file\" : \"${image}\",\
  267. \"encrypted\" : \"${encrypted}\" }")
  268. set_property(TARGET ${target_name} APPEND PROPERTY IMAGES "${offset} ${image}")
  269. if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
  270. # When flash encryption mode is enabled, if the current binary needs to
  271. # be encrypted, do the same as previously but prefixing target names
  272. # with "encrypted-".
  273. if(encrypted)
  274. set_property(TARGET encrypted-${target_name} APPEND PROPERTY FLASH_FILE
  275. "\"${offset}\" : \"${image}\"")
  276. set_property(TARGET encrypted-${target_name} APPEND PROPERTY FLASH_ENTRY
  277. "\"${image_name}\" : { \"offset\" : \"${offset}\", \"file\" : \"${image}\" , \
  278. \"encrypted\" : \"${encrypted}\" }")
  279. set_property(TARGET encrypted-${target_name} APPEND PROPERTY ENCRYPTED_IMAGES "${offset} ${image}")
  280. else()
  281. # The target doesn't need to be encrypted, thus, add the current
  282. # file to the NON_ENCRYPTED_IMAGES property
  283. set_property(TARGET encrypted-${target_name} APPEND PROPERTY NON_ENCRYPTED_IMAGES "${offset} ${image}")
  284. endif()
  285. endif()
  286. endfunction()
  287. function(esptool_py_flash_target target_name main_args sub_args)
  288. set(single_value OFFSET IMAGE) # template file to use to be able to
  289. # flash the image individually using esptool
  290. set(options ALWAYS_PLAINTEXT)
  291. cmake_parse_arguments(_ "${options}" "${single_value}" "" "${ARGN}")
  292. idf_build_get_property(idf_path IDF_PATH)
  293. idf_build_get_property(build_dir BUILD_DIR)
  294. idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
  295. add_custom_target(${target_name}
  296. COMMAND ${CMAKE_COMMAND}
  297. -D "IDF_PATH=${idf_path}"
  298. -D "SERIAL_TOOL=${ESPTOOLPY}"
  299. -D "SERIAL_TOOL_ARGS=${main_args};write_flash;@${target_name}_args"
  300. -D "WORKING_DIRECTORY=${build_dir}"
  301. -P ${esptool_py_dir}/run_serial_tool.cmake
  302. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  303. USES_TERMINAL
  304. VERBATIM
  305. )
  306. set_target_properties(${target_name} PROPERTIES SUB_ARGS "${sub_args}")
  307. # Create the expression that contains the list of file names to pass
  308. # to esptool script
  309. set(flash_args_content "$<JOIN:$<TARGET_PROPERTY:${target_name},SUB_ARGS>, >\n\
  310. $<JOIN:$<TARGET_PROPERTY:${target_name},IMAGES>,\n>")
  311. # Write the previous expression to the target_name_args.in file
  312. file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${target_name}_args.in"
  313. CONTENT "${flash_args_content}")
  314. # Generate the actual expression value from the content of the file
  315. # we just wrote
  316. file(GENERATE OUTPUT "${build_dir}/${target_name}_args"
  317. INPUT "${CMAKE_CURRENT_BINARY_DIR}/${target_name}_args.in")
  318. # Check if the target has to be plain text or not, depending on the macro
  319. # CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT and the parameter
  320. # ALWAYS_PLAINTEXT
  321. set(encrypted FALSE)
  322. if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT AND
  323. NOT __ALWAYS_PLAINTEXT)
  324. set(encrypted TRUE)
  325. endif()
  326. # If the file needs to be encrypted, create a target file that lets the user
  327. # flash this partition independently from other files.
  328. # For example, if 'target_name' is app-flash and 'encrypted' is TRUE,
  329. # 'build' directory will contain a file name 'encrypted_app-flash_args'
  330. if(${encrypted})
  331. add_custom_target(encrypted-${target_name}
  332. COMMAND ${CMAKE_COMMAND}
  333. -D "IDF_PATH=${idf_path}"
  334. -D "SERIAL_TOOL=${ESPTOOLPY}"
  335. -D "SERIAL_TOOL_ARGS=${main_args};write_flash;@encrypted_${target_name}_args"
  336. -D "WORKING_DIRECTORY=${build_dir}"
  337. -P ${esptool_py_dir}/run_serial_tool.cmake
  338. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  339. USES_TERMINAL
  340. VERBATIM
  341. )
  342. # Generate the parameters for esptool.py command
  343. # In case we have both non encrypted and encrypted files to flash, we
  344. # can use --encrypt-files parameter to specify which ones should be
  345. # encrypted.
  346. # If we only have encrypted images to flash, we must use legacy
  347. # --encrypt parameter.
  348. # As the properties ENCRYPTED_IMAGES and NON_ENCRYPTED_IMAGES have not
  349. # been geenrated yet, we must use CMake expression generator to test
  350. # which esptool.py options we can use.
  351. # The variable has_non_encrypted_image will be evaluated to "1" if some
  352. # images must not be encrypted. This variable will be used in the next
  353. # expression
  354. set(has_non_encrypted_images "$<BOOL:$<TARGET_PROPERTY:\
  355. encrypted-${target_name},NON_ENCRYPTED_IMAGES>>")
  356. # Prepare esptool arguments (--encrypt or --encrypt-files)
  357. set(if_non_enc_expr "$<IF:${has_non_encrypted_images},,--encrypt>")
  358. set_target_properties(encrypted-${target_name} PROPERTIES SUB_ARGS
  359. "${sub_args}; ${if_non_enc_expr}")
  360. # Generate the list of files to pass to esptool
  361. set(encrypted_files "$<JOIN:$<TARGET_PROPERTY\
  362. :encrypted-${target_name},ENCRYPTED_IMAGES>,\n>")
  363. set(non_encrypted_files "$<JOIN:$<TARGET_PROPERTY:\
  364. encrypted-${target_name},NON_ENCRYPTED_IMAGES>,\n>")
  365. # Put both lists together, use --encrypted-files if we do also have
  366. # plain images to flash
  367. set(if_enc_expr "$<IF:${has_non_encrypted_images},--encrypt-files\n,>")
  368. set(flash_args_content "$<JOIN:$<TARGET_PROPERTY:\
  369. encrypted-${target_name},SUB_ARGS>, >\
  370. ${non_encrypted_files}\n\
  371. ${if_enc_expr}\
  372. ${encrypted_files}")
  373. # The expression is ready to be geenrated, write it to the file which
  374. # extension is .in
  375. file_generate("${CMAKE_CURRENT_BINARY_DIR}/encrypted_${target_name}_args.in"
  376. CONTENT "${flash_args_content}")
  377. # Generate the actual string from the content of the file we just wrote
  378. file_generate("${build_dir}/encrypted_${target_name}_args"
  379. INPUT "${CMAKE_CURRENT_BINARY_DIR}/encrypted_${target_name}_args.in")
  380. else()
  381. fail_target(encrypted-${target_name} "Error: The target encrypted-${target_name} requires"
  382. "CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT to be enabled.")
  383. endif()
  384. endfunction()
  385. function(esptool_py_custom_target target_name flasher_filename dependencies)
  386. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  387. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  388. idf_build_get_property(build_dir BUILD_DIR)
  389. esptool_py_flash_target(${target_name} "${main_args}" "${sub_args}")
  390. # Copy the file to flash_xxx_args for compatibility for select target
  391. file_generate("${build_dir}/flash_${flasher_filename}_args"
  392. INPUT "${build_dir}/${target_name}_args")
  393. add_dependencies(${target_name} ${dependencies})
  394. if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
  395. file_generate("${build_dir}/flash_encrypted_${flasher_filename}_args"
  396. INPUT "${build_dir}/encrypted_${target_name}_args")
  397. add_dependencies(encrypted-${target_name} ${dependencies})
  398. endif()
  399. endfunction()
  400. if(NOT BOOTLOADER_BUILD)
  401. set(flash_deps "partition_table_bin")
  402. if(CONFIG_APP_BUILD_GENERATE_BINARIES)
  403. list(APPEND flash_deps "app")
  404. endif()
  405. if(CONFIG_APP_BUILD_BOOTLOADER)
  406. list(APPEND flash_deps "bootloader")
  407. endif()
  408. esptool_py_custom_target(flash project "${flash_deps}")
  409. endif()