1 Linux 设备树概述
1.1 Linux 设备树概述
Linux 设备树是一个包含节点和属性的简单树状结构。属性是基于 key-value 对的,
而节点可以同时包含属性和子节点。下面这个树就是一个典型结构:
/ {
node1 {
a-string-property = “A string”;
a-string-list-property = “first string”, “second string”;
a-byte-data-property = [0x01 0x23 0x34 0x56];
child-node1 {
first-child-property;
second-child-property = <1>;
a-string-property = “Hello, world”;
};
child-node2 {
};
};
node2 {
an-empty-property;
a-cell-property = <1 >; /* each number (cell) is a uint32 */
child-node1 {
};
};
};
这棵树没有描述任何东西,但是它体现了节点的一些属性:
一个单独的根节点:“/”
两个子节点:“node1”和“node2”
两个 node1 的子节点:“child-node1”和“child-node2”
一堆分散在树里的属性
可以这么简单理解:节点就是树枝,属性就是树叶;树枝上可以有再长树枝也可以长
树叶,而树叶上则不会再长树枝。
属性是基于 key-value 结构的,value 可以为空或者特定格式的字符串内容。由于数据
类型并不被编码到最终的数据结构中,设备树源代码中仅能支持有限的几种基本数据类
型,如下:
文本字符串(无结束符)可以用双引号表示:
string-property = “a string”
'Cells’是 32 位无符号整数,用尖括号表示:
cell-property = <0xbeef xabcd>
二进制数据用方括号表示:
binary-property = [0x01 0x23 0x45 0x67];
不同表示形式的数据可以使用逗号连在一起:
mixed-property = “a string”, [0x01 0x23 0x45 0x67], <0x12345678>;
逗号也可用于创建字符串列表:
string-list = “red fish”, “blue fish”;