Try Embedded

The Linux boot process

ROM code, U-Boot, the kernel, initramfs and init.

From power-on to a login prompt

An embedded Linux board (a Raspberry Pi, a BeagleBone, an i.MX, STM32MP1 or Rockchip-based product) boots through a chain of stages. Each stage initialises just enough hardware to load the next, larger one. When a board does not boot, the first question is always "which stage stopped?", and the serial console answers it.

Boot ROM  ->  SPL / first-stage loader  ->  U-Boot  ->  Linux kernel  ->  initramfs (optional)  ->  rootfs + init  ->  services
(in chip)     (in internal SRAM)            (in DRAM)

1. Boot ROM

Code burned into the SoC at manufacture. It reads boot-mode pins or fuses to choose a boot device (SD card, eMMC, NAND, SPI NOR flash, USB, UART recovery), loads the first-stage loader into the SoC's small internal SRAM (tens to hundreds of KB) and runs it. On secure-boot-enabled parts it first verifies the loader's signature against a key hash in fuses.

DRAM is not usable yet: its controller needs board-specific timing parameters.

2. First-stage loader (SPL, TF-A, MLO)

A small program that fits in internal SRAM. Its main job is initialising DRAM (timing, training), then loading the full bootloader into DRAM. Names vary: U-Boot SPL, MLO on TI parts, and on Arm64 parts the Trusted Firmware-A (TF-A) stages, which also set up the secure world (OP-TEE) before handing over.

3. U-Boot

U-Boot, the standard embedded Linux bootloader, runs from DRAM with drivers for storage, network, USB and display. It:

  1. reads its environment (variables such as bootcmd and bootargs) from flash
  2. loads the kernel image, the device tree blob (DTB) and optionally an initramfs into memory, from storage or over the network (TFTP, useful in development)
  3. optionally verifies signatures (FIT images with verified boot)
  4. passes the kernel command line and DTB address, and jumps to the kernel
=> printenv bootcmd
bootcmd=run mmcboot
=> setenv bootargs console=ttymxc0,115200 root=/dev/mmcblk0p2 rootwait ro
=> load mmc 0:1 ${kernel_addr_r} zImage
=> load mmc 0:1 ${fdt_addr_r} board.dtb
=> bootz ${kernel_addr_r} - ${fdt_addr_r}

Pressing a key during the countdown stops at the U-Boot prompt, which is invaluable for recovery and debugging. Products often disable it or protect it with a password.

4. The kernel

The kernel decompresses itself, sets up memory management and the MMU, then initialises subsystems and drivers. It learns what hardware exists from the device tree passed by the bootloader, matching each node's compatible string to a driver.

The kernel command line (bootargs) controls key choices:

ParameterMeaning
console=ttyS0,115200Where kernel messages go
root=/dev/mmcblk0p2The root filesystem device
rootfstype=ext4Filesystem type
rootwaitWait for the root device to appear (slow SD/USB)
ro / rwMount root read-only or read-write
init=/sbin/initThe first userspace program
quiet, loglevel=Console verbosity

The famous failure, Kernel panic - not syncing: VFS: Unable to mount root fs, means the kernel could not find or mount the root filesystem: wrong root=, a missing storage or filesystem driver (built as a module that is not available yet), or a missing rootwait.

5. initramfs (optional)

An initramfs is a small filesystem archive loaded into RAM with the kernel. The kernel runs its /init before the real root is mounted. It is used to:

  • load modules needed to reach the root filesystem
  • unlock encrypted storage, assemble RAID or LVM
  • choose between A/B root partitions, or run a recovery or factory-reset environment
  • check filesystem integrity (dm-verity) before switching root

When done, it mounts the real root and calls switch_root to continue. Many simple embedded systems skip it and mount root directly.

6. init and userspace

The kernel starts the first process, PID 1, from the root filesystem. Common choices:

initTypical system
systemdLarger systems; parallel start, dependencies, journald, watchdog integration
BusyBox init + shell scriptsSmall systems; /etc/inittab, /etc/init.d/rcS
SysVinitOlder systems
A custom application as PID 1Single-purpose appliances

init mounts remaining filesystems, starts services (networking, logging, the application) and, if configured, a login shell on the console.

Measuring and reducing boot time

Products often need to boot in a few seconds. Measure first:

dmesg | head            # kernel timestamps
systemd-analyze blame   # slowest services
systemd-analyze critical-chain

Typical savings: shorten or remove the U-Boot delay, remove unused kernel drivers and features, build in (rather than as modules) what boot needs, use a faster or compressed-appropriately kernel image, avoid probing absent hardware, start the critical application early, defer non-essential services, and use a read-only root that needs no filesystem check.

#include <stdio.h>

int main(void) {
  /* A boot-time budget, in milliseconds, before and after typical optimisations. */
  const char *stage[] = { "ROM + SPL + DRAM init", "U-Boot (incl. delay)", "kernel to init", "init to application" };
  int before[] = { 350, 3200, 2600, 4100 };
  int after[]  = { 350,  300, 1100,  600 };
  int tb = 0, ta = 0;
  for (int i = 0; i < 4; i++) {
    printf("%-22s %5d -> %4d ms\n", stage[i], before[i], after[i]);
    tb += before[i]; ta += after[i];
  }
  printf("%-22s %5d -> %4d ms\n", "total", tb, ta);
  return 0;
}

Pitfall: Without a serial console you are debugging boot problems blind. Bring out the debug UART on every board revision, including production hardware (on a test pad if needed).

Interview question: Describe the embedded Linux boot sequence.

Answer: The SoC's boot ROM reads the boot-mode pins or fuses, loads a first-stage loader (U-Boot SPL or TF-A) from the boot device into internal SRAM and optionally verifies it. That loader initialises DRAM and loads U-Boot. U-Boot reads its environment, loads the kernel, device tree blob and optional initramfs, sets the kernel command line and jumps to the kernel. The kernel initialises memory management and drivers according to the device tree, runs the initramfs's /init if present, mounts the root filesystem and starts PID 1 (systemd or BusyBox init), which brings up services and the application.

Interview question: The kernel panics with "VFS: Unable to mount root fs". What do you check?

Answer: The root= argument in the kernel command line (correct device and partition, which may be named differently, such as mmcblk0 versus mmcblk1), whether the kernel has the storage controller and filesystem drivers built in rather than as modules unavailable before root is mounted, whether rootwait is needed for slow devices, the rootfstype, whether the partition actually contains a valid filesystem, and whether the device tree enables the storage controller. The earlier kernel log usually shows which block devices were detected.

Build it: boot the right root filesystem, and fall back

This is step 1 of the module project, a smart-home gateway: a small Linux board that talks Zigbee to the lamps and sensors in a house and connects them to the owner's phone. It has two root filesystems on its eMMC, A on partition 2 and B on partition 3, and updates are written to the one not running. A new system that does not come up must not leave the house dark, so the bootloader counts boots, the way U-Boot's bootcount and bootlimit do.

Lab: Choose the slot, count the tries, build the command line

The environment the bootloader keeps holds the current slot ('A' or 'B'), a bootcount, a bootlimit, and upgrade_available, set by the updater after it switched slots to a freshly written system.

  • boot_select(env) runs at every boot and returns the slot to boot. Only while upgrade_available is set: add 1 to bootcount, and once it is greater than bootlimit, the new system has failed too often: switch back to the other slot, clear upgrade_available and set bootcount to 0.
  • boot_mark_good(env) is what the gateway's software calls once it is fully up (connected, Zigbee running): clear upgrade_available and bootcount.
  • boot_cmdline(out, cap, slot, quiet) writes the kernel command line, console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait ro for slot A, with p3 for slot B, and quiet appended when quiet is set. Return its length, or -1 when it does not fit in cap bytes with its terminating zero: a cut-off command line can boot the wrong root, or none.

Going deeper

Interview question: A smart home hub sometimes fails to boot after a power cut. How would you make it robust?

Answer: Use A/B root file systems with a boot counter in the bootloader, so a failed boot falls back to the last good image; keep the root file system read-only with writable data on a journalled partition; and run a hardware watchdog from the bootloader onwards. Then test with hundreds of random power cuts.

Interview question: What is a FIT image in U-Boot?

Answer: A Flattened Image Tree packages the kernel, one or more device trees, an initramfs and configurations into one file described by a device-tree-like structure, with hashes and optional signatures for each component. U-Boot can verify the signatures before booting (verified boot) and choose a configuration for the board, making it the standard format for secure and multi-board Linux boot.

Interview question: How would you speed up a slow embedded Linux boot?

Answer: Measure first with timestamps in the bootloader, dmesg and systemd-analyze. Then remove the U-Boot delay, load the kernel from fast storage, trim the kernel configuration and build in what is needed at boot, avoid probing absent hardware, skip filesystem checks with a read-only root, reduce or parallelise init scripts and services, and start the critical application first. Falcon mode can skip U-Boot entirely.

Explain it: In your own words, explain why an embedded Linux board needs several boot stages.

Answer: When the chip powers up only its small internal ROM and SRAM work; the large external DRAM needs board-specific setup before it can be used. So the boot ROM loads a tiny first-stage loader into internal SRAM, whose main job is to initialise DRAM. That loader then loads a full bootloader such as U-Boot into DRAM, which has drivers for storage and network and loads the kernel and device tree. Each stage brings up just enough hardware to load the next, larger one.