從dtc manpage可以簡略瞭解一下DTC(Device Tree Compiler)功能, 就是將device-tree的format轉成另一種format, 其input格式有三種,
- dts - device tree source text
- dtb - device tree blob
- fs - /proc/device-tree style directory
而output格式也有三種,
- dts - device tree source text
- dtb - device tree blob
- asm - assembler source
而dtc支援的phandle可支援三種
- legacy - "linux,phandle" properties only
- epapr - "phandle" properties only
- both - Both "linux,phandle" and "phandle" properties
根據
Device Tree Mysteries,
what is the reason for having a phandle?
It is really just a hack to get around the fact that device tree does
not have a pointer data type.
It is a way to reference
"that node over there that is related to this node for some reason".
簡單來說, phandler就是pointer data type, 用個例子說明
pic@10000000 {
phandle = < 1 >;
};
A phandle value of 1 is defined.
Another device node could reference the pic node with a
phandle value of 1:
uart@20000000 {
interrupt-parent = > 1 >;
};
"phandle = < 1 >"的"1"是一個隨意的unit32數值, 只要不衝突即可, 但是這並不是很好記, 所以DTC貼心的可以用lable來建立phandle,如下範例
PIC_3: pic@10000000 {
interrupt-controller;
};
uart@20000000 {
interrupt-parent = < &PIC_3 >;
};
這裡的"&"是告訴DTC後面接一個字串, 是個phandle參考到某個lable, 然後DTC就會幫user建立unit32的數值, 建立出phandle. 除此之外也可以使用full path來取代lable, 如下範例
/{
soc {
PIC_3: pic@10000000 {
interrupt-controller;
};
};
uart@20000000 {
interrupt-parent = < &PIC_3 >;
};
uart@30000000 {
interrupt-parent = < &{/soc/pic@10000000} >;
};
};
下面再用一個例子同時說明DTC與phandle
brook@vista:~/dts$ cat test_phandle.dts
/dts-v1/;
/{
soc {
PIC_3: pic@10000000 {
interrupt-controller;
};
};
uart@20000000 {
interrupt-parent = < &PIC_3 >;
};
uart@30000000 {
interrupt-parent = < &{/soc/pic@10000000} >;
};
};
brook@vista:~/dts$ dtc -O dtb -I dts test_phandle.dts > test_phandle.dtb
brook@vista:~/dts$ dtc -O dts -I dtb test_phandle.dtb
/dts-v1/;
/ {
soc {
pic@10000000 {
interrupt-controller;
linux,phandle = <0x1>;
phandle = <0x1>;
};
};
uart@20000000 {
interrupt-parent = <0x1>;
};
uart@30000000 {
interrupt-parent = <0x1>;
};
};
這篇文章主要簡單講解利用dtc來轉換dtb與dts, 順帶說明一下phandle是一種pointer data type, 與其基本原理