Linux裝置樹的用法
/ { node1 { a-string-property = "A string"; a-string-list-property = "first string", "second string"; a-byte-data-property = [0x01 0x23 0x34 0x56]; child-node1 { first-child-property; second-child-property = <1>; a-string-property = "Hello, world"; }; child-node2 { }; }; node2 { an-empty-property; a-cell-property = <1 2 3 4>; /* each number (cell) is a uint32 */ child-node1 { }; }; }; |
- 一個根節點: "/"
- 兩個子節點: "node1" 和 "node2"
- node1下面又有兩個子節點:"child-node1" 和 "child-node2"
- 一堆的屬性分散與整顆樹的各個節點上
- text string
- string-property = "a string"
- cells 是32位無符號整形數,以尖括號括起來,如
- cell-property = <0xbeef 123 0xabcd1234>
- binary data 以方括號括起來,如:
- binary-property = [0x01 0x23 0x45 0x67];
- 不同型別資料可以在同一個屬性中存在,以逗號分格,如:
- mixed-property = "a string", [0x01 0x23 0x45 0x67], <0x12345678>;
- 多個字串組成的列表也使用逗號分格,如:
- string-list = "red fish","blue fish";
- 32bit ARM CPU
- 處理器的本地記憶體匯流排連線如下裝置:串列埠,SPI匯流排控制器,I2C控制器,終端控制器以及外部匯流排橋
- 256MB SDRAM 位於地址:0x0
- 兩個串列埠,位於地址:0x101F1000 及 0x101F2000
- GPIO控制器位於地址:0x101F3000
- SPI控制器位於地址:0x10170000,在它下面連線瞭如下裝置:
- MMC卡槽,其SS腳連線了GPIO1
- 外部匯流排橋上接瞭如下裝置:
- SMC91111 乙太網控制器,位於地址:0x10100000
- I2C控制器,位於地址:0x10160000,在它下面連線瞭如下裝置:
- Maxim DS1338實時時鐘,I2C地址為0x58
- 64MB NOR flash 位於地址:0x30000000
/ { compatible = "acme,coyotes-revenge"; }; |
/ { compatible = "acme,coyotes-revenge"; cpus { [email protected] { compatible = "arm,cortex-a9"; }; [email protected] { compatible = "arm,cortex-a9"; }; }; }; |
/ { compatible = "acme,coyotes-revenge"; cpus { [email protected] { compatible = "arm,cortex-a9"; }; [email protected] { compatible = "arm,cortex-a9"; }; }; [email protected] { compatible = "arm,pl011"; }; [email protected] { compatible = "arm,pl011"; }; [email protected] { compatible = "arm,pl061"; }; [email protected] { compatible = "arm,pl190"; }; [email protected] { compatible = "arm,pl022"; }; external-bus { [email protected],0 { compatible = "smc,smc91c111"; }; [email protected],0 { compatible = "acme,a1234-i2c-bus"; [email protected] { compatible = "maxim,ds1338"; }; }; [email protected],0 { compatible = "samsung,k8f1315ebm", "cfi-flash"; }; }; }; |
- 每個裝置節點都都一個compatible屬性
- flash這個節點的compatible屬性有兩個字串,下面一節將介紹為什麼這麼寫。
- 在前文中曾提到:節點名反應的是裝置型別而非裝置型號。請參考ePAPR的2.2.2節中列出的常用節點名。
- reg
- #address-cells
- #size-cells
cpus { #address-cells = <1>; #size-cells = <0>; [email protected] { compatible = "arm,cortex-a9"; reg = <0>; }; [email protected] { compatible = "arm,cortex-a9"; reg = <1>; }; }; |
/ { #address-cells = <1>; #size-cells = <1>; ... [email protected] { compatible = "arm,pl011"; reg = <0x101f0000 0x1000 >; }; [email protected] { compatible = "arm,pl011"; reg = <0x101f2000 0x1000 >; }; [email protected] { compatible = "arm,pl061"; reg = <0x101f3000 0x1000 0x101f4000 0x0010>; }; [email protected] { compatible = "arm,pl190"; reg = <0x10140000 0x1000 >; }; [email protected] { compatible = "arm,pl022"; reg = <0x10115000 0x1000 >; }; ... }; |
external-bus { #address-cells = <2> #size-cells = <1>; [email protected],0 { compatible = "smc,smc91c111"; reg = <0 0 0x1000>; }; [email protected],0 { compatible = "acme,a1234-i2c-bus"; reg = <1 0 0x1000>; [email protected] { compatible = "maxim,ds1338"; }; }; [email protected],0 { compatible = "samsung,k8f1315ebm", "cfi-flash"; reg = <2 0 0x4000000>; }; }; |
[email protected],0 { compatible = "acme,a1234-i2c-bus"; #address-cells = <1>; #size-cells = <0>; reg = <1 0 0x1000>; [email protected] { compatible = "maxim,ds1338"; reg = <58>; }; }; |
/ { compatible = "acme,coyotes-revenge"; #address-cells = <1>; #size-cells = <1>; ... external-bus { #address-cells = <2> #size-cells = <1>; ranges = <0 0 0x10100000 0x10000 // Chipselect 1, Ethernet 1 0 0x10160000 0x10000 // Chipselect 2, i2c controller 2 0 0x30000000 0x1000000>; // Chipselect 3, NOR Flash [email protected],0 { compatible = "smc,smc91c111"; reg = <0 0 0x1000>; }; [email protected],0 { compatible = "acme,a1234-i2c-bus"; #address-cells = <1>; #size-cells = <0>; reg = <1 0 0x1000>; [email protected] { compatible = "maxim,ds1338"; reg = <58>; }; }; [email protected],0 { compatible = "samsung,k8f1315ebm", "cfi-flash"; reg = <2 0 0x4000000>; }; }; }; |
- CS0,偏移量為0的本地地址被對映到父節點地址空間的 0x10100000~0x1010ffff
- CS1,偏移量為1的本地地址被對映到父節點地址空間的 0x10160000~0x1016ffff
- CS2,偏移量為0的本地地址被對映到父節點地址空間的 0x30000000~0x31000000
- interrupt-controller 這個屬性沒有值,他表示這個節點是一個接收中斷訊號的裝置
- #interrupt-cells 這個屬性是一個interrupt-controller節點的屬性,他說明了這個 interrupt-controller的每個中斷說明符(interrupt specifier)有幾個cells,類似#address-cells 與 #size-cells的作用
- interrupt-parent 這是一個裝置節點的屬性,用於表明當前裝置的中斷是屬於哪一個interrupt-controller的,如果沒有這個屬性,則繼承其父節點的interrupt-parent屬性
- interrupts 這是一個裝置節點的屬性,他是 中斷說明符 列表,每一個 中斷說明符 表示此裝置的一箇中斷訊號輸出。
/ { compatible = "acme,coyotes-revenge"; #address-cells = <1>; #size-cells = <1>; interrupt-parent = <&intc>; cpus { #address-cells = <1>; #size-cells = <0>; [email protected] { compatible = "arm,cortex-a9"; reg = <0>; }; [email protected] { compatible = "arm,cortex-a9"; reg = <1>; }; }; [email protected] { compatible = "arm,pl011"; reg = <0x101f0000 0x1000 >; interrupts = < 1 0 >; }; [email protected] { compatible = "arm,pl011"; reg = <0x101f2000 0x1000 >; interrupts = < 2 0 >; }; [email protected] { compatible = "arm,pl061"; reg = <0x101f3000 0x1000 0x101f4000 0x0010>; interrupts = < 3 0 >; }; intc: [email protected] { compatible = "arm,pl190"; reg = <0x10140000 0x1000 >; interrupt-controller; #interrupt-cells = <2>; }; [email protected] { compatible = "arm,pl022"; reg = <0x10115000 0x1000 >; interrupts = < 4 0 >; }; external-bus { #address-cells = <2> #size-cells = <1>; ranges = <0 0 0x10100000 0x10000 // Chipselect 1, Ethernet 1 0 0x10160000 0x10000 // Chipselect 2, i2c controller 2 0 0x30000000 0x1000000>; // Chipselect 3, NOR Flash [email protected],0 { compatible = "smc,smc91c111"; reg = <0 0 0x1000>; interrupts = < 5 2 >; }; [email protected],0 { compatible = "acme,a1234-i2c-bus"; #address-cells = <1>; #size-cells = <0>; reg = <1 0 0x1000>; interrupts = < 6 2 >; [email protected] { compatible = "maxim,ds1338"; reg = <58>; interrupts = < 7 3 >; }; }; [email protected],0 { compatible = "samsung,k8f1315ebm", "cfi-flash"; reg = <2 0 0x4000000>; }; }; }; |
- 此machine僅有一箇中斷控制器:[email protected]
- 標籤"intc:"被加到了中斷控制器的節點上,這個標籤在父節點上建立了一個phandle,這個phandle就是父節點的interrupt-parent。所以這個中斷控制器就成了系統所有子節點的預設終端控制器,只有當子節點明確的聲明瞭其interrupt-parent才會被覆蓋。
- 每個裝置使用interrupt屬性來區分不同的終端輸入線。
- #interrupt-cells(在[email protected]節點中)的值是2,所以,每個中斷說明符由兩個cell資料組成。這個例子中用的是最常見的 中斷說明符 形式,第一個cell表示中斷線的序號,第二個cell表示終端型別的flag(表示高有效,低有效。。。),對於不同的終端控制器,需要閱讀對應的binding document來得知其 中斷說明符 的格式。
aliases { ethernet0 = ð0; serial0 = &serial0; }; |