Booting NuttX on RK3588S

I wanted to get NuttX running on my Orange Pi 5 Pro, even just an nsh> prompt to start with. Linux was already booting on it, so I had a working boot path to start from (which helps a lot, but doesn't tell you what your own kernel needs to do yet). I wanted to understand where NuttX would enter that path, what was already set up for me and what I actually had to implement.

That took me to U-Boot and TF-A. They were already doing the firmware work, so I needed to figure out the exact handoff NuttX could rely on. Especially the memory setup, because a wrong memory attribute can stop the boot before you even get anything from UART.

Where I started looking

I had worked on AM67A at Baykar, and Matteo Golin's Raspberry Pi 4B port was another useful reference. These helped me follow the ARM64 startup code. What helped was following how they reached the common NuttX code, then looking at what they had to prepare before that (because that is where my board could need something different). I could reuse the common startup, but the addresses and the CPU state on entry still needed checking on mine ofc.

Before NuttX starts

First, the boot chain. By the time NuttX gets control, DRAM is initialized, TF-A has run, and U-Boot has configured UART2's clock and pins. So I didn't have to start by getting DRAM working, for example. I could follow the last part of the boot chain, where U-Boot loads the image and jumps to it.

BootROM
  → DDR initialization / TPL
  → U-Boot SPL
  → TF-A BL31
  → U-Boot proper
  → NuttX

U-Boot already speaks the ordinary ARM64 Linux Image convention: the DTB address goes in x0, then execution branches to the image entry point. So I could use booti to load NuttX with that same convention (the first version doesn't actually parse the DTB, but it can still use this entry path). That let me work on the NuttX side of the handoff. (Linux ARM64 boot protocol, U-Boot handoff)

The downstream U-Boot cleanup code disables caches and the MMU on this path. On my board I observed an EL2 entry, so that was the state I needed to follow through the NuttX startup code.

Wait, where did the image go?

The ARM64 Image header was part of figuring out that jump too. It has a load offset and a relocatable-image flag alongside the entry stub, which means booti can move the image. So just knowing where I loaded the file wasn't enough, I needed to follow where it ended up.

I load nuttx.bin at 0x02000000. The NuttX header sets the relocatable-image flag, so the U-Boot relocation calculation is:

ALIGN(0x02000000 - 0x00480000, 2 MiB) + 0x00480000
= 0x02080000

So I loaded nuttx.bin at 0x02000000 and U-Boot moved it to 0x02080000. That's where the value for CONFIG_RAM_START comes from.. looking only at the load command would give me the wrong address (the command says where to put the file, then booti moves it according to the header). That's why I had to look at the loader calculation too.

The first version uses identity mappings and exposes a conservative 512 MiB RAM window. That is the configured CONFIG_RAM_SIZE, not an RK3588S hardware limit. I kept the initial map inside the available DRAM above the firmware reservations; the port does not yet consume the device tree.

What state are we entering in?

With the load address figured out, I could follow what happens after the jump. The CPU arrived at EL2, and NuttX already had common ARM64 startup code for this (so I could follow the existing EL2-to-EL1 path instead of implementing that again in my board code). It sets up an early stack, clears .bss, prepares the EL2 state, and uses eret to reach EL1.

U-Boot booti
  → __start / real_start
  → arm64_earlyprintinit()
  → clear .bss
  → arm64_boot_el2_init()
  → eret to EL1
  → arm64_boot_el1_init()
  → arm64_chip_boot()
  → build the RK3588 mappings and enable the MMU
  → nx_start()

The EL1 setup installs the exception vector table and prepares FP/SIMD and timer state. The RK3588-specific arm64_chip_boot() then creates the platform mappings, enables the MMU, selects the SMC conduit for PSCI, and hands serial initialization to the normal 16550 driver before the common path enters nx_start().

What I needed for the first boot

From there I could see what the board-specific part needed to provide for the shell. The first things were the interrupt controller, timer, serial console, reset path, and enough memory mapped correctly. So I started with those and kept the initial memory map small.

UART2  device-nGnRnE
GICD   device-nGnRnE
GICR   device-nGnRnE
DRAM   normal memory

Getting the first byte out

When nothing comes out of UART you don't have much to go on.. so I needed a way to print before the normal serial driver was ready (otherwise how do I see what's going wrong on the way to initializing that driver?). There is no scheduler or interrupts to rely on here. The early routine just checks a status bit and writes the character to the UART register.

U-Boot has already set up UART2's clock, pins, and 1.5 Mbaud rate. NuttX is configured not to disturb them at the beginning, so arm64_earlyprintinit() simply returns (there's nothing to configure there for this handoff, U-Boot already did it). (Orange Pi 5 Pro configuration)

arm64_lowputc() expands to the essential part of a polling transmit path:

ldr   x15, =CONSOLE_UART_BASE
1: ldr   w2, [x15, #0x14]
   tst   w2, #(1 << 5)
   b.eq  1b
   str   w0, [x15, #0x00]
   ret

The common startup loop loads each character into w0 before calling the routine. x15 holds 0xfeb50000, the UART2 base address exposed as the first configured 16550 instance. With four-byte register spacing, the line-status register is at 0x14. Bit 5 is THRE: the transmit holding register is empty and can accept another byte.

1b loops back until THRE is set; the final store sends the character. Once that worked I could finally print things during startup and see how far the boot was getting :D

Trying the boot path

The documented SD-card boot looks like this:

load mmc <dev>:1 0x02000000 /nuttx.bin
load mmc <dev>:1 ${fdt_addr_r} /boot/dtb/rockchip/rk3588s-orangepi-5-pro.dtb
booti 0x02000000 - ${fdt_addr_r}

It boots.. what else should I check?

I got the prompt :) then I could check more than just how far the startup code got (printing the prompt proves UART transmit works, but I still need to receive what I type, and the timer needs to work too). I checked both build configurations, serial I/O, /proc/uptime and sleep, PSCI reboot, and OSTest on the board.

Why I checked the memory map first

There's a reason I kept coming back to the memory map. On AM67A at Baykar, incorrect MPU attributes had caused boot failures, and it wasn't obvious from the symptoms that the attributes were the problem. So I wanted to pay attention to that part this time too.

Device registers, SRAM, and DDR didn't all want the same treatment. Fixing those attributes and cacheability got the boot moving. So on RK3588S I wrote down the device and normal-memory regions early, so I had that part clear while working on the startup code.

The Orange Pi was a different situation. Working Linux and U-Boot support already existed downstream; public board support included this U-Boot patch and Linux device tree. I applied board support for both and was adding NuttX on top of a boot path that was already working.

That is why RK3588S starts with UART and GIC as device-nGnRnE and DRAM as normal memory. It is a small map, not a complete description of the SoC. (memory map)

Where the port stands

I got the shell, and the initial hardware checks passed. That was the first goal done, but there is still more board support to work on.. DTB parsing, secondary cores, and most peripherals are still future work.

The port was merged in Apache NuttX PR #19489: RK3588 SoC support, the Orange Pi 5 Pro board, and the bring-up guide.