devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Allow specifying target node in fdtoverlay
@ 2025-03-12 19:41 Ayush Singh
  2025-03-12 19:42 ` [PATCH 1/3] libfdt: Add fdt_relative_path_offset Ayush Singh
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ayush Singh @ 2025-03-12 19:41 UTC (permalink / raw)
  To: David Gibson, Andreas Gnau, d-gole, lorforlinux, jkridner,
	robertcnelson, Andrew Davis, Geert Uytterhoeven, Simon Glass,
	Herve Codina, Luca Ceresoli, Thomas Petazzoni
  Cc: devicetree-compiler, Ayush Singh

Linux kernel supports applying overlays to a specific node. This is to
allow kernel drivers to use devicetree for device hotplugging usecases
such as connector + addon-board setups.

The overlays designed in such cases will not work with fdtoverlay
without modification since there is currently no way to specify target
nodes in fdtoverlay.

This functionality is required to allow using the same overlays that can
be used by drivers by providing the target node using program argument.

It is important to note that this only works with `target-path`
fragments. It does not have any effect on phandle target.

In practice, it looks as follows:

base.dts:

```
/dts-v1/;

/ {
        my_node: my-node {
                prop = "hello";
        };
};
```

overlay.dtso:

```
/dts-v1/;
/plugin/;
/ {
	fragment@1 {
		target-path = "";
		__overlay__ {
			baz: baznode {
				baz-property = "baz";
			};
		};
	};
};
```

Apply overlay:

fdtoverlay -t "/my-node" -i base.dtb overlay.dtbo -o final.dtb

Result:

```
/ {
    my-node {
        prop = "hello";
        phandle = <0x00000001>;
        baznode {
            phandle = <0x00000002>;
            baz-property = "baz";
        };
    };
    __symbols__ {
        baz = "/baznode";
        my_node = "/my-node";
    };
};
```

Why not do path fixing in devicetree overlay instead of passing around
target?

I want to provide an implementation that will work in libfdt which seems
to require no allocation. But yes, fixing the target paths in the
overlay blob directly will allow removing most of the other plumbing in
this patch series.

Open Items:

1. Backwards compatibility

   I am not sure what the guidelines for API compatibility are. So, I
   have introduced new functions instead of changing the old function
   signatures. 
   
   Additionally, I have named the new functions differently from the old
   ones (except for fdt_overlay_target_offset_v2) to kinda make them
   completely seperate functions.
   
   Depending on if and when we are allowed to break the API, one of the
   below approaches can be taken:

   a. Break API in future:

      All new functions can be labeled as v2, to signal that they will
      replace the old ones in some future version

   b. Break API now:
      
      Self explanatory. I guess a version bump would be needed, but I am
      not sure how versioning is handled in dtc.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
Ayush Singh (3):
      libfdt: Add fdt_relative_path_offset
      fdtoverlay: Add target option
      tests: Add test for fdtoverlay target argument

 fdtoverlay.c             |  33 ++++++++-------
 libfdt/fdt_overlay.c     |  62 +++++++++++++++++++++-------
 libfdt/fdt_ro.c          |  17 ++++++--
 libfdt/libfdt.h          | 105 +++++++++++++++++++++++++++++++++++++++++++++++
 libfdt/version.lds       |   2 +
 tests/overlay_target.dts |  18 ++++++++
 tests/run_tests.sh       |  14 +++++++
 7 files changed, 218 insertions(+), 33 deletions(-)
---
base-commit: 18f4f305fdd7e14c8941658a29c7b85c27d41de4
change-id: 20250311-fdtoverlay-target-fc638e4c8748

Best regards,
-- 
Ayush Singh <ayush@beagleboard.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-12 19:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-12 19:41 [PATCH 0/3] Allow specifying target node in fdtoverlay Ayush Singh
2025-03-12 19:42 ` [PATCH 1/3] libfdt: Add fdt_relative_path_offset Ayush Singh
2025-03-12 19:42 ` [PATCH 2/3] fdtoverlay: Add target option Ayush Singh
2025-03-12 19:42 ` [PATCH 3/3] tests: Add test for fdtoverlay target argument Ayush Singh

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).