The Boot Process of Embedded Linux on RK3399

1. Introduction

The RK3399 is a high-performance SoC launched by Rockchip, widely used in smart devices, embedded systems, and industrial control applications. Understanding its boot process is crucial for developers to optimize system boot time, customize firmware, and troubleshoot boot issues. This article will detail the boot process of the RK3399, including the BootROM, bootloader, Linux kernel, and root filesystem loading procedures.

2. Overview of the RK3399 Boot Process

The boot process of the RK3399 can be roughly divided into the following stages:

  1. BootROM (Built-in Boot Code)
  2. First Stage Bootloader (First Stage Bootloader, typically TPL/SPL or U-Boot SPL)
  3. Second Stage Bootloader (U-Boot)
  4. Linux Kernel Loading
  5. Root Filesystem Mounting
  6. User Space Initialization

Next, we will analyze each stage of the boot process in detail.

3. BootROM (Built-in Boot Code)

BootROM is the ROM inside the SoC, pre-burned into the chip, responsible for initializing the CPU, clock, memory, and boot storage devices (such as eMMC, SPI Flash, SD card, or USB). Its main functions are as follows:

  • Detect boot devices (eMMC, SD card, USB OTG, SPI Flash, etc.).
  • Read the bootloader from the storage medium (usually SPL or TPL).
  • If the boot code is found successfully, it is loaded into RAM and executed; otherwise, it enters MaskROM mode (waiting for USB OTG for firmware flashing).

Boot Device Detection Order

The RK3399 uses a fixed boot device detection order:

  1. SPI Nor Flash
  2. eMMC boot0 partition
  3. SD card
  4. USB OTG Download Mode

If the previous media are unavailable, BootROM will attempt the next medium, ultimately entering USB OTG download mode, waiting for external tools (such as <span>rkdeveloptool</span>) to flash the firmware.

4. First Stage Bootloader (SPL/TPL)

TPL (Tertiary Program Loader)

If DDR requires additional initialization, the RK3399 will first load TPL to configure the DDR controller, making RAM available. TPL is typically used in scenarios where DDR initialization is complex.

SPL (Secondary Program Loader)

SPL is responsible for further initializing DDR, clocks, and other hardware, and loading the complete U-Boot (second stage bootloader). SPL is smaller in size, and its main tasks include:

  • Configuring DRAM to make it available.
  • Reading and loading the second stage U-Boot (usually located in the boot partition of eMMC/SD card).
  • Jumping to the second stage U-Boot to continue execution.

In the typical boot process of the RK3399, SPL mainly loads U-Boot from the boot0 partition of eMMC or SD card.

5. Second Stage Bootloader (U-Boot)

U-Boot is a powerful bootloader that supports network booting, environment variable storage, device tree parsing, and more. During the RK3399 boot process, U-Boot mainly performs the following tasks:

  1. Loading the Device Tree (DTB)

  • The device tree describes hardware information such as CPU, memory, peripherals, etc.
  • U-Boot parses the DTB and makes necessary additions or modifications.
  • Initializing Storage Devices, Network, etc.

    • U-Boot is responsible for initializing eMMC, SD card, USB, SPI Flash, and other peripherals.
  • Finding and Loading the Linux Kernel

    • U-Boot parses the boot partition or <span>extlinux.conf</span> to obtain the kernel image path.
    • Reads the Linux kernel (Image/zImage) and loads it into memory.
  • Finding and Loading Ramdisk (Optional)

    • If initramfs/initrd is enabled, U-Boot will load it.
  • Passing Boot Parameters and Starting the Kernel

    • Boot parameters such as root filesystem path and console device (<span>console=ttyS2,115200</span>) are passed via <span>bootargs</span>.
    • Calls <span>bootm</span> or <span>booti</span> command to start the kernel.

    6. Linux Kernel Loading

    Once U-Boot successfully jumps to the Linux kernel, the Linux kernel takes over system control and performs the following operations:

    1. Decompressing the Kernel Image

    • The kernel image is usually compressed using gzip or LZ4 and needs to be decompressed before execution.
  • Initializing CPU and Memory Management

    • Setting up page tables and initializing the MMU (Memory Management Unit).
  • Loading the Device Tree (DTB)

    • Parsing the device tree and initializing internal peripherals of the SoC, such as serial ports, GPIO, I2C, etc.
  • Initializing Drivers

    • Loading drivers for SD/eMMC, USB, network, etc.
  • Mounting the Root Filesystem

    • Finding and mounting the root filesystem via the <span>root=</span> parameter.

    7. Root Filesystem Mounting

    The root filesystem (RootFS) is the user space environment that Linux relies on to operate. Common types of root filesystems for RK3399 include:

    • ext4 filesystem based on eMMC/SD card
    • UBIFS-based SPI Flash filesystem
    • NFS-based network filesystem
    • RAM root filesystem based on initramfs (ramdisk)

    After mounting the root filesystem, Linux will execute <span>/sbin/init</span> or <span>/init</span> as the first user-space process.

    8. User Space Initialization

    Once the root filesystem is loaded, the system enters user mode, starting the <span>init</span> process, which performs the following tasks:

    1. Loading System Configuration

    • Parsing <span>/etc/inittab</span> or systemd configuration to determine startup items.
  • Starting Daemons

    • Starting <span>udevd</span> for dynamic management of hardware devices.
    • Starting <span>networkd</span> to configure the network.
  • Starting Shell or GUI

    • Embedded Linux devices typically start <span>bash</span> or <span>busybox</span> as the shell.
    • Android devices will start <span>surfaceflinger</span> to enter the GUI interface.

    At this point, the boot process of the RK3399 is complete, and the system enters normal operating status.

    9. Conclusion

    The boot process of the RK3399 involves multiple stages, from BootROM to U-Boot, and then to the Linux kernel and user space, with each link being crucial. Developers can optimize boot time by analyzing boot logs, adjusting boot parameters, optimizing U-Boot, and trimming kernel modules.

    For RK3399 developers, understanding the boot process not only helps in debugging boot issues but also provides technical support for customized development. We hope this article serves as a reference for RK3399 development work!

    Leave a Comment