SpacemiT MUSE Pi Pro

Tags: arch:risc-v chip:spacemit-k1x-rcpu vendor:spacemit

The MUSE Pi Pro is a SpaceMiT K1 board: eight X60 application cores running Linux next to a Nuclei N308 real-time core. This documentation covers running NuttX on the real-time core.

The real-time core has no boot media of its own. Its firmware is delivered by the application processor: the kernel loads it at boot through the standard remoteproc interface, exactly the way it loads the vendor firmware. The console comes out of the core’s own UART.

Features

  • SpaceMiT K1 SoC; the core is described in the chip documentation

  • Console UART on GPIO47 (TX) and GPIO48 (RX), 3.3 V

  • JTAG for the real-time core, through the SoC debug transport

Serial Console

The console is the real-time core’s UART at 0xc0881000, brought out on GPIO47 and GPIO48, at 115200 8N1 with no flow control. It appears on the host as a USB serial adapter.

This is not the application processor’s console: that is a different UART on a different adapter, so two serial adapters are expected on this board.

Building

./tools/configure.sh muse-pi-pro:nsh
make

The result is nuttx, the ELF file the board runs.

Vendor tree

The application processor side has to be told that this firmware exists. The changes for that belong to the SpaceMiT Buildroot SDK, https://gitee.com/spacemit-buildroot/buildroot-sdk, which builds the kernel, the initramfs and the flashable images for this board.

Two places in it matter:

bsp-src/linux-6.6/                     kernel, including the device tree
buildroot-ext/board/spacemit/k1/       initramfs (dracut) and root file system

The patches for both are kept next to this documentation, in the readme directory of the board port at boards/risc-v/spacemit-k1x-rcpu/muse-pi-pro/readme. Apply them at the top of the SDK:

cd buildroot-sdk
patch -p1 < nuttx/boards/risc-v/spacemit-k1x-rcpu/muse-pi-pro/readme/0001-*.patch
patch -p1 < nuttx/boards/risc-v/spacemit-k1x-rcpu/muse-pi-pro/readme/0002-*.patch

The first one changes the rcpu_rproc@0 node in arch/riscv/boot/dts/spacemit/k1-x.dtsi: it adds firmware-name = "nuttx.elf", which is the name the kernel looks for and without which the driver falls back to the vendor name esos.elf; it sets esos-entry-point to 0x30300000, the address this firmware is linked at; and it removes the second, later firmware-name in the same node, because device tree properties are last-one-wins and leaving it there would silently undo the first change.

The second one adds one line to buildroot-ext/board/spacemit/k1/dracut-modules/99custom/module-setup.sh, which already copies the vendor firmware into the initramfs. The initramfs is where the kernel reads the firmware from, so the new file has to be listed there too.

Putting the firmware on a board

Copy the ELF into the board overlay before building the SDK:

cp nuttx/nuttx \
   buildroot-sdk/buildroot-ext/board/spacemit/k1/target_overlay/lib/firmware/nuttx.elf

Then rebuild the kernel and the image:

cd buildroot-sdk/output/k1_v2
make linux-rebuild
make

Loading the firmware

The image is linked into the rcpu_mem_0 region at 0x30300000.

With a debugger

Faster while developing: no image rebuild and no reflash. The same ELF works, because it is linked for the address it runs at.

The application processor has to have booted at least once, since it is what programs the DDR window translation the firmware is linked against.

Start OpenOCD on the real-time core:

openocd -f interface/jlink.cfg -c "transport select jtag" \
        -f target/riscv.cfg \
        -c "set _TARGETNAME k1.rcpu" \
        -c "riscv create k1.rcpu 0" \
        -c "k1.rcpu configure -event examine-end { riscv set_ir idle }" \
        -c "init" -c "targets k1.rcpu"

and load the image with GDB:

riscv64-unknown-elf-gdb nuttx
(gdb) set architecture riscv:rv32
(gdb) target remote 127.0.0.1:1024
(gdb) monitor halt
(gdb) load
(gdb) set $pc = 0x30300000
(gdb) monitor resume
(gdb) detach
(gdb) quit

set $pc is needed because load does not set the program counter and the core would otherwise continue wherever it was.

Do not use OpenOCD’s reset on this board: it resets the whole SoC without bringing the application processor back up, and recovering needs a power cycle.

By flashing

This is the delivery path: the application processor loads the firmware at power on, with no debugger and no manual step.

images/Buildroot-k1_v2-sdcard.img is the full image, and images/bootfs.img is the boot file system that carries the kernel, the device tree and the initramfs. Flashing the boot file system alone is enough when the board already runs a matching image, and is much faster than a full flash. It is partition 5 of the eMMC:

adb push images/bootfs.img /tmp/bootfs.img
adb shell "dd if=/tmp/bootfs.img of=/dev/mmcblk2p5 bs=1M"
adb reboot

For a board that does not boot yet, flash Buildroot-k1_v2-sdcard.img with the vendor procedure: hold the boot select, feed the image with the flashserver tool from the SDK, then power cycle.

Either way the shell comes up on the real-time core’s UART at 115200 8N1:

NuttShell (NSH) NuttX-13.1.1-RC0
nsh>

Going back to the vendor firmware

Remove or rename nuttx.elf and drop the patches, or simply set firmware-name back to esos.elf, then rebuild and reflash.

Supported features

  • interrupt driven console and NuttX shell

  • system tick from the core private timer

  • ECLIC interrupts

  • heap in DDR

  • procfs

Not supported yet: rpmsg to the application processor, and suspend.