原文地址:http://blog.chinaunix.net/uid-29616823-id-4390033.html
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
接上xx路由器的串口后有输出但无法输入,用示波器量下信号-----可能是uboot里面把RX引脚给配置了。
1.属性的定义采用property = value的形式,“”字符串、<>32或64位值、[]二进制[0x01 0x02]
2.用=赋值的才是节点属性,其他是子节点。
3.root节点的compitable属性供内核选择匹配机器码machinetype,其他节点的compitable属性供内核选择匹配对应的驱动
(如三星2416的lcd控制器节点,内核里面lcd的驱动有很多)
4.DTB文件头boot_paras_header,其中的magic字段用来标志Uboot传来的启动参数是DTB还是taglist(bootargs)
,xx_offset标志DTB在内存中的地址。
compatible:兼容的,相容的
/ {---------------------"/"表示根节点的名称,一个设备树只能有一个根节点多个文件中的根节点在编译时会被合并。
#address-cells = <1>;---------------表示地址空间的个数,如系统有两片内存,那就需要<a b c d>两组数据来表示,ab表示内存1的空间 cd表示内存2空间。
#size-cells = <1>;------------------表示地址空间所需字节数,如表示64位的GPIO控制寄存器组就需要<0x00000001 0x000000002 0x00000001 0x000000006>
表示的空间是0x00000001000000002到00000001000000006
compatible = "ralink,mtk7620a-soc";----“compatible”属性表示CPU所述系列,如mips架构ralink,mtk7620a系列
、arm架构stm32,cortex-M3系列。
cpus {
cpu@0 {---------节点名称@节点寄存器偏移地址或节点设备编号,若该节点无reg属性则不写定义成空节点即可。
compatible = "mips,mips24KEc";
};
};
chosen {
bootargs = "console=ttyS0,57600";-----通过dts给内核传递uboot的bootargs参数,uboot省事了
};
cpuintc: cpuintc@0 {-------------该节点名称是中断控制器,cpuintc是标签即cpuintc@0,
为了方便引用cpuintc@0。
#address-cells = <0>;
#interrupt-cells = <1>;
interrupt-controller;
compatible = "mti,cpu-interrupt-controller";
};
palmbus@10000000 {------palmbus类似arm的AMBA,属于片内总线。
compatible = "palmbus";
reg = <0x10000000 0x200000>;---reg属性表示该控制器的reg地址及总长度
ranges = <0x0 0x10000000 0x1FFFFF>;
#address-cells = <1>;----若节点的子节点有控制寄存器,则必须定义这两个属性。
#size-cells = <1>;
sysc@0 {
compatible = "ralink,mt7620a-sysc", "ralink,rt3050-sysc";
reg = <0x0 0x100>;
};
timer@100 {
compatible = "ralink,mt7620a-timer", "ralink,rt2880-timer";
reg = <0x100 0x20>;
interrupt-parent = <&intc>;
interrupts = <1>;
};
watchdog@120 {
compatible = "ralink,mt7620a-wdt", "ralink,rt2880-wdt";
reg = <0x120 0x10>;
resets = <&rstctrl 8>;
reset-names = "wdt";
interrupt-parent = <&intc>;
interrupts = <1>;
};
intc: intc@200 {-----intc为标签(为方便被其他节点引用)
compatible = "ralink,mt7620a-intc", "ralink,rt2880-intc";
reg = <0x200 0x100>;
resets = <&rstctrl 19>;
reset-names = "intc";
interrupt-controller;
#interrupt-cells = <1>;
interrupt-parent = <&cpuintc>;--------引用节点cpuintc
interrupts = <2>;
};
memc@300 {----------描述系统内存的节点,为根节点的子节点
compatible = "ralink,mt7620a-memc", "ralink,rt3050-memc";
reg = <0x300 0x100>;
resets = <&rstctrl 20>;
reset-names = "mc";
interrupt-parent = <&intc>;
interrupts = <3>;
};
gpio0: gpio@600 {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x600 0x34>;
resets = <&rstctrl 13>;
reset-names = "pio";
interrupt-parent = <&intc>;
interrupts = <6>;---------表示其在中断控制器中的硬件中断编号,分系统异常中断/systick中断/两个外部中断。。。等
gpio-controller;
#gpio-cells = <2>;-----表示gpio控制寄存器是64位的
ralink,gpio-base = <0>;----该组gpio从GPIO0开始
ralink,num-gpios = <24>;-------到GPIO24结束
ralink,register-map = [ 00 04 08 0c
20 24 28 2c
30 34 ];
};
gpio1: gpio@638 {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x638 0x24>;
interrupt-parent = <&intc>;
interrupts = <6>;
gpio-controller;
#gpio-cells = <2>;
ralink,gpio-base = <24>;
ralink,num-gpios = <16>;
ralink,register-map = [ 00 04 08 0c
10 14 18 1c
20 24 ];-----执行cat /proc/iomem显示的数值?
status = "disabled";
};
gpio2: gpio@660 {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x660 0x24>;
interrupt-parent = <&intc>;
interrupts = <6>;
gpio-controller;
#gpio-cells = <2>;
ralink,gpio-base = <40>;
ralink,num-gpios = <32>;
ralink,register-map = [ 00 04 08 0c
10 14 18 1c
20 24 ];
status = "disabled";
};
gpio3: gpio@688 {
compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
reg = <0x688 0x24>;
interrupt-parent = <&intc>;
interrupts = <6>;
gpio-controller;
#gpio-cells = <2>;
ralink,gpio-base = <72>;
ralink,num-gpios = <1>;
ralink,register-map = [ 00 04 08 0c
10 14 18 1c
20 24 ];
status = "disabled";
};
i2c@900 {
compatible = "link,mt7620a-i2c", "ralink,rt2880-i2c";
reg = <0x900 0x100>;
resets = <&rstctrl 16>;
reset-names = "i2c";
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
pinctrl-names = "default";----i2c除了对i2c控制器寄存器定义外,还要对i2c所用的gpio管脚定义
pinctrl-0 = <&i2c_pins>;
};
i2s@a00 {
compatible = "ralink,mt7620a-i2s";
reg = <0xa00 0x100>;
resets = <&rstctrl 17>;
reset-names = "i2s";
interrupt-parent = <&intc>;
interrupts = <10>;
dmas = <&gdma 4>,
<&gdma 5>;
dma-names = "tx", "rx";
status = "disabled";
};
spi@b00 {
compatible = "ralink,mt7620a-spi", "ralink,rt2880-spi";
reg = <0xb00 0x100>;
resets = <&rstctrl 18>;
reset-names = "spi";
#address-cells = <1>;
#size-cells = <1>;
status = "disabled";
pinctrl-names = "default";
pinctrl-0 = <&spi_pins>;-----spi_pins不在dts文件中定义?
};
uartlite@c00 {
compatible = "ralink,mt7620a-uart", "ralink,rt2880-uart", "ns16550a";
reg = <0xc00 0x100>;
resets = <&rstctrl 19>;
reset-names = "uartl";
interrupt-parent = <&intc>;
interrupts = <12>;
reg-shift = <2>;
pinctrl-names = "default";
pinctrl-0 = <&uartlite_pins>;
};
uart@500 {
compatible = "ralink,mt7620a-uart", "ralink,rt2880-uart", "ns16550a";
reg = <0x500 0x100>;
resets = <&rstctrl 12>;
reset-names = "uart";
interrupt-parent = <&intc>;
interrupts = <5>;
reg-shift = <2>;
pinctrl-names = "default";
pinctrl-0 = <&pcm_uartf_pins>;
};
systick@d00 {
compatible = "ralink,mt7620a-systick", "ralink,cevt-systick";
reg = <0xd00 0x10>;
resets = <&rstctrl 28>;
reset-names = "intc";
interrupt-parent = <&cpuintc>;
interrupts = <7>;
};
pcm@2000 {
compatible = "ralink,mt7620a-pcm";
reg = <0x2000 0x800>;
resets = <&rstctrl 11>;--------resets属性含义?
reset-names = "pcm";
interrupt-parent = <&intc>;
interrupts = <4>;
status = "disabled";
};
gdma: gdma@2800 {
compatible = "ralink,mt7620a-gdma", "ralink,rt2880-gdma";
reg = <0x2800 0x800>;
resets = <&rstctrl 14>;
reset-names = "dma";
interrupt-parent = <&intc>;
interrupts = <7>;
#dma-cells = <1>;
#dma-channels = <16>;
#dma-requests = <16>;
status = "disabled";
};
};
pinctrl {
compatible = "ralink,rt2880-pinmux";
pinctrl-names = "default";
pinctrl-0 = <&state_default>;
state_default: pinctrl0 {
};
pcm_uartf_pins: pcm_uartf {
pcm_uartf {
ralink,group = "uartf";
ralink,function = "pcm uartf";
};
};
spi_pins: spi {
spi {
ralink,group = "spi";
ralink,function = "spi";
};
};
i2c_pins: i2c {
i2c {
lantiq,group = "i2c";
lantiq,function = "i2c";
};
};
uartlite_pins: uartlite {
uart {
ralink,group = "uartlite";
ralink,function = "uartlite";
};
};
mdio_pins: mdio {
mdio {
ralink,group = "mdio";
ralink,function = "mdio";
};
};
ephy_pins: ephy {
ephy {
ralink,group = "ephy";
ralink,function = "ephy";
};
};
wled_pins: wled {
wled {
ralink,group = "wled";
ralink,function = "wled";
};
};
rgmii1_pins: rgmii1 {
rgmii1 {
ralink,group = "rgmii1";
ralink,function = "rgmii1";
};
};
rgmii2_pins: rgmii2 {
rgmii2 {
ralink,group = "rgmii2";
ralink,function = "rgmii2";
};
};
};
rstctrl: rstctrl {
compatible = "ralink,mt7620a-reset", "ralink,rt2880-reset";
#reset-cells = <1>;
};
ubsphy {
compatible = "ralink,mt7620a-usbphy";
resets = <&rstctrl 22 &rstctrl 25>;
reset-names = "host", "device";
};
ethernet@10100000 {
compatible = "ralink,mt7620a-eth";
reg = <0x10100000 10000>;
#address-cells = <1>;
#size-cells = <0>;
interrupt-parent = <&cpuintc>;
interrupts = <5>;
resets = <&rstctrl 21 &rstctrl 23>;----当<>内出现多个数据时,一般两个数据一组。。。
reset-names = "fe", "esw";
port@4 {
compatible = "ralink,mt7620a-gsw-port", "ralink,eth-port";
reg = <4>;
status = "disabled";
};
port@5 {
compatible = "ralink,mt7620a-gsw-port", "ralink,eth-port";
reg = <5>;
status = "disabled";
};
mdio-bus {
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
};
};
gsw@10110000 {
compatible = "ralink,mt7620a-gsw";
reg = <0x10110000 8000>;
interrupt-parent = <&intc>;
interrupts = <17>;
};
sdhci@10130000 {
compatible = "ralink,mt7620a-sdhci";
reg = <0x10130000 4000>;
interrupt-parent = <&intc>;
interrupts = <14>;
status = "disabled";
};
ehci@101c0000 {
compatible = "ralink,rt3xxx-ehci";
reg = <0x101c0000 0x1000>;
interrupt-parent = <&intc>;
interrupts = <18>;
status = "disabled";
};
ohci@101c1000 {
compatible = "ralink,rt3xxx-ohci";
reg = <0x101c1000 0x1000>;
interrupt-parent = <&intc>;
interrupts = <18>;
status = "disabled";
};
pcie@10140000 {
compatible = "ralink,mt7620a-pci";
reg = <0x10140000 0x100
0x10142000 0x100>;
resets = <&rstctrl 26>;
reset-names = "pcie0";
interrupt-parent = <&cpuintc>;
interrupts = <4>;
status = "disabled";
};
};
==============================================================================
例如一个在.dts文件中关于gpio资源的描述:
gpio: gpio-controller@1070000000800 {
#gpio-cells = <2>;
compatible = "cavium,octeon-3860-gpio";
reg = <0x10700 0x00000800 0x0 0x100>;
gpio-controller;
........
根据其描述, 可知道gpio控制器的IO内存起始地址为:0x107900000800, 长度为0x100.
即从 0x107900000800 到 0x1079000008ff.
在目标板里使用 cat /proc/iomem 可以看到:
1070000000800-10700000008ff : /soc@0/gpio-controller@1070000000800
/dts-v1/;
/include/ "xxe.dtsi"
/ {
compatible = "xxx0", "ralink,mt7620a-soc";
model = "xxxxx";------model属性表示my board name。
palmbus@10000000 {
gpio1: gpio@638 {
status = "okay";
};
gpio2: gpio@660 {
status = "okay";
};
spi@b00 {
status = "okay";
m25p80@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "en25q64";
reg = <0 0>;
linux,modalias = "m25p80", "w25p128";
spi-max-frequency = <10000000>;
partition@0 {----@后面为该节点寄存器的偏移地址或设备编号
label = "u-boot";
reg = <0x0 0x30000>;---reg属性表示寄存器偏移地址和长度,
还能表示flash分区的便宜地址和长度
read-only;
};
partition@30000 {
label = "u-boot-env";
reg = <0x30000 0x10000>;
read-only;
};
factory: partition@40000 {
label = "factory";
reg = <0x40000 0x10000>;
};
partition@50000 {
label = "firmware";
reg = <0x50000 0xfb0000>;
};
};
};
};
pinctrl {
state_default: pinctrl0 {
default {
ralink,group = "i2c", "rgmii1", "rgmii2";
ralink,function = "gpio";
};
};
};
ethernet@10100000 {
mtd-mac-address = <&factory 0x28>;
ralink,port-map = "llllw";
};
gsw@10110000 {
ralink,port4 = "ephy";
};
ehci@101c0000 {
status = "okay";
};
ohci@101c1000 {
status = "okay";
};
gpio-leds {
compatible = "gpio-leds";
sys {
label = "xxx:blue:sys";
gpios = <&gpio2 20 1>;---用gpio2组的GPIO管脚,偏移地址是20即该组的第20个管脚,默认输出高电平。
};
wan {
label = "xxx:blue:wan";
gpios = <&gpio2 24 1>;
};
wireless {
label = "xxx:blue:wireless";
gpios = <&gpio2 21 1>;
};
};
gpio-keys-polled {
compatible = "gpio-keys-polled";
#address-cells = <1>;
#size-cells = <0>;
poll-interval = <20>;
zigbee {
label = "zigbee";
gpios = <&gpio2 23 1>;-------按此按键后开启zigbee模块业务?
linux,code = <0x197>;
};
reset {
label = "reset";
gpios = <&gpio2 22 1>;
linux,code = <0x198>;-------该属性的含义?
};
};
i2c-gpio {
compatible = "i2c-gpio";
gpios = <&gpio0 1 0 &gpio0 2 0>;-------i2c总线配置两个GPIO管脚
i2c-gpio,delay-us = <100>; /*10KHz */
#address-cells = <1>;
#size-cells = <0>;
pcf8563@51 {-----------------pcf8563为挂在该i2c总线的rtc芯片型号
compatible = "nxp,pcf8563";
reg = <0x51>;
};
};
};