如何查看设备树——设备树格式解析

如何查看设备树——设备树格式解析

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 = &ethernet0;
		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 = &ethernet0;
		serial0 = &uart4;
		serial1 = &usart1;
		serial2 = &usart2;
		serial3 = &usart3;		
	};

offer a faster way to find the device being aliased.

  • 16
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值