nuttx/tools/ameba/Config.mk
raul_chen 541e9d13a2 arch/arm/ameba: add CMake build support for RTL8721Dx and RTL8720F
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>
2026-07-17 08:30:47 -03:00

81 lines
3.7 KiB
Makefile

############################################################################
# tools/ameba/Config.mk
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
#
# Realtek Ameba WHC flashing support.
#
# Including this fragment in a board's scripts/Make.defs (after
# ameba_board.mk) adds the `flash` target. Usage:
#
# make flash AMEBA_PORT=/dev/ttyUSB0 [ AMEBA_BAUD=1500000 ]
#
# The board must set AMEBA_FLASH_PROFILE to the profile base name
# (e.g. "RTL8721Dx" or "RTL8720F") before including this file.
#
# AMEBA_PORT -- serial port (required)
# AMEBA_BAUD -- baud rate (default 1500000)
#
# Dependencies:
# The ameba-rtos SDK must already be fetched (auto-fetched on first
# build) and its python venv or dep-ful system python must be on PATH
# so that AmebaFlash.py (from the SDK) can import its dependencies.
# AMEBA_BAUD -- serial baud rate (default 1500000)
AMEBA_BAUD ?= 1500000
# FLASH -- Download boot.bin + nuttx.bin via the SDK's AmebaFlash.py. The whole
# recipe (flash-offset lookup from the regenerated platform_autoconf.h, python /
# .rdev-profile resolution, the two AmebaFlash.py downloads) lives in the shared
# ameba_flash.sh, used by BOTH the make and cmake `flash` paths so they flash
# identically. Serial port + baud are passed to it through the environment.
define FLASH
$(Q) AMEBA_PORT="$(AMEBA_PORT)" AMEBA_BAUD="$(AMEBA_BAUD)" \
$(AMEBA_COMMON_DIR)$(DELIM)tools$(DELIM)ameba_flash.sh \
$(AMEBA_SDK) $(AMEBA_FLASH_PROFILE) $(AMEBA_AUTOCONF) \
$(AMEBA_PREBUILT) $(TOPDIR)$(DELIM)nuttx.bin
endef
# ameba_menuconfig -- edit the vendor SDK menuconfig for this board using the
# SDK's own native menuconfig UI, and save the result as the board overlay
# fragment (boards/.../ameba_sdk.conf). The counterpart to NuttX's own
# `make menuconfig`, for the SDK-side options (Wi-Fi/BT firmware, flash layout,
# feature switches). The next build applies the change automatically (the
# fragment is hashed into the SDK-config stamp; see ameba_sdk_config.sh).
#
# Reachable as a top-level target because this fragment is included via the
# board scripts/Make.defs (the $(TOPDIR)/Make.defs symlink), like the flash
# target's FLASH macro. The logic lives in the standalone script so it can
# also be run directly.
# This fragment is pulled in (via the board Make.defs / the $(TOPDIR)/Make.defs
# symlink) BEFORE the main build makefile defines its `all` rule, so a plain
# target here would become make's default goal and `make` with no argument
# would run it instead of building. Save the default goal, define the target,
# then restore it (falling back to `all`, NuttX's default, when nothing was set
# yet). The flash target avoids this because it lives in tools/Unix.mk, after
# `all`; this one lives here, so it must guard the default goal itself.
AMEBA_PREV_GOAL := $(.DEFAULT_GOAL)
.PHONY: ameba_menuconfig
ameba_menuconfig:
$(Q) $(TOPDIR)$(DELIM)tools$(DELIM)ameba$(DELIM)ameba_menuconfig.sh
.DEFAULT_GOAL := $(or $(AMEBA_PREV_GOAL),all)