Skip to content

Instantly share code, notes, and snippets.

@HelloWorld017
Last active June 7, 2025 17:44
Show Gist options
  • Save HelloWorld017/fe7649dd5e2f69c1a99bd60aa842b795 to your computer and use it in GitHub Desktop.
Save HelloWorld017/fe7649dd5e2f69c1a99bd60aa842b795 to your computer and use it in GitHub Desktop.

Radxa ROCK 5B+

셋업을 시도하면서 찾아본 내용을 정리해본다.
오개념이 있을 수 있다.

부팅 관련

부팅 매체

직접 부팅을 허용하는 저장소: MicroSD / SPI NOR Flash / eMMC (해당 없음)

  • MicroSD 에 U-Boot을 포함한 시스템 이미지를 적어놓은 상태로 그리로 바로 부팅하는 방법
  • SPI 에 부트로더 (U-Boot or EDK2)를 올려서 NVMe or MicroSD로 부팅하는 방법
  • 부팅 우선순위는 SPI > MicroSD

Maskrom 모드

  • AP 내부에 미리 저장된 코드로 부팅하는 모드
  • 주로 SPI에 플래시 하기 위해 사용하는 듯 함
  • 플래시 순서
    1. rkdeveloptool db를 통해 SPL Loader를 로딩시켜서 플래시를 할 수 있는 상태로 만든 후
    2. rkdeveloptool wl 로 SPI에 플래시할 수 있음

사용 가능한 부트로더

  • EDK2-rk3588

    • 가장 일반적인 컴퓨팅 환경에 근접해보임.
    • Rock 5B+ 는 아직 Bronze Support임.
      • 이슈를 찾아보니 DMC (Dynamic Memory Controller인 듯)가 작동하지 않는다는 말이 있음
  • Vendor U-Boot (Download)

    • U-Boot 버전이 낮다고 함
      • 커널 이름 길이나 이런 데에서 문제가 조금씩 있을 수 있다고 함
    • 최근에 업데이트가 된 것으로 보임 (확실치 않음)
  • Close-to-Mainline U-Boot (Artifacts)

    • Collabora 측에서 Upstreaming을 시도하고 있는 U-Boot

기타 노트

  • MicroSD에 U-Boot을 설치하는 방법도 있다는 듯 하다.
  • U-Boot도 UEFI 스펙의 일부를 구현하고 있어 UEFI로서 부팅이 가능하다는 듯 하다.
  • 시리얼 콘솔에 문제가 있다면 케이블을 체크하자
    • 기본 baudrate가 1.5M이라 가지고 있는 케이블로는 안됐었다.

참조 링크

커널 관련

작업 순서

U-Boot 올리기

  1. 레포를 클론한다.
$ git clone https://gitlab.collabora.com/hardware-enablement/rockchip-3588/u-boot.git
$ git clone https://gitlab.collabora.com/hardware-enablement/rockchip-3588/rkbin.git
  1. 크로스빌드 환경을 구축한다.
let
  nixpkgs = import <nixpkgs> {};
  crosspkgs = import <nixpkgs> {
    crossSystem = { config = "aarch64-unknown-linux-gnu"; };
  };
in
  nixpkgs.mkShell {
    nativeBuildInputs = (with crosspkgs.buildPackages; [
      binutils
      bison
      flex
      gcc
    ]) ++ (with nixpkgs; [
      gnutls
      openssl
      python312
      python312Packages.pip
      python312Packages.pyelftools
      python312Packages.virtualenv
      python312Packages.setuptools
      swig
    ]);
  }
  1. u-boot를 빌드한다.
$ nix-shell
$ cd u-boot
$ make rock5b-rk3588_defconfig

# 빌드한다.
$ export ROCKCHIP_TPL=../rkbin/bin/rk35/rk3588_ddr_lp4_2112MHz_lp5_2400MHz_v1.18.bin
$ export BL31=../rkbin/bin/rk35/rk3588_bl31_v1.47.elf
$ make CROSS_COMPILE="aarch64-unknown-linux-gnu-"
$ ls -alh u-boot.idb idbloader.img
-rw-r--r-- 1 nenw nenw 216K May  6 03:33 idbloader.img
-rw-r--r-- 1 nenw nenw 1.5M May  6 03:33 u-boot.itb

# 기존 이미지에 덮어씌운다.
$ cp ~/rock-5b-spi-image-gd1cf491-20240523-debug.img ./rock-5b-plus-bootloader-20250506.img
$ dd if=idbloader.img of=rock-5b-plus-bootloader-20250506.img seek=64 conv=notrunc
$ dd if=u-boot.itb of=rock-5b-plus-bootloader-20250506.img seek=16384 conv=notrunc

NixOS 설치 디스크 만들기

  1. NixOS Download 에서 Minimal ISO (64-bit ARM) 을 다운로드한다.
  2. USB에 쓴다.
$ lsblk

# 주의! `/dev/sdX` 를 이전 `lsblk` 에서 알아낸 USB의 디바이스 파일로 교체한다.
#       잘못 수행 시 엉뚱한 디스크가 날아갈 수 있으므로 주의할 것
$ dd if=nixos-minimal-25.05.802674.7848cd8c982f-aarch64-linux.iso of=/dev/sdX bs=4M status=progress conv=fdatasync
  1. u-boot의 이미지가 플래시된 SD카드와 NixOS 설치 이미지가 플래시된 USB를 꽂고 부팅하면 깔끔하게 설치 이미지 부팅에 성공한다. image
@breuhan
Copy link

breuhan commented May 29, 2025

I followed your instructions, but I end up in a boot loop:

U-Boot SPL 2025.07-rc2-gcf6b761a8782 (Jan 01 1980 - 00:00:00 +0000)
Trying to boot from SPI
Error: -22
Trying to boot from MMC2
spl: mmc init failed with error: -95
Error: -95
Trying to boot from MMC1
Card did not respond to voltage select! : -110
spl: mmc init failed with error: -95
Error: -95
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

@HelloWorld017
Copy link
Author

HelloWorld017 commented May 30, 2025

@breuhan
You should not follow this guide as this is not a complete guide. I also did not finish all the setup yet.
I'll update the guide whenever there is more progression.


For your error message:
I think your message states the first-stage bootloader (= U-Boot SPL) has been loaded but it had not found the second-stage bootloader (= U-Boot). I've uploaded my build artifact here, so try flashing it directly to the SD Card using balenaEtcher or other tools.

@breuhan
Copy link

breuhan commented May 30, 2025

I was able to resolve my issue by flashing u-boot-rockchip-spi.bin in the same directory into the SPI. Thanks! I'm now able to boot NixOS

@breuhan
Copy link

breuhan commented Jun 7, 2025

Maybe you are interested in that. I created a pkgs/uboot.nix that create a rock-5b-plus-spi.img . This file can be directly flashed to SPI flash.
sudo dd if=rock-5b-plus-spi.img of=/dev/mtd0 bs=1M
It is as close to the vendor firmware as possible.
It can also be flashed via USB-C in maskrom mode.


{
  lib,
  fetchgit,
  src,
  pkgs,
  buildUBoot,
  rkbin,
  ...
}@args:
{
  rock5b_plus_uboot = (
    buildUBoot {
      version = "2025.07";

      src = fetchgit {
        url = "https://gitlab.collabora.com/hardware-enablement/rockchip-3588/u-boot.git";
        branchName = "rockchip";
        hash = "sha256-vTUxTMEwk0RgbLyDF3KhmLJHdKTItS7YKHXRFheRuZs=";
      };

      rkbin = fetchgit {
        url = "https://gitlab.collabora.com/hardware-enablement/rockchip-3588/rkbin.git";
        branchName = "master";
        hash = "sha256-KBmO++Z1AfIKvAmx7CzXScww16Stvq2BWr2raPiR6Q8=";
      };

      patches = [ ];

      extraConfig = ''
        CONFIG_DISPLAY_CPUINFO=y
        CONFIG_DISPLAY_BOARDINFO=y
        CONFIG_DISABLE_CONSOLE=n
        CONFIG_CMD_NVME=y
        CONFIG_BOOTDELAY=5
        CONFIG_CMD_LOG=y
        CONFIG_ENV_IS_NOWHERE=n
        CONFIG_ENV_IS_IN_SPI_FLASH=y
        CONFIG_ENV_SECT_SIZE_AUTO=y
        CONFIG_ENV_OVERWRITE=y
        CONFIG_ENV_SIZE=0x8000
        CONFIG_ENV_OFFSET=0x3F8000
        CONFIG_SYS_SPI_U_BOOT_OFFS=0x800000
        CONFIG_NETCONSOLE=y
      '';
      extraMeta.platforms = [ "aarch64-linux" ];

      defconfig = "rock5b-rk3588_defconfig";
      BL31 = "${rkbin}/bin/rk35/rk3588_bl31_v1.47.elf";
      ROCKCHIP_TPL = rkbin.TPL_RK3588;

      postBuild = ''

        SPI_IMAGE="rock-5b-plus-spi.img"

        dd if=/dev/zero of=$SPI_IMAGE bs=1M count=0 seek=16
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE mklabel gpt
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE unit s mkpart idbloader 64 7167
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE unit s mkpart vnvm 7168 7679
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE unit s mkpart reserved_space 7680 8063
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE unit s mkpart reserved1 8064 8127
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE unit s mkpart uboot_env 8128 8191
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE unit s mkpart reserved2 8192 16383
        ${pkgs.parted}/bin/parted -s $SPI_IMAGE unit s mkpart uboot 16384 32734

        dd if=idbloader.img of=$SPI_IMAGE seek=64 conv=notrunc
        dd if=u-boot.itb of=$SPI_IMAGE seek=16384 conv=notrunc
      '';

      filesToInstall = [
        "idbloader.img"
        "u-boot.itb"
        "rock-5b-plus-spi.img"
        "u-boot-rockchip-spi.bin"
      ];
    }
  );
}

@HelloWorld017
Copy link
Author

Nice work! 👍 Thank you for reproducible builds!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment