Device Tree(设备树)是一种树型数据结构,用来描述计算机上的硬件信息。使得开发人员可以无需修改系统、驱动、内核代码来适配不同的硬件设备。这篇文章带你5分钟了解DTS文件的配置语法。该文为RK3568平台Android开发从零到上市系列配置实录,请订阅后输入密码查看,订阅方式请见系列目录。
文件类型
.dts
:板级的DTS配置文件,一块板子(只要硬件上有一点差异)对应一个.dts
文件
.dtb
:编译后的二进制dts文件,真正包含在固件中的DTS配置文件,编译内核时自动编译
.dtsi
:可被引用的DTS配置文件,前面说到一块板子对应一个.dts
文件,我们可以将公共部分提取出来放在一个.dtsi
文件里,供板级配置文件引用
DTS语法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
/dts-v1/;
#include "rk3568.dtsi" #include "rk3568-evb.dtsi"
/ { compatible = "";
label: name@address { status = "okay"; compatible = ""; power-supply = <&vcc5v0_sys>; pinctrl-names = "default"; pinctrl-0 = <&bluetooth>; pinctrl-1 = <&uart>
string-key = "value"; number-key = <0>;
sub_label: sub-node@address { }; };
label: name@address { #address-cells = <1>; #size-cells= <0>;
port@0 { reg = <0>; }; port@1 { reg = <1>; }; }; };
|
地址空间举例
1 2 3 4 5 6 7
|
soc { #address-cells = <x>; #size-cells = <y>; serial { reg = <0x0 0x100 0x0 0x200>; } };
|
- 如果x=1, y=1,那么子节点中reg解析为:addr1 = 0x0, size1 = 0x100; addr2 = 0x0, size2 = 0x200
- 如果x=2, y=2,那么子节点中reg解析为:addr1 = 0x100, size1 = 0x200
- 如果x=2, y=0,那么子节点中reg解析为:addr1 = 0x100, addr2 = 0x200
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
/dts-v1/;
#include "rk3568.dtsi" #include "rk3568-evb.dtsi"
/ { model = "Project Alpha"; compatible = "Kuretru,rk3568-alpha", "rockchip,rk3568";
cpus { #address-cells = <2>; #size-cells = <0>; cpu0: cpu@0 { compatible = "arm,cortex-a55"; reg = <0x0 0x0>; }; cpu1: cpu@1 { compatible = "arm,cortex-a55"; reg = <0x0 0x100>; }; }; };
|
删除节点或属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
&node1 { /delete-property/ pinctrl-names; /delete-property/ pinctrl-0; };
&node2 { /delete-node/ ir_key1; /delete-node/ ir_key2; /delete-node/ ir_key3; };
/delete-node/ &rk809_sound; /delete-node/ mxc6655xa@15;
|
如何查找某个设备该配置哪些属性
- 查找其他配置好的DTS文件中是否有定义过类似的设备
1 2 3 4
|
cd kernel/arch/arm/boot/dts/ cd kernel/arch/arm64/boot/dts/rockchip/ grep -n "es8316" *.dtsi
|
- 查找驱动程序的文档
1 2
|
cd kernel/Documentation/devicetree/bindings/ find . -name "*.txt" -exec grep -n -H "es8316" {} \;
|
- 直接查看对应驱动程序的probe函数
1 2 3
|
cd kernel/drivers/ cd kernel/sound/ find . -name "*.c" -exec grep -n -H "rockchip,remotectl-pwm" {} \;
|
编译DTS文件
1 2 3 4 5
|
dtc alpha.dts > alpha.dtb
dtc alpha.dtb > alpha.dts
|