8. Introduction to device tree¶
8.1. Introduction to device tree¶
The function of the device tree is to describe the hardware resources of a hardware platform. This “device tree” can be passed to the kernel by the bootloader (uboot), and the kernel can obtain hardware information from the device tree.
The device tree has two characteristics when describing hardware resources.
First, describe hardware resources in a “tree” structure. For example, the local bus is the “backbone” of the tree and is called the “root node” in the device tree. The IIC bus, SPI bus, and UART bus mounted to the local bus are the “branches” of the tree and are called “child nodes of the root node” in the device tree. There is more than one IIC device under the IIC bus, and these “branches” can be further divided.
Second, the device tree can be like a header file (.h file). One device tree file refers to another device tree file. This enables “code” reuse. For example, multiple hardware platforms use RK3568 as the main control chip, then we can write the hardware resources of the RK3568 chip into a separate device tree file, generally using the “.dtsi” suffix. Other device tree files can be referenced directly using “#includexxx”.
For example, arch/arm64/boot/dts/rockchip/rk3568.dtsi, this file is generally provided by the chip manufacturer, and contains almost all devices and peripheral interfaces in the rk3568 chip. When we use it, we only need to write #include “rk3568.dtsi” in the device tree source file of our board to import all the devices of the rk3568 chip, and then we can modify it according to the peripherals on the board.
8.2. Several common DT¶
DTS refers to a file in .dts format, which is a device tree description in ASII text format and is also the device tree source code we want to write. Generally, one .dts file corresponds to one hardware platform.
DTSI refers to the device tree file provided by the chip manufacturer and “shared” by the same chip platform.
DTC refers to the tool for compiling device tree source code. Generally, we need to install this compilation tool manually.
DTB is a file generated by compiling the device tree source code, similar to the “.bin” file generated by compiling the “.c” file in our C language.
DTBO is a file compiled and generated by the device tree overlay, which can be added to the DTB.
8.3. Node preparation of device tree¶
For detailed writing tutorials, please refer to Linux Device Tree