The boot process in Linux and Raspberry Pi involves a series of steps that load the operating system and prepare the system for use. This topic introduces the key stages of booting, focusing on how Linux and Raspberry Pi initialize hardware, load the kernel, and start essential services.
When a Linux computer is powered on, the boot process begins with the firmware:
Power-On and POST(Power-On Self Test): The system performs basic hardware checks to ensure all computers like CPU, RAM, and connected devices are functioning properly.
Device Detection: The BIOS/UEFI detects all hardware components connected to the system, including CPU, RAM, and storage devices.
Boot Device Selection: The firmware determines the boot device according to the configured priority order, which can be a hard drive, SSD, USB drive, or even network boot.
BIOS/UEFI runs the boot loader (GRUB): which provides a menu to choose the OS or the kernel functions.
After the firmware identifies the boot device, the process moves to the boot loader stage:
Boot Loader Loading: The firmware locates and loads the boot loader (typically GRUB2-Grand Unified Bootloader) from the boot device into RAM
Boot Menu Display: The boot loader displays a menu allowing users to select an operating system or kernel to boot. If there's no interaction, the system automatically selects the default entry after a configured timeout.
Kernel and initramfs Loading: The boot loader loads the Linux kernel and initramfs (initial RAM file system) into memory.
Control Transfer: The boot loader transfers control to the Linux kernel to continue the boot process.
When the Linux kernel is loaded into memory and receives control, it performs the following tasks:When the Linux kernel is loaded into memory and receives control, it performs the following tasks:
Decompression and Initialization: The kernel decompresses itself in memory and begins initialization.
Hardware Initialization: The kernel initializes and configures computer memory and all connected hardware.
Temporary Filesystem Mounting: The kernel mounts the temporary RAM filesystem (initramfs) to access necessary drivers and modules before mounting the actual root filesystem.
Device Driver Loading: The kernel loads essential drivers for storage devices, network interfaces, and peripherals.
Root Filesystem Mounting: The kernel mounts the root filesystem (/) from disk, initially in read-only mode.
Transition from initramfs to Real Filesystem: The kernel performs pivot_root() to switch from the temporary filesystem to the actual root filesystem.
When a Raspberry Pi 4 is powered on, the boot process begins with the VideoCore GPU:
BCM2711 Activation: Upon power-up, the BCM2711 chip is activated with the VPU (VideoCore Processing Unit) core powered on, while the ARM CPU cores remain in a powered-down state.
Boot ROM Execution: The program counter is set to address 0x60000000, which maps to the on-chip boot ROM. The VPU initially runs at a low frequency (54MHz) and performs basic initialization tasks.
OTP Registers Check: The Boot ROM reads One-Time Programmable (OTP) registers related to the boot process (specifically registers 17/18, 66, and 67).
The Raspberry Pi 4 differs from earlier Pi models in that it uses an EEPROM chip to store the bootloader:
Recovery.bin Check: The Boot ROM checks for a recovery.bin file on the first FAT partition of the SD card. This provides a mechanism to recover the device if the EEPROM becomes corrupted.
Firmware Loading from EEPROM: The Boot ROM loads firmware from the Winbond W25X40 EEPROM chip via the SPI0 protocol on GPIO pins 40-43.
USB Recovery Mode: If previous steps fail, the chip enters USB device mode (via the USB Type-C port) and waits to receive a recovery image from a USB host.
When the Linux kernel is loaded into memory, the process moves to the final stage:
CPU Wake-up: The GPU wakes up the ARM CPU cores.
Control Transfer: Control is transferred from the GPU to the ARM CPU. Until this point, all processes run on the GPU, but from here on, the kernel runs on the ARM.
System Startup: The Linux kernel boots and initiates the init process, which starts up the entire system.
An important feature of the Raspberry Pi 4 is its ability to boot from USB SSDs, which can significantly improve performance compared to SD cards:
EEPROM Update: To boot from USB, you need to ensure the bootloader EEPROM has been updated to a version that supports USB booting (versions from 09-03-2020 onwards).
BOOT_ORDER Configuration Check: The default BOOT_ORDER code is 0xf41, read from right to left: 1 = Try SD card, 4 = Try USB mass storage, f = Restart.
OS Image Copying: Use the SD Card Copier tool to copy the entire operating system from the SD card to the USB SSD.
Comments