如何查看设备树——设备树格式解析
device tree
浅尝一下英文记录,懒得再转译一遍了。
basic view
#include "stm32mp157c.dtsi"
#include "stm32mp157cac-pinctrl.dtsi"
#include "stm32mp157c-m4-srm.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/mfd/st,stpmic1.h>
/ {
model = "Embedfire STM32MP157 Star LubanCat Robot S1 Board";
compatible = "st,stm32mp157a-dk1", "st,stm32mp157";
aliases {
ethernet0 = ðernet0;
serial0 = &uart4;
serial1 = &usart1;
serial2 = &usart2;
serial3 = &usart3;
};
chosen {
stdout-path = "serial0:115200n8";
};
memory@c0000000 {
reg = <0xc0000000 0x40000000>;
};
sram: sram@10050000 {
compatible = "mmio-sram";
reg = <0x10050000 0x10000>;
#address-cells = <1>;
#size-cells = <1>;
ranges = <0 0x10050000 0x10000>;
dma_pool: dma_pool@0 {
reg = <0x0 0x10000>;
pool;
};
};
};
elemets introduction
include
like #include
in c source file, but we can import files with suffix bith .h
and .dts
.
#include "stm32mp157c.dtsi"
#include <dt-bindings/input/input.h>
root node
dts file contains many node like start with {
and end with };
, a node could be nested in a high level node, to distinguish with normal node, the top level of a device node should start with /
.
root node should be like:
/ {
};
multilevel nesting:
/ {
sram: sram@10050000 {
compatible = "mmio-sram";
reg = <0x10050000 0x10000>;
#address-cells = <1>;
#size-cells = <1>;
ranges = <0 0x10050000 0x10000>;
dma_pool: dma_pool@0 {
reg = <0x0 0x10000>;
pool;
};
};
};
node name
node name could be a little bit complicate, like:
- [tipname] [nodename]@[addr]
tipname
is a abbreviation of nodename
, the two are equivalent.
sram: sram@10050000 {
};
the node name above means there is a sarm at address 0x10050000
.
node attributes
-
compatible: string type, one of the method to find node (the other two are node name and node path).
-
model: which model this device using.
-
status: string type, show the operation mode of device, to disable or enable device through this attribute.
address
Devices that are addressable use the following properties to encode address information into the device tree:
- reg
- #address-cells
- #size-cells
Each addressable device gets a reg which is a list of tuples in the form reg = <address1 length1 [address2 length2] [address3 length3] … >. Each tuple represents an address range used by the device. Each address value is a list of one or more 32 bit integers called cells. Similarly, the length value can either be a list of cells, or empty.
Since both the address and length fields are variable of variable size, the #address-cells and #size-cells properties in the parent node are used to state how many cells are in each field. Or in other words, interpreting a reg property correctly requires the parent node’s #address-cells and #size-cells values. To see how this all works, lets add the addressing properties to the sample device tree, starting with the CPUs.
CPU addressing
The CPU nodes represent the simplest case when talking about addressing. Each CPU is assigned a single unique ID, and there is no size associated with CPU ids.
cpus {
#address-cells = <1>;
#size-cells = <0>;
cpu@0 {
compatible = "arm,cortex-a9";
reg = <0>;
};
cpu@1 {
compatible = "arm,cortex-a9";
reg = <1>;
};
};
In the cpus node, #address-cells is set to 1, and #size-cells is set to 0. This means that child reg values are a single uint32 that represent the address with no size field. In this case, the two cpus are assigned addresses 0 and 1. #size-cells is 0 for cpu nodes because each cpu is only assigned a single address.
You’ll also notice that the reg value matches the value in the node name. By convention, if a node has a reg property, then the node name must include the unit-address, which is the first address value in the reg property.
more please refer to Device_Tree_Usage
append content for ndde
Outside of root node, we could add content to nodes which are exist already.
&cpu0{
//cpu-supply = <&vddcore>;
clock-frequency = <650000000>;
};
their name should start with &
, followed by name of the node to be appended.
aliases node
take a aliase for nodes.
aliases {
ethernet0 = ðernet0;
serial0 = &uart4;
serial1 = &usart1;
serial2 = &usart2;
serial3 = &usart3;
};
offer a faster way to find the device being aliased.