设备树示意图:
一 DTS 文件布局(layout):
/dts-v1/; // 表示版本 [memory reservations] // 格式为: /memreserve/ <address> <length>; / { //"/"表示根,”{};“表示节点。 [property definitions] [child nodes] };
多节点布局:
/dts-v1/; /{ cpu{ }; memory{ }; i2c{ }; ....... };
二 节点的格式:设备树中的基本单元,被称为“node”,其格式为:
[label:] node-name[@unit-address] {
[properties definitions]
[child nodes]
};
1 label 是标号,可以省略。label 的作用是为了方便地引用 node,比如:
/dts-v1/; / { uart0: uart@fe001000 { compatible="ns16550"; reg=<0xfe001000 0x100>; }; };
可以使用下面 2 种方法来修改 uart@fe001000 这个 node:
// 在根节点之外使用 label 引用 node: &uart0 { status = “disabled”; }; 或在根节点之外使用全路径: &{/uart@fe001000} { status = “disabled”; };
2 properties 的格式
简单地说,properties 就是“name=value”,value 有多种取值方式。
① Property 格式 1:[label:] property-name = value;
② Property 格式 2(没有值):[label:] property-name;
Property 取值只有 3 种:
arrays of cells(1 个或多个 32 位数据, 64 位数据使用 2 个 32 位数据表示), string(字符串), bytestring(1 个或多个字节)
示例:
a. Arrays of cells : cell 就是一个 32 位的数据,用尖括号包围起来
interrupts = <17 0xc>;
b. 64bit 数据使用 2 个 cell 来表示,用尖括号包围起来:
clock-frequency = <0x00000001 0x00000000>;
c. A null-terminated string (有结束符的字符串),用双引号包围起来:
compatible = "simple-bus";
d. A bytestring(字节序列) ,用中括号包围起来:
local-mac-address = [00 00 12 34 56 78]; // 每个 byte 使用 2 个 16 进制数来表示 local-mac-address = [000012345678]; // 每个 byte 使用 2 个 16 进制数来表示
e. 可以是各种值的组合, 用逗号隔开:
compatible = "ns16550", "ns8250"; example = <0xf00f0000 19>, "a strange property format";