Skip to content

Commit b6ea668

Browse files
refactor(esptool_py): Removed global scope variables from esptool_py project_include.cmake
This commit global variables such as ESPTOOLPY, ESPSECUREPY, ESPEFUSEPY, ESPMONITOR and ESPTOOLPY_CHIP from the project_include.cmake file of esptool_py component. All other components which use these variables have been updated to fetch the same from esptool_py component's properties.
1 parent 8582294 commit b6ea668

File tree

7 files changed

+30
-27
lines changed

7 files changed

+30
-27
lines changed

components/bootloader_support/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ if(NOT BOOTLOADER_BUILD)
153153
endif()
154154

155155
if(CONFIG_SECURE_SIGNED_APPS AND (CONFIG_SECURE_BOOT_V1_ENABLED OR CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME))
156+
idf_component_get_property(espsecure_py_cmd esptool_py ESPSECUREPY_CMD)
156157
if(BOOTLOADER_BUILD)
157158
# Whether CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES or not, we need verification key to embed
158159
# in the library.
@@ -165,7 +166,7 @@ if(CONFIG_SECURE_SIGNED_APPS AND (CONFIG_SECURE_BOOT_V1_ENABLED OR CONFIG_SECURE
165166
"signature_verification_key.bin"
166167
ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
167168
add_custom_command(OUTPUT "${secure_boot_verification_key}"
168-
COMMAND ${ESPSECUREPY}
169+
COMMAND ${espsecure_py_cmd}
169170
extract_public_key --keyfile "${secure_boot_signing_key}"
170171
"${secure_boot_verification_key}"
171172
DEPENDS ${secure_boot_signing_key}
@@ -193,7 +194,7 @@ if(CONFIG_SECURE_SIGNED_APPS AND (CONFIG_SECURE_BOOT_V1_ENABLED OR CONFIG_SECURE
193194
ABSOLUTE BASE_DIR "${project_dir}")
194195

195196
add_custom_command(OUTPUT "${secure_boot_verification_key}"
196-
COMMAND ${ESPSECUREPY}
197+
COMMAND ${espsecure_py_cmd}
197198
extract_public_key --keyfile "${secure_boot_signing_key}"
198199
"${secure_boot_verification_key}"
199200
WORKING_DIRECTORY ${project_dir}

components/esptool_py/espefuse.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ cmake_minimum_required(VERSION 3.16)
22

33
# Executes a espefuse.py command and returns a cleaned log
44
function(espefuse_cmd cmd output_log)
5+
# espefuse_cmd can be called from a project's CMakeLists.txt file, which
6+
# can invoke this function in CMake scripting mode (-P). If that is the case,
7+
# we do not have access to convenience functions like idf_component_get_property.
8+
# In scripting mode, the path to espefuse.py must be passed in via the
9+
# 'ESPEFUSEPY' variable using the -D flag.
10+
#
11+
# When called during the normal build configuration phase, 'ESPEFUSEPY' is not
12+
# defined as a variable, and we must fetch it from the esptool_py component's
13+
# properties.
14+
if(NOT DEFINED ESPEFUSEPY)
15+
idf_component_get_property(ESPEFUSEPY esptool_py ESPEFUSEPY_CMD)
16+
endif()
517
set(SERIAL_TOOL ${ESPEFUSEPY})
618
if(${ESPEFUSEPY_OFFLINE})
719
set(VIRT_OPTION "--virt")

components/esptool_py/project_include.cmake

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
# esptool_py component project_include.cmake
22

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-
8-
idf_build_get_property(non_os_build NON_OS_BUILD)
9-
10-
set(chip_model ${target})
11-
12-
set(ESPTOOLPY ${python} "$ENV{ESPTOOL_WRAPPER}" "${CMAKE_CURRENT_LIST_DIR}/esptool/esptool.py" --chip ${chip_model})
13-
set(ESPSECUREPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espsecure.py")
14-
set(ESPEFUSEPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espefuse.py")
15-
set(ESPMONITOR ${python} -m esp_idf_monitor)
16-
set(ESPTOOLPY_CHIP "${chip_model}")
17-
183
# esptool_py_partition_needs_encryption
194
#
205
# @brief Determine if a partition needs to be encrypted when flash encryption is enabled.

components/partition_table/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,19 @@ endif()
139139

140140
# Add signing steps
141141
if(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
142+
idf_component_get_property(espsecure_py_cmd esptool_py ESPSECUREPY_CMD)
142143
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
143144
add_custom_target(gen_unsigned_partition_bin ALL DEPENDS
144145
"${build_dir}/partition_table/${unsigned_partition_bin}")
145146

146147
add_custom_command(OUTPUT "${build_dir}/partition_table/${final_partition_bin}"
147-
COMMAND ${ESPSECUREPY} sign_data --version 1 --keyfile "${SECURE_BOOT_SIGNING_KEY}"
148+
COMMAND ${espsecure_py_cmd} sign_data --version 1 --keyfile "${SECURE_BOOT_SIGNING_KEY}"
148149
-o "${build_dir}/partition_table/${final_partition_bin}"
149150
"${build_dir}/partition_table/${unsigned_partition_bin}"
150151
DEPENDS "${build_dir}/partition_table/${unsigned_partition_bin}"
151152
VERBATIM)
152153
else()
153-
string(REPLACE ";" " " espsecurepy "${ESPSECUREPY}")
154+
string(REPLACE ";" " " espsecurepy "${espsecure_py_cmd}")
154155
add_custom_command(TARGET partition-table POST_BUILD
155156
COMMAND ${CMAKE_COMMAND} -E echo
156157
"Partition table built but not signed. Sign partition data before flashing:"

examples/system/efuse/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ idf_build_set_property(MINIMAL_BUILD ON)
88
project(efuse)
99

1010
idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
11+
idf_component_get_property(espefuse_py_cmd esptool_py ESPEFUSEPY_CMD)
1112
set(efuse_names "MAC" "WR_DIS")
1213
add_custom_target(efuse-filter
1314
COMMAND ${CMAKE_COMMAND}
1415
-D "IDF_PATH=${IDF_PATH}"
1516
-D "esptool_py_dir=${esptool_py_dir}"
16-
-D "ESPEFUSEPY=${ESPEFUSEPY}"
17+
-D "ESPEFUSEPY=${espefuse_py_cmd}"
1718
-D "ESPEFUSEPY_OFFLINE=${CONFIG_IDF_CI_BUILD}" # Only for CI tests. Do not establish a connection with the chip
1819
-D "IDF_TARGET=${IDF_TARGET}"
1920
-D "efuse_names=${efuse_names}"

tools/cmake/project.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,10 @@ macro(project project_name)
948948
# Add uf2 related targets
949949
idf_build_get_property(idf_path IDF_PATH)
950950
idf_build_get_property(python PYTHON)
951+
idf_build_get_property(target IDF_TARGET)
951952

952953
set(UF2_ARGS --json "${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json")
953-
set(UF2_CMD ${python} "${idf_path}/tools/mkuf2.py" write --chip ${chip_model})
954+
set(UF2_CMD ${python} "${idf_path}/tools/mkuf2.py" write --chip ${target})
954955

955956
add_custom_target(uf2
956957
COMMAND ${CMAKE_COMMAND}

tools/test_apps/security/secure_boot/main/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ idf_component_register(SRCS "${main_src}" INCLUDE_DIRS ".")
99
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
1010

1111
if(CONFIG_EXAMPLE_TARGET_QEMU)
12+
set(PROJECT_BIN "${CMAKE_PROJECT_NAME}")
1213
set(bootloader_unsigned_bin "bootloader-unsigned.bin")
1314
set(app_unsigned_bin "${PROJECT_BIN}-unsigned.bin")
1415

16+
idf_component_get_property(espsecure_py_cmd esptool_py ESPSECUREPY_CMD)
17+
1518
add_custom_target(sign_bootloader ALL
1619
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/bootloader/bootloader.bin"
1720
"${CMAKE_BINARY_DIR}/bootloader/${bootloader_unsigned_bin}"
18-
COMMAND ${ESPSECUREPY} sign_data --version 2 --keyfile
21+
COMMAND ${espsecure_py_cmd} sign_data --version 2 --keyfile
1922
${PROJECT_DIR}/test/secure_boot_signing_key0.pem
2023
${PROJECT_DIR}/test/secure_boot_signing_key1.pem
2124
${PROJECT_DIR}/test/secure_boot_signing_key2.pem
@@ -29,14 +32,13 @@ if(CONFIG_EXAMPLE_TARGET_QEMU)
2932
add_dependencies(sign_bootloader bootloader)
3033

3134
add_custom_target(sign_app ALL
32-
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/${PROJECT_BIN}"
35+
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/${PROJECT_BIN}.bin"
3336
"${CMAKE_BINARY_DIR}/${app_unsigned_bin}"
34-
COMMAND ${ESPSECUREPY} sign_data --version 2 --keyfile
37+
COMMAND ${espsecure_py_cmd} sign_data --version 2 --keyfile
3538
${PROJECT_DIR}/test/secure_boot_signing_key1.pem
36-
-o "${CMAKE_BINARY_DIR}/${PROJECT_BIN}"
39+
-o "${CMAKE_BINARY_DIR}/${PROJECT_BIN}.bin"
3740
"${CMAKE_BINARY_DIR}/${app_unsigned_bin}"
38-
COMMAND ${CMAKE_COMMAND} -E echo "Generated signed binary image ${CMAKE_BINARY_DIR}/${PROJECT_BIN}"
39-
"from ${CMAKE_BINARY_DIR}/${app_unsigned_bin}"
41+
COMMAND ${CMAKE_COMMAND} -E echo "Generated signed binary image ${CMAKE_BINARY_DIR}/${PROJECT_BIN}.bin"
4042
VERBATIM
4143
COMMENT "Generated the test-specific signed application")
4244

0 commit comments

Comments
 (0)