project_include.cmake 20 KB

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