设备树覆盖:片段编号

device-tree overlay: fragment numbers

考虑以下设备树覆盖示例。 片段编号为 0、1、2。

数字重要吗? 他们必须按升序排列吗? 或者 0、2、1 也可以吗? 在哪里指定的?

/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&foo>;
        __overlay__ {
            ...
        };
    };

    fragment@1 {
        target = <&bar>;
        __overlay__ {
            ...
        };
    };

    fragment@2 {
        target = <&baz>;
        __overlay__ {
            ...
        };
    };

};

那些数字(和名字)并不重要。看看 drivers/of/overlay.c:

中的下一个函数

of_overlay_create() -> of_build_overlay_info() -> of_fill_overlay_info() -> find_target_node()

如您所见,代码只是遍历 tree(使用 for_each_child_of_node()),然后通过 "__overlay__" 名称获取感兴趣的节点,如下所示:

ovinfo->overlay = of_get_child_by_name(info_node, "__overlay__");

所以那些碎片只是一些节点,它们的名字并不重要。唯一真正使用的是那些节点的内容。

我什至可以假设您可以完全省略那些 @1@2 后缀。看一下 Device Tree specification(第 2.2.1 节节点名称):

Each node in the device tree is named according to the following convention:

node-name@unit-address

The unit-address component of the name is specific to the bus type on which the node sits. It consists of one or more ASCII characters from the set of characters in Table 2-1. The unit-address must match the first address specified in the reg property of the node. If the node has no reg property, the @ and unit-address must be omitted and the node-name alone differentiates the node from other nodes at the same level in the tree. The binding for a particular bus may specify additional, more specific requirements for the format of reg and the unit-address.

当然,在解析设备树文件的代码中可以有一些技巧,像这样:drivers/of/fdt.c, unflatten_dt_node():

if ((*p1) == '@')

但我真的怀疑“@”后面的数字是否有意义(在你的情况下)。