refactor(build-system): Simplify flash target creation

This commit refactors the flash target creation. Now bootloader and
partition table components add dependencies to the flash target directly
from their component CMakeLists.txt files instead of it being done in
the esptool_py component. The commit also removes the redundant
__esptool_py_setup_main_flash_target() function.
This commit is contained in:
Sudeep Mohanty
2025-09-09 12:21:31 +02:00
parent aae5071dff
commit b719292b75
4 changed files with 13 additions and 37 deletions

View File

@@ -32,4 +32,7 @@ if(NOT CONFIG_SECURE_BOOT OR CONFIG_SECURE_BOOT_FLASH_BOOTLOADER_DEFAULT)
esptool_py_flash_target_image(flash bootloader esptool_py_flash_target_image(flash bootloader
${CONFIG_BOOTLOADER_OFFSET_IN_FLASH} ${CONFIG_BOOTLOADER_OFFSET_IN_FLASH}
"${BOOTLOADER_BUILD_DIR}/bootloader.bin") "${BOOTLOADER_BUILD_DIR}/bootloader.bin")
# Add bootloader as a dependency to the flash target
add_dependencies(flash bootloader)
endif() endif()

View File

@@ -745,39 +745,6 @@ function(__esptool_py_setup_utility_targets)
) )
endfunction() endfunction()
# __esptool_py_setup_main_flash_target
#
# @brief Sets up the main `flash` target and its dependencies.
#
# This function creates the main `flash` target, which is used to flash multiple
# images to the target device. It determines the dependencies for a full
# project flash (bootloader, partition table, the main app) and then calls
#
function(__esptool_py_setup_main_flash_target)
__ensure_esptool_py_setup()
idf_build_get_property(non_os_build NON_OS_BUILD)
if(NOT non_os_build)
set(flash_deps "")
if(CONFIG_APP_BUILD_TYPE_APP_2NDBOOT)
list(APPEND flash_deps "partition_table_bin")
endif()
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
list(APPEND flash_deps "app")
endif()
if(CONFIG_APP_BUILD_BOOTLOADER)
list(APPEND flash_deps "bootloader")
endif()
# Create the flash target. If encryption is enabled, it will also create
# an encrypted-flash target.
esptool_py_custom_target(flash project "${flash_deps}" FILENAME_PREFIX "flash")
endif()
endfunction()
# Adds espefuse functions for global use # Adds espefuse functions for global use
idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR) idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)

View File

@@ -174,5 +174,8 @@ if(CONFIG_APP_BUILD_GENERATE_BINARIES AND CONFIG_APP_BUILD_TYPE_APP_2NDBOOT)
"${build_dir}/partition_table/${final_partition_bin}") "${build_dir}/partition_table/${final_partition_bin}")
esptool_py_flash_target_image(flash partition-table "${PARTITION_TABLE_OFFSET}" esptool_py_flash_target_image(flash partition-table "${PARTITION_TABLE_OFFSET}"
"${build_dir}/partition_table/${final_partition_bin}") "${build_dir}/partition_table/${final_partition_bin}")
# Add partition table as a dependency to the flash target
add_dependencies(flash partition_table_bin)
add_deprecated_target_alias(partition_table-flash partition-table-flash) add_deprecated_target_alias(partition_table-flash partition-table-flash)
endif() endif()

View File

@@ -11,13 +11,16 @@ function(__idf_build_setup_flash_targets)
idf_build_get_property(build_dir BUILD_DIR) idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(project_bin PROJECT_BIN) idf_build_get_property(project_bin PROJECT_BIN)
partition_table_get_partition_info(app_partition_offset "--partition-boot-default" "offset") partition_table_get_partition_info(app_partition_offset "--partition-boot-default" "offset")
# Create app-flash target for flashing just the application
esptool_py_custom_target(app-flash app "app") esptool_py_custom_target(app-flash app "app")
esptool_py_flash_target_image(app-flash app "${app_partition_offset}" "${build_dir}/${project_bin}") esptool_py_flash_target_image(app-flash app "${app_partition_offset}" "${build_dir}/${project_bin}")
esptool_py_flash_target_image(flash app "${app_partition_offset}" "${build_dir}/${project_bin}")
# Setup the main flash target and dependencies # Create main flash target for flashing the entire system (bootloader + partition table + app)
__esptool_py_setup_main_flash_target() # Note: Bootloader and partition table components add their own dependencies to this flash target
# in their respective CMakeLists.txt files
esptool_py_custom_target(flash project "app" FILENAME_PREFIX "flash")
esptool_py_flash_target_image(flash app "${app_partition_offset}" "${build_dir}/${project_bin}")
# Generate flasher_args.json configuration files # Generate flasher_args.json configuration files
__idf_build_generate_flasher_args() __idf_build_generate_flasher_args()