More Related Content Similar to Device tree (20) More from Rouyun Pan (20) Device tree5. How to work with device tree
complier
Device tree
description
binary data
bootloader kernel
platform
probe
carry
HW configuration
pass
DTS
DTC
DTB
6. Device tree misc.
• DTS
- device tree source file
• DTC
- device tree compiler, It compiles DTS to DTB.
• DTB
- device tree blob, the binary data to store the
information of DTS.
7. DTS Format(1)
/{!
! properties = ”value as string” | <value as u32 list> | [ value as byte stream ] |
<&node name>!
! child_node[@address] {!
! ! child_properties!
! }!
}!
!
&node_name {!
! compatible = "<manufacturer>,<model>"!
! properties!
}!
“/“ 表⽰示根節點, 不需要寫節點名稱
屬性Properties可以⽤用混合格式表⽰示,
如“字串”,或<32位元整數列表>,或[位元組流]或
<&其他參考節點名稱>
每個 Node 都會有⼀一個’compatible’ property. 格式為
"<manufacturer>,<model>",第⼀一個字串表⽰示確切名
稱,第⼆二個字串表⽰示可兼容的其他設備。
8. DTS Format(2)
/{!
! properties = ”value as string” | <value as u32 list> | [ value as byte stream ] |
<&node name>!
! child_node[@address] {!
! ! child_properties!
! }!
}!
!
&node_name {!
! compatible = "<manufacturer>,<model>"!
! properties!
}!
結點的命名,遵循的格式為:
<name>[@address]
name是⼀一個ASCII字串,⽤用於描述結點對應的
裝置類型. 如果⼀一個結點描述的裝置有記憶體地
址,則填⼊入@address。多個相同類型設備結點
的name可以⼀一樣,只要address不同即可
9. DTS format(3)
/ {
compatible = "acme,coyotes-revenge";
#address-cells = <1>;
#size-cells = <1>;
interrupt-parent = <&intc>;
cpus {
#address-cells = <1>;
#size-cells = <0>;
cpu@0 {
compatible = "arm,cortex-a9";
reg = <0>;
};
cpu@1 {
compatible = "arm,cortex-a9";
reg = <1>;
};
};
serial@1010adbd {
compatible = "arm,pl011";
reg = <0x101abcd 0x1000>;
reg_name = “”
};
節點1
節點2!
⼦子節點1!
⼦子節點2!
根節點
10. DTS format(4)/ {
compatible = "acme,coyotes-revenge";
#address-cells = <1>; !
#size-cells = <1>;
interrupt-parent = <&intc>;
cpus {
#address-cells = <1>; !
#size-cells = <0>;
cpu@0 {
compatible = "arm,cortex-a9";
reg = <0>;
};
cpu@1 {
compatible = "arm,cortex-a9";
reg = <1>;
};
};
serial@1010adbd {
compatible = "arm,pl011";
reg = <0x101abcd 0x1000>;!
! reg_name = “”!
};
有位址的裝置會使⽤用
#address-cells 和 #size-cells 來決定⼦子結點
的’reg’屬性的格式怎麼填
reg = <address1 length1 [address2 length2] ... >
#size-cells = <0>; 表⽰示只填⼊入Reg的starting address
#address-cells = <1>; !
#size-cells = <1>; !
填⼊入格式為 Reg = <Starting_address Size>
11. .dts & dtsi
• .dts 是採⽤用ASCII 格式的Device Tree描述檔⽂文件.
⼀一般放置位在 kernel/arch/arm/boot/dts/。
• ⼀一個SoC可能拿來開發多個產品線,為了⽅方便,
把SoC公⽤用的硬體設定或不同產品的共同部分提
煉為.dtsi,類似C語⾔言的.h。其他不同產品的.dts
可以引⽤用這些共通的.dtsi。
13. for example - Driver probe
@mdss_mdp.cpp
static const struct of_device_id mdss_mdp_dt_match[] =
.compatible = "qcom,mdss_mdp"
MODULE_DEVICE_TABLE (of, mdss_mdp_dt_match);
!
static struct platform_driver mdss_mdp_driver = {
.probe = mdss_mdp_probe,
.driver = {
.name = "mdp",
.of_match_table = mdss_mdp_dt_match,
}
}
!
static int __init mdss_mdp_driver_init (void) {
platform_driver_register( &mdss_mdp_driver );
}
@msm1234-mdss.dtsi
&soc {
!
mdss_mdp: qcom,mdss_mdp@12340000 {
compatible = "qcom,mdss_mdp";
reg = <0x12340000 0xff00>
reg-names = "mdp_phys", "vbif_phys";
…
!
mdss_dsi0: qcom,mdss_dsi@12345000 {
compatible = "qcom,mdss-dsi-ctrl";
qcom,mdss-mdp = <&mdss_mdp>;
…
!
qcom,mdss_wb_panel {
compatible = "qcom,mdss_wb";
…
…
14. Parsing APIs of Device Tree
property * of_find_property();
device_node * of_find_node_by_name();
of_find_node_by_type();
of_find_compatible_node();
of_find_matching_node_and_match();
of_find_node_by_path();
of_find_node_by_phandle();
void * of_get_property();
int of_property_read_u32_index()
of_property_read_u8_array();
of_property_read_u16_array();
of_property_read_u32_array();
of_property_read_string();
of_property_read_string_index();
int of_parse_phandle_with_args(),
of_parse_phandle_with_fixed_args(),
of_count_phandle_with_args()