DTS(Device Tree Source)是Linux内核中用于描述硬件配置的一种数据结构,它解决了传统内核中硬件信息硬编码的问题,使得同一内核可以支持多种硬件平台。
/ {
node1 {
a-string-property = "A string";
a-string-list-property = "first string", "second string";
a-byte-data-property = [0x01 0x23 0x34 0x56];
child-node1 {
first-child-property;
second-child-property = <1>;
};
child-node2 {
};
};
node2 {
an-empty-property;
a-cell-property = <1 2 3 4>;
};
};
使用dtc工具将.dts编译为.dtb:
dtc -I dts -O dtb -o output.dtb input.dts
在内核源码中编译:
make dtbs
U-Boot传递:通过bootm命令加载dtb
bootm <kernel_addr> - <dtb_addr>
内嵌DTB:将dtb编译进内核镜像
/ {
compatible = "acme,coyotes-revenge";
gpio0: gpio@10000000 {
compatible = "acme,gpio";
reg = <0x10000000 0x1000>;
interrupts = <1>;
gpio-controller;
#gpio-cells = <2>;
};
leds {
compatible = "gpio-leds";
led0 {
label = "system-status";
gpios = <&gpio0 3 0>;
linux,default-trigger = "heartbeat";
};
};
};
查看系统设备树:
ls /proc/device-tree/
反编译dtb:
dtc -I dtb -O dts -o output.dts input.dtb
内核配置:
CONFIG_PROC_DEVICETREE=y
CONFIG_OF=y
DTS是现代Linux系统支持多种硬件平台的关键技术,掌握DTS的使用可以大大提高嵌入式Linux开发的效率和灵活性。