device tree

15
Device Tree Rouyun Pan

Upload: rouyunpan

Post on 07-May-2015

899 views

Category:

Software


6 download

TRANSCRIPT

Page 1: Device tree

Device TreeRouyun Pan

Page 2: Device tree

緣起• 某年某⽉月的某⼀一天... 神⼈人Linus Torvalds寫了⼀一封信

有⼀一堆闌尾在⽴立法院, 可割可棄!!!

Page 3: Device tree

So, 割闌尾~• 科科跟宅宅們參考了PowerPC等其他體系架構下已經使⽤用的Flattened Device Tree(FDT).起源於 OpenFirmware IEEE 1275 device-tree notion.

• ⽇日後決定採⽤用Device Tree為描述硬體平台的資料結構.

Page 4: Device tree

Device Tree• 由⼀一系列被命名的結點(Node)和屬性(Property)來組成. Node可包含Sub-Node. Property是成對的name和value. 可讀性⾼高.

• 可以在開機的時候, 在透過它將訊息傳遞給作業系統,⽽而不需要在把這些資訊放在程式碼中.

• 未來也很⽅方便增減修改Device Tree, 容易⽀支援不同的Soc或硬體週邊.

Z > B!!!

Page 5: Device tree

How to work with device tree

complier

Device tree description

binary data

bootloader kernel

platform

probe

carry

HW configuration

pass

DTS

DTC

DTB

Page 6: Device tree

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.

Page 7: Device tree

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>",第⼀一個字串表⽰示確切名稱,第⼆二個字串表⽰示可兼容的其他設備。

Page 8: Device tree

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不同即可

Page 9: Device tree

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!

根節點

Page 10: Device tree

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>

Page 11: Device tree

.dts & dtsi

• .dts 是採⽤用ASCII 格式的Device Tree描述檔⽂文件.⼀一般放置位在 kernel/arch/arm/boot/dts/。

• ⼀一個SoC可能拿來開發多個產品線,為了⽅方便,把SoC公⽤用的硬體設定或不同產品的共同部分提煉為.dtsi,類似C語⾔言的.h。其他不同產品的.dts可以引⽤用這些共通的.dtsi。

Page 12: Device tree

Modularizationmsm1234-abc.dts

msm1234-abc.dtsi

panel-abc.dtsi msm1234.dtsi

msm1234-gpu.dtsi msm1234-iommu.dtsi

msm1234-mdss.dtsi

Page 13: Device tree

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"; … …

Page 14: Device tree

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()

Page 15: Device tree

Reference• http://www.devicetree.org/Main_Page

• http://www.devicetree.org/Device_Tree_Usage

• Device Tree Support on ARM Linux Chih-Min Chao) http://gplus.to/cmchao COSCUP 2011 in Taiwan

• http://blog.csdn.net/21cnbao/article/details/8457546