Skip to content
systemcoding.dev
Embedded Linux

What a Device Tree Is and Why ARM Boards Need One

A device tree is a data file that tells the Linux kernel what hardware a board has, because ARM chips cannot be probed. Learn what is in it and why it exists.

6 min read
Summarize in AI
Flat illustration of a single-board computer with its SoC, memory, header and ports, with the Arm, Linux and NXP logos.

Plug a USB stick into a PC and the kernel finds it. Boot the same kernel on a Raspberry Pi and it also finds the USB controller, the UART and the Ethernet chip, without anyone compiling a special kernel for that model. The first system, the PC, discovers its hardware by asking it. The second, an ARM board, cannot ask, and a file called the device tree answers instead. This post explains the problem the device tree solves, what the file contains, how it travels from the build to the kernel and what it does not do. It assumes no prior knowledge of embedded Linux, and the examples use Linux 6.12 on a 64-bit ARM board.

The problem: hardware you cannot ask about

A PC has a bus that is self describing. PCI devices answer a configuration query with a vendor and device identifier, USB devices announce themselves when plugged in, and ACPI tables from the firmware list what is soldered on the motherboard. The kernel walks these structures and loads the matching drivers.

An ARM system on a chip (SoC) has no such structure. The UART, the I2C controller, the interrupt controller and the clock generator are blocks of silicon placed at fixed physical addresses, and the chip gives no way to ask "what is at 0x10000000?". Reading an address that holds nothing can hang the bus. So the kernel needs somebody to tell it: there is a UART at this address, it uses interrupt number 33, it is clocked from this clock and it is wired to these two pins.

Before about 2011, that information was C code inside the kernel. Each board had its own file under arch/arm/mach-*/ with hand written tables of devices, and every new board meant a kernel patch. The tree grew by thousands of files, and in 2011 Linus Torvalds objected publicly to the churn. The answer was to move the description out of C and into data: the device tree, a format borrowed from the Open Firmware standard used on PowerPC machines. ARM, ARM64 and RISC-V now use it as the normal way to describe hardware.

What a device tree is

A device tree is a hierarchy of nodes, each describing one piece of hardware or one bus, and each node carries properties that state facts about it. The text form is called device tree source, a .dts file. Here is a small, complete example that describes a UART:

uart-example.dtsdts
/dts-v1/;

/ {
	compatible = "acme,example-board";
	#address-cells = <1>;
	#size-cells = <1>;

	serial@10000000 {
		compatible = "ns16550a";
		reg = <0x10000000 0x100>;
		interrupts = <33>;
		clock-frequency = <24000000>;
		status = "okay";
	};
};

Reading it line by line:

  • / { ... }; is the root node. Every tree has exactly one.

  • compatible is a string that names the hardware. The kernel matches it against driver tables to pick the code that handles the device.

  • #address-cells and #size-cells say how many 32-bit numbers an address and a size take in the children of this node. Here one each.

  • serial@10000000 is a child node. The part before @ is a generic name, and the part after is the unit address, which repeats the first address in reg.

  • reg = <0x10000000 0x100> gives the base address and the length of the register block: 256 bytes starting at 0x10000000.

  • interrupts and clock-frequency are facts the driver needs, and status = "okay" says the device is enabled.

Nothing here is code. It is a table, and that is the point: the same kernel image can run on a board with a UART at 0x10000000 and on one with the UART somewhere else, because the difference lives in a data file.

From source to the kernel

The source is compiled by the device tree compiler, dtc, into a compact binary called a device tree blob, with the extension .dtb:

Shell
dtc -I dts -O dtb -o uart-example.dtb uart-example.dts

In a kernel build, make dtbs does this for every board that is configured, and the outputs land in arch/arm64/boot/dts/<vendor>/. The bootloader, usually U-Boot, loads the blob into RAM next to the kernel and passes its address in a register when it jumps to Linux. On arm64 that register is x0. The kernel parses the blob very early, before most of its own code has run, and builds its internal view of the hardware from it.

You can see the result on a running system. The kernel exposes the tree as a directory of files:

Shell
ls /proc/device-tree/
cat /proc/device-tree/model
Text
#address-cells  #size-cells  chosen  compatible  cpus  interrupt-controller@8000000  memory@40000000  model  name  serial@10000000
Acme Example Board

The listing is what the board's tree defines, so yours will differ. model is a human readable string, and the directory names are the nodes. The kernel uses the tree for more than drivers: the memory size, the CPU list and the kernel command line (/chosen/bootargs) all come from it.

Matching drivers to the description

The link between a node and a driver is compatible. A driver announces which strings it handles in a table:

c
static const struct of_device_id ns16550_of_match[] = {
	{ .compatible = "ns16550a" },
	{ }
};
MODULE_DEVICE_TABLE(of, ns16550_of_match);

At boot, the kernel creates a platform device for each node whose status is okay (or absent), then finds a driver whose table contains one of the node's compatible strings and calls its probe() function. The driver reads reg and interrupts from the node and uses them, instead of hard coded addresses. This arrangement means a driver does not know where its device is. It only knows how to run one.

Why ARM boards in particular

x86 PCs avoid the problem through a firmware layer, the BIOS or UEFI with ACPI, standardized by industry groups since the 1990s. ARM never had one standard platform. Phones, routers, set top boxes and single board computers each had their own bootloader and a different memory map. Server class ARM hardware did adopt UEFI and ACPI later, and the kernel supports both on arm64, but nearly every embedded ARM board still ships with a device tree. RISC-V followed ARM here, and so did several MIPS and PowerPC systems.

What the device tree does not do

It does not describe things the hardware can announce itself. A PCIe card plugged into a slot is found by enumeration, and the device tree only describes the PCIe controller. It does not contain driver code, and a node for a device does not make the device work: the driver must exist in the kernel or as a module, and its dependencies, such as the clock and the pin controller, must be described too. And it is not a configuration file for the user: it describes the hardware as built, so a setting like a network address belongs in userspace.

The failure you will hit first is a node with no driver. The device shows in /proc/device-tree and nowhere else, because nothing claimed it. The tools that connect the two are in /sys/bus/platform/devices/, where a bound device has a driver link.

When this advice does not apply: on a PC, a server with ACPI or any system where the firmware provides a full hardware description, you will rarely edit a device tree, and lspci and lsusb replace it for diagnosis.

Share

Keep reading

Flat illustration of user space above the system call boundary, the kernel and the hardware, with the Linux, C and GNU logos.
Kernels

Write a Pin Controller Driver With pinctrl

Write a Linux 6.12 pin controller driver: pinctrl_desc, pins, groups and functions, the set_mux callback, and the device tree states that consumers select.

8 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.