A question that gets to the heart of how Linux boots on ARM-based systems!
Background: What is a Device Tree?
On ARM-based systems, the Device Tree (DT) is a data structure that describes the hardware components of the system, such as:
- CPUs (number, type, frequencies)
- Memory layout (RAM, ROM, flash)
- Peripherals (UART, SPI, I2C, GPIO, etc.)
- Interrupt controllers (GIC, NVIC, etc.)
- Clocks and resets
- Bus topology (platform bus, AMBA bus, etc.)
The Device Tree is essentially a hardware description file that tells the operating system (Linux, in this case) what hardware is present, how it's connected, and how to interact with it.
The Device Tree is usually represented as a Device Tree Source (.dts) file, which is compiled into a Device Tree Binary (.dtb) file using the dtc (Device Tree Compiler) tool. The .dtb file is then loaded by the bootloader (e.g., U-Boot) along with the Linux kernel image.
Traditional Boot Flow with Device Tree
Here's the typical boot flow on an ARM board with Device Tree:
- BootROM (on-chip ROM code): Initializes the CPU, sets up basic clocks, and loads the bootloader (e.g., U-Boot) from a boot medium (e.g., SD card, flash).
- Bootloader (U-Boot):
- Initializes more hardware (e.g., DRAM, serial console).
- Loads the Linux kernel image (
zImage, uImage, or Image) and Device Tree Binary (.dtb) from storage into RAM.
- Passes the DTB address and kernel boot arguments (e.g.,
console=ttyS0,115200) to the kernel via registers (e.g., r0, r1, r2 on ARM).
- Jumps to the Linux kernel entry point.
- Linux kernel:
- Uncompresses itself (if necessary).
- Unflattens the Device Tree: interprets the DTB, creating an in-memory representation of the hardware topology.
- Uses the DT info to detect and initialize hardware components (e.g., serial console, GPIO, network).
- Continues booting: mounts rootfs, starts init, etc.
Booting without Device Tree ( legacy "ATAGS" mode)
Now, to boot Linux without a Device Tree on an ARM board, we need to fall back to the legacy boot method, also known as "ATAGS" mode (short for "ARM Tags"). This method was used before Device Trees became the norm (pre-2008, roughly).
Here's the modified boot flow:
- BootROM: Same as above.
- Bootloader (U-Boot):
- Initializes hardware (as above).
- Loads the Linux kernel image (no DTB this time).
- Creates a ATAGS (ARM Tags) list in RAM, which is a linear, simple data structure containing essential boot information:
ATAG_CORE: basic board info (e.g., machine ID, CPU count).
ATAG_MEM: memory region descriptions (start, size).
ATAG_CMDLINE: kernel command line (boot arguments, e.g., console=ttyS0,115200).
ATAG_RAMDISK (optional): ramdisk info (address, size).
- Passes the ATAGS list address and kernel boot arguments via registers (e.g.,
r0, r1, r2 on ARM).
- Jumps to the Linux kernel entry point.
- Linux kernel:
- Uncompresses itself (if necessary).
- Parses the ATAGS list: extracts boot information (memory layout, command line, etc.).
- Uses a MACH- (Machine) type static board file (
.c file, compiled into the kernel) to:
- Identify the machine type (e.g.,
arch/arm/mach-s3c24xx/mach-smdk2410.c for an SMDK2410 board).
- Hardcoded initialization for that specific board (e.g., UART, GPIO, clocks).
- Continues booting: mounts rootfs, starts init, etc.
Key requirements for ATAGS boot:
- Kernel configuration:
CONFIG_ARM_ATAG_DTB_COMPAT must be set in the kernel .config. This option allows the kernel to boot with ATAGS instead of DT.
- MACH-type static board file: The kernel must have a matching MACH-type file (under
arch/arm/mach-*) for your specific board. This file contains the hardcoded board initialization routines.
- Bootloader support: The bootloader (e.g., U-Boot) must be configured to create and pass the ATAGS list instead of loading a DTB.
Caveats and Why You Should Use Device Trees
While booting without a Device Tree is still possible, it's strongly discouraged for new designs:
- Maintenance nightmare: Each board variant requires custom kernel modifications (MACH-type files), leading to forks and diverged codebases.
- Inflexibility: Adding new hardware or changing the board layout requires kernel rebuilds.
- Limited scalability: As the number of boards grows, so does the kernel's complexity and build time.
In contrast, Device Trees:
- Decouple kernel from board-specific details.
- Simplify board bring-up (just modify the
.dts file).
- Enable bootloader/kernel genericity (less board-specific code).
In conclusion: While booting Linux on ARM without a Device Tree is possible using the legacy ATAGS method, it's recommended to use Device Trees for any new projects or boards. The flexibility, scalability, and maintainability benefits far outweigh the slightly increased boot complexity.
Hope this detailed explanation helps! Let me know if you have further questions.