设备树文本文件的写入顺序有关系吗?

The order in which the device-tree text file is written, does it matter?

设备树文本文件 (.dts) 的写入顺序是否重要?

例如,如果您从文件的顶部取出一个节点并将其移动到底部,它会改变硬件检测顺序、IRQ 配置或其他什么吗?

Does the order in which the device-tree text file (.dtx) is written matter at all ?

.dts.dtsi 源文件的答案是 "depends".
设备树具有结构,因此节点的重新排列可能会也可能不会更改系统硬件配置。


总体而言,设备树的结构如下(Device Tree for Dummies 的幻灯片 23)

/ {
    aliases { ... };
    cpus { ... };
    apb@80000000 {
        apbh@80000000 {
            /* Some devices */
        };
        apbx@80040000 {
            /* Some devices */
        };
    };
    ahb@80080000 {
        /* Some devices */
    };
};

设备将由节点描述。
连接到特定总线的设备节点(例如 apbh@80000000)可以按设备地址的数字顺序或按设备名称的字母顺序排序。这种节点顺序(在总线内)并不重要。
但是如果 "you take a node from the top of the file and move it to the bottom" 并且将节点重新分配给不同的总线,那么显然你会定义不同的配置(这可能是不正确的)。


设备树源文本的文件结构由 .dts 文件(用于板)和可选的 .dtsi 组成文件。理想情况下,SoC 应该有一个通用的 .dtsi 文件,并且可以包含在每个使用该 SoC 的 .dts 板文件中。

SoC 的 .dtsi 文件通常由供应商提供,并且应该具有针对所有芯片设备的定义。基本设备(例如电源管理、DMA 控制器)将被定义和启用。但是,非必需的可选外围设备 and/or 那些 I/O 连接到多路复用引脚的外围设备将被禁用。

apbh@80000000 {
    [...]
    hsadc: hsadc@80002000 {
        reg = <0x80002000 0x2000>;
        [...]
        status = "disabled";
    };
    [...]
};

如果您想在开发板上使用可选外围设备,则不应修改或自定义仅适用于开发板的 SoC .dtsi 文件。
相反,您应该在顶级板文件(包括 SoC .dtsi 文件)中增加该设备的节点,并重新声明设备的状态。

#include "my_soc.dtsi"
/ {
    apb@80000000 {
        apbh@80000000 {

            hsadc: hsadc@80002000 {
                status = "okay";
            };

            [...]
        };
    };
};

为了获得正确的配置,带有 status = "okay" 的节点必须位于通用节点之后(在包含的 .dtsi 中),以便 status = "disabled" 可以被覆盖。
很明显,这是位置依赖的另一种情况。


I mean if for example you take a node from the top of the file and move it to the bottom, will it change the order of hardware detection, irq configuration, or whatever ?

设备树仅用于定义系统硬件的配置。设备驱动程序的执行顺序由驱动程序的构建方式控制,即 initcall 宏。参见 init function invocation of drivers compiled into kernel and What is the difference between module_init and subsys_initcall while initializing the driver?
设备驱动程序对资源的获取受该驱动程序的控制,不受设备树属性的控制,设备树属性仅由驱动程序读取。