[ ← BACK TO TUTORIALS ]

Raspberry Pi Zero 2 W Boot Process: A Bare Metal Guide

If you have ever built a custom operating system or dug into low-level digital forensics, you know that understanding how a device wakes up is just as important as the OS it runs.

The Raspberry Pi Zero 2 W is a favorite for lightweight cybersecurity tools and headless servers. But unlike a standard desktop PC that relies on a traditional BIOS or UEFI, the Raspberry Pi utilizes a unique, GPU-centric architecture.

In this guide, we are going to break down the exact seven-stage "handshake" protocol that brings the Broadcom System-on-Chip (SoC) to life, from the moment voltage hits the board to the second your custom Linux command prompt appears.


πŸ—οΈ The Master and the Peripheral

Before we look at the stages, you have to invert how you think about computer architecture. On a standard x86 motherboard, the CPU is the master. On the Raspberry Pi, the Broadcom VideoCore GPU is the captain of the ship.

When you plug in the power ⚑, the main ARM Cortex-A53 processor is completely inactive. It is up to the GPU to prepare the environment, initialize the memory, and ultimately wake the CPU up. Here is exactly how that relay race happens:

πŸŸ₯ Stage 1: The Mask ROM (The Root of Trust)

When 5V power is applied, a tiny fragment of hardwired instructions deep inside the silicon wafer wakes up the GPU. This is the Mask ROM.

🟧 Stage 2: Waking the RAM (bootcode.bin)

At this millisecond, the Pi has absolutely no working system memory. The GPU loads bootcode.bin into its own internal cache.

🟨 Stage 3: The GPU Firmware (start.elf)

With the RAM active, the GPU loads start.elf. This is the most complex piece of closed-source, proprietary firmware on the board.

🟩 Stage 4: Your Hardware Control Panel (config.txt)

Before the GPU considers waking up the main ARM processor, it reads a plain-text file called config.txt.

Think of this as the equivalent of pressing "Delete" to enter your BIOS settings. By defining parameters here, you dictate how the hardware behaves before the OS even exists πŸ› οΈ.

For example, if you are building a headless cybersecurity tool and want to maximize the RAM available for your scripts, you can shrink the GPU's memory allocation and enable the serial console with just two lines:

πŸ’» gpu_mem=16
πŸ”Œ enable_uart=1

🟦 Stage 5: The CPU Takeover (kernel8.img)

This is the grand finale of the hardware bootloader. The GPU locates your compiled operating system kernel (typically kernel8.img for a 64-bit environment).

From this millisecond forward, your operating system is officially in charge. The GPU respectfully steps back into a supporting role.


🐧 The Transition: From Bare Metal to Linux

At the end of Stage 5, we officially leave the "hardware firmware" phase and enter the Software Phase. Here is how your custom Linux operating system stands itself up.

πŸŸͺ Stage 6: Kernel Initialization and the Device Tree (The Bridge)

The Linux kernel is the engine, but when it first wakes up, it is essentially blind πŸ¦‡. It doesn't know what kind of board it is running on.

🟫 Stage 7: PID 1 and "Userland" (The Embedded init Phase)

Now the system has to cross the boundary from "Kernel Space" (privileged, low-level) to "User Space" 🌍 (where your full commands, scripts, and cybersecurity tools actually run).

To do this, the kernel executes the very first program on the system, typically /sbin/init. It is permanently assigned Process ID 1 (PID 1). In a custom, lightweight embedded OS tailored for the Pi Zero, PID 1 is handled by a streamlined init system that follows a strict, sequential script:

  1. πŸ—‚οΈ Mounting the API Filesystems: The init program immediately creates the "virtual" filesystems: /proc, /sys, and /dev. These live in the Pi's RAM and allow your standard commands (like fdisk or ps) to see the hardware and running processes.
  2. πŸ“œ The Blueprint (/etc/inittab): The init program reads a single configuration file containing the master instructions for the boot sequence.
  3. πŸƒ The Master Startup Script (/etc/init.d/rcS): Your custom Pi OS runs a master startup script that executes commands sequentially:
  4. It populates your /dev folder with your physical hardware nodes.
  5. It brings up the Wi-Fi interface (wlan0) πŸ“‘ and requests an IP address.
  6. It launches a lightweight SSH daemon πŸ”‘, opening port 22 for remote access.
  7. (Note: Because this runs sequentially, you can inject custom packet-sniffing or security scripts right here to execute with root privileges before login).
  8. πŸ’» The Shell (The Prompt): Finally, init spawns a getty process on your active terminal (UART serial or HDMI). This handles the login prompt. Once authenticated, it drops you into your full command-line shell (like Bash), with the vast majority of your RAM completely free.

🏁 Why Custom OS Engineers Care

By understanding this entire pipeline, you can see exactly how a 5-volt power source turns into a functional, hacking-ready embedded Linux machine in just a few seconds.

Phase Stage Active Component Primary Action
🧱 Hardware 1. Mask ROM GPU Hardwired root of trust; looks for SD card.
πŸ’½ Firmware 2. bootcode.bin GPU Initializes and stabilizes the 512MB SDRAM.
πŸ’½ Firmware 3. start.elf GPU Hidden RTOS takes over board power/thermals.
πŸ› οΈ Config 4. config.txt GPU Applies your custom hardware limits (e.g., gpu_mem=16).
🀝 Handoff 5. kernel8.img CPU GPU copies Linux to RAM and wakes up the ARM CPU.
🐧 Kernel 6. Device Tree / VFS CPU Kernel maps the hardware and mounts your rootfs.
πŸ§‘β€πŸ’» Userland 7. The init Process CPU Sequential scripts mount /sys, start Wi-Fi/SSH, and spawn the Bash login prompt.

🎯 The Domino Effect: Your Role as the OS Architect

Think of the boot process like setting up a line of dominoes 🎲. When you plug the Pi into the wall πŸ”Œ, gravity (the hardware) knocks all the dominoes down automatically from Stage 1 to 7. The Pi "takes care of everything" during the actual boot-up.

However, as the custom OS engineer, you have to manually design and place dominoes 4, 5, 6, and 7 before you ever plug the power cable in 🧠.

Here is the exact breakdown of who does what before the Pi boots:

πŸ›‘ The "Hands-Off" Stages (Broadcom’s Job)

You do not code, alter, or compile anything here. Buildroot simply downloads these pre-made files and puts them on your SD card.

πŸ› οΈ The "Hands-On" Stages (Your Job)

If you do nothing here, the boot process will fail or run poorly. You must "do something" for these stages during your Buildroot setup:

🏁 The Bottom Line

Once the SD card is flashed and inserted, the Pi Zero takes care of the entire 7-stage sequence in less than 5 seconds without you touching a keyboard ⚑. But to get to that point, you are the architect responsible for engineering stages 4 through 7! πŸš€