From b719292b75ace52bfb88a916a1180954da51c3f6 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Tue, 9 Sep 2025 12:21:31 +0200 Subject: [PATCH] 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. --- components/bootloader/CMakeLists.txt | 3 ++ components/esptool_py/project_include.cmake | 33 --------------------- components/partition_table/CMakeLists.txt | 3 ++ tools/cmake/flash_targets.cmake | 11 ++++--- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/components/bootloader/CMakeLists.txt b/components/bootloader/CMakeLists.txt index b8135bb25c..8ebd8e9051 100644 --- a/components/bootloader/CMakeLists.txt +++ b/components/bootloader/CMakeLists.txt @@ -32,4 +32,7 @@ if(NOT CONFIG_SECURE_BOOT OR CONFIG_SECURE_BOOT_FLASH_BOOTLOADER_DEFAULT) esptool_py_flash_target_image(flash bootloader ${CONFIG_BOOTLOADER_OFFSET_IN_FLASH} "${BOOTLOADER_BUILD_DIR}/bootloader.bin") + + # Add bootloader as a dependency to the flash target + add_dependencies(flash bootloader) endif() diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index 1dc57cf960..7110dacf37 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -745,39 +745,6 @@ function(__esptool_py_setup_utility_targets) ) 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 idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR) diff --git a/components/partition_table/CMakeLists.txt b/components/partition_table/CMakeLists.txt index d6b296b497..be94b4e011 100644 --- a/components/partition_table/CMakeLists.txt +++ b/components/partition_table/CMakeLists.txt @@ -174,5 +174,8 @@ if(CONFIG_APP_BUILD_GENERATE_BINARIES AND CONFIG_APP_BUILD_TYPE_APP_2NDBOOT) "${build_dir}/partition_table/${final_partition_bin}") esptool_py_flash_target_image(flash partition-table "${PARTITION_TABLE_OFFSET}" "${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) endif() diff --git a/tools/cmake/flash_targets.cmake b/tools/cmake/flash_targets.cmake index 9856bf7d3d..942a5bf671 100644 --- a/tools/cmake/flash_targets.cmake +++ b/tools/cmake/flash_targets.cmake @@ -11,13 +11,16 @@ function(__idf_build_setup_flash_targets) idf_build_get_property(build_dir BUILD_DIR) idf_build_get_property(project_bin PROJECT_BIN) 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_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 - __esptool_py_setup_main_flash_target() + # Create main flash target for flashing the entire system (bootloader + partition table + app) + # 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 __idf_build_generate_flasher_args()