1、设备树格式
- 设备树节点的node格式
[label:] node-name[@unit-address] {
[properties definitions]
[child nodes]
};
例子:
1150 fusb0: fusb30x@22 {
1151 compatible = "fairchild,fusb302";
1152 reg = <0x22>;
1153 pinctrl-names = "default";
1154 pinctrl-0 = <&fusb0_int>, <&fusb0_vbus>;
1155 int-n-gpios = <&gpio1 RK_PA2 GPIO_ACTIVE_HIGH>;
1156 vbus-5v-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_HIGH>;
1157 status = "okay";
1158 };
- Property格式
格式一:
[label:] property-name = value;
格式二:
[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、特殊的默认属性
- 根节点
#address-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address)
#size-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)
compatible // 定义一系列的字符串, 用来指定内核中哪个machine_desc可以支持本设备
// 即这个板子兼容哪些平台
// uImage : smdk2410 smdk2440 mini2440 ==> machine_desc
model // 咱这个板子是什么
// 比如有2款板子配置基本一致, 它们的compatible是一样的
// 那么就通过model来分辨这2款板子
/memory
device_type = "memory";
reg // 用来指定内存的地址、大小
/chosen
bootargs // 内核command line参数, 跟u-boot中设置的bootargs作用一样
/cpus
/cpus节点下有1个或多个cpu子节点, cpu子节点中用reg属性用来标明自己是哪一个cpu
所以 /cpus 中有以下2个属性:
#address-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address)
#size-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)
// 必须设置为0
/cpus/cpu*
device_type = "cpu";
reg // 表明自己是哪一个cpu
注意:
1、同一节点的名字不能一样,即任意节点的全路径不能相同
本blog设备树知识来源于韦东山设备树的学习视频,感谢韦老师的付出!