project_include.cmake 20 KB

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