From ca3974c937e88a2c6a27674ad79f66c8202f7b0d Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Mon, 24 Nov 2025 14:58:02 +0100 Subject: [PATCH] feat(cmakev2/ldgen): provide ldgen with a list of mutable libraries The build system keeps track of each component source. Currently there are four types of sources: 1. "project_components" - project components 2. "project_extra_components" - components from EXTRA_COMPONENT_DIRS 3. "project_managed_components" - custom project dependencies managed by the IDF Component Manager 4. "idf_components" - ESP-IDF built-in components, typically under /components This can be used to identify the component libraries that are likely to change during application development and pass them to ldgen as mutable libraries. Add all components with "project_components" as their source as mutable. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/build.cmake | 23 +++++++++++++++++++++++ tools/cmakev2/ldgen.cmake | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index fe0088ab12..c6df26c8c0 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -364,6 +364,29 @@ function(idf_build_library library) idf_library_set_property("${library}" __LDGEN_FRAGMENT_FILES "${ldfragments}" APPEND) endforeach() + # Collect the filenames of project component archives, which are considered + # mutable, in the __LDGEN_MUTABLE_LIBS library property. These libraries + # are placed by ldgen into a separate location in the linker script, + # enabling the fast reflashing feature. + foreach(component_interface IN LISTS component_interfaces_linked) + idf_component_get_property(component_source "${component_interface}" COMPONENT_SOURCE) + idf_component_get_property(component_target "${component_interface}" COMPONENT_TARGET) + idf_component_get_property(component_type "${component_interface}" COMPONENT_TYPE) + + if("${component_type}" STREQUAL "CONFIG_ONLY") + # Configuration only component interface target without a library. + continue() + endif() + + if(NOT "${component_source}" STREQUAL "project_components") + # Add only project components as mutable. + continue() + endif() + + idf_library_set_property("${library}" __LDGEN_MUTABLE_LIBS + "$" APPEND) + endforeach() + # Collect archive files from all targets linked to the library interface # and store them in the __LDGEN_DEPENDS and __LDGEN_LIBRARIES library # properties. These properties are used by ldgen to generate linker scripts diff --git a/tools/cmakev2/ldgen.cmake b/tools/cmakev2/ldgen.cmake index 4e30ce5b13..e6959a20a2 100644 --- a/tools/cmakev2/ldgen.cmake +++ b/tools/cmakev2/ldgen.cmake @@ -83,6 +83,17 @@ function(__ldgen_process_template) idf_msg("Mapping check enabled in ldgen") endif() + if(CONFIG_ESPTOOLPY_FAST_REFLASHING) + # 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) + set(mutable_libs_path "${build_dir}/ldgen_mutable_libraries${ARG_SUFFIX}") + list(JOIN ldgen_mutable_libs "\n" ldgen_mutable_libs_str) + file(GENERATE OUTPUT "${mutable_libs_path}" + CONTENT "${ldgen_mutable_libs_str}") + set(mutable_libs_option "--mutable-libraries-file" "${mutable_libs_path}") + endif() + add_custom_command( OUTPUT "${ARG_OUTPUT}" COMMAND ${python} "${idf_path}/tools/ldgen/ldgen.py" @@ -96,6 +107,7 @@ function(__ldgen_process_template) --libraries-file "${build_dir}/ldgen_libraries${ARG_SUFFIX}" --objdump "${CMAKE_OBJDUMP}" ${ldgen_check} + ${mutable_libs_option} DEPENDS ${ARG_TEMPLATE} ${ldgen_fragment_files} ${ldgen_depends} ${sdkconfig} VERBATIM )