From 3515724f9a74e9b9cc7e113ebe3480068cab8ffc Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 23:57:31 +0700 Subject: [PATCH] bootrom: give phase2 .data its own RW segment instead of an RWX one .data shared the bootphase2 output section with the RAM-executed code, so the PM5 bootrom linked with "LOAD segment with RWX permissions" (CMake silenced it with --no-warn-rwx-segments). Put .data in .bootphase2_data with its own PT_LOAD, placed right after .bootphase2 in RAM and flash so the existing copy loop still covers it; asserts guard the contiguity. Same image size on RDV4/PM5/PM5+BWM; code identical bar .ramfunc moving ahead of .data, data bytes unchanged. Co-Authored-By: Claude Opus 5.5 --- bootrom/CMakeLists.txt | 3 --- bootrom/ldscript-flash-common | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bootrom/CMakeLists.txt b/bootrom/CMakeLists.txt index 851da02b5..8c5976213 100644 --- a/bootrom/CMakeLists.txt +++ b/bootrom/CMakeLists.txt @@ -98,9 +98,6 @@ if (PM5) set(LIBS ${LIBS} pm5_at32_armlib) endif () -# Fix: warning: bootrom\bootrom.elf has a LOAD segment with RWX permissions -set(CROSS_LDFLAGS ${CROSS_LDFLAGS} -Wl,--no-warn-rwx-segments) - # Create version_pm3.c before bootrom build. add_custom_command( OUTPUT ${VERSION_PM3_C} diff --git a/bootrom/ldscript-flash-common b/bootrom/ldscript-flash-common index 23ad383a9..a3caed6f6 100644 --- a/bootrom/ldscript-flash-common +++ b/bootrom/ldscript-flash-common @@ -23,6 +23,7 @@ PHDRS { phase1 PT_LOAD; phase2 PT_LOAD; + phase2data PT_LOAD; bss PT_LOAD; } @@ -49,15 +50,23 @@ SECTIONS *(.glue_7t) *(.rodata) *(.rodata.*) - *(.data) - *(.data.*) *(.ramfunc) . = ALIGN(4); } >ram AT>bootphase2 :phase2 + /* own RW segment, else phase2 is RWX; copied together with .bootphase2 */ + .bootphase2_data : { + *(.data) + *(.data.*) + . = ALIGN(4); + } >ram AT>bootphase2 :phase2data + __bootphase2_src_start__ = LOADADDR(.bootphase2); __bootphase2_start__ = ADDR(.bootphase2); - __bootphase2_end__ = __bootphase2_start__ + SIZEOF(.bootphase2); + __bootphase2_end__ = ADDR(.bootphase2_data) + SIZEOF(.bootphase2_data); + + ASSERT(ADDR(.bootphase2_data) == __bootphase2_start__ + SIZEOF(.bootphase2), "bootphase2 data not contiguous in RAM") + ASSERT(LOADADDR(.bootphase2_data) == __bootphase2_src_start__ + SIZEOF(.bootphase2), "bootphase2 data not contiguous in flash") .bss : { __bss_start__ = .;