本文档转载于博客:https://blog.csdn.net/u012489236/article/details/97137007。方便查找。
一、DTS基本知识
1、dts
硬件的相应信息都会写在 .dts 为后缀的文件中,每一款硬件可以单独写一份 xxxx.dts,一般在 Linux 源码中存在大量的 dts 文件,对于 arm 架构可以在 arch/arm/boot/dts 找到相应的 dts,一个 dts 文件对应一个 ARM 的 machie。
2、dtsi
对于一些相同的 dts 配置可以抽象到 dtsi 文件中,然后类似于 C 语言的方式可以 include 到 dts 文件中,对于同一个节点的设置情况,dts 中的配置会覆盖 dtsi 中的配置。
注:一般主控芯片的内部外设描述被抽象到 dtsi 文件。
3、dtc
dtc 是编译 dts 的工具,可以在 Ubuntu 系统上通过指令 apt-get install device-tree-compiler 安装 dtc 工具,不过在内核源码 scripts/dtc 路径下已经包含了 dtc 工具;
4、dtb
dtb(Device Tree Blob),dts 经过 dtc 编译之后会得到 dtb 文件,dtb 通过 Bootloader 引导程序加载到内核。所以Bootloader 需要支持设备树才行;Kernel 也需要加入设备树的支持。
二、DTS结构
/dts-v1/;
/ {
node1 {
a-string-property = "A string";
a-string-list-property = "first string", "second string";
// hex is implied in byte arrays. no '0x' prefix is required
a-byte-data-property = [01 23 34 56];
child-node1 {
first-child-property;
second-child-property = <1>;
a-string-property = "Hello, world";
};
child-node2 {
};
};
node2 {
an-empty-property;
a-cell-property = <1 2 3 4>; /* each number (cell) is a uint32 */
child-node1 {
};
};
};
device tree 的基本单元是 node。这些 node 被组织成树状结构,除了 root node,每个 node 都只有一个 parent。一个 device tree 文件中只能有一个 root node。每个 node 中包含了若干的 property/value 来描述该 node 的一些特性。每个 node 用节点名字(node name)标识,节点名字的格式是 node-name@unit-address。如果该 node 没有 reg 属性(后面会描述这个property),那么该节点名字中必须不能包括 @ 和 unit-address。unit-address 的具体格式是和设备挂在那个 bus 上相关。例如对于 cpu,其 unit-address 就是从 0 开始编址,以此加 1。而具体的设备,例如以太网控制器,其 unit-address 就是寄存器地址。root node 的 node name 是确定的,必须是 “/”。
三、DTS语法介绍
了解了基本的 device tree 的结构后,我们总要把这些结构体现在 device tree source code 上来。在 linux kernel 中,扩展名是 dts 的文件就是描述硬件信息的 device tree source file,在 dts 文件中,一个 node 被定义成:
[label:] node-name[@unit-address] {
[properties definitions]
[child nodes]
}
“[]” 表示 option,因此可以定义一个只有 node name 的空节点,label 方便在 dts 文件中引用。
本文详细介绍了Linux设备树DTS的基础知识,包括dts、dtsi、dtc和dtb的概念及作用。dts文件用于描述硬件信息,dtsi用于抽象共通配置,dtc是编译工具,dtb是加载到内核的二进制形式。DTS结构以树形组织,每个节点包含属性和子节点,用于描述硬件特性。此外,还讲解了DTS的语法结构。
7648

被折叠的 条评论
为什么被折叠?



