目录
1. 概念
DT(Device Tree), 是一种描述硬件的数据结构,起源于OpenFirmware(OF)。
DTS(Device Tree Source), 设备树源文件,描述板级硬件资源,由驱动工程师编写。
DTC(Device Tree Compiler), 设备树编译器,编译DTS成DTB
DTB(Device Tree Blob), 设备树的二进制文件,通过boot program传入内核
2. 生命周期
3. DTC编译
dtc编译器可以把dts文件编译成为dtb,也可把dtb编译成为dts文件,编译命令格式如下:
dtc [-I input-format] [-O output-format][-o output-filename] [-V output_version] input_filename
参数说明
input-format:
- “dtb”: “blob” format
- “dts”: “source” format.
- “fs” format.
output-format:
- “dtb”: “blob” format
- “dts”: “source” format
- “asm”: assembly language file
output_version:
定义”blob”的版本,在dtb文件的字段中有表示,支持1 2 3和16,默认是3,在16版本上有许多特性改变
1) dts编译成dtb
./dtc -I dts -O dtb -o xxx.dtb xxx.dts
2) dtb编译生成dts
./dtc -I dtb -O dts -o xx .dts xxx.dtb
编译错误分析:
Error: xxx.dts:1.1-2 syntax error
Is reporting that something is not valid
in file xxx.dts
line 1
columns 1-2
4. 示例
来源:https://e-mailky.github.io/2016-12-06-dts-introduce
/ {
compatible = "acme, coyote-revenge";
#address-cells = <1>;
#size-cells = <1>;
interrupt-parent = <&intc>;
cpus {
#address-cells = <1>;
#sizec-cells = <0>;
cpu@0{
compatible = "arm, cortex-a9";
reg = <0>;
};
cpu@1 {
compatible = "arm, cortex-a9";
reg = <1>;
};
};
serial@101F0000 {
compatible = "arm, pl011";
reg = <0x101f0000, 0x1000>;
interrupts = <1 0>;
};
serial@101F2000 {
compatible = "arm, pl011";
reg = <0x101f2000 0x1000>;
interrupts = <2 0>;
};
gpio@101F3000 {
compatible = "arm, pl016";
reg = <0x101f3000 0x1000 0x101f4000 0x0010>;
interrupts = <3 0>;
};
intc: interrupt-controller@10140000 {
compatible = "arm, pl190";
reg = <0x10140000 0x1000 >;
interrupt-controller;
#interrupt-cells = <2>;
};
spi@10115000 {
compatible = "arm, pl022";
reg = <0x10115000 0x1000 >;
interrupts = <4 0>;
};
external-bus {
#address-cells = <2>;
#size-cells = <1>;
ranges = <0 0 0x10100000 0x10000 // Chipselect 1, Ethernet
1 0 0x10160000 0x10000 // Chipselect 2, i2c controller
2 0 0x30000000 0x1000000>; // Chipselect 3, NOR Flash
ethernet@0,0 {
compatible = "smc, scm91c111";
reg = <0 0 0x1000>;
interrupts = <5 2>;
};
i2c@1,0 {
compatible = "acme, a1234-i2c-bus";
#address-cells = <1>;
#size-cells = <0>;
reg = <1 0 0x1000>;
interrupts = <6 2>;
rtc@58 {
compatible = "maxim, ds1338";
interrupts = <7 3>;
};
};
flash@2,0 {
compatible = "samsung,k8f1315ebm", "cfi-flash";
reg = <2 0 0x4000000>;
};
};
};
5. 参考
版权声明:本文为xhrc007原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。