# CMake script to patch sections.ld file # This script adds 64KB alignment after .flash.appdesc section string(REPLACE "\\" "/" CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}") set(SECTIONS_LD "${CMAKE_BINARY_DIR}/esp-idf/esp_system/ld/sections.ld") if(EXISTS ${SECTIONS_LD}) file(READ ${SECTIONS_LD} CONTENT) # 检查是否已经应用了修复 if(NOT CONTENT MATCHES "Rust segment overlap fix") # 查找 .flash.appdesc 段的结束 string(FIND "${CONTENT}" ".flash.appdesc" APPDESC_POS) if(APPDESC_POS GREATER -1) # 查找 .flash.appdesc 段的结束 string(FIND "${CONTENT}" "} >default_rodata_seg" APPDESC_END_POS ${APPDESC_POS}) if(APPDESC_END_POS GREATER -1) # 计算插入位置 math(EXPR INSERT_POS "${APPDESC_END_POS} + 20") # 在 .flash.appdesc 段结束后添加 64KB 对齐 string(SUBSTRING "${CONTENT}" 0 ${INSERT_POS} CONTENT_HEAD) string(SUBSTRING "${CONTENT}" ${INSERT_POS} -1 CONTENT_TAIL) set(NEW_CONTENT "${CONTENT_HEAD} /* Rust segment overlap fix */ . = ALIGN(0x10000); ${CONTENT_TAIL}") file(WRITE ${SECTIONS_LD} "${NEW_CONTENT}") message(STATUS "Applied segment overlap fix: added 64KB alignment after appdesc") else() message(WARNING "Could not find .flash.appdesc section end") endif() else() message(WARNING "Could not find .flash.appdesc section") endif() else() message(STATUS "Segment overlap fix already applied") endif() else() message(WARNING "sections.ld not found at ${SECTIONS_LD}") endif()