The Kernel Device Tree is a data structure used by the Linux kernel to describe the hardware components of a system. Instead of hardcoding hardware details (like memory addresses, interrupt lines, and GPIO pins) into the C source code of the kernel, these details are abstracted into Device Tree Source (DTS) files.
DTS Files for Hardware Description
A DTS file is a human-readable text file that describes the topology of the hardware. The kernel reads this structure at boot time to know exactly what hardware is present and how to communicate with it, allowing a single kernel binary to run on multiple slightly different hardware revisions.
A DTS file consists of a tree of nodes and properties:
/ {
model = "Google Pixel 7";
compatible = "google,panther", "arm,armv8";
memory@80000000 {
device_type = "memory";
reg = <0x0 0x80000000 0x0 0x80000000>; /* 2GB at 0x80000000 */
};
soc {
#address-cells = <2>;
#size-cells = <2>;
compatible = "simple-bus";
i2c@1c2b000 {
compatible = "google,gs201-i2c";
reg = <0x0 0x01c2b000 0x0 0x1000>;
interrupts = <0 10 4>;
/* Touchscreen connected to this I2C bus */
touchscreen@4a {
compatible = "synaptics,s3908";
reg = <0x4a>;
interrupt-parent = <&gpio>;
interrupts = <12 2>; /* GPIO 12, edge falling */
};
};
};
};
In this example, the DTS defines the memory layout, an I2C controller within the System-on-Chip (SoC), and a touchscreen device connected to that specific I2C bus, including its interrupt routing.
Integrating DTS with the AOSP Kernel Build
The DTS files (.dts and .dtsi for includes) are typically located in the kernel source tree under arch/arm64/boot/dts/vendor/.
During the kernel compilation process, the Device Tree Compiler (dtc) converts the human-readable text files into a binary format called the Device Tree Blob (DTB).
In modern Android boot architectures (like Generic Kernel Image or GKI), the DTB is appended to the kernel image, placed in a dedicated dtb partition, or bundled into the boot.img. The bootloader loads the DTB into RAM alongside the kernel and passes the memory address of the DTB to the kernel upon execution.
Device Tree Overlays (DTBO)
Because Android devices often have multiple hardware variants (e.g., a US variant and a Global variant with different RF chips) that share the same base SoC, maintaining entirely separate DTS files for each variant becomes unmanageable.
Device Tree Overlays (DTBO) solve this. A base DTB is compiled for the core SoC. Then, smaller overlay files (.dtbo) are compiled to describe the variant-specific hardware modifications.
/* Fragment for a specific variant adding a sensor */
/dts-v1/;
/plugin/;
&i2c_sensor_bus {
status = "okay";
ambient_light@39 {
compatible = "ams,tmd2725";
reg = <0x39>;
};
};
These .dtbo files are usually packed into a dedicated dtbo.img partition.
At boot time, the bootloader reads hardware identification fuses or EEPROMs to determine the exact device variant. It then loads the base DTB and dynamically applies the correct DTBOs in memory before passing the final, merged Device Tree to the Linux kernel. This architecture allows OEMs to build a single firmware image that supports multiple hardware SKUs.