第二课.设备树的规范(dts和dtb)

it2023-06-07  72

设备树的规范dts和dtb

第01节_DTS格式第02节_DTB格式

第01节_DTS格式

(1) 语法: Devicetree node格式:

  [label:] node-name[@unit-address] {      [properties definitions]      [child nodes]   };

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”;

(2) DTS文件布局(layout): /dts-v1/;

[memory reservations]    // 格式为: /memreserve/ <address> <length>; / {    [property definitions]    [child nodes] };

(3) 特殊的、默认的属性: a. 根节点:

#address-cells    // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address) #size-cells       // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size) compatible      // 定义一系列的字符串, 用来指定内核中哪个machine_desc可以支持本设备             // 即这个板子兼容哪些平台             // uImage : smdk2410 smdk2440 mini2440 ==> machine_desc model         // 咱这个板子是什么              // 比如有2款板子配置基本一致, 它们的compatible是一样的              // 那么就通过model来分辨这2款板子

b. /memory

device_type = “memory”; reg         // 用来指定内存的地址、大小

c. /chosen

bootargs      // 内核command line参数, 跟u-boot中设置的bootargs作用一样

d. /cpus

/cpus节点下有1个或多个cpu子节点, cpu子节点中用reg属性用来标明自己是哪一个cpu,所以 /cpus 中有以下2个属性: #address-cells    // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address) #size-cells     // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)           // 必须设置为0

e. /cpus/cpu*

device_type = “cpu”; reg          // 表明自己是哪一个cpu

(4) 引用其他节点:

a. phandle : // 节点中的phandle属性, 它的取值必须是唯一的(不要跟其他的phandle值一样)

pic@10000000 {    phandle = <1>;    interrupt-controller; }; another-device-node {    interrupt-parent = <1>; // 使用phandle值为1来引用上述节点 };

b. label:

PIC: pic@10000000 {    interrupt-controller; }; another-device-node {    interrupt-parent = <&PIC>;   // 使用label来引用上述节点,                 // 使用lable时实际上也是使用phandle来引用,                   // 在编译dts文件为dtb文件时, 编译器dtc会在dtb中插入phandle属性 };

官方设备树格式文档手册



第02节_DTB格式

Documentation/devicetree/booting-without-of.txt,emsp; 内核设备树文档目录

------------------------------ base -> | struct boot_param_header | ------------------------------ | (alignment gap) (*) | ------------------------------ | memory reserve map | ------------------------------ | (alignment gap) | ------------------------------ | | | device-tree structure | | | ------------------------------ | (alignment gap) | ------------------------------ | | | device-tree strings | | | -----> ------------------------------ | | --- (base + totalsize)
以上内容参考自韦东山老师设备树的教学资料
最新回复(0)