dgibson / dtc

Device Tree Compiler
219 stars 130 forks source link

dtc: introduce label relative path references #54

Closed a3f closed 2 years ago

a3f commented 2 years ago

Reference via label allows extending nodes with compile-time checking of whether the node being extended exists. This is useful to catch renamed/removed nodes after an update of the device trees to be extended.

In absence of labels in the original device trees, new style path references can be used:

/* upstream device tree */
/ {
    leds: some-non-standard-led-controller-name {
        led-0 {
            default-state = "off";
        };
    };
};

/* downstream device tree */
&{/some-non-standard-led-controller-name/led-0} {
    default-state = "on";
};

This is a common theme within the barebox bootloader0, which extends the upstream (Linux) device trees in that manner. The downside is that, especially for deep nodes, these references can get quite long and tend to break often due to upstream rework (e.g. rename to adhere to bindings).

Often there is a label a level or two higher that could be used. This patch allows combining both a label and a new style path reference to get a compile-time-checked reference, which allows rewriting the previous downstream device tree snippet to:

&leds/led-0 {
    default-state = "on";
};

This won't be broken when /some-non-standard-led-controller-name is renamed or moved while keeping the label. And if led-0 is renamed, we will get the expected compile-time error.

Overlay support is skipped for now as they require special support: The label and relative path parts need to be resolved at overlay apply-time, not at compile-time.

a3f commented 2 years ago

@dgibson Any feedback?

dgibson commented 2 years ago

@dgibson Any feedback?

Sorry I've taken so long. I've been pretty busy with other things, and then I injured myself :/.

a3f commented 2 years ago

Sorry I've taken so long. I've been pretty busy with other things, and then I injured myself :/.

Get well soon! Thanks for the feedback, I've just incorporated it.

dgibson commented 2 years ago

Merged, thanks!

a3f commented 2 years ago

Thank you! :)

a3f commented 2 years ago

Just fixed a regression that would've been avoidable with a relative path reference: https://lore.barebox.org/barebox/20220811192612.3021687-1-ahmad@a3f.at/T/#u

Will there perhaps be a new dtc release soon? :-)