转自:https://blog.csdn.net/pwl999/article/details/79631434
1、DTS语法
对于DeviceTree的来历和用处大部分人都已经非常了解了,DeviceTree发源于PowerPC架构,为了消除代码中冗余的各种device注册代码而产生的,现在已经成为了linux的通用机制。
DeviceTree的结构非常简单,由两种元素组成:Node(节点)、Property(属性)。下图是一个真实的简单的DeviceTree树形结构图。
这里写图片描述
Node节点。在DTS中使用一对花括号”node-name{}”来定义;
Property属性。在Node中使用”property-name=value”字符串来定义;
/ {
model = "mt6799";
compatible = "mediatek,mt6799";
interrupt-parent = <&gic>;
#address-cells = <2>;
#size-cells = <2>;
/* chosen */
chosen {
bootargs = "console=tty0 console=ttyMT0,921600n1 root=/dev/ram";
};
}
上述例子中定义了一个根节点”/”和一个子节点“chosen”,其他的字符串“model = “mt6799”;”、“compatible = “mediatek,mt6799”;”都是property。
Node、Property的名字和值都是可以自定义的,没有太大限制。但是DeviceTree的标准还是预定义了一些标准的Node和Property,在标准Node和Property之间还定义了一些约束规则。关于这些描述在 The DeviceTree Specification官方spec中有详细描述。这里为了方便大家,还是重复做一些搬运。
1.1、标准Property
Property的格式为”property-name=value”,其中value的取值类型如下:
Property values: Value Description
<empty> Value is empty. Used for conveying true-false information, when the presence of absence of the property itself is sufficiently descriptive.
Property值为空,用property本身出现或者不出现来表示一个treue/false值。
<u32> A 32-bit integer in big-endian format. Example: the 32-bit value 0x11223344 would be represented in memory as:
address 11
address+1 22
address+2 33
address+3 44
32bit的值,用大端格式存储。
<u64> Represents a 64-bit integer in big-endian format. Consists of two <u32> values where the first value contains the most significant bits of the integer and the second value contains the least significant bits.
Example: the 64-bit value 0x1122334455667788 would be represented as two cells as: .
The value would be represented in memory as:
address 11
address+1 22
address+2 33
address+3 44
address+4 55
address+5 66
address+6 77
address+7 88
64bit的值,用大端格式存储。
<string> Strings are printable and null-terminated. Example: the string “hello” would be represented in memory as:
address 68 ‘h’
address+1 65 ‘e’
address+2 6C ‘l’
address+3 6C ‘l’
address+4 6F ‘o’
address+5 00 ‘