This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 597fc8c93b4176e5f5bbd3aca06ac9d179785745 Author: dechao_gong <[email protected]> AuthorDate: Thu Aug 27 09:34:59 2026 +0800 arch/arm/ameba: fix CMake link for rtl8721f (multi ROM ld) The shared CMake build hardcoded a single ROM symbol linker script (ameba_rom_symbol_acut_s.ld), so a CMake build of rtl8721f failed to link: __rom_bss_start_ns__ / __rom_bss_end_ns__ and the rtw_* WiFi ROM symbols were left undefined. The make build already appends rtl8721f's four ROM symbol scripts (secure + wifi + os + NS) in arch/arm/src/rtl8721f/ameba_board.mk; the CMake path did not. Make the ROM symbol script set per-IC: - ameba_gen_ldscript.sh now takes one or more ROM ld files as trailing arguments and cat's them in order (was a single fixed argument). - ameba_board.cmake keeps the previous single-script default and lets an arch CMakeLists override it via AMEBA_ROM_LDS; the list is resolved to full paths and passed to the generator. - rtl8721f/CMakeLists.txt sets AMEBA_ROM_LDS to its four ROM symbol scripts, matching its ameba_board.mk cat order. rtl8721dx and rtl8720f are unchanged (still the single default script). Verified on rtl8721f: the nsh CMake build now links the nuttx ELF cleanly with no undefined NS-BSS or rtw_* symbols. Signed-off-by: dechao_gong <[email protected]> Assisted-by: Claude <[email protected]> --- arch/arm/src/common/ameba/cmake/ameba_board.cmake | 18 ++++++++++--- .../src/common/ameba/tools/ameba_gen_ldscript.sh | 31 ++++++++++++---------- arch/arm/src/rtl8721f/CMakeLists.txt | 7 +++++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/arch/arm/src/common/ameba/cmake/ameba_board.cmake b/arch/arm/src/common/ameba/cmake/ameba_board.cmake index cb02887ae9a..9d15af42f64 100644 --- a/arch/arm/src/common/ameba/cmake/ameba_board.cmake +++ b/arch/arm/src/common/ameba/cmake/ameba_board.cmake @@ -208,16 +208,28 @@ list(APPEND AMEBA_EXTRA_LIBS ${_crtbegin} ${_crtend} -lm -lstdc++) set(AMEBA_KM4_LD ${AMEBA_KM4_PROJ}/ld) set(AMEBA_IMG2_LD ${AMEBA_KM4_LD}/ameba_img2_all.ld) -set(AMEBA_ROM_LD ${AMEBA_KM4_LD}/ameba_rom_symbol_acut_s.ld) set(GENLDSCRIPT ${AMEBA_PREBUILT}/ld.script.gen) +# ROM symbol linker script(s), appended after the preprocessed image2 script. +# Most ICs (rtl8721dx / rtl8720f) use a single script; rtl8721f overrides +# AMEBA_ROM_LDS in its arch CMakeLists with four scripts (secure + wifi + os + +# NS) so the ROM BSS (__rom_bss_*_ns__) and WiFi ROM (rtw_*) symbols resolve -- +# mirroring that IC's ameba_board.mk cat order. +if(NOT DEFINED AMEBA_ROM_LDS) + set(AMEBA_ROM_LDS ameba_rom_symbol_acut_s.ld) +endif() +set(AMEBA_ROM_LD_PATHS "") +foreach(_ld ${AMEBA_ROM_LDS}) + list(APPEND AMEBA_ROM_LD_PATHS ${AMEBA_KM4_LD}/${_ld}) +endforeach() + message( STATUS "ameba: generating ld.script.gen (AP ${AMEBA_AP_PROJECT} image2)") execute_process( COMMAND sh ${AMEBA_TOOLS_DIR}/ameba_gen_ldscript.sh ${CMAKE_C_COMPILER} - ${AMEBA_IMG2_LD} ${AMEBA_ROM_LD} ${AMEBA_AUTOCONF} ${AMEBA_PREBUILT} - ${AMEBA_AP_PROJECT} ${GENLDSCRIPT} + ${AMEBA_IMG2_LD} ${AMEBA_AUTOCONF} ${AMEBA_PREBUILT} ${AMEBA_AP_PROJECT} + ${GENLDSCRIPT} ${AMEBA_ROM_LD_PATHS} RESULT_VARIABLE _rc) if(NOT _rc EQUAL 0) message(FATAL_ERROR "ameba_gen_ldscript.sh failed (rc=${_rc})") diff --git a/arch/arm/src/common/ameba/tools/ameba_gen_ldscript.sh b/arch/arm/src/common/ameba/tools/ameba_gen_ldscript.sh index d65d571aa6f..b25c8332872 100755 --- a/arch/arm/src/common/ameba/tools/ameba_gen_ldscript.sh +++ b/arch/arm/src/common/ameba/tools/ameba_gen_ldscript.sh @@ -10,15 +10,17 @@ # 1. C-preprocess ameba_img2_all.ld (it #includes ameba_layout.ld and the # config-derived platform_autoconf.h, staged as # project_<proj>/platform_autoconf.h on the include path). -# 2. Append ameba_rom_symbol_acut_s.ld (ROM symbol addresses). +# 2. Append the ROM symbol linker script(s) (ROM symbol addresses). Most +# ICs pass a single script; rtl8721f passes four scripts (secure + wifi + +# os + NS), matching the make build's cat. # 3. Fold NuttX's .vectors orphan section into the loadable SRAM data region # so the large power-of-two aligned vector table does not land in and # overflow the tiny fixed KM4_IMG2_ENTRY region. # # This reproduces the SDK-generated rlx8721d.ld; the SDK tree stays read-only. # -# Usage: ameba_gen_ldscript.sh <cc> <img2_ld> <rom_ld> <autoconf> \ -# <prebuilt_dir> <ap_project> <out> +# Usage: ameba_gen_ldscript.sh <cc> <img2_ld> <autoconf> <prebuilt_dir> \ +# <ap_project> <out> <rom_ld>... # # SPDX-License-Identifier: Apache-2.0 # @@ -43,16 +45,17 @@ set -e CC="$1" IMG2_LD="$2" -ROM_LD="$3" -AUTOCONF="$4" -PREBUILT="$5" -AP_PROJECT="$6" -OUT="$7" +AUTOCONF="$3" +PREBUILT="$4" +AP_PROJECT="$5" +OUT="$6" +shift 6 +ROM_LDS="$@" -if [ -z "$CC" ] || [ -z "$IMG2_LD" ] || [ -z "$ROM_LD" ] || [ -z "$AUTOCONF" ] \ - || [ -z "$PREBUILT" ] || [ -z "$AP_PROJECT" ] || [ -z "$OUT" ]; then - echo "usage: ameba_gen_ldscript.sh <cc> <img2_ld> <rom_ld> <autoconf>" \ - "<prebuilt_dir> <ap_project> <out>" >&2 +if [ -z "$CC" ] || [ -z "$IMG2_LD" ] || [ -z "$AUTOCONF" ] || [ -z "$PREBUILT" ] \ + || [ -z "$AP_PROJECT" ] || [ -z "$OUT" ] || [ -z "$ROM_LDS" ]; then + echo "usage: ameba_gen_ldscript.sh <cc> <img2_ld> <autoconf> <prebuilt_dir>" \ + "<ap_project> <out> <rom_ld>..." >&2 exit 1 fi @@ -61,9 +64,9 @@ fi mkdir -p "$PREBUILT/project_$AP_PROJECT" cp "$AUTOCONF" "$PREBUILT/project_$AP_PROJECT/platform_autoconf.h" -# 1) preprocess, 2) append ROM symbols +# 1) preprocess, 2) append ROM symbol script(s), in the given order "$CC" -E -P -xc -c "$IMG2_LD" -o "$OUT" -I "$PREBUILT" -cat "$ROM_LD" >> "$OUT" +cat $ROM_LDS >> "$OUT" # 3) fold NuttX .vectors into the loadable SRAM data region sed -i 's|^\([[:space:]]*\)\*(\.data\*)|\1*(.vectors*)\n\1*(.data*)|' "$OUT" diff --git a/arch/arm/src/rtl8721f/CMakeLists.txt b/arch/arm/src/rtl8721f/CMakeLists.txt index b6a03913440..a827f0553f9 100644 --- a/arch/arm/src/rtl8721f/CMakeLists.txt +++ b/arch/arm/src/rtl8721f/CMakeLists.txt @@ -90,6 +90,13 @@ set(AMEBA_NP_TARGET km4ns) set(AMEBA_CFG_WIFI ${CONFIG_RTL8721F_WIFI}) set(AMEBA_CFG_FLASHFS ${CONFIG_RTL8721F_FLASH_FS}) +# rtl8721f's combined image2 linker script must append four ROM symbol scripts +# (secure + wifi + os + NS), in this order, to match +# arch/arm/src/rtl8721f/ameba_board.mk. ameba_board.cmake consumes this; the +# other ICs leave it unset and default to the single script. +set(AMEBA_ROM_LDS ameba_rom_symbol_bcut_s.ld ameba_rom_symbol_bcut_wifi.ld + ameba_rom_symbol_bcut_os.ld ameba_rom_symbol_bcut.ld) + # Resolve AMEBA_SDK / asdk toolchain (provisioned by `. tools/ameba/env.sh`) # before the SDK-relative source lists below reference it. include(${AMEBA_COMMON}/cmake/ameba_sdk.cmake)
