Device Tree Source

From WRTnode Wiki Site
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English 100% • ‎中文(中国大陆)‎ 100%

一:device tree source birth

 In the past linux kernel, such as: ARM Linux in, arch/arm/plat-xxx and arch/arm/mach-xxx filled with a lot of garbage code, a considerable majority of the code just in describing the board level detail.

These board-level details for the kernel is concerned, but is garbage, such as platform device board, resource, i2c_board_info, spi_board_info and various hardware platform_data.

Device Tree is a data structure describing the hardware, which originated in OpenFirmware (OF).

 In Linux 2.6 in, ARM architecture plate too much hardware details are hard-coded in the arch /arm/plat-xxx and arch/arm/mach-xxx, after using the Device Tree, many details of the hardware can be passed directly through it to Linux, without the need for a lot of redundancy in the coding in kernel.
 Device Tree named by a series of nodes (node) and attribute (property) composed of the node itself may contain sub nodes. The so-called property, in fact, occur in pairs name and value. In the Device Tree, the information can be described, including (former mostly hard code this information to the kernel in):

The number and type of CPU

Memory base address and size

Bus and bridge

Peripheral connections

Interrupt controller and interrupt usage

GPIO controller and GPIO usage

Clock controller and Clock Usage

It is basically draw a circuit board CPU, bus, equipment consisting of trees, Bootloader will be passed to the kernel tree, then the kernel can identify this tree, And according to it launched a Linux kernel platform_device, i2c_client, spi_device and other equipment, and these devices use memory, IRQ and other resources, has also been passed to the kernel, the kernel will bind these resources to expand the appropriate device.


二: Device Tree composition and structure

Device Tree involve the whole broad face, that adds new text format used to describe the device hardware information, but also increases the tool to compile the text, but also needs the support Bootloader Device compiled Tree will be passed to the Linux kernel.

DTS (device tree source)

.dts file is an ASCII text description Device Tree format, the text format is very user-friendly, suitable for human reading habits.

Basically, mips Linux, a .dts file corresponds to a mips the machine, usually placed in /target/linux/ramips/dts directory.

Due to an SoC may correspond to multiple machine (an SoC can correspond to multiple products and circuit boards), bound to these .dts file should contain many common parts, Linux kernel in order to simplify,

The common part of the common parts of SoC or more machine usually refined for .dtsi, similar to the C language header files. Other machine corresponding .dts to include this .dtsi. For example, for MT762n terms, mt7620n.dtsi was called WRTNODE.dts, WRTNODE.dts the following line:

/include/ "mt7620n.dtsi"

Of course, and is similar to the C language header files, .dtsi can also include other .dtsi, for example, almost all ARM SoC's .dtsi all references skeleton.dtsi. .dts (or which include a .dtsi) basic elements and attributes of the nodes is described hereinbefore

For example:m25p80的spi flash

m25p80@0 { 
               #address-cells = <1>; 
               #size-cells = <1>; 
               #compatible = "mx25l6405d"; 
               compatible = "w25q128"; 
               reg = <0 0>; 
               linux,modalias = "m25p80", "w25q128"; 
               spi-max-frequency = <10000000>; 
               partition@0 { 
                   label = "u-boot"; 
                   reg = <0x0 0x30000>; 
                   read-only; 
               }; 
               partition@30000 { 
                   label = "u-boot-env"; 
                   reg = <0x30000 0x10000>; 
                   read-only; 
               }; 
               factory: partition@40000 { 
                   label = "factory"; 
                   reg = <0x40000 0x10000>; 
                   read-only; 
               }; 
               partition@50000 { 
                   label = "firmware"; 
                   reg = <0x50000 0xfb0000>; 
               }; 
           };

m25p80 @ 0 is the junction point, partition @ 0, factory: partition @ 40000 is his child nodes.

Organizational form compatible attribute is <manufacturer>, <model>, in fact, remove the manufacturer alias prefix compatible property before the comma. On this point, you can see drivers /spi/spi.c source code, function spi_match_device () exposes more detail, if an alias appears in the device spi_driver of id_table inside, or alias name field spi_driver same, SPI devices and drive can be matched.

Specific dts presentation can refer [1]