[PATCH 0/3] Allow specifying target node in fdtoverlay

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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@xxxxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxxx>





[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux