Ground Embedded KO Subscribe

Notes / Embedded Linux

Device tree: telling the kernel how the board is put together

A file that records which devices are attached at which addresses and pins. The reason the same kernel can run on many boards.

GROUND EMBEDDED · NOTEEmbedded Linux 04Device tree 1$ make ARCH=arm 2$ insmod gnd_gpio.ko 3[ 1.024] gnd: probe ok 4$ cat /dev/gnd0 50x5A 6$ _

Why it is needed

Board description.dtsCompiled.dtbKernel reads itMatching drivers bound
The same kernel runs on several boards with only the device tree changed.

MCU firmware wrote pin numbers into the code for each board. Linux, to use the same kernel binary on many boards, separates the board configuration into a data file. That is the device tree (.dts → compile → .dtb).

Example: adding a temperature sensor on I2C

&i2c1 {
    status = "okay";
    clock-frequency = <400000>;
    tmp102@48 {
        compatible = "ti,tmp102";
        reg = <0x48>;
    };
};
  • compatible: the kernel finds the driver that matches this string and binds it
  • reg: the address (I2C address, memory-mapped address)
  • status = "okay": turns on a controller that is off by default
RoadmapSee where this note sits in Embedded Linux→

Overlays

Boards such as the Raspberry Pi add expansion-board configuration by laying an overlay (.dtbo) over the base .dtb. A dtoverlay= line in config.txt is exactly that.

Checking

  • After boot, check the tree that was actually applied under /proc/device-tree/
  • Check that the driver bound with dmesg | grep tmp102
  • If the pin-function selection (pinctrl) is missing, the controller is on but no signal reaches the pins
FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →