Skip to content

Commit 3a1f343

Browse files
refactor(esptool_py): Move flasher_args.json generation to project level
This commit refactors the esptool_py component to move the flasher_args.json file generation to the main project level cmake file when idf_build_executable() runs.
1 parent 7c75795 commit 3a1f343

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

components/esptool_py/CMakeLists.txt

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,3 @@ if(esp_tee_build)
1111
endif()
1212

1313
idf_component_register(REQUIRES bootloader PRIV_REQUIRES partition_table)
14-
15-
if(NOT BOOTLOADER_BUILD)
16-
idf_build_get_property(build_dir BUILD_DIR)
17-
18-
19-
20-
21-
# Generate flasher_args.json for tools that need it. The variables below are used
22-
# in configuring the template flasher_args.json.in.
23-
# Some of the variables (flash mode, size, frequency, chip) are already set in project_include.cmake.
24-
25-
set(ESPTOOLPY_BEFORE "${CONFIG_ESPTOOLPY_BEFORE}")
26-
set(ESPTOOLPY_AFTER "${CONFIG_ESPTOOLPY_AFTER}")
27-
if(CONFIG_ESPTOOLPY_NO_STUB)
28-
set(ESPTOOLPY_WITH_STUB false)
29-
else()
30-
set(ESPTOOLPY_WITH_STUB true)
31-
endif()
32-
33-
if(CONFIG_SECURE_BOOT OR CONFIG_SECURE_FLASH_ENC_ENABLED)
34-
# If security enabled then override post flash option
35-
set(ESPTOOLPY_AFTER "no_reset")
36-
endif()
37-
38-
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
39-
# Generate flasher args files
40-
file(READ "flasher_args.json.in" flasher_args_content)
41-
string(CONFIGURE "${flasher_args_content}" flasher_args_content)
42-
43-
file_generate("${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in"
44-
CONTENT "${flasher_args_content}")
45-
file_generate("${CMAKE_BINARY_DIR}/flasher_args.json"
46-
INPUT "${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in")
47-
endif()
48-
endif() # NOT BOOTLOADER_BUILD

tools/cmake/build.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,42 @@ function(idf_build_executable elf)
848848
# Setup the main flash target and dependencies
849849
__esptool_py_setup_main_flash_target()
850850

851+
# Generate flasher_args.json for tools that need it. The variables below are used
852+
# in configuring the template flasher_args.json.in.
853+
# Some of the variables (flash mode, size, frequency) are set as esptool_py component's properties.
854+
855+
idf_build_get_property(target IDF_TARGET)
856+
set(ESPTOOLPY_CHIP "${target}")
857+
set(ESPTOOLPY_BEFORE "${CONFIG_ESPTOOLPY_BEFORE}")
858+
set(ESPTOOLPY_AFTER "${CONFIG_ESPTOOLPY_AFTER}")
859+
if(CONFIG_ESPTOOLPY_NO_STUB)
860+
set(ESPTOOLPY_WITH_STUB false)
861+
else()
862+
set(ESPTOOLPY_WITH_STUB true)
863+
endif()
864+
865+
if(CONFIG_SECURE_BOOT OR CONFIG_SECURE_FLASH_ENC_ENABLED)
866+
# If security enabled then override post flash option
867+
set(ESPTOOLPY_AFTER "no_reset")
868+
endif()
869+
870+
idf_component_get_property(ESPFLASHMODE esptool_py ESPFLASHMODE)
871+
idf_component_get_property(ESPFLASHFREQ esptool_py ESPFLASHFREQ)
872+
idf_component_get_property(ESPFLASHSIZE esptool_py ESPFLASHSIZE)
873+
idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
874+
875+
# Generate flasher args files
876+
file(READ "${esptool_py_dir}/flasher_args.json.in" flasher_args_content)
877+
string(CONFIGURE "${flasher_args_content}" flasher_args_content)
878+
879+
# We need to create a flasher_args.json.in to create the final flasher_args.json
880+
# because CMake only resolves generator expressions in the file_generate command
881+
# with the INPUT keyword during the generation phase.
882+
file_generate("${build_dir}/flasher_args.json.in"
883+
CONTENT "${flasher_args_content}")
884+
file_generate("${build_dir}/flasher_args.json"
885+
INPUT "${build_dir}/flasher_args.json.in")
886+
851887
# Create the following post-build targets after __idf_build_binary() is called to ensure that the
852888
# app target is available.
853889

0 commit comments

Comments
 (0)