Home / Learn Chip Programming / Device Tree: Describing Hardware to the Kernel

Device Tree: Describing Hardware to the Kernel

A text file tells Linux which chips exist and where.

In shortA text file tells Linux which chips exist and where.

Theory in plain words

Device tree useboard.dtsdtc compileboard.dtbU-Boot passes to kerneldriver binds by "compatible"
Device tree use

What it is

A device tree (.dts) is a data structure that lists CPUs, memory, buses and devices with addresses, interrupts and properties. It is compiled to a .dtb binary that U-Boot passes to the kernel.

Why we use it

The same kernel binary works on many boards because the hardware description is separate. Adding a sensor means adding a node, not changing kernel code.

How it works

Nodes are named device@address; compatible strings select the driver; reg gives the address; interrupts and clocks reference other nodes; status = "okay" enables it.

Where it is used

  • Adding an I2C sensor on Raspberry Pi
  • Custom board bring-up
  • Overlays

Device tree node builder

Generate an I2C sensor nodeTry it Yourself

The node name carries the address; the compatible string selects the driver. After adding it the sensor appears under /sys/bus/iio or /dev.

PropertyMeaning
compatibledriver match string "vendor,model"
regaddress and size (or I2C address)
status"okay" or "disabled"
interrupts / interrupt-parentwhich IRQ line
clocks / resetsreferences to clock and reset controllers
pinctrl-0pin multiplexing setup
gpiosGPIO controller, pin, flags
Tip:On Raspberry Pi you can add overlays in config.txt (dtoverlay=i2c-rtc,ds3231) instead of editing the full tree.

Quick quiz

1. What does "compatible" do?

2. Compiled device tree extension?

Common questions

What does "compatible" do?

Selects the matching driver. The kernel matches it with driver tables.

Compiled device tree extension?

.dtb. Device tree blob.