From 4848dfa710d9b9e54950e4e630bbe5790c53b223 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 21 Jun 2019 12:18:29 +0800 Subject: [PATCH] esptool_py: use component property to simplify arg file generation esptool_py used to create its own custom target to attach properties to. This commit uses component properties instead, and the APIs used to set and retrieve those properties in order to simplify generation of argument files to esptool.py. --- components/esptool_py/CMakeLists.txt | 9 +++++++ components/esptool_py/flash_project_args.in | 2 +- components/esptool_py/flasher_args.json.in | 4 +-- components/esptool_py/project_include.cmake | 30 +++++++-------------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/components/esptool_py/CMakeLists.txt b/components/esptool_py/CMakeLists.txt index c83cd5286..d30210531 100644 --- a/components/esptool_py/CMakeLists.txt +++ b/components/esptool_py/CMakeLists.txt @@ -10,6 +10,15 @@ if(NOT BOOTLOADER_BUILD) set(ESPTOOLPY_FLASH_PROJECT_OPTIONS "") endif() + # FLASH_PROJECT_ARGS, FLASH_PROJECT_ARGS_JSON, FLASH_PROJECT_ARGS_ENTRY_JSON + # are used in the flasher args input files (flash_project_args.in, flasher_args.json.in) + idf_component_get_property(FLASH_PROJECT_ARGS ${COMPONENT_NAME} + FLASH_PROJECT_ARGS GENERATOR_EXPRESSION) + idf_component_get_property(FLASH_PROJECT_ARGS_JSON ${COMPONENT_NAME} + FLASH_PROJECT_ARGS_JSON GENERATOR_EXPRESSION) + idf_component_get_property(FLASH_PROJECT_ARGS_ENTRY_JSON ${COMPONENT_NAME} + FLASH_PROJECT_ARGS_ENTRY_JSON GENERATOR_EXPRESSION) + # Generate the flash project args and the flasher args json file using the accumulated values # from esptool_py_flash_project_args calls. The file is first configured using configure_file() for all variable values, # and then generated using file(GENERATE... for generator expressions. diff --git a/components/esptool_py/flash_project_args.in b/components/esptool_py/flash_project_args.in index 640626af1..b6e3f8f9e 100644 --- a/components/esptool_py/flash_project_args.in +++ b/components/esptool_py/flash_project_args.in @@ -1,3 +1,3 @@ ${ESPTOOLPY_FLASH_PROJECT_OPTIONS} -$, +$ \ No newline at end of file diff --git a/components/esptool_py/flasher_args.json.in b/components/esptool_py/flasher_args.json.in index aa3aad2cc..ca8693cc7 100644 --- a/components/esptool_py/flasher_args.json.in +++ b/components/esptool_py/flasher_args.json.in @@ -8,10 +8,10 @@ "flash_freq": "${ESPFLASHFREQ}" }, "flash_files" : { - $,, + $ }, - $,, + $, "extra_esptool_args" : { "after" : "${ESPTOOLPY_AFTER}", diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index d4f8c3f93..78dc03cbb 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -149,9 +149,6 @@ if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT) esptool_py_custom_target(encrypted-app-flash encrypted_app "app") endif() - -add_custom_target(flash_project_args_target) - # esptool_py_flash_project_args # # Add file to the flasher args list, to be flashed at a particular offset. @@ -164,17 +161,14 @@ function(esptool_py_flash_project_args entry offset image) # flash the image individually using esptool cmake_parse_arguments(_ "${options}" "${single_value}" "" "${ARGN}") - idf_build_get_property(build_dir BUILD_DIR) - get_property(flash_project_entries TARGET flash_project_args_target PROPERTY FLASH_PROJECT_ENTRIES) - if(${entry} IN_LIST flash_project_entries) message(FATAL_ERROR "entry '${entry}' has already been added to flash project entries") endif() - list(APPEND flash_project_entries "${entry}") - set_property(TARGET flash_project_args_target PROPERTY FLASH_PROJECT_ENTRIES "${flash_project_entries}") + idf_component_set_property(esptool_py FLASH_PROJECT_ENTRIES "${entry}" APPEND) - file(RELATIVE_PATH image ${CMAKE_BINARY_DIR} ${image}) + idf_build_get_property(build_dir BUILD_DIR) + file(RELATIVE_PATH image ${build_dir} ${image}) # Generate the standalone flash file to flash the image individually using esptool set(entry_flash_args ${build_dir}/flash_${entry}_args) @@ -201,21 +195,15 @@ function(esptool_py_flash_project_args entry offset image) APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${entry_flash_args}) # Generate standalone entries in the flasher args json file - get_property(flash_project_args_entry_json TARGET - flash_project_args_target PROPERTY FLASH_PROJECT_ARGS_ENTRY_JSON) - list(APPEND flash_project_args_entry_json - "\"${entry}\" : { \"offset\" : \"${offset}\", \"file\" : \"${image}\" }") - set_property(TARGET flash_project_args_target - PROPERTY FLASH_PROJECT_ARGS_ENTRY_JSON "${flash_project_args_entry_json}") + idf_component_set_property(esptool_py FLASH_PROJECT_ARGS_ENTRY_JSON + "\"${entry}\" : { \"offset\" : \"${offset}\", \"file\" : \"${image}\" }" APPEND) # Generate entries in the flasher args json file if(__FLASH_IN_PROJECT) - get_property(flash_project_args TARGET flash_project_args_target PROPERTY FLASH_PROJECT_ARGS) - list(APPEND flash_project_args "${offset} ${image}") - set_property(TARGET flash_project_args_target PROPERTY FLASH_PROJECT_ARGS "${flash_project_args}") + idf_component_set_property(esptool_py FLASH_PROJECT_ARGS + "${offset} ${image}" APPEND) - get_property(flash_project_args_json TARGET flash_project_args_target PROPERTY FLASH_PROJECT_ARGS_JSON) - list(APPEND flash_project_args_json "\"${offset}\" : \"${image}\"") - set_property(TARGET flash_project_args_target PROPERTY FLASH_PROJECT_ARGS_JSON "${flash_project_args_json}") + idf_component_set_property(esptool_py FLASH_PROJECT_ARGS_JSON + "\"${offset}\" : \"${image}\"" APPEND) endif() endfunction()