如何编程 Linux .dts 设备树文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17488320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:23:42  来源:igfitidea点击:

How to program Linux .dts device tree files?

linuxlinux-kerneldevice-tree

提问by Ezio

I'm going to launch a Linux on my development board, and i need a dts file (device tree file) to describe the whole hardware. But I only know very little about the syntax of this file which is not enough to run Linux properly on the board.

我要在我的开发板上启动一个 Linux,我需要一个 dts 文件(设备树文件)来描述整个硬件。但是我对这个文件的语法知之甚少,不足以在板上正确运行 Linux。

What i know now are only how to describe a unit's interrupt number, frequency, address, parent-unit and its compatible driver type (as described below):

我现在只知道如何描述单元的中断号、频率、地址、父单元及其兼容的驱动程序类型(如下所述):

ps7_scuwdt_0: ps7-scuwdt@f8f00620 {
                        compatible = "xlnx,ps7-scuwdt-1.00.a";
                        device_type = "watchdog";
                        interrupt-parent = <&ps7_scugic_0>;
                        interrupts = < 1 14 769 >;
                        reg = < 0xf8f00620 0xe0 >;
                } ;

Other advanced usage or grammar is unfamiliar to me.

其他高级用法或语法对我来说并不熟悉。

采纳答案by TheCodeArtist

Take a look at the dts of the board which most closely resembles your dev-board. Use that as a reference and make changes to the dts according to the differences between the reference board and your dev-board.

看看与您的开发板最相似的板的 dts。将其用作参考并根据参考板和开发板之间的差异对 dts 进行更改。

Also checkout the following :
- Device-tree Documentation projectat eLinux (has a vast collection of links to start reading).
- Series of articleson the basics of device tree.
- Walkthroughof migrating to device-tree.

另请查看以下内容:
- eLinux 上的设备树文档项目(有大量链接可供开始阅读)。
-关于设备树基础知识的系列文章
-迁移到设备树的演练

回答by Rathin Paul

Lets take a example and I will explain each one of them as below

让我们举一个例子,我将解释每一个如下

auart0: serial@8006a000 {
compatible = "fsl,imx28-auart", "fsl,imx23-auart";
reg = <0x8006a000 0x2000>;
interrupts = <112>;
dmas = <&dma_apbx 8>, <&dma_apbx 9>;
dma-names = "rx", "tx";
};

Required properties:
- compatible : Should be "fsl,-auart". The supported SoCs include imx23 and imx28.
- reg : Address and length of the register set for the device
- interrupts : Should contain the auart interrupt numbers
- dmas: DMA specifier, consisting of a phandle to DMA controller node and AUART DMA channel ID.
- dma-names: "rx" for RX channel, "tx" for TX channel.

必需的属性:
- 兼容:应该是“fsl,-auart”。支持的 SoC 包括 imx23 和 imx28。
- reg:为设备设置的寄存器的地址和长度
- 中断:应包含 auart 中断号
- dmas:DMA 说明符,由 phandle 到 DMA 控制器节点和 AUART DMA 通道 ID 组成。
- dma-names:RX 通道为“rx”,TX 通道为“tx”。

Note: Each auart port should have an alias correctly numbered in "aliases" node.
For more advance properties, please go to this link, it is very useful
Device Tree Explanation

注意:每个 auart 端口都应该有一个在“别名”节点中正确编号的别名。
有关更多高级属性,请转到此链接,这是非常有用的
设备树说明

Hope it helps!

希望能帮助到你!

回答by h0ch5tr4355

Complementary to the other answers:

补充其他答案:

Keep in mind, that there is also a section for devicetrees in the official kernel source under root/Documentation/devicetree(https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree?h=v5.2-rc5).

请记住,在root/Documentation/devicetree( https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree ?h=v5.2-rc5)。