Turning RockPro64 into a "normal" UEFI PC

Props to Marcin Juszkiewicz for writing post series on boot standards in ARM. The goal is to get rid of the SD card holding U-boot and boot files by flashing UEFI-enabled U-boot to SPI and boot without fiddling with offsets and the like. U-boot should reside in SPI and nowhere else, scan all connected media on boot (USB sticks and SATA drives in my case) and present boot options.

ATF requires arm-none-eabi-gcc to build, it's not in Arch ARM repos, but we can steal packages from Manjaro (find a Manjaro mirror close to you). Building them on Arch ARM from AUR packages is problematic because arm-none-eabi-newlib requires arm-none-eabi-gcc to build and vice versa.

https://mirror.truenetwork.ru/manjaro/arm-stable/extra/aarch64/arm-none-eabi-newlib-4.2.0.20211231-1-any.pkg.tar.zst

https://mirror.truenetwork.ru/manjaro/arm-stable/extra/aarch64/arm-none-eabi-gcc-12.1.0-1-aarch64.pkg.tar.zst

https://mirror.truenetwork.ru/manjaro/arm-stable/extra/aarch64/arm-none-eabi-binutils-2.38-1-aarch64.pkg.tar.zst

git clone --depth=1 -b v2.13.0 https://github.com/ARM-software/arm-trusted-firmware.git
find . -name '*.bin' -exec rm -vf '{}' \;
make -j $(nproc) CC=gcc PLAT=rk3399 bl31

U-boot:

git clone --depth=1 -b v2025.04 https://source.denx.de/u-boot/u-boot.git
export BL31=/path/to/built/bl31.elf
make mrproper && make rockpro64-rk3399_defconfig
make menuconfig

In the menu I changed some things to enable USB before boot (to be able to interrupt autoboot with keyboard), disable all networking (don't need it, smaller U-boot), increase boot delay, present boot menu, add some commands, lower baud rate. Here are the variables in .config, but don't just copy them to your .config - search for them in menuconfig and change there, the menu will take care of dependencies.

CONFIG_BOOTDELAY=20
CONFIG_BOOTCOMMAND="bootflow scan -lbm"
CONFIG_CMD_ERASEENV=y
CONFIG_CMD_NVEDIT_LOAD=y
CONFIG_NO_NET=y
CONFIG_BAUDRATE=115200
CONFIG_USE_PREBOOT=y
CONFIG_PREBOOT="usb start"
CONFIG_PREBOOT_DEFINED=y
make -j $(nproc)

Writing to SD card first to test it (from doc/README.rockchip in U-boot source, "Option 3: Package the image with TPL"):

dd if=idbloader.img of=/dev/sdX seek=64
dd if=u-boot.itb of=/dev/sdX seek=16384
sync

Flashing to SPI used to be a complex process (see Gentoo Wiki link), much simpler nowadays, see doc/board/rockchip/rockchip.rst in U-boot source. Create a partition with FAT filesystem on the same SD card, place u-boot-rockchip-spi.bin on it, reboot, get to U-boot cmdline and:

sf probe
load mmc 1:1 $kernel_addr_r u-boot-rockchip-spi.bin
sf update $fileaddr 0 $filesize

If sf probe returns an error or booting from SPI fails, short pins 23 and 25 on GPIO to temporarily disable SPI. After booting disconnect them again and erase SPI to at least get SD boot working.

U-boot environment section on SPI might be empty, broken or contain wrong variables. To get default environment for installed version of U-boot, remove situational partitions variable and save the environment to SPI, run in U-boot cmdline:

env default -a
env delete partitions
env save

I then created a 1 GiB EFI partition on SATA drive (type ef00, FAT filesystem), moved boot_arch and extlinux directories from SD card to it, removed SD card and rebooted. U-boot enumerates storage devices on boot, looks inside filesystems for various predefined files - EFI executables, boot.scr etc, including extlinux/extlinux.conf file, if present checks and adds them to boot menu. In my case it ran extlinux.conf from SATA same way as when it was on SD card. This is not a EFI boot, files could've been placed on any EXT4/FAT filesystem - U-boot just doesn't care that it's on EFI partition. Next to find BSD/Linux distros that provide UEFI-capable ARM64 images and try to install them with a typical "burn image to USB pen drive -> reboot -> go through installer" procedure.

https://marcin.juszkiewicz.com.pl/2021/03/14/u-boot-and-generic-distro-boot/

https://marcin.juszkiewicz.com.pl/2020/06/17/ebbr-on-rockpro64/

https://wiki.gentoo.org/wiki/PINE64_ROCKPro64/Installing_U-Boot