Files
JoyD/ESP32/my_usb_project/fix_linker_script.cmake
2026-04-01 11:39:33 +08:00

25 lines
1.0 KiB
CMake

# CMake script to fix linker script after build
# This script modifies sections.ld to add 64KB alignment for both appdesc and rodata
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)
# Check if the appdesc 64KB alignment fix is already applied
if(NOT CONTENT MATCHES "\\.flash\\.appdesc.*\\}.*default_rodata_seg.*\\n.*\\. = ALIGN\\(0x10000\\)")
# Add 64KB alignment after .flash.appdesc section ends
string(REGEX REPLACE
"(\\*\\(\\.rodata_custom_desc.*\\.\\*\\).*\\} >default_rodata_seg)"
"\\1\n . = ALIGN(0x10000);"
NEW_CONTENT "${CONTENT}")
file(WRITE ${SECTIONS_LD} "${NEW_CONTENT}")
message(STATUS "Applied linker script fix: added 64KB alignment after appdesc")
else()
message(STATUS "Linker script fix already applied")
endif()
else()
message(WARNING "sections.ld not found at ${SECTIONS_LD}")
endif()