设备树规范

设备树的规范(dts和dtb)
DTS格式
(1) 语法:
Devicetree node格式:
[label:] node-name[@unit-address] {
[properties definitions]
[child nodes]
};

Property格式1:
[label:] property-name = value(属性=值);

Property格式2(没有值):
[label:] property-name;

Property取值只有3种:
arrays of cells(1个或多个32位数据, 64位数据使用2个32位数据表示),
string(字符串),
bytestring(1个或多个字节)

示例:
a. Arrays of cells : cell就是一个32位的数据
interrupts = <17 0xc>;

b. 64bit数据使用2个cell来表示:
clock-frequency = <0x00000001 0x00000000>;

c. A null-terminated string (有结束符的字符串):
compatible = “simple-bus”;

d. A bytestring(字节序列) :
local-mac-address = [00 00 12 34 56 78]; // 每个byte使用2个16进制数来表示
local-mac-address = [000012345678]; // 每个byte使用2个16进制数来表示

e. 可以是各种值的组合, 用逗号隔开:
compatible = “ns16550”, “ns8250”;
example = <0xf00f0000 19>, “a strange property format”;

(2) DTS文件布局(layout):
/dts-v1/;
[memory reservations] // 格式为: /memreserve/

;
/ {
[property definitions]
[child nodes]
};

(3) 特殊的、默认的属性:
a. 根节点:
#address-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address)
#size-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)
compatible // 定义一系列的字符串, 用来指定内核中哪个machine_desc可以支持本设备
// 即这个板子兼容哪些平台
// uImage : smdk2410 smdk2440 mini2440 ==> machine_desc

model // 咱这个板子是什么
// 比如有2款板子配置基本一致, 它们的compatible是一样的
// 那么就通过model来分辨这2款板子

b. /memory
device_type = “memory”;
reg // 用来指定内存的地址、大小
指定多块内存时:memory@30000000(首地址)

c. /chosen
bootargs // 内核command line参数, 跟u-boot中设置的bootargs作用一样

d. /cpus
/cpus节点下有1个或多个cpu子节点, cpu子节点中用reg属性用来标明自己是哪一个cpu
所以 /cpus 中有以下2个属性:
#address-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address)

#size-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)
// 必须设置为0

e. /cpus/cpu*
device_type = “cpu”;
reg // 表明自己是哪一个cpu

(4) 引用其他节点:
a. phandle : // 节点中的phandle属性, 它的取值必须是唯一的(不要跟其他的phandle值一样)

pic@10000000 {
phandle = <1>;
interrupt-controller;
};

another-device-node {
interrupt-parent = <1>; // 使用phandle值为1来引用上述节点
};

b. label:

PIC: pic@10000000 {
interrupt-controller;
};

another-device-node {
interrupt-parent = <&PIC>; // 使用label来引用上述节点,
// 使用lable时实际上也是使用phandle来引用,
// 在编译dts文件为dtb文件时, 编译器dtc会在dtb中插入phandle属性
};

官方文档:
https://www.devicetree.org/specifications/

第02节_DTB格式
官方文档:
https://www.devicetree.org/specifications/

内核文档:
Documentation/devicetree/booting-without-of.txt

DTB文件布局:
------------------------------
base -> | struct boot_param_header |
------------------------------
| (alignment gap) (*) |
------------------------------
| memory reserve map |
------------------------------
| (alignment gap) |
------------------------------
| |
| device-tree structure |
| |
------------------------------
| (alignment gap) |
------------------------------
| |
| device-tree strings |
| |
-----> ------------------------------
|
|
— (base + totalsize)

zj2440-irq.dts

/*
 * SAMSUNG SMDK2416 board device tree source
 *
 * Copyright (c) 2013 Heiko Stuebner <heiko@sntech.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/dts-v1/;
#include "s3c2440.dtsi"
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/dma/s3c2440_dma_ch.h>

/ {
	model = "JZ2440";
	compatible = "samsung,s3c2440", "samsung,smdk2440";

	aliases {
		i2c1 = &i2c_gpio_1;
	};

	memory {
	        device_type = "memory";
		reg =  <0x30000000 0x4000000>;
	};

	chosen {
		/*bootargs = "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200n8 earlyprintk";*/
		bootargs = "noinitrd root=/dev/mtdblock4 rw init=/linuxrc console=ttySAC0,115200";
	};

	srom-cs4@20000000 {
		compatible = "simple-bus";
		#address-cells = <1>;
		#size-cells = <1>;
		reg = <0x20000000 0x8000000>;
		ranges;

		ethernet@20000000 {
			compatible = "davicom,dm9000";
			reg = <0x20000000 0x2 0x20000004 0x2>;
			interrupt-parent = <&gpf>;
			interrupts = <7 IRQ_TYPE_EDGE_RISING>;
			local-mac-address = [00 00 de ad be ef];
			davicom,no-eeprom;
		};
	};

	i2c_gpio_1: i2c-gpio-1 {
		compatible = "i2c-gpio";
		#address-cells = <1>;
		#size-cells = <0>;
		gpios = <&gpe 15 GPIO_ACTIVE_HIGH>,  // SDA
			<&gpe 14 GPIO_ACTIVE_HIGH>;  // SCL
		i2c-gpio,delay-us = <5>; // 100KHz
		status = "disabled";

		eeprom@50 {
			compatible = "24c02";
			reg = <0x50>;
			pagesize = <32>;
			status = "okay";
		};
	};

	fb0: fb@4d000000{
		compatible = "jz2440,lcd";
		reg = <0x4D000000 0x60>;
		interrupts = <0 0 16 3>;
		clocks = <&clocks HCLK_LCD>;
		clock-names = "lcd";
		pinctrl-names = "default";
		pinctrl-0 = <&lcd_pinctrl &lcd_backlight>;
		status = "okay";

		lcdcon5 = <0xb09>;
		type = <0x60>;
		width = /bits/ 16 <480>;
		height = /bits/ 16 <272>;
		pixclock = <100000>;
		xres = /bits/ 16 <480>;
		yres = /bits/ 16 <272>;
		bpp = /bits/ 16 <16>;
		left_margin = /bits/ 16 <2>;
		right_margin =/bits/ 16  <2>;
		hsync_len = /bits/ 16 <41>;
		upper_margin = /bits/ 16 <2>;
		lower_margin = /bits/ 16 <2>;
		vsync_len = /bits/ 16 <10>;
	};

	jz2440ts@5800000 {
		compatible = "jz2440,ts";
		reg = <0x58000000 0x100>;
		reg-names = "adc_ts_physical";
		interrupts = <1 31 9 3>, <1 31 10 3>;
		interrupt-names = "int_ts", "int_adc_s";
		clocks = <&clocks PCLK_ADC>;
		clock-names = "adc";
	};

	dma: s3c2410-dma@4B000000 {
		compatible = "s3c2440-dma";
		reg = <0x4B000000 0x1000>;
		interrupts = <0 0 17 3>, <0 0 18 3>,
				<0 0 19 3>, <0 0 20 3>;
		#dma-cells = <1>;
	};

	s3c2440_iis@55000000 {
		compatible = "s3c24xx-iis";
		reg = <0x55000000 0x100>;
		clocks = <&clocks PCLK_I2S>;
		clock-names = "iis";
		pinctrl-names = "default";
		pinctrl-0 = <&s3c2440_iis_pinctrl>;
		dmas = <&dma DMACH_I2S_IN>, <&dma DMACH_I2S_OUT>;
		dma-names = "rx", "tx";
	};

	s3c24xx_uda134x {
		compatible = "s3c24xx_uda134x";
		clocks = <&clocks MPLL>, <&clocks PCLK_I2S>;
		clock-names = "mpll", "iis";
	};

	uda134x-codec {
		compatible = "uda134x-codec";
		pinctrl-names = "default";
		pinctrl-0 = <&uda1340_codec_pinctrl>;

		uda,clk_gpio  = <&gpb 4 GPIO_ACTIVE_LOW>;
		uda,data_gpio = <&gpb 3 GPIO_ACTIVE_LOW>;
		uda,mode_gpio = <&gpb 2 GPIO_ACTIVE_LOW>;

		uda,use_gpios;
		uda,data_hold;
		uda,data_setup;
		uda,clock_high;
		uda,mode_hold;
		uda,mode;
		uda,mode_setup;

		uda,model = <2>;  //UDA134X_UDA1341
	};
};

&watchdog {
	status = "okay";
};

&rtc {
	status = "okay";
};

&uart0 {
	status = "okay";
};
/*
&i2c {
	status = "okay";
	samsung,i2c-max-bus-freq = <200000>;

	eeprom@50 {
		compatible = "24c02";
		reg = <0x50>;
		pagesize = <32>;
		status = "okay";
	};
};
*/
&nand0 {
	status = "okay";
	nand,tacls = <0xa>;
	nand,twrph0 = <0x19>;
	nand,twrph1 = <0xa>;

	#address-cells = <1>;
	#size-cells = <1>;

	partitions {
		/* MTD partition table */
		#address-cells = <1>;
		#size-cells = <1>;
		nr-chips = <1>;
		set-name = "jz2440-0";

		partition@0 {
			label = "bootloader";
			reg = <0x0000000 0x40000>;
			read-only;
		};

		partition@40000 {
			label = "device_tree";
			reg = <0x40000 0x20000>;
			read-only;
		};

		partition@60000 {
			label = "params";
			reg = <0x60000 0x20000>;
			read-only;
		};

		partition@80000 {
			label = "kernel";
			reg = <0x80000 0x400000>;
			read-only;
		};

		partition@480000 {
			label = "rootfs";
			reg = <0x480000 0>;
		};
	};
};

&usb_ohci {
	status = "okay";
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值