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 )