Skip to content

arch/arm/ameba: add CMake build support for RTL8721Dx and RTL8720F#19463

Merged
acassis merged 4 commits into
apache:masterfrom
Ameba-AIoT:cmake-upstream
Jul 17, 2026
Merged

arch/arm/ameba: add CMake build support for RTL8721Dx and RTL8720F#19463
acassis merged 4 commits into
apache:masterfrom
Ameba-AIoT:cmake-upstream

Conversation

@raulcxw

@raulcxw raulcxw commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Both Realtek Ameba boards (pke8721daf / RTL8721Dx and rtl8720f_evb /
RTL8720F) previously built only via the make build; their board
CMakeLists.txt fell back to a FATAL_ERROR. This wires up the full
vendor-SDK machinery for CMake so cmake --build produces the same flashable
nuttx.bin as make, with no change to any shared/arch-common CMake file
(arch/arm/src/cmake/* untouched).

  • tools/ameba/env.sh — source once before cmake
    (. tools/ameba/env.sh <board>). It resolves/auto-fetches the ameba-rtos
    SDK and the SDK-pinned asdk toolchain (reusing the same helper scripts the
    make build already uses) and puts the toolchain on PATH, so CMake's normal
    compiler probe finds it — like every other NuttX board. No per-chip hook is
    added to the shared arch Toolchain.cmake.
  • common/ameba/cmake/{ameba_sdk,ameba_board}.cmake — the shared mechanism:
    SDK resolve + compiler/version guard, autoconf generation, libameba_fwlib.a
    / libameba_wifi.a built with the isolated SDK include set, the image2 linker
    script + link flags, nuttx.bin packaging and the flash target. Per-IC
    inputs are set by each arch chip CMakeLists.txt.
  • common/ameba/tools/{ameba_gen_ldscript,ameba_package,ameba_flash}.sh
    shared shell steps used by both the make and cmake paths so the two produce
    identical output; tools/ameba/Config.mk flashes via ameba_flash.sh too.
  • Per-IC asdk toolchain resolution (ameba_asdk_version.sh) — each IC pins
    its asdk version in the SDK (RTL8720F -> 12.3.1, RTL8721Dx -> 10.3.1). make
    and cmake now build the NuttX objects with the version the IC pins, matching
    the SDK archives they link against. A configure-time guard fails with a
    fix-it message if a stale environment puts the wrong compiler on PATH.
    (Supersedes and includes arch/arm/ameba: fix per-IC asdk toolchain selection and fwlib archive hygiene #19352.)
  • fwlib/wifi archive hygiene — the archives are packed from an explicit
    object list instead of a *.o glob, so a stale object from a previous
    configuration can no longer be pulled into the image.
  • CONFIG_SCHED_WAITPID enabled in both nsh defconfigs so foreground
    builtins (e.g. wapi) run synchronously with a correct exit status.
  • Docs — each chip page documents the SDK + toolchain (auto-fetched: by make
    on first build, by env.sh for cmake) and a Building and Flashing section
    with With make / With CMake subsections; build-time config options are
    shared, only the menuconfig entry point differs.

Impact

  • New: CMake build for both Ameba boards. The make build is unchanged —
    sourcing env.sh is optional for make, required for cmake.
  • No change to any shared/arch-common file (arch/arm/src/cmake/* untouched).

Testing

  • Both boards build, flash and boot with Wi-Fi over both the make and cmake
    paths (hardware verified: NSH + ifup wlan0 + WPA2).
  • Fork CI on top of current apache/master, all green: fresh-VM matrix
    (make + cmake x 2 boards), plus single-runner ops jobs that exercise the
    kconfig backend (olddefconfig / savedefconfig), switching boards both
    ways
    across the per-IC asdk boundary (10.3.1 <-> 12.3.1), make distclean,
    and the abnormal cases (stale / absent env.sh caught by the guards; a board
    switch without make distclean refused).
CMake build — pke8721daf:nsh (RTL8721Dx, asdk 10.3.1)
$ . tools/ameba/env.sh pke8721daf
Fetching asdk toolchain asdk-10.3.1-4602 (one-time) into ~/rtk-toolchain ...
  installed asdk-10.3.1-4602
$ cmake -B build -DBOARD_CONFIG=pke8721daf:nsh -GNinja
--   Board:  pke8721daf
--   Config: nsh
-- Found assembler: ~/rtk-toolchain/asdk-10.3.1-4602/linux/newlib/bin/arm-none-eabi-gcc
$ cmake --build build
[1458/1460] Linking C executable nuttx
PACK: wrote build/nuttx.bin
-rw-r--r-- 1 root root  742176 build/nuttx.bin
CMake build — rtl8720f_evb:nsh (RTL8720F, asdk 12.3.1)
$ . tools/ameba/env.sh rtl8720f_evb
Fetching asdk toolchain asdk-12.3.1-4600 (one-time) into ~/rtk-toolchain ...
  installed asdk-12.3.1-4600
$ cmake -B build -DBOARD_CONFIG=rtl8720f_evb:nsh -GNinja
--   Board:  rtl8720f_evb
--   Config: nsh
-- Found assembler: ~/rtk-toolchain/asdk-12.3.1-4600/linux/newlib/bin/arm-none-eabi-gcc
$ cmake --build build
[1458/1460] Linking C executable nuttx
PACK: wrote build/nuttx.bin
-rw-r--r-- 1 root root  693920 build/nuttx.bin

raulcxw added 4 commits July 17, 2026 16:05
Both Ameba WHC boards (pke8721daf, rtl8720f_evb) previously built only via the
make build; the board CMakeLists fell back to a FATAL_ERROR.  Wire up the full
vendor-SDK machinery for CMake so `cmake --build` produces the same flashable
nuttx.bin as make, with no change to any shared/arch-common file:

  - tools/ameba/env.sh: source it once before cmake.  It resolves/auto-fetches
    the ameba-rtos SDK + its pinned asdk toolchain (reusing the same helper
    scripts the make build uses) and puts the toolchain on PATH, so cmake's
    normal compiler probe finds it -- exactly like every other NuttX board's
    toolchain.  No per-chip hook is added to the shared arch Toolchain.cmake.
  - common/ameba/cmake/ameba_sdk.cmake: resolve AMEBA_SDK + asdk dir from that
    environment (fall back to the in-tree checkout) and sanity-check the
    compiler; included by each arch chip CMakeLists before its SDK-relative
    source lists.
  - common/ameba/cmake/ameba_board.cmake: the shared mechanism -- autoconf,
    libameba_fwlib.a / libameba_wifi.a compiled with the isolated SDK include
    set, the image2 linker script, the image2 link flags + EXTRA_LIBS, nuttx.bin
    packaging and the flash target.  Per-IC inputs are set by each arch chip
    CMakeLists.
  - common/ameba/tools/{ameba_gen_ldscript,ameba_package,ameba_flash}.sh:
    shared shell steps used by both the make and cmake paths so the two produce
    identical output; tools/ameba/Config.mk now flashes via ameba_flash.sh too.
  - Fix a latent rtl8720f CMakeLists source list bug (ameba_ipc.c was missing
    for the WiFi / flash-fs configs).

The make build is unchanged (it still auto-fetches everything, so sourcing
env.sh is optional there and required only for cmake).  Verified on hardware:
both boards build, flash and boot with WiFi over the CMake path.

Assisted-by: Claude Code:claude-opus-4-8
Signed-off-by: raul_chen <raul_chen@realsil.com.cn>
Without SCHED_WAITPID, NSH cannot waitpid() on a spawned builtin application,
so every foreground builtin (e.g. wapi) is run in the background and NSH echoes
"<cmd> [pid:priority]" instead of blocking until it finishes.  Enable
CONFIG_SCHED_WAITPID (the setting used by the large majority of nsh defconfigs)
so foreground builtins run synchronously with a correct exit status and no
spurious [pid:priority] echo.

Assisted-by: Claude Code:claude-opus-4-8
Signed-off-by: raul_chen <raul_chen@realsil.com.cn>
Each ameba IC pins its asdk (arm-none-eabi) version in the SDK
(component/soc/<soc>/project/CMakeLists.txt): RTL8720F needs 12.3.1 while
RTL8721Dx needs 10.3.1.  Both share the same arm-none-eabi triple and differ
only by install directory.  The make + cmake setup previously read only the
global default, so the NuttX objects for an IC pinning a newer asdk were built
with the wrong compiler (not the one its SDK archives were built with).

Resolve the version per-IC from a single helper (ameba_asdk_version.sh, keyed
by the SoC) used by every caller:
  - toolchain.mk / ameba_board.mk: make picks the right asdk automatically
    (it already knows the SoC), no user action.
  - ameba_fetch_toolchain.sh: fetches the version the SoC pins.
  - tools/ameba/env.sh: takes an optional board (`. tools/ameba/env.sh
    <board>`) so cmake, which locks the compiler at project() time, gets the
    matching asdk on PATH before it probes.  No board -> the global default.
  - ameba_sdk.cmake: fail configure with a fix-it message if the on-PATH
    compiler is not the version this IC needs (e.g. a stale env from another
    board), instead of silently mis-compiling.

Assisted-by: Claude Code:claude-opus-4-8
Signed-off-by: raul_chen <raul_chen@realsil.com.cn>
The make PREBUILD packed the fwlib/wifi static archives with `ar crs <a>
<objdir>/*.o`.  The glob also picks up stale objects left in the obj dir from a
previous configuration (e.g. a renamed/removed SDK source), which can pull a
duplicate/old translation unit into the image (seen on RTL8720F as a spurious
ROM-overlay symbol from an old log.o).  Accumulate the exact object list the
loop compiled and `ar` that instead, removing the archive first so it is
rebuilt from precisely the current sources.

Assisted-by: Claude Code:claude-opus-4-8
Signed-off-by: raul_chen <raul_chen@realsil.com.cn>
@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: arm Issues related to ARM (32-bit) architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: arm labels Jul 17, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis
acassis merged commit cc46e73 into apache:master Jul 17, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Documentation Improvements or additions to documentation Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants