# Mainline Linux 7.1 on the $29 Cubie A7Z – Dual 4-Lane ISP and Open NPU

> Source: <http://allthingsembedded.blogspot.com/2026/12/cubie-a7z-v2-boot-up-on-mainline-linux.html>
> Published: 2026-12-06 21:29:40+00:00

**Recommendation:** When supporting multiple boards from one image, detect hardware straps in U-Boot to set ${fdtfile} and apply board-specific overlays with automatic rollback on error.
More in the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

**By Tim Michals**

*Embedded Linux, Edge AI & Robotics Engineering Blog*

## Cubie A7Z v2 Boot-Up: What's New in v2 and Why One Unified Image?

We just got the new **Radxa Cubie A7Z v2** on the bench
and brought it up on mainline **Linux `7.1.0 SMP PREEMPT_RT`**!

If you saw [Hackster.io's
launch coverage of the original Radxa Cubie A7Z v1](https://www.hackster.io/news/radxa-targets-cost-conscious-edge-ai-projects-with-the-compact-radxa-cubie-a7z-131ac9f35921), you already know
the core appeal: an octa-core **Allwinner A733
(`sun60i`)** edge-AI SBC (dual Cortex-A76 + hexa
Cortex-A55, 3.0 TOPS `VIP9000Nano-DI` NPU, Hardware ISP 602,
Cedrus VPU, and a 200 MHz XuanTie E902 RISC-V core) packed into a
Raspberry Pi Zero-sized PCB.

Before diving into the **Cubie A7Z v2 boot-up**, look at
what changed on the backside of the v2.00 hardware revision:

*Radxa Cubie A7Z
v2.00 backside layout: microSD slot (left), **dual 4-lane MIPI
CSI-2 camera connectors** (highlighted in red, top and bottom,
wired to `MCSIA`/` i2c4` and
`MCSIB`/` i2c3`), display/expansion FPC (green),
and 1-lane PCIe Gen 3 FPC (cyan) beside the onboard UFS/eMMC
flash.*

Compared to the single-camera v1 board, **Cubie A7Z v2 adds a
second 4-lane MIPI CSI-2 connector (`MCSIA` /
`i2c4`)** alongside an updated backside FPC layout
(dual red CSI ports, green display FPC, cyan 1-lane PCIe Gen 3 FPC, UFS,
and microSD)—turning a Zero-sized SBC into a native **stereo
dual-camera edge-AI board**.

To boot the **Cubie A7Z v2** without forking our
existing **Cubie A7A** (LPDDR5, Gigabit Ethernet, single
2-lane OV5647) Buildroot tree into a second SD card image, we built
directly on my earlier Hackster.io deep dive—**[Using
Device Trees to Configure Linux Hardware Interfaces](https://www.hackster.io/MichalsTC/using-device-trees-to-configure-linux-hardare-interfaces-4b0569)** ([devicetreeOverlay.md](https://github.com/tcmichals/cubie-a5e/blob/main/docs/articles/devicetreeOverlay.md))—and
extended our Raspberry Pi-style `/boot/config.txt` +
`boot.cmd` overlay engine to **runtime multi-board
auto-detection**.

The result is **one single 592 MiB
`sdcard.img`** that boots cleanly on
**both** the Cubie A7A (**LPDDR5**) and Cubie
A7Z v2 (**LPDDR4/4X**) without touching a single file on
the card—enabling dual 4-lane Sony IMX214 camera bring-up on A7Z v2 and
setting up apples-to-apples NPU and memory performance benchmarks across
both boards:

1. **Stage 0 (`boot0` / `SPL-2.0` +
`boot_package.fex`)** : How the early bootloader
auto-trains**LPDDR5** vs.**LPDDR4/4X** from
hardware straps before handing off to a patched FIT image (BL31 +
U-Boot, minus`scp.fex` ).
2. **Stage 1 (Radxa A733 U-Boot)** : How U-Boot reads the
PCB's**GPADC + `BOARD-ID-SEL-GPIO`** straps at
runtime to set`${fdtfile}` automatically.
3. **Stage 2 (`boot.cmd` +
`/boot/config.txt`)** : How our dynamic boot script
auto-selects**both** the board's base Device Tree
(`.dtb` )**and** its board-specific Device Tree
Overlays (`.dtbo` ) with automatic rollback on error—proven on
live A7A and A7Z v2 silicon.

## 1. Cubie A7A vs. Cubie A7Z v2: What Actually Differs on the PCB?

Before unifying the image, we audited
`radxa_cubie_a7z_schematic_v2.00.pdf` against the Cubie A7A
and refactored all common A733 SoC peripherals (CPU clusters, CCU,
`npu@3600000`, `syscon`/` sunxi_sram`,
`cedrus-enc`, `sun6i-csi-capture` +
`csi1`, `sun60i-isp`, THS thermal zones, E902
`remoteproc`, USB/MMC/I2C/UART) into a shared
**`sun60i-a733.dtsi`**.

That left two small, clean board
files—`sun60i-a733-cubie-a7a.dts` and
`sun60i-a733-cubie-a7z.dts`—capturing the exact PCB
deltas:

| Subsystem | Radxa Cubie A7A ( `sun60i-a733-cubie-a7a.dts` ) | Radxa Cubie A7Z v2.00 ( `sun60i-a733-cubie-a7z.dts` ) | 
|---|---|---|
| **DRAM** | **LPDDR5** (`DRAM Type = 9` , 2400 MHz, e.g. 6 GiB) | **LPDDR4 / LPDDR4X** (`DRAM Type = 8` , e.g. 2 GiB / 4 GiB) | 
| **PMIC (`s_twi0 @ 0x36`)** | `x-powers,axp8191` | **AXP318-WBBGA** (register-compatible with`x-powers,axp8191` ) | 
| **Ethernet** | Gigabit RGMII ( `gmac0` +`mdio0` , PHY reset`PH16` ) | **None** (Wi-Fi 6 / BT 5.4 only) | 
| **Onboard Wi-Fi 6 / BT** | USB1 AIC8800D80 ( `PM0` PWR,`PM1` REG_ON) | USB1 AIC8800D80 ( `PM0` PWR,`PM1` WL-REG-ON) | 
| **USB VBUS Control** | `usb0-vbus` (`PL2` ),`usb1-vbus` (`PM5` ) | `usb0-vbus` (`PL2`` USB0-DRVVBUS` );**`PM5` freed for 40-pin GPIO** | 
| **Status LEDs** | Blue user ( `PJ27` ), Green power (`PJ26` ) | Single Green user ( `PM2` ,`radxa:green:user` ,`heartbeat` ) | 
| **MIPI CSI-2 Cameras** | Single port: `MCSIB` (`dphy1` /`mipi1` /`csi` ,`i2c3` ) →**2-lane OV5647** | **Dual 4-lane** : CSI-R (`MCSIB` /`i2c3` ) + CSI-L (`MCSIA` /`dphy0` /`mipi0` /`csi1` /`i2c4` ) →**2× Sony IMX214** | 

Because every SoC block lives in `sun60i-a733.dtsi`, a
single `Image` binary handles both boards identically—as long
as the boot chain trains the right DRAM and hands Linux the right merged
Device Tree.

```
+------------------------------------------------------------------------------+
|                   UNIFIED ALLWINNER A733 SINGLE-IMAGE BOOT                   |
+------------------------------------------------------------------------------+
  |
  +-> 1. boot0 / SPL-2.0 (raw 0..16 MiB, radxa_a733_bootloader.bin)
  |      Reads DDR-PARA-SEL-GPIO + DDR-PARA-SEL-ADC (GPADC0)
  |      -> A7A: LPDDR5 (Type 9, 2400 MHz) | A7Z: LPDDR4/4X (Type 8)
  |      -> Loads FIT @ sector 848 (0x6a000): BL31 + U-Boot (NO scp.fex!)
  |
  +-> 2. Radxa A733 U-Boot (board_late_init)
  |      Reads BOARD-ID-SEL-ADC (GPADC) + BOARD-ID-SEL-GPIO
  |      -> Sets ${fdtfile} = "allwinner/sun60i-a733-cubie-a7a.dtb"
  |                        or "allwinner/sun60i-a733-cubie-a7z.dtb"
  |      -> Runs board-agnostic uboot.env -> loads & executes boot.scr
  |
  +-> 3. boot.scr (compiled from boot.cmd) + /boot/config.txt (FAT32 mmc 0:1)
  |      Maps ${fdtfile} -> ${base_dtb}
  |      Imports /boot/config.txt via `env import -t`
  |      -> A7A: dtoverlay_a7a = "cubie-a7a-rproc cubie-a7a-ov5647"
  |      -> A7Z: dtoverlay_a7z = "cubie-a7a-rproc cubie-a7z-imx214"
  |      Loads ${base_dtb} -> `fdt resize 0x10000` -> `fdt apply` each .dtbo
  |      (Rolls back to clean ${base_dtb} automatically if any overlay fails)
  |
  +-> 4. Mainline Linux 7.1.0 PREEMPT_RT (`booti ${kernel_addr_r} - ${fdt_addr_r}`)
         Same kernel Image + same ext4 rootfs + board-accurate merged FDT
```

## 2.
Pillar 1: `boot0` DRAM Auto-Training & Stripping
`scp.fex` from the FIT

### How One Bootloader Blob Trains Both LPDDR5 and LPDDR4/4X

Before U-Boot or Linux can touch RAM, Allwinner's first-stage
`boot0` (`SPL-2.0` preboot) runs from on-chip
SRAM. Radxa's unified A733 bootloader blob
(`radxa_a733_bootloader.bin`, stored in the first 16 MiB of
the SD card) embeds multiple DRAM parameter tables
(`boot_package.fex` / DRAM config) covering the A733 board
lineup.

On power-up, `boot0` initializes the AXP8191/AXP318 PMIC,
brings up the CPU/DSU PLLs, and samples two hardware straps on the
PCB:

- **`DDR-PARA-SEL-GPIO`** : digital strap
(`gpio_idx` )
- **`DDR-PARA-SEL-ADC`** via**` GPADC0`** : analog resistor-divider strap
(`adc_idx` )

Here is an actual live serial capture from a **Cubie
A7A** cold boot showing `boot0` probing those straps
and selecting the LPDDR5 training table (`DRAM Type = 9`)
before handing off to U-Boot SPL and Arm Trusted Firmware (BL31):

```
[215] SPL-2.0 - preboot 2026-06-17 10:06:51 +0800 {853efe0f-dirty}
[229] PMU: AXP8191
[234] set pll start
[248] set pll end
[257] cur pin val 0
[259] GPADC0: Clk init ok
[262] GPADC0: Init ok
[274] adc_idx 1 gpio_idx 0
DRAM BOOT DRIVE INFO: V0.6036
DRAM_VCC set to 560 mv
DRAM CLK =2400 MHZ
DRAM Type =9 (8:LPDDR4,9:LPDDR5)
Training result is = 7
DRAM Pstate 1 training, frequency is 1200 Mhz
DRAM Pstate 2 training, frequency is 800 Mhz
DRAM Pstate 3 training, frequency is 400 Mhz
DRAM Pstate 0 training, frequency is 2400 Mhz
Actual DRAM SIZE =6144 M
DRAM simple test OK.
[4709] DRAM size 6144 MB

U-Boot SPL 2026.04-3-boot-dlan17-g24da4dae7637-dirty
DRAM: 6144 MiB
Trying to boot from MMC1
NOTICE:  BL31: OP-TEE 32bit detected
NOTICE:  BL31: U-BOOT 64bit used
```

Insert the **exact same SD card** into a **Cubie
A7Z v2**, and the A7Z's `DDR-PARA-SEL-ADC` /
`DDR-PARA-SEL-GPIO` resistor straps select the
**LPDDR4/4X (`DRAM Type = 8`)** parameter table
instead, training the 2 GiB (or 4 GiB) LPDDR4/4X package cleanly with
zero software changes.

### Freeing
the XuanTie E902 RISC-V Core: `patch_fit_no_scp.py`

Right after DRAM comes up, U-Boot SPL loads the FIT image embedded at
**sector 848 (`0x6a000`)** inside
`radxa_a733_bootloader.bin`. By default, Radxa's FIT
`/configurations/config-1` lists:

```
loadables = "scp", "uboot";
```

When `"scp"` is present, stock BL31 loads Allwinner's
`scp.fex` and boots the on-die 200 MHz **XuanTie E902
RISC-V** core as its `arisc` power-management
coprocessor—locking Linux `remoteproc0` out of the E902.

Rather than recompiling or binary-patching BL31, our Buildroot
`post-image.sh` runs [`patch_fit_no_scp.py`](https://github.com/tcmichals/cubie-a5e/blob/main/project-cubie-a5e/board/radxa/cubie_a7a/patch_fit_no_scp.py)
on a pristine copy of `radxa_a733_bootloader.bin`. It walks
the FDT structure inside the FIT and edits `loadables`
**in place** from `"scp\0uboot\0"` (10 bytes) to
`"uboot\0"` (6 bytes), filling the freed 4-byte word with
`FDT_NOP` (`0x00000004`):

```
old_span = align4(len(OLD_VALUE))
new_span = align4(len(NEW_VALUE))
struct.pack_into(">I", fit, pos + 4, len(NEW_VALUE))
fit[pos + 12:pos + 12 + new_span] = NEW_VALUE.ljust(new_span, b"\0")
for nop in range(pos + 12 + new_span, pos + 12 + old_span, 4):
    struct.pack_into(">I", fit, nop, FDT_NOP)
```

The FIT total size and every image offset remain byte-for-byte
identical, BL31 stays 100% stock, and the E902 RISC-V core is left free
for Linux `remoteproc0` on **both** A7A and
A7Z.

### Preserving
the MBR Partition Table in `genimage.cfg`

Finally, [`genimage.cfg`](https://github.com/tcmichals/cubie-a5e/blob/main/project-cubie-a5e/board/radxa/cubie_a7a/genimage.cfg)
lays down the 16 MiB bootloader blob at offset `0` while
punching a hole over bytes `440..512` so
`genimage` can write a clean MBR partition table for the 64
MiB FAT32 `/boot` partition (at offset `16M`) and
the 512 MiB `rootfs.ext4` partition:

```
image boot.vfat {
    vfat {
        files = {
            "sun60i-a733-cubie-a7a.dtb",
            "sun60i-a733-cubie-a7z.dtb",
            "cubie-a7a-rproc.dtbo",
            "cubie-a7a-ov5647.dtbo",
            "cubie-a7z-imx214.dtbo",
            "config.txt",
            "uEnv.txt",
            "boot.scr",
            "Image",
            "uboot.env"
        }
    }
    size = 64M
}

image sdcard.img {
    hdimage {}

    partition u-boot {
        in-partition-table = false
        image = "radxa_a733_bootloader.bin"
        offset = 0
        holes = {"(440; 512)"}
    }

    partition boot {
        partition-type = 0xC
        bootable = "true"
        image = "boot.vfat"
        offset = 16M
    }

    partition rootfs {
        partition-type = 0x83
        image = "rootfs.ext4"
    }
}
```

## 3.
Pillar 2: How Radxa A733 U-Boot Auto-Detects A7A vs. A7Z
(`${fdtfile}`)

Once BL31 hands off to 64-bit U-Boot proper, U-Boot needs to know
*which* A733 board it is running on.

Checking the **Cubie A7Z v2.00 schematic**
(`radxa_cubie_a7z_schematic_v2.00.pdf`), Radxa implements a
hardware board-ID matrix using two signals:

1. **`BOARD-ID-SEL-ADC` (`BOARD-ID-ADC0` /
`BOARD-ID-ADC1`)** : An analog voltage divider
connected to the A733's on-die**GPADC** . A fixed**10 kΩ 1% pull-up resistor (`R5`)** ties the
line to`AVCC` , while a board-specific**pull-down
resistor (`R6`)** sets a unique voltage band per
SKU.
2. **`BOARD-ID-SEL-GPIO`** : A digital GPIO
strap on the`VCC-PK` rail used alongside the GPADC reading
to disambiguate board variants.

During U-Boot initialization—**even after
`Loading Environment from FAT... OK` reads
`uboot.env`**—Radxa's A733 board code samples the
GPADC and `BOARD-ID-SEL-GPIO`, maps the hardware ID to the
board's canonical DTB name, and updates `${fdtfile}`:

```
Loading Environment from FAT... OK
In:    serial@2500000
Out:   serial@2500000
Err:   serial@2500000
Allwinner mUSB OTG (Peripheral)
Override default fdtfile to allwinner/sun60i-a733-cubie-a7a.dtb
```

On the **Cubie A7Z v2**, that exact same line
prints:

```
Override default fdtfile to allwinner/sun60i-a733-cubie-a7z.dtb
```

At the same time, U-Boot fixes up the `/memory@40000000`
node in the loaded FDT with the exact DRAM capacity trained by
`boot0` (e.g., 6 GiB on A7A, 2 GiB / 1.9 GiB usable on A7Z
v2), so Linux always sees the true physical RAM size regardless of the
fallback `reg` in the `.dts` file.

### The Golden Rule for
`uboot.env`

Keep `uboot.env` **100% board-agnostic**. Our
[`uboot-env.txt`](https://github.com/tcmichals/cubie-a5e/blob/main/project-cubie-a5e/board/radxa/cubie_a7a/uboot-env.txt)
only defines memory map addresses and a single boot command:

```
bootdelay=1
baudrate=115200
bootcmd=load mmc 0:1 0x4fc00000 boot.scr && source 0x4fc00000

kernel_addr_r=0x40200000
fdt_addr_r=0x4fa00000
scriptaddr=0x4fc00000
fdtoverlay_addr_r=0x4fe00000
ramdisk_addr_r=0x4ff00000
```

It never hardcodes `fdtfile` or `base_dtb`, so
U-Boot's hardware-detected `${fdtfile}` passes straight into
`boot.scr`.

## 4.
Pillar 3: Dynamic Multi-DTB & Per-Board Overlays
(`boot.cmd` + `/boot/config.txt`)

### Building Both DTBs and All Overlays in One Pass

In Buildroot's [`cubie_a7a_defconfig`](https://github.com/tcmichals/cubie-a5e/blob/main/project-cubie-a5e/configs/cubie_a7a_defconfig),
compiling both base Device Trees is a single line:

```
BR2_LINUX_KERNEL_INTREE_DTS_NAME="allwinner/sun60i-a733-cubie-a7a allwinner/sun60i-a733-cubie-a7z"
```

And [`post-image.sh`](https://github.com/tcmichals/cubie-a5e/blob/main/project-cubie-a5e/board/radxa/cubie_a7a/post-image.sh)
stages every compiled `.dtbo` overlay alongside
`boot.scr`, `uboot.env`, and
`config.txt` into `${BINARIES_DIR}` before
invoking `genimage`:

```
${HOST_DIR}/bin/mkimage -A arm64 -T script -C none -d "${BOARD_DIR}/boot.cmd" "${BINARIES_DIR}/boot.scr"
${HOST_DIR}/bin/mkenvimage -s 0x10000 -o "${BINARIES_DIR}/uboot.env" "${BOARD_DIR}/uboot-env.txt"

for ov in cubie-a7a-rproc.dtbo cubie-a7a-ov5647.dtbo cubie-a7z-imx214.dtbo; do
    if [ -f "${BOARD_DIR}/../../dts-overlay/allwinner/${ov}" ]; then
        cp -f "${BOARD_DIR}/../../dts-overlay/allwinner/${ov}" "${BINARIES_DIR}/${ov}"
    fi
done
```

### Extending
`/boot/config.txt` from Single-Board (A5E) to Multi-Board
(A7A + A7Z)

In **[Using
Device Trees to Configure Linux Hardware Interfaces](https://www.hackster.io/MichalsTC/using-device-trees-to-configure-linux-hardare-interfaces-4b0569)**, a
single-board Cubie A5E image only needed one `dtoverlay=`
line in `/boot/config.txt` because every card booted the same
motherboard. On a unified multi-board A733 image, auto-selecting the
base `.dtb` is only half the story: if you apply the Cubie
A7A's `cubie-a7a-ov5647.dtbo` overlay on a Cubie A7Z v2 with
dual IMX214 cameras attached, Linux tries to probe `ov5647`
at `i2c3 0x36` (which fails) while leaving both IMX214
sensors unpowered!

So we extended the exact same Raspberry Pi-style [`/boot/config.txt`](https://github.com/tcmichals/cubie-a5e/blob/main/project-cubie-a5e/board/radxa/cubie_a7a/config.txt)
pattern with board-scoped overlay variables (`dtoverlay_a7a`
and `dtoverlay_a7z`) while preserving generic
`dtoverlay=` as a backward-compatible fallback:

```
# /boot/config.txt - Radxa Cubie A7A/A7Z Hardware & Overlay Configuration
# (Raspberry Pi style configuration for Allwinner A733)

# Per-board default overlays (unified A733 SD image):
# - Cubie A7A: XuanTie E902 remoteproc + OV5647 camera (MIPI CSI-2)
# - Cubie A7Z: XuanTie E902 remoteproc + Dual Radxa Camera 13M 214 (IMX214)
dtoverlay_a7a=cubie-a7a-rproc cubie-a7a-ov5647
dtoverlay_a7z=cubie-a7a-rproc cubie-a7z-imx214

# Optional extra kernel command-line arguments
cmdline=
```

Notice how clean the modularity is:

- **`cubie-a7a-rproc.dtbo`** is**shared
by both boards** —it reserves the E902 DRAM carveout and enables`remoteproc0` on both A7A and A7Z.
- **`cubie-a7a-ov5647.dtbo`** (A7A only) wires
the 2-lane OmniVision OV5647 on`i2c3 @ 0x36` with a 25 MHz
fixed clock and`PE8` power-down to`mipi1_in` .
- **`cubie-a7z-imx214.dtbo`** (A7Z only) wires**two 4-lane Sony IMX214 sensors** simultaneously:
  - **CSI-R (`MCSIB` / `dphy1` /
`mipi1`)** :` i2c3 @ 0x10` , 24 MHz`CLK_CSI_MASTER1` (`PE5` ),`PE8` STBY-R
regulator,`PE9` RST-R, 4 data lanes
(`PK10..PK19` ).
  - **CSI-L (`MCSIA` / `dphy0` /
`mipi0`)** :` i2c4 @ 0x10` , 24 MHz`CLK_CSI_MASTER0` (`PE0` ),`PE12` STBY-L regulator,`PE13` RST-L, 4 data lanes
(`PK0..PK9` ).

### Inside
`boot.cmd`: Runtime DTB + Overlay Dispatch with Rollback

Here is the core logic from [`project-cubie-a5e/board/radxa/cubie_a7a/boot.cmd`](https://github.com/tcmichals/cubie-a5e/blob/main/project-cubie-a5e/board/radxa/cubie_a7a/boot.cmd):

```
# 1. Auto-select board DTB from Radxa A733 U-Boot's GPADC/GPIO-detected ${fdtfile}
echo ">>> U-Boot detected fdtfile: ${fdtfile}"
if test "${fdtfile}" = "allwinner/sun60i-a733-cubie-a7z.dtb"; then
    setenv base_dtb sun60i-a733-cubie-a7z.dtb
elif test "${fdtfile}" = "allwinner/sun60i-a733-cubie-a7a.dtb"; then
    setenv base_dtb sun60i-a733-cubie-a7a.dtb
else
    setenv base_dtb sun60i-a733-cubie-a7a.dtb
fi
setenv overlays ""

# 2. Import Raspberry Pi-style config.txt (with armbianEnv.txt / uEnv.txt fallbacks)
if load mmc 0:1 ${ramdisk_addr_r} config.txt; then
    echo ">>> Found Raspberry Pi-style config.txt! Importing configuration..."
    env import -t ${ramdisk_addr_r} ${filesize}
elif load mmc 0:1 ${ramdisk_addr_r} armbianEnv.txt; then
    env import -t ${ramdisk_addr_r} ${filesize}
elif load mmc 0:1 ${ramdisk_addr_r} uEnv.txt; then
    env import -t ${ramdisk_addr_r} ${filesize}
fi

# 3. Pick board-specific overlay list (falling back to generic dtoverlay)
if test "${base_dtb}" = "sun60i-a733-cubie-a7z.dtb" && test -n "${dtoverlay_a7z}"; then
    setenv overlays "${dtoverlay_a7z}"
elif test "${base_dtb}" = "sun60i-a733-cubie-a7a.dtb" && test -n "${dtoverlay_a7a}"; then
    setenv overlays "${dtoverlay_a7a}"
elif test -n "${dtoverlay}"; then
    setenv overlays "${dtoverlay}"
fi

# 4. Load base DTB and expand FDT buffer by 64 KB (0x10000) for overlays
if load mmc 0:1 ${fdt_addr_r} ${base_dtb}; then
    fdt addr ${fdt_addr_r}
    fdt resize 0x10000
else
    echo "ERROR: Failed to load base DTB ${base_dtb}!"
    reset
fi

# 5. Apply each .dtbo in RAM; roll back to clean base DTB on any failure
if test -n "${overlays}"; then
    setenv fdt_apply_error 0
    for overlay in ${overlays}; do
        setenv loaded 0
        if load mmc 0:1 ${fdtoverlay_addr_r} ${overlay}.dtbo; then
            setenv loaded 1
        elif load mmc 0:1 ${fdtoverlay_addr_r} ${overlay}; then
            setenv loaded 1
        elif load mmc 0:1 ${fdtoverlay_addr_r} overlays/${overlay}.dtbo; then
            setenv loaded 1
        fi

        if test "${loaded}" = "1"; then
            if fdt apply ${fdtoverlay_addr_r}; then
                echo "    [OK] Applied ${overlay} successfully."
            else
                echo "    [ERROR] fdt apply failed for ${overlay}!"
                setenv fdt_apply_error 1
            fi
        fi
    done

    if test "${fdt_apply_error}" = "1"; then
        echo ">>> [WARNING] One or more overlays failed! Reloading clean base DTB..."
        load mmc 0:1 ${fdt_addr_r} ${base_dtb} && fdt addr ${fdt_addr_r}
    fi
fi

# 6. Boot mainline Linux 7.1 kernel Image with the merged FDT
load mmc 0:1 ${kernel_addr_r} Image && booti ${kernel_addr_r} - ${fdt_addr_r}
```

Two details here save hours of field debugging:

- **`fdt resize 0x10000`** adds 64 KiB of
headroom to the in-memory FDT before`fdt apply` . Without it,
applying a second overlay like`cubie-a7z-imx214.dtbo` fails
with`FDT_ERR_NOSPACE` .
- **Automatic clean-base rollback** : If an experimental
overlay has a broken phandle target,`boot.cmd` detects`fdt_apply_error=1` , reloads the pristine`${base_dtb}` , and still boots Linux into a recoverable shell
instead of hanging at`Starting kernel ...` .

## 5. First-Silicon Verification on Both Boards

We flashed the single unified `bld.a7a/images/sdcard.img`
(**592 MiB**, mainline **Linux
`7.1.0 SMP PREEMPT_RT`**) and booted it live on
**both** the Radxa Cubie A7A (LPDDR5) and Radxa Cubie A7Z
v2.00 (LPDDR4/4X, tested bare without a heatsink at a 780 MHz thermal
cap, 37.0–50.9 °C):

| Subsystem | Cubie A7A (LPDDR5) | Cubie A7Z v2.00 (LPDDR4/4X) | 
|---|---|---|
| **Auto-Selected DTB** | `sun60i-a733-cubie-a7a.dtb` (`Radxa Cubie A7A` , 6 GiB) | `sun60i-a733-cubie-a7z.dtb` (`Radxa Cubie A7Z` , 1.9 GiB usable) | 
| **Auto-Applied Overlays** | `cubie-a7a-rproc` +`cubie-a7a-ov5647` | `cubie-a7a-rproc` +`cubie-a7z-imx214` | 
| **PMIC & CPU DVFS** | AXP8191, `policy0` (416–1794 MHz) &`policy6` (416–2002 MHz) | AXP318/AXP8191 (all 45 regulators), `policy0` &`policy6` DVFS live | 
| **Thermal & Cooling Maps** | 5 THS zones ( `cpu-big` ,`ddr` ,`npu` ,`cpu-little` ,`gpu` ) +`npu-thermal` | 5 THS zones + `cdev0/cdev1` (`cpufreq` ) +`npu-thermal` (70/90 °C →`3600000.npu` ) | 
| **Networking** | Gigabit `eth0` (`gmac0` ) + USB1 AIC8800D80 Wi-Fi 6 | USB1 AIC8800D80 Wi-Fi 6 ( `a69c:8d80` →`a69c:8d81` ,`wlan0` HT/VHT/HE UP) | 
| **Status LEDs** | `radxa:blue:user` (`PJ27` ),`radxa:green:power` (`PJ26` ) | `radxa:green:user` (`PM2` ,`[heartbeat]` ) | 
| **E902 `remoteproc0`** | `start` →`running` , live`trace0` + RPMsg, clean`stop` | `start` →`running` , live`trace0` telemetry, clean`stop` →`offline` | 
| **3.0 TOPS NPU (`etnaviv` + Teflon)** | `/dev/dri/renderD128` , 6/6 bit-exact, 203 FPS MobileNetV1 | `/dev/dri/renderD128` ,**`/usr/bin/npu-smoke-test` 6/6 PASS (`max_diff=0`, `Cosine=1.000000`)** | 
| **Cedrus VPU & ISP 602** | `cedrus-enc` (`/dev/video3` ),`sun60i-isp` (`/dev/video1..2` ) | `cedrus-enc` (`/dev/video3` ,`NV12` → H.264/HEVC),`sun60i-isp`**1080p NV12 (15/15 frames)** | 
| **MIPI CSI-2 Cameras** | OV5647 ( `i2c-3 0x36` ) 2-lane capture | **Dual 4-lane IMX214** (`i2c-3 0x10 = UU` +`i2c-4 0x10 = UU` ), live**1080p `RG10` @ ~47 FPS** | 

**One honest open item on A7Z v2:** Warm software
`reboot` on the A7Z v2 currently resets without returning to
`boot0` (cold power-cycle boots cleanly every time). We are
investigating whether AXP318's cold-reset register
(`0x54`/` 0x55`) or the A733 watchdog timer reset
(`WDT_CFG`) needs a board-specific quirk.

## 6. Live Cubie A7Z v2 Silicon Results: Dual 4-Lane Cameras, Hardware H.264/H.265 & NPU Performance Comparison

With the unified image booted on the **Cubie A7Z v2**, we benchmarked the full edge-AI vision stack—dual 4-lane IMX214 cameras, Cedrus 1080p H.264/H.265 hardware compression, and Mainline Linux 7.1 `etnaviv` + Mesa Teflon NPU vs. CPU + LPDDR4/4X using `tools/npu_perf_compare.py`:

*Live mainline Linux 7.1 performance summary on the Radxa Cubie A7Z v2 (full clock 1.79/2.00 GHz with fan, 36.3–43.6 °C) alongside Cubie A7A (LPDDR5) reference numbers.*

### 6.1 Concurrent Dual 4-Lane Sony IMX214 Capture (95.41 FPS Combined, 1.2% CPU)

*(Captured on a bare board with passive cooling—no heatsink or fan—accounting for the 53.0–53.1 °C readings compared to the fan-cooled runs in Sections 6.3 and 6.4.)*

- **1× CSI-R Solo (`/dev/video0`, 100 frames, 1080p RAW10)** :**46.76 FPS** ,` p50 = 20.55 ms` ,**0.7% CPU** ,`53.1 °C`
- **2× Concurrent Dual-Cam (100 frames each, 1080p RAW10)** :
  - **CSI-R (`/dev/video0`, `imx214 3-0010`)** :**46.76 FPS** (` p50 = 20.55 ms` , real Bayer pixels**98.6% non-zero** ,`mean=63.7` )
  - **CSI-L (`/dev/video1`, `imx214 4-0010`)** :**48.65 FPS** (` p50 = 20.55 ms` ,**`p99 = 20.57 ms`** ,**20 µs jitter** , real Bayer pixels**100.0% non-zero** ,`mean=64.7` )
  - **Combined throughput** :**95.41 FPS** sustained (peak**97.3 FPS** ) at just**1.2% total CPU** and**53.0 °C** .

### 6.2 Hardware Video Compression (`cedrus-enc` 1080p H.264 & H.265/HEVC — up to 72.62 FPS)

*(Captured on a bare board with passive cooling—no heatsink or fan—accounting for the 53.1–55.9 °C readings.)*

- **H.264 (AVC)** :**51.65–62.97 FPS** (**15.88–19.36 ms/frame** ,`75.6 KB` for 60 frames),**4.2–4.5% total CPU** ,`53.1–55.1 °C`
- **H.265 (HEVC)** :**72.62 FPS** (**13.77 ms/frame** ,`32.2 KB` —**2.3× smaller** than H.264),**5.8% total CPU** ,`55.9 °C`

### 6.3 4-Engine Concurrent Vision Pipeline (Dual-Cam TDM200 + ISP 602 NV12 + Dual 3A + Live H.265 + 3.0 TOPS NPU)

With all hardware engines running **simultaneously** on Mainline Linux 7.1 `PREEMPT_RT` (full clocks 1.79/2.00 GHz, fan on, zero dropped frames and zero ISP/TDM errors; note that V4L2 `/dev/videoX` indices shift when dual-ISP channels and both 3A params/stats nodes occupy `/dev/video2..5`, moving `cedrus-enc` from `/dev/video3` in Section 5's single-ISP table to `/dev/video6`):

- **Dual-Camera Time-Multiplexed Hardware ISP 602 (TDM200 offline mode + VIPP/BK virtual-channel demux)** :
  - **Forward Camera (CSI-R `/dev/video0`, 4-lane IMX214 → TDM200 RX0 → ISP 602 ch0 → 1080p NV12)** :**48.65 FPS** (150/150 frames, 0 drops,`rx_fe=0` ,`ist=0` )
  - **Downward Camera (CSI-L `/dev/video1`, 4-lane IMX214 → TDM200 RX1 → ISP 602 ch1 → 1080p NV12)** :**48.65 FPS** (150/150 frames, 0 drops —**97.30 FPS combined dual-camera Hardware ISP 602 1080p NV12** )
  - **Independent Dual Closed-Loop Hardware 3A (`/usr/bin/a733-isp-3a --ch 0` & `--ch 1`)** : Live per-frame hardware AE zone readback (` 432 × u16` zones via`/dev/video3` &`/dev/video5` ) + dynamic WB gain injection (`/dev/video2` &`/dev/video4` ) running on both channels simultaneously (120/120 stats frames each,`rc=0` )
- **3.0 TOPS NPU (`etnaviv` + Mesa Teflon) Concurrently with Dual-ISP 1080p NV12 + Dual 3A** :**MobileNetV1 INT8 @ 170.0 FPS** (`5.37 ms` p50,**`Cosine = 0.999958`** , 411 NPU IRQs,**13.9% total 8-core CPU** ;**191.3 FPS** /`5.23 ms` mean /**4% avg CPU** /**36.3 °C peak** alongside CSI-R ISP NV12 + CSI-L RAW10 + live Cedrus H.265)
- **Cedrus H.265 Encoder (`/dev/video6`)** :**60/60 live IMX214 + ISP 602 1080p NV12 frames → `173.6 KB` valid `HEVC (Main) 1920×1080` bitstream** (verified clean decode via`ffprobe` /`ffmpeg` )

### 6.4 Standard TFLite INT8 NPU Benchmarks (`etnaviv` + Teflon vs. CPU) & LPDDR4/4X

Captured live on the Cubie A7Z v2 at **full clock (`1.79 GHz` A55 / `2.00 GHz` A76, fan on, 36.3–43.6 °C)** using official Google TFLite INT8 models (30 timed iterations):

- **MobileNetV1 INT8 (224×224)** :**197.3 FPS** (**5.07 ms** , 60 NPU IRQs,**10.9% CPU** ,**`Cosine = 0.999958`** , 39.4 °C) —**within 2.8% of the LPDDR5 Cubie A7A (203.0 FPS)** ; vs. CPU-4T`74.4 FPS` (50.5% CPU) / CPU-1T`51.2 FPS` .
- **MobileNetV2 INT8 (224×224)** :**180.8 FPS** (**5.53 ms** , 360 NPU IRQs,**16.3% CPU** , 36.3 °C) —**within 2.8% of the LPDDR5 Cubie A7A (186.0 FPS)** ; vs. CPU-4T`63.0 FPS` (50.1% CPU) / CPU-1T`20.9 FPS` .
- **SSD-MobileNetV1 INT8 (300×300 Object Detection)** :**78.9 FPS** (**12.67 ms** , 272 NPU IRQs,**13.8% CPU** , 43.6 °C); vs. CPU-4T`45.8 FPS` (43.7% CPU) / CPU-1T`36.7 FPS` .
- **LPDDR4/4X DRAM Probe (32 MiB × 20 @ full clock)** :**3,639.8 MB/s copy** (**7,279.5 MB/s** total R+W traffic) |**7,967.9 MB/s write** .
- **Onboard 128 GB UFS 3.x Storage (`ufs-sun60i`, HS-G4 Rate B)** :**YMTC `YMUS8A1TE2D1C1` (`/dev/sda`, 119 GiB)** enumerated in 180 ms at**757.2 MB/s sequential read** (512 MiB in 0.676 s — ~20× faster than microSD).

### 6.5 How the A733 Open-Source NPU Compares Against Other Edge Platforms (`mobilenet_v1_1.0_224_quant.tflite`, INT8)

| Platform / Accelerator | Driver Stack | MobileNetV1 INT8 | Notes | 
|---|---|---|---|
| **Radxa Cubie A7A (A733, LPDDR5)***(measured)* | Mainline 7.1 `etnaviv` + Mesa Teflon (100% open-source) | **4.93 ms (203.0 FPS)** | Built-in 3.0 TOPS NPU, zero proprietary blobs | 
| **Radxa Cubie A7Z v2 (A733, LPDDR4/4X)***(measured)* | Mainline 7.1 `etnaviv` + Mesa Teflon (100% open-source) | **5.07 ms (197.3 FPS)** | 10.9% CPU, `Cosine=0.999958` (**191.3 FPS** with dual 1080p cams + ISP + H.265) | 
| **Google Coral USB (4 TOPS)***(published ref)* | Proprietary EdgeTPU compiler/runtime | ~5–7 ms (~140–200 FPS) | External ~$60 USB dongle (EOL) | 
| **Rockchip RK3588 (6 TOPS)***(published ref)* | Open-source Mesa Teflon (single-core) | ~10–11 ms (~90–100 FPS) | $100+ SBC; multi-core requires vendor RKNN blob | 
| **Raspberry Pi 5 (4× A76 CPU)***(published ref)* | TFLite XNNPACK CPU | ~10–15 ms (~67–100 FPS) | High CPU load; NPU requires ~$70 Hailo-8L HAT | 
| **Cubie A7Z v2 (CPU-only, 4T @ 2.0 GHz)***(measured)* | TFLite CPU | 13.44 ms (74.4 FPS) | 50.5% CPU (2.7× slower than its own NPU) | 

Running **100% open-source Mainline Linux 7.1 + Mesa Teflon**, the $29–$39 Cubie A7Z v2 matches or beats a discontinued $60 Google Coral USB dongle and runs ~2× faster than single-core open-source RK3588 Teflon—while simultaneously handling dual 4-lane 1080p cameras, Hardware ISP 602, H.265 encoding, and 128 GB UFS 3.x storage.

## 7. Why This Pattern Scales

Adding a third A733 board—such as the **Radxa Cubie
A7S**—takes four small steps instead of a whole new
distribution:

1. Add `sun60i-a733-cubie-a7s.dts``#include "sun60i-a733.dtsi"` and append it to`BR2_LINUX_KERNEL_INTREE_DTS_NAME` .
2. Add it to `boot.vfat` in`genimage.cfg` .
3. Add an `elif` branch for`${fdtfile}` and a`dtoverlay_a7s=` entry in`boot.cmd` and`/boot/config.txt` .
4. Flash one SD card and plug it into any A733 board on the bench.

## Where to Grab the Code

- **Boot Script, Config, Packaging & FIT Patcher** ([cubie-a5e](https://github.com/tcmichals/cubie-a5e) ):
- **Device Tree Overlays** :
- **Mainline Linux 7.1 Device Trees** ([linux-cubie
(`a7a_remoteproc_camera_usb`)](https://github.com/tcmichals/linux-cubie) ):
  - `arch/arm64/boot/dts/allwinner/sun60i-a733.dtsi`
  - `arch/arm64/boot/dts/allwinner/sun60i-a733-cubie-a7a.dts`
  - `arch/arm64/boot/dts/allwinner/sun60i-a733-cubie-a7z.dts`
