Hello David, On Thu, Mar 14, 2024 at 03:43:13PM +1100, David Gibson wrote: > On Sun, Mar 10, 2024 at 09:30:31AM +0100, Uwe Kleine-König wrote: > > On Mon, Feb 26, 2024 at 04:53:53PM +1100, David Gibson wrote: > > > On Sun, Feb 25, 2024 at 06:54:23PM +0100, Uwe Kleine-König wrote: > > > > A phandle in an overlay is not supposed to overwrite a phandle that > > > > already exists in the base dtb as this breaks references to the > > > > respective node in the base. > > > > > > > > So add another iteration over the fdto that checks for such overwrites > > > > and fixes the fdto phandle's value to match the fdt's. > > > > > > > > A test is added that checks that newly added phandles and existing > > > > phandles work as expected. > > > > > > > > Signed-off-by: Uwe Kleine-König > > > > --- > > > > Hello, > > > > > > > > here comes the next iteration of the patch that fixes overlay > > > > application to not overwrite existing phandles. > > > > > > > > It is rebased to current main branch. The changes since v2 are: > > > > > > > > - Add documentation > > > > - Apply the simplification from 24f60011fd43 ("libfdt: Simplify > > > > adjustment of values for local fixups") in the functions added here. > > > > - Rename functions using shorter and better names > > > > - Changed the test device trees to yield a hole in the phandle space > > > > - Checked each phandle value not being overwritten separately > > > > > > > > Note I didn't switch the order of overlay_prevent_phandle_overwrite() and > > > > overlay_fixup_phandles() because the overlay's phandles must be resolved > > > > before I can do the recursion needed in > > > > overlay_prevent_phandle_overwrite(). > > > > > > I'm not following what you mean here. IIUC, conflicts of the sort > > > you're handling can only arise when the overlay describes a phandle > > > for the target node of the reference - and therefore that target is in > > > the overlay. In that case all references to it in the overlay should > > > be encoded in __local_fixups__ rather than __fixups__. __fixups__, in > > > contrast describes references to nodes that aren't in the overlay, and > > > so can't be filled in - even with a tentative value - until the > > > overlay is applied. > > > > > > So, I'm not seeing how fixing these conflicts depends on resolution of > > > those "external" fixups, rather than just the "local" fixups. Am I > > > missing something? > > > > yupp, look at the overlay dts I added in tests/. It has > > > > &node_a { > > value = <32>; > > }; > > > > which is translated to: > > > > fragment@1 { > > target = <0xffffffff>; > > __overlay__ { > > value = <0x00000020>; > > }; > > }; > > ... > > __fixups__ { > > node_a = ..., "/fragment@1:target:0" > > }; > > > > Before I can recurse over fragment@1 and the matching base dtb node to > > check for phandle conflicts, I need /fragment@1:target resolved; > > otherwise I don't know where to look in the base dtb. > > > > So if I switch the order, fdtoverlay reports > > > > Failed to apply 'overlay_overlay_phandle.test.dtb': FDT_ERR_BADPHANDLE > > > > in make check. > > Ah, right. It's specifically that we need to resolve the fragment > targets (including via external symbols) before we can resolve this. > Do you have a test case for this specific problem? If not, I'd be > worried, that I or someone else might forget the subtletey and try to > re-order at some point in the future. The test I added fails if you swap the two operations. That's how I noticed. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |