From: "Uwe Kleine-König" <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: David Gibson
<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>,
Jon Loeliger <loeliger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Devicetree Compiler
<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Yves-Alexis Perez
<corsac-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org>,
Ahmad Fatoum <a.fatoum-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Subject: Re: ftdoverlay overwrites phandle
Date: Mon, 1 Aug 2022 14:22:37 +0200 [thread overview]
Message-ID: <20220801122237.n2vaqncnl3h4dnsu@pengutronix.de> (raw)
In-Reply-To: <CAL_JsqJbU6vUhxRodTSFmPjPUAvw3-qcu=usdPp9Ym43CM+t9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 4464 bytes --]
Hello Rob,
On Tue, Jul 12, 2022 at 09:53:57AM -0600, Rob Herring wrote:
> On Wed, Jun 29, 2022 at 3:20 PM Uwe Kleine-König <ukleinek-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org> wrote:
> >
> > Hello,
> >
> > I want to apply an overlay to a device tree that is compiled without -@
> > because that's how dtbs are shipped by the Debian kernel package.
>
> Does applying this overlay work as expected if -@ is used? I would
> imagine so as there is an assumption the base dtb was compiled with
> -@.
No it doesn't. I created a minimal (oh well, at least small) reproducer:
uwe@taurus:~/gsrc/oftreemerge$ cat base.dts
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
node_a: a {
prop = "blub";
};
node_b: b {
a = <&node_a>;
};
};
uwe@taurus:~/gsrc/oftreemerge$ cat overlay.dts
/dts-v1/;
/plugin/;
/ {
fragment@0 {
target-path = "/";
__overlay__ {
node_a: a {
};
c {
a = <&node_a>;
};
};
};
};
When compiling without -@ (as reported initially) I get:
uwe@taurus:~/gsrc/oftreemerge$ dtc -I dts -O dtb -o base.dtb base.dts
uwe@taurus:~/gsrc/oftreemerge$ dtc -I dts -O dtb -o overlay.dtbo overlay.dts
uwe@taurus:~/gsrc/oftreemerge$ fdtoverlay -i base.dtb -o patched.dtb overlay.dtbo
uwe@taurus:~/gsrc/oftreemerge$ fdtdump patched.dtb
...
/ {
#address-cells = <0x00000001>;
#size-cells = <0x00000001>;
c {
a = <0x00000002>;
};
a {
prop = "blub";
phandle = <0x00000002>;
};
b {
a = <0x00000001>;
};
};
So b.a gets broken as the phandle for a got updated.
When doing the same with -@ the result is identical (apart from the
expected changes: more and different phandles, __symbols__ node etc):
uwe@taurus:~/gsrc/oftreemerge$ dtc -@ -I dts -O dtb -o base.dtb base.dts
uwe@taurus:~/gsrc/oftreemerge$ dtc -@ -I dts -O dtb -o overlay.dtbo overlay.dts
uwe@taurus:~/gsrc/oftreemerge$ fdtoverlay -i base.dtb -o patched.dtb overlay.dtbo
uwe@taurus:~/gsrc/oftreemerge$ fdtdump patched.dtb
...
/ {
#address-cells = <0x00000001>;
#size-cells = <0x00000001>;
c {
a = <0x00000003>;
};
a {
prop = "blub";
phandle = <0x00000003>;
};
b {
a = <0x00000001>;
phandle = <0x00000002>;
};
__symbols__ {
node_a = "/a";
node_b = "/b";
};
};
b.a still points to a non-existing node.
> The fix is to fix Debian dtbs
One of the blockers for that is that adding -@ to the kernel default
rules was rejected more than once.
(https://lore.kernel.org/linux-arm-kernel/CAK7LNAS5t1wew0MMFjdB5HGCAMerhU7pAGiFhcTtCRUAAjGLpw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org/)
> (or don't use them as dtbs should come from firmware rather than
> distros).
In this case the distro provides the firmware, too. So well, you could
argue the dtbs should (in this case) be provided by the raspi-firmware
package and not the kernel image package, but that only makes things
harder to handle, because the kernel is effectively the upstream for the
device tree files.
> There might be sufficient information to make your case work because
> IIRC all the (resolved) overlay phandle values get adjusted when
> applied as they could collide with the base tree phandle values.
> However, doing so would mean users may start working around base DTs
> compiled without -@. That would remove labels being an ABI which I
> don't love, but it would also remove the abstraction that labels
> provide.
My point of view is a bit different. It would allow to practically apply
overlays to device trees without -@. It doesn't limit in any way the
semantic of labels in the case where -@ is used. I can accept we're
differing in that point and I don't think working on reaching an
agreement here is time spend well.
> Certainly, the base phandle value shouldn't just be silently overwritten.
We agree here, which is good enough for me.
Fixing that is a bit complicated, because currently fdtoverlay just
applies a fixed offset to the phandle values defined in the overlay. I
think it would need another pass over the device tree to determine
already existing phandles and maintaining a mapping for these.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2022-08-01 12:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-29 20:59 ftdoverlay overwrites phandle Uwe Kleine-König
[not found] ` <20220629205925.v56wxrvib33tgu65-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2022-07-04 20:04 ` Uwe Kleine-König
2022-07-12 15:53 ` Rob Herring
[not found] ` <CAL_JsqJbU6vUhxRodTSFmPjPUAvw3-qcu=usdPp9Ym43CM+t9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-08-01 12:22 ` Uwe Kleine-König [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220801122237.n2vaqncnl3h4dnsu@pengutronix.de \
--to=u.kleine-koenig-bicnvbalz9megne8c9+irq@public.gmane.org \
--cc=a.fatoum-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=corsac-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=loeliger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).