From c62515671d1816dd63d2c0a56ad77f875e7758eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radim=20Karni=C5=A1?= Date: Fri, 27 Feb 2026 10:44:02 +0100 Subject: [PATCH] change(build): Rename Fast reflashing configuration to Minimize binary changes, make non-experimental --- Kconfig | 69 ++++++++++++++++++++++- components/esp_system/ld/ld.common | 18 +++--- components/esp_system/ld/ld.dram.sections | 2 +- components/esptool_py/Kconfig.projbuild | 60 -------------------- tools/cmake/ldgen.cmake | 2 +- tools/cmakev2/ldgen.cmake | 2 +- 6 files changed, 79 insertions(+), 74 deletions(-) diff --git a/Kconfig b/Kconfig index a4c2de5aa95..f5638adad96 100644 --- a/Kconfig +++ b/Kconfig @@ -276,6 +276,72 @@ mainmenu "Espressif IoT Development Framework Configuration" config APP_BUILD_USE_FLASH_SECTIONS bool # Whether to place code/data into memory-mapped flash sections + menu "Minimize binary changes between builds" + depends on APP_BUILD_TYPE_APP_2NDBOOT + + config APP_BUILD_MINIMIZE_BINARY_CHANGES + bool "Minimize binary changes between builds" + select COMPILER_NO_MERGE_CONSTANTS if IDF_TOOLCHAIN_GCC + help + Optimize the application binary so that "idf.py flash" can + flash only the data sectors that changed. Fast reflashing works + without this option, enabling it improves reflash effectiveness + by reducing the amount of data written on each reflash. + + Enabling this option classifies component libraries into two + categories: mutable and immutable. Mutable libraries are + expected to change frequently during development, while + immutable libraries are considered stable. All project + component libraries are treated as mutable; all other libraries + are treated as immutable. + + In the generated linker script, input sections from immutable + libraries are placed before those from mutable libraries. This + layout helps localize changes in the output sections of the ELF + file, so that recompilation primarily affects a confined area + associated with the mutable libraries. + + To support this, some compiler optimizations, such as constant + merging, are disabled, which helps minimize differences in the + binary image between builds. However, this may increase the + overall image size and flash usage. + + Additionally, this option inserts a padding, defined by the + APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING option, after the input + sections of mutable libraries. This allows further isolation of + changes but also increases the size of the binary image and + flash consumption. + + This option is primarily intended for development. It increases + binary size and disables optimizations; it is not recommended + for production builds. + + choice APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_SIZE + prompt "Padding size" + default APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_4KB + depends on APP_BUILD_MINIMIZE_BINARY_CHANGES + help + Selects the amount of padding (in kilobytes) to add after input + sections of mutable libraries when "Minimize binary changes + between builds" is enabled. + + config APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_2KB + bool "2 KB" + config APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_4KB + bool "4 KB" + config APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_8KB + bool "8 KB" + endchoice + + config APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING + int + depends on APP_BUILD_MINIMIZE_BINARY_CHANGES + default 2048 if APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_2KB + default 4096 if APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_4KB + default 8192 if APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING_8KB + + endmenu # Minimize binary changes between builds + config APP_REPRODUCIBLE_BUILD bool "Enable reproducible build" default n @@ -575,7 +641,7 @@ mainmenu "Espressif IoT Development Framework Configuration" bool depends on IDF_TOOLCHAIN_GCC depends on IDF_TARGET_ARCH_XTENSA - default y if ESPTOOLPY_FAST_REFLASHING + default y if APP_BUILD_MINIMIZE_BINARY_CHANGES help Intersperse Xtensa literals within the text section to keep them as close as possible to their references. This prevents @@ -790,4 +856,3 @@ mainmenu "Espressif IoT Development Framework Configuration" - CONFIG_ESP_WIFI_ENABLE_ROAMING_APP - CONFIG_USB_HOST_EXT_PORT_RESET_ATTEMPTS - CONFIG_GDMA_ENABLE_WEIGHTED_ARBITRATION - - CONFIG_ESPTOOLPY_FAST_REFLASHING diff --git a/components/esp_system/ld/ld.common b/components/esp_system/ld/ld.common index b624c4a365e..8b25103935c 100644 --- a/components/esp_system/ld/ld.common +++ b/components/esp_system/ld/ld.common @@ -116,23 +116,23 @@ ASSERT((ADDR(NEXT_SECTION) == ADDR(PREV_SECTION) + SIZEOF(PREV_SECTION)), \ #endif /* - * FAST_REFLASHING_PADDING + * APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING * - * Aligns the current location (.) to CONFIG_ESPTOOLPY_FAST_REFLASHING_PADDING. + * Aligns the current location (.) to CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING. * If more than half of the alignment block is already consumed, * extra padding is applied to skip to the next boundary. * For example, if the current location (.) is 0x1900 and the padding is 4 KB, * the location will be moved to 0x3000 instead of 0x2000 because less than * half of the current 4 KB block remains (0x2000 - 0x1900 < 2 KB). */ -#if CONFIG_ESPTOOLPY_FAST_REFLASHING -#define FAST_REFLASHING_PADDING() \ +#if CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES +#define APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING() \ . = ALIGN((. + ( \ - (CONFIG_ESPTOOLPY_FAST_REFLASHING_PADDING - (ALIGN(CONFIG_ESPTOOLPY_FAST_REFLASHING_PADDING) - .)) + \ - (CONFIG_ESPTOOLPY_FAST_REFLASHING_PADDING / 2) \ - )), CONFIG_ESPTOOLPY_FAST_REFLASHING_PADDING); + (CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING - (ALIGN(CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING) - .)) + \ + (CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING / 2) \ + )), CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING); #else -#define FAST_REFLASHING_PADDING() +#define APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING() #endif #if CONFIG_LIBC_PICOLIBC @@ -153,4 +153,4 @@ ASSERT((ADDR(NEXT_SECTION) == ADDR(PREV_SECTION) + SIZEOF(PREV_SECTION)), \ #define SECTION_MAPPINGS_WITH_PADDING(SECTION_NAME) \ \n SECTION_MAPPINGS(SECTION_NAME) \ -\n FAST_REFLASHING_PADDING() +\n APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING() diff --git a/components/esp_system/ld/ld.dram.sections b/components/esp_system/ld/ld.dram.sections index a2e6796b28e..1a14460deda 100644 --- a/components/esp_system/ld/ld.dram.sections +++ b/components/esp_system/ld/ld.dram.sections @@ -95,7 +95,7 @@ mapping[dram0_data] mutable[dram0_data] - FAST_REFLASHING_PADDING(); + APP_BUILD_MINIMIZE_BINARY_CHANGES_PADDING(); _data_end_high = ABSOLUTE(.); } > dram_high_seg diff --git a/components/esptool_py/Kconfig.projbuild b/components/esptool_py/Kconfig.projbuild index de77430213e..2df271b95f0 100644 --- a/components/esptool_py/Kconfig.projbuild +++ b/components/esptool_py/Kconfig.projbuild @@ -214,64 +214,4 @@ menu "Serial flasher config" default ESP_CONSOLE_UART_BAUDRATE if ESP_CONSOLE_UART default 115200 if !ESP_CONSOLE_UART - menu "Fast Reflashing" - - config ESPTOOLPY_FAST_REFLASHING - bool "Enable fast reflashing (Experimental)" - depends on IDF_EXPERIMENTAL_FEATURES - select COMPILER_NO_MERGE_CONSTANTS if IDF_TOOLCHAIN_GCC - help - Enabling this option classifies component libraries into two - categories: mutable and immutable. Mutable libraries are - expected to change frequently during development, while - immutable libraries are considered stable. All project - component libraries are treated as mutable; all other libraries - are treated as immutable. - - In the generated linker script, input sections from immutable - libraries are placed before those from mutable libraries. This - layout helps localize changes in the output sections of the ELF - file, so that recompilation primarily affects a confined area - associated with the mutable libraries. - - This enables the generation of binary images with large - unmodified regions across recompilations, allowing to flash - only the parts that have changed. - - To support this, some compiler optimizations, such as constant - merging, are disabled, which helps minimize differences in the - binary image between builds. However, this may increase the - overall image size and flash usage. - - Additionally, this option inserts a padding, defined by the - ESPTOOLPY_FAST_REFLASHING_PADDING option, after the input - sections of mutable libraries. This allows further isolate - changes but also increases the size of the binary image and - flash consumption. - - choice ESPTOOLPY_FAST_REFLASHING_PADDING_SIZE - prompt "Padding size" - default ESPTOOLPY_FAST_REFLASHING_PADDING_4KB - depends on ESPTOOLPY_FAST_REFLASHING - help - Selects the amount of padding (in kilobytes) to add after input - sections of mutable libraries when fast reflashing is enabled. - - config ESPTOOLPY_FAST_REFLASHING_PADDING_2KB - bool "2 KB" - config ESPTOOLPY_FAST_REFLASHING_PADDING_4KB - bool "4 KB" - config ESPTOOLPY_FAST_REFLASHING_PADDING_8KB - bool "8 KB" - endchoice - - config ESPTOOLPY_FAST_REFLASHING_PADDING - int - depends on ESPTOOLPY_FAST_REFLASHING - default 2048 if ESPTOOLPY_FAST_REFLASHING_PADDING_2KB - default 4096 if ESPTOOLPY_FAST_REFLASHING_PADDING_4KB - default 8192 if ESPTOOLPY_FAST_REFLASHING_PADDING_8KB - - endmenu - endmenu diff --git a/tools/cmake/ldgen.cmake b/tools/cmake/ldgen.cmake index 0b0b5b6a929..2bfda233672 100644 --- a/tools/cmake/ldgen.cmake +++ b/tools/cmake/ldgen.cmake @@ -203,7 +203,7 @@ function(__ldgen_create_target exe_target) message(STATUS "Mapping check enabled in ldgen") endif() - if(CONFIG_ESPTOOLPY_FAST_REFLASHING) + if(CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES) # Create a file containing a list of mutable libraries used by ldgen # for fast reflashing. set(mutable_libs_path "${build_dir}/ldgen_mutable_libraries") diff --git a/tools/cmakev2/ldgen.cmake b/tools/cmakev2/ldgen.cmake index e6959a20a28..0212fc464e9 100644 --- a/tools/cmakev2/ldgen.cmake +++ b/tools/cmakev2/ldgen.cmake @@ -83,7 +83,7 @@ function(__ldgen_process_template) idf_msg("Mapping check enabled in ldgen") endif() - if(CONFIG_ESPTOOLPY_FAST_REFLASHING) + if(CONFIG_APP_BUILD_MINIMIZE_BINARY_CHANGES) # Create a file containing a list of mutable libraries used by ldgen # for fast reflashing. idf_library_get_property(ldgen_mutable_libs "${ARG_LIBRARY}" __LDGEN_MUTABLE_LIBS)