Skip to content

Commit c8f68c7

Browse files
Merge branch 'feat/remove_global_cmake_vars' into 'master'
change(esptool_py): Make esptool_py component idempotent in the build Closes IDF-13073 See merge request espressif/esp-idf!39589
2 parents e1213c8 + 7204704 commit c8f68c7

File tree

49 files changed

+900
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+900
-464
lines changed

components/app_update/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ if(NOT BOOTLOADER_BUILD)
2929

3030
add_custom_target(blank_ota_data ALL DEPENDS ${blank_otadata_file})
3131
add_dependencies(flash blank_ota_data)
32-
add_dependencies(encrypted-flash blank_ota_data)
32+
if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
33+
add_dependencies(encrypted-flash blank_ota_data)
34+
endif()
3335

3436
set(otatool_py "${python}" "${COMPONENT_DIR}/otatool.py")
3537

components/bootloader/subproject/CMakeLists.txt

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,36 @@ idf_build_set_property(COMPILE_DEFINITIONS "BOOTLOADER_BUILD=1" APPEND)
7979
idf_build_set_property(COMPILE_DEFINITIONS "NON_OS_BUILD=1" APPEND)
8080
idf_build_set_property(COMPILE_OPTIONS "-fno-stack-protector" APPEND)
8181

82+
# Set up the bootloader binary generation targets
83+
set(PROJECT_BIN "bootloader.bin")
84+
if(CONFIG_SECURE_BOOT_V2_ENABLED AND CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
85+
set(bootloader_unsigned_bin "bootloader-unsigned.bin")
86+
else()
87+
set(bootloader_unsigned_bin "${PROJECT_BIN}")
88+
endif()
89+
90+
# Set the final binary name as a project property
91+
idf_build_set_property(PROJECT_BIN "${PROJECT_BIN}")
92+
93+
# Generate the unsigned binary from the ELF file.
94+
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
95+
set(target_name "gen_bootloader_binary")
96+
__idf_build_binary("${bootloader_unsigned_bin}" "${target_name}")
97+
endif()
98+
8299
idf_component_get_property(main_args esptool_py FLASH_ARGS)
83100
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
101+
idf_component_get_property(esptool_py_cmd esptool_py ESPTOOLPY_CMD)
102+
idf_component_get_property(espsecure_py_cmd esptool_py ESPSECUREPY_CMD)
103+
idf_component_get_property(espefuse_py_cmd esptool_py ESPEFUSEPY_CMD)
84104

85105
# String for printing flash command
86106
string(REPLACE ";" " " esptoolpy_write_flash
87-
"${ESPTOOLPY} --port=(PORT) --baud=(BAUD) ${main_args} "
107+
"${esptool_py_cmd} --port=(PORT) --baud=(BAUD) ${main_args} "
88108
"write_flash ${sub_args}")
89109

90-
string(REPLACE ";" " " espsecurepy "${ESPSECUREPY}")
91-
string(REPLACE ";" " " espefusepy "${ESPEFUSEPY}")
110+
string(REPLACE ";" " " espsecurepy "${espsecure_py_cmd}")
111+
string(REPLACE ";" " " espefusepy "${espefuse_py_cmd}")
92112

93113
# Suppress warning: "Manually-specified variables were not used by the project: SECURE_BOOT_SIGNING_KEY"
94114
set(ignore_signing_key "${SECURE_BOOT_SIGNING_KEY}")
@@ -109,7 +129,7 @@ if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
109129
ABSOLUTE BASE_DIR "${CMAKE_BINARY_DIR}")
110130

111131
add_custom_command(OUTPUT "${secure_bootloader_key}"
112-
COMMAND ${ESPSECUREPY} digest_private_key
132+
COMMAND ${espsecure_py_cmd} digest_private_key
113133
--keylen "${key_digest_len}"
114134
--keyfile "${SECURE_BOOT_SIGNING_KEY}"
115135
"${secure_bootloader_key}"
@@ -134,7 +154,7 @@ if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
134154

135155
add_custom_command(OUTPUT "${bootloader_digest_bin}"
136156
COMMAND ${CMAKE_COMMAND} -E echo "DIGEST ${bootloader_digest_bin}"
137-
COMMAND ${ESPSECUREPY} digest_secure_bootloader --keyfile "${secure_bootloader_key}"
157+
COMMAND ${espsecure_py_cmd} digest_secure_bootloader --keyfile "${secure_bootloader_key}"
138158
-o "${bootloader_digest_bin}" "${CMAKE_BINARY_DIR}/bootloader.bin"
139159
MAIN_DEPENDENCY "${CMAKE_BINARY_DIR}/.bin_timestamp"
140160
DEPENDS gen_secure_bootloader_key gen_project_binary
@@ -143,39 +163,34 @@ if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
143163
add_custom_target(gen_bootloader_digest_bin ALL DEPENDS "${bootloader_digest_bin}")
144164
endif()
145165

166+
# If secure boot is enabled, generate the signed binary from the unsigned one.
146167
if(CONFIG_SECURE_BOOT_V2_ENABLED)
147-
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
148-
get_filename_component(secure_boot_signing_key
149-
"${SECURE_BOOT_SIGNING_KEY}" ABSOLUTE BASE_DIR "${project_dir}")
168+
set(target_name "gen_signed_bootloader")
150169

151-
if(NOT EXISTS "${secure_boot_signing_key}")
152-
message(FATAL_ERROR
153-
"Secure Boot Signing Key Not found."
154-
"\nGenerate the Secure Boot V2 RSA-PSS 3072 Key."
155-
"\nTo generate one, you can use this command:"
156-
"\n\t${espsecurepy} generate_signing_key --version 2 ${SECURE_BOOT_SIGNING_KEY}")
170+
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
171+
# The SECURE_BOOT_SIGNING_KEY is passed in from the parent build and
172+
# is already an absolute path.
173+
if(NOT EXISTS "${SECURE_BOOT_SIGNING_KEY}")
174+
message(FATAL_ERROR
175+
"Secure Boot Signing Key Not found."
176+
"\nGenerate the Secure Boot V2 RSA-PSS 3072 Key."
177+
"\nTo generate one, you can use this command:"
178+
"\n\t${espsecurepy} generate_signing_key --version 2 your_key.pem"
179+
)
157180
endif()
158181

159-
set(bootloader_unsigned_bin "bootloader-unsigned.bin")
160-
add_custom_command(OUTPUT ".signed_bin_timestamp"
161-
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/${PROJECT_BIN}"
162-
"${CMAKE_BINARY_DIR}/${bootloader_unsigned_bin}"
163-
COMMAND ${ESPSECUREPY} sign_data --version 2 --keyfile "${secure_boot_signing_key}"
164-
-o "${CMAKE_BINARY_DIR}/${PROJECT_BIN}" "${CMAKE_BINARY_DIR}/${bootloader_unsigned_bin}"
165-
COMMAND ${CMAKE_COMMAND} -E echo "Generated signed binary image ${build_dir}/${PROJECT_BIN}"
166-
"from ${CMAKE_BINARY_DIR}/${bootloader_unsigned_bin}"
167-
COMMAND ${CMAKE_COMMAND} -E md5sum "${CMAKE_BINARY_DIR}/${PROJECT_BIN}"
168-
> "${CMAKE_BINARY_DIR}/.signed_bin_timestamp"
169-
DEPENDS "${build_dir}/.bin_timestamp"
170-
VERBATIM
171-
COMMENT "Generated the signed Bootloader")
182+
set(comment "Generated the signed Bootloader")
183+
set(key_arg KEYFILE "${SECURE_BOOT_SIGNING_KEY}")
172184
else()
173-
add_custom_command(OUTPUT ".signed_bin_timestamp"
174-
VERBATIM
175-
COMMENT "Bootloader generated but not signed")
185+
# If we are not building signed binaries, we don't pass a key.
186+
set(comment "Bootloader generated but not signed")
187+
set(key_arg "")
176188
endif()
177189

178-
add_custom_target(gen_signed_bootloader ALL DEPENDS "${build_dir}/.signed_bin_timestamp")
190+
__idf_build_secure_binary("${bootloader_unsigned_bin}" "${PROJECT_BIN}" "${target_name}"
191+
COMMENT "${comment}"
192+
${key_arg}
193+
)
179194
endif()
180195

181196
if(CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH)
@@ -259,3 +274,19 @@ elseif(CONFIG_SECURE_BOOT_V2_ENABLED AND NOT CONFIG_SECURE_BOOT_FLASH_BOOTLOADER
259274
DEPENDS gen_signed_bootloader
260275
VERBATIM)
261276
endif()
277+
278+
# Generate bootloader post-build check of the bootloader size against the offset
279+
partition_table_add_check_bootloader_size_target(bootloader_check_size
280+
DEPENDS gen_project_binary
281+
BOOTLOADER_BINARY_PATH "${CMAKE_BINARY_DIR}/${PROJECT_BIN}"
282+
RESULT bootloader_check_size_command)
283+
add_dependencies(app bootloader_check_size)
284+
285+
if(CONFIG_SECURE_BOOT_V2_ENABLED AND CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
286+
# Check the size of the bootloader + signature block.
287+
partition_table_add_check_bootloader_size_target(bootloader_check_size_signed
288+
DEPENDS gen_signed_bootloader
289+
BOOTLOADER_BINARY_PATH "${CMAKE_BINARY_DIR}/${PROJECT_BIN}"
290+
RESULT bootloader_check_size_signed_command)
291+
add_dependencies(app bootloader_check_size_signed)
292+
endif()

components/bootloader_support/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if(esp_tee_build)
2828

2929
idf_component_register(SRCS ${tee_srcs}
3030
INCLUDE_DIRS ${tee_inc_dirs}
31-
PRIV_REQUIRES efuse esp_app_format)
31+
PRIV_REQUIRES efuse esp_app_format esptool_py)
3232
return()
3333
endif()
3434

@@ -72,7 +72,7 @@ endif()
7272
if(BOOTLOADER_BUILD OR CONFIG_APP_BUILD_TYPE_RAM)
7373
set(include_dirs "include" "bootloader_flash/include"
7474
"private_include")
75-
set(priv_requires micro-ecc spi_flash efuse esp_bootloader_format esp_app_format)
75+
set(priv_requires micro-ecc spi_flash efuse esp_bootloader_format esp_app_format esptool_py)
7676
list(APPEND srcs
7777
"src/bootloader_init.c"
7878
"src/bootloader_clock_loader.c"
@@ -89,7 +89,7 @@ else()
8989
set(include_dirs "include" "bootloader_flash/include")
9090
set(priv_include_dirs "private_include")
9191
# heap is required for `heap_memory_layout.h` header
92-
set(priv_requires spi_flash mbedtls efuse heap esp_bootloader_format esp_app_format)
92+
set(priv_requires spi_flash mbedtls efuse heap esp_bootloader_format esp_app_format esptool_py)
9393
endif()
9494

9595
if(BOOTLOADER_BUILD)
@@ -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/driver/test_apps/legacy_i2c_driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(COMPONENTS main esp_pm)
1212
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
1313
project(legacy_i2c_test)
1414

15+
idf_build_get_property(elf EXECUTABLE)
1516
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1617
add_custom_target(check_test_app_sections ALL
1718
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py

components/driver/test_apps/legacy_twai/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(COMPONENTS main)
77
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
88
project(twai_test)
99

10+
idf_build_get_property(elf EXECUTABLE)
1011
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1112
add_custom_target(check_test_app_sections ALL
1213
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py

components/esp_adc/test_apps/adc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(COMPONENTS main)
99
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
1010
project(adc_test)
1111

12+
idf_build_get_property(elf EXECUTABLE)
1213
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1314
add_custom_target(check_test_app_sections ALL
1415
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py

components/esp_driver_ana_cmpr/test_apps/analog_comparator/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(COMPONENTS main)
77
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
88
project(test_ana_cmpr)
99

10+
idf_build_get_property(elf EXECUTABLE)
1011
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1112
add_custom_target(check_test_app_sections ALL
1213
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py

components/esp_driver_dac/test_apps/dac/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(COMPONENTS main)
77
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
88
project(dac_test)
99

10+
idf_build_get_property(elf EXECUTABLE)
1011
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1112
add_custom_target(check_test_app_sections ALL
1213
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py

components/esp_driver_gpio/test_apps/gpio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(COMPONENTS main)
77
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
88
project(gpio_test)
99

10+
idf_build_get_property(elf EXECUTABLE)
1011
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1112
add_custom_target(check_test_app_sections ALL
1213
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py

components/esp_driver_gpio/test_apps/gpio_extensions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(COMPONENTS main)
77
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
88
project(gpio_extension_test)
99

10+
idf_build_get_property(elf EXECUTABLE)
1011
if(CONFIG_COMPILER_DUMP_RTL_FILES)
1112
add_custom_target(check_test_app_sections ALL
1213
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py

0 commit comments

Comments
 (0)