Devicetree in Modern Operating Systems
In the world of embedded systems and hardware architecture, managing how an operating system interacts with diverse hardware configurations is a significant challenge. Devicetree serves as a standardized method for describing hardware, allowing a single compiled kernel to support various hardware configurations within a broad architecture family without needing to be recompiled for every minor board variation.
How Devicetree Works
The primary goal of a device tree is to move hardware descriptions out of the kernel binary and into a separate data structure. This replaces the need for numerous board-specific C source files and compile-time options. The process involves two main stages:
- Devicetree Source (.dts): A human-readable text file where the hardware is specified. These files can include other source files via device tree source includes.
- Devicetree Blob (.dtb): The .dts file is processed by the Devicetree Compiler (DTC) to create a binary file, also known as a flattened device tree.
During the boot process, the boot loader hands this compiled blob to the kernel, providing the necessary map of the hardware it is running on.
[ไม่มีภาพประกอบ]Devicetree Implementation Across Platforms
Linux
Linux utilizes device trees across a wide array of architectures, including ARM, RISC-V, PowerPC, MIPS, ARC, C6x, H8/300, MicroBlaze, NDS32, Nios II, OpenRISC, SuperH, and Xtensa. On ARM architectures, device trees have been mandatory for all new Systems on a Chip (SoCs) since 2012. This shift addressed the proliferation of Linux and Das U-Boot forks that were previously required to support marginally different ARM boards.
While many ARM-based distributions traditionally required customized boot loaders for specific boards—such as the Raspberry Pi or Hackberry A10—modern SoCs like the Freescale i.MX6 utilize vendor-provided boot loaders that store the device tree on a separate chip from the operating system. Additionally, Devicetree is widely employed in ARM-based Android devices.
Other Operating Systems and Projects
- BSD: Supports device trees, as they are commonly adopted for embedded devices.
- Apple: In the boot sequence for iOS, iPadOS, and ARM-based macOS, the Low-Level Bootloader (LLB) loads an Apple-encrypted devicetree into main memory before loading iBoot.
- Coreboot: This project utilizes device trees, though they differ from the flattened device trees used by the Linux kernel.
- Windows: Unlike the systems mentioned above, Windows does not use DTB files; instead, it relies on ACPI (Advanced Configuration and Power Interface) to discover and manage hardware devices.
Key Facts
- Standardization: Mandatory for new ARM SoCs since 2012 to reduce kernel fragmentation.
- Workflow: .dts (Source) → DTC (Compiler) → .dtb (Binary/Blob).
- Purpose: Separates hardware description from the kernel binary.
- Alternatives: Allwinner SoCs often use a proprietary FEX file format; Windows uses ACPI.
| Platform/OS | Mechanism Used | Notes |
|---|---|---|
| Linux (ARM, RISC-V, etc.) | Devicetree (.dtb) | Mandatory for new ARM SoCs since 2012 |
| Windows | ACPI | Does not use DTB files |
| Apple (ARM macOS/iOS) | Encrypted Devicetree | Loaded by LLB before iBoot |
| Allwinner SoCs | FEX | Proprietary configuration format |
| BSD | Devicetree | Commonly used in embedded contexts |
Frequently Asked Questions
What is the difference between a .dts and a .dtb file?
A .dts (Devicetree Source) file is a human-readable text file used to describe hardware. A .dtb (Devicetree Blob) is the compiled binary version of that file, which the kernel can process efficiently during boot.
Why did ARM make device trees mandatory in 2012?
They were made mandatory to stop the creation of countless forks of Linux and Das U-Boot. By moving hardware descriptions into a separate blob, the same kernel binary can support multiple different boards.
Does Windows use Devicetree?
No, Windows does not use the Devicetree (DTB) system. It uses ACPI to discover and manage its hardware devices.
How does Apple handle device trees in its ARM devices?
Apple uses an encrypted version of the devicetree, which is loaded into the main memory by the Low-Level Bootloader (LLB) during the initial boot process.
What is the role of the DTC?
The DTC, or Devicetree Compiler, is the tool that converts the human-readable .dts source files into the binary .dtb files used by the operating system.