* [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
* [PATCH 1/3] libfdt: Add fdt_relative_path_offset
2025-03-12 19:41 [PATCH 0/3] Allow specifying target node in fdtoverlay Ayush Singh
@ 2025-03-12 19:42 ` 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
2 siblings, 0 replies; 4+ messages in thread
From: Ayush Singh @ 2025-03-12 19:42 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
Add helper to allow searching for subnode path given a base node offset.
Behaves the same as fdt_path_offset when offset = 0.
Aliases are only allowed when offset == 0.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
libfdt/fdt_ro.c | 17 ++++++++++++++---
libfdt/libfdt.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index b78c4e48f1cb351504af4d861513b47f375262f5..f426183651cff746b67ebfe86e5809325cad4fec 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -247,11 +247,11 @@ int fdt_subnode_offset(const void *fdt, int parentoffset,
return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));
}
-int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
+static int fdt_relative_path_offset_namelen(const void *fdt, const char *path,
+ int namelen, size_t offset)
{
const char *end = path + namelen;
const char *p = path;
- int offset = 0;
FDT_RO_PROBE(fdt);
@@ -259,7 +259,7 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
return -FDT_ERR_BADPATH;
/* see if we have an alias */
- if (*path != '/') {
+ if (*path != '/' && offset == 0) {
const char *q = memchr(path, '/', end - p);
if (!q)
@@ -295,11 +295,22 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
return offset;
}
+int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
+{
+ return fdt_relative_path_offset_namelen(fdt, path, namelen, 0);
+}
+
int fdt_path_offset(const void *fdt, const char *path)
{
return fdt_path_offset_namelen(fdt, path, strlen(path));
}
+int fdt_relative_path_offset(const void *fdt, const char *path, size_t offset)
+{
+ return fdt_relative_path_offset_namelen(fdt, path, strlen(path),
+ offset);
+}
+
const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
{
const struct fdt_node_header *nh = fdt_offset_ptr_(fdt, nodeoffset);
diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index f2675b12f674b2221273d666d51b8e31f9b4dfbe..9b61215ecd11c8990128c0b523443b83f84b1013 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -562,6 +562,59 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
*/
int fdt_path_offset(const void *fdt, const char *path);
+/**
+ * fdt_relative_path_offset - find a tree node by its relative path
+ * @fdt: pointer to the device tree blob
+ * @path: full path of the node to locate
+ * @offset: Offset of starting node
+ *
+ * fdt_relative_path_offset() finds a node of a given path in the device
+ * tree relative to a prior node.
+ *
+ * Each path component may omit the unit address portion, but the
+ * results of this are undefined if any such path component is
+ * ambiguous (that is if there are multiple nodes at the relevant
+ * level matching the given component, differentiated only by unit
+ * address).
+ *
+ * If the path is not absolute (i.e. does not begin with '/') and the
+ * starting offset is not 0, the first component is treated as an alias.
+ * That is, the property by that name is looked up in the /aliases node,
+ * and the value of that property used in place of that first component.
+ *
+ * For example, for this small fragment
+ *
+ * / {
+ * aliases {
+ * i2c2 = &foo; // RHS compiles to "/soc@0/i2c@30a40000/eeprom@52"
+ * };
+ * soc@0 {
+ * foo: i2c@30a40000 {
+ * bar: eeprom@52 {
+ * };
+ * };
+ * };
+ * };
+ *
+ * these would be equivalent:
+ *
+ * /soc@0/i2c@30a40000/eeprom@52
+ * i2c2/eeprom@52
+ *
+ * returns:
+ * structure block offset of the node with the requested path (>=0), on
+ * success
+ * -FDT_ERR_BADPATH, given path does not begin with '/' and the first
+ * component is not a valid alias
+ * -FDT_ERR_NOTFOUND, if the requested node does not exist
+ * -FDT_ERR_BADMAGIC,
+ * -FDT_ERR_BADVERSION,
+ * -FDT_ERR_BADSTATE,
+ * -FDT_ERR_BADSTRUCTURE,
+ * -FDT_ERR_TRUNCATED, standard meanings.
+ */
+int fdt_relative_path_offset(const void *fdt, const char *path, size_t offset);
+
/**
* fdt_get_name - retrieve the name of a given node
* @fdt: pointer to the device tree blob
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] fdtoverlay: Add target option
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 ` Ayush Singh
2025-03-12 19:42 ` [PATCH 3/3] tests: Add test for fdtoverlay target argument Ayush Singh
2 siblings, 0 replies; 4+ messages in thread
From: Ayush Singh @ 2025-03-12 19:42 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.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
fdtoverlay.c | 33 +++++++++++++++-------------
libfdt/fdt_overlay.c | 62 +++++++++++++++++++++++++++++++++++++++-------------
libfdt/libfdt.h | 52 +++++++++++++++++++++++++++++++++++++++++++
libfdt/version.lds | 2 ++
4 files changed, 119 insertions(+), 30 deletions(-)
diff --git a/fdtoverlay.c b/fdtoverlay.c
index ee1eb8f3ad28b14762aca9ab5c8a4e36aac967d8..94c6b089e7ab6054a5ed8794fb183eb69c9a6b89 100644
--- a/fdtoverlay.c
+++ b/fdtoverlay.c
@@ -24,24 +24,23 @@
static const char usage_synopsis[] =
"apply a number of overlays to a base blob\n"
" fdtoverlay <options> [<overlay.dtbo> [<overlay.dtbo>]]";
-static const char usage_short_opts[] = "i:o:v" USAGE_COMMON_SHORT_OPTS;
+static const char usage_short_opts[] = "i:o:t:v" USAGE_COMMON_SHORT_OPTS;
static struct option const usage_long_opts[] = {
- {"input", required_argument, NULL, 'i'},
- {"output", required_argument, NULL, 'o'},
- {"verbose", no_argument, NULL, 'v'},
+ { "input", required_argument, NULL, 'i' },
+ { "output", required_argument, NULL, 'o' },
+ { "target", optional_argument, NULL, 't' },
+ { "verbose", no_argument, NULL, 'v' },
USAGE_COMMON_LONG_OPTS,
};
-static const char * const usage_opts_help[] = {
- "Input base DT blob",
- "Output DT blob",
- "Verbose messages",
- USAGE_COMMON_OPTS_HELP
-};
+static const char *const usage_opts_help[] = { "Input base DT blob",
+ "Output DT blob", "Target node",
+ "Verbose messages",
+ USAGE_COMMON_OPTS_HELP };
int verbose = 0;
static void *apply_one(char *base, const char *overlay, size_t *buf_len,
- const char *name)
+ const char *name, const char *target)
{
char *tmp = NULL;
char *tmpo;
@@ -68,7 +67,7 @@ static void *apply_one(char *base, const char *overlay, size_t *buf_len,
memcpy(tmpo, overlay, fdt_totalsize(overlay));
- ret = fdt_overlay_apply(tmp, tmpo);
+ ret = fdt_overlay_apply_with_target(tmp, tmpo, target);
if (ret == -FDT_ERR_NOSPACE) {
*buf_len += BUF_INCREMENT;
}
@@ -97,7 +96,7 @@ fail:
return NULL;
}
static int do_fdtoverlay(const char *input_filename,
- const char *output_filename,
+ const char *output_filename, const char *target,
int argc, char *argv[])
{
char *blob = NULL;
@@ -142,7 +141,7 @@ static int do_fdtoverlay(const char *input_filename,
/* apply the overlays in sequence */
for (i = 0; i < argc; i++) {
- blob = apply_one(blob, ovblob[i], &buf_len, argv[i]);
+ blob = apply_one(blob, ovblob[i], &buf_len, argv[i], target);
if (!blob)
goto out_err;
}
@@ -171,6 +170,7 @@ int main(int argc, char *argv[])
int opt, i;
char *input_filename = NULL;
char *output_filename = NULL;
+ const char *target = NULL;
while ((opt = util_getopt_long()) != EOF) {
switch (opt) {
@@ -185,6 +185,9 @@ int main(int argc, char *argv[])
case 'v':
verbose = 1;
break;
+ case 't':
+ target = optarg;
+ break;
}
}
@@ -207,7 +210,7 @@ int main(int argc, char *argv[])
printf("overlay[%d] = %s\n", i, argv[i]);
}
- if (do_fdtoverlay(input_filename, output_filename, argc, argv))
+ if (do_fdtoverlay(input_filename, output_filename, target, argc, argv))
return 1;
return 0;
diff --git a/libfdt/fdt_overlay.c b/libfdt/fdt_overlay.c
index e6b9eb6439585364ff4e84eecacea7a61bcc67eb..b8df3a9d69949d73f61b4f8644e20cebe44c444b 100644
--- a/libfdt/fdt_overlay.c
+++ b/libfdt/fdt_overlay.c
@@ -40,8 +40,9 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)
return fdt32_to_cpu(*val);
}
-int fdt_overlay_target_offset(const void *fdt, const void *fdto,
- int fragment_offset, char const **pathp)
+int fdt_overlay_target_offset_v2(const void *fdt, const void *fdto,
+ int fragment_offset, char const **pathp,
+ const char *target)
{
uint32_t phandle;
const char *path = NULL;
@@ -56,10 +57,24 @@ int fdt_overlay_target_offset(const void *fdt, const void *fdto,
if (!phandle) {
/* And then a path based lookup */
path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len);
- if (path)
- ret = fdt_path_offset(fdt, path);
- else
+ if (path) {
+ /* Either target or path should be non-null */
+ if (target == NULL && strlen(path) == 0)
+ return -FDT_ERR_BADPATH;
+
+ ret = 0;
+ if (target) {
+ ret = fdt_path_offset(fdt, target);
+
+ if (ret < 0)
+ return ret;
+ }
+
+ if (strlen(path) > 0)
+ ret = fdt_relative_path_offset(fdt, path, ret);
+ } else {
ret = path_len;
+ }
} else
ret = fdt_node_offset_by_phandle(fdt, phandle);
@@ -84,6 +99,13 @@ int fdt_overlay_target_offset(const void *fdt, const void *fdto,
return ret;
}
+int fdt_overlay_target_offset(const void *fdt, const void *fdto,
+ int fragment_offset, char const **pathp)
+{
+ return fdt_overlay_target_offset_v2(fdt, fdto, fragment_offset, pathp,
+ NULL);
+}
+
/**
* overlay_phandle_add_offset - Increases a phandle by an offset
* @fdt: Base device tree blob
@@ -710,7 +732,8 @@ static int overlay_prevent_phandle_overwrite_node(void *fdt, int fdtnode,
* 0 on success
* Negative error code on failure
*/
-static int overlay_prevent_phandle_overwrite(void *fdt, void *fdto)
+static int overlay_prevent_phandle_overwrite(void *fdt, void *fdto,
+ const char *target_path)
{
int fragment;
@@ -726,7 +749,8 @@ static int overlay_prevent_phandle_overwrite(void *fdt, void *fdto)
if (overlay < 0)
return overlay;
- target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL);
+ target = fdt_overlay_target_offset_v2(fdt, fdto, fragment, NULL,
+ target_path);
if (target == -FDT_ERR_NOTFOUND)
/*
* The subtree doesn't exist in the base, so nothing
@@ -826,7 +850,7 @@ static int overlay_apply_node(void *fdt, int target,
* 0 on success
* Negative error code on failure
*/
-static int overlay_merge(void *fdt, void *fdto)
+static int overlay_merge(void *fdt, void *fdto, const char *target_path)
{
int fragment;
@@ -846,7 +870,8 @@ static int overlay_merge(void *fdt, void *fdto)
if (overlay < 0)
return overlay;
- target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL);
+ target = fdt_overlay_target_offset_v2(fdt, fdto, fragment, NULL,
+ target_path);
if (target < 0)
return target;
@@ -902,7 +927,7 @@ static int get_path_len(const void *fdt, int nodeoffset)
* 0 on success
* Negative error code on failure
*/
-static int overlay_symbol_update(void *fdt, void *fdto)
+static int overlay_symbol_update(void *fdt, void *fdto, const char *target_p)
{
int root_sym, ov_sym, prop, path_len, fragment, target;
int len, frag_name_len, ret, rel_path_len;
@@ -989,7 +1014,8 @@ static int overlay_symbol_update(void *fdt, void *fdto)
return -FDT_ERR_BADOVERLAY;
/* get the target of the fragment */
- ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
+ ret = fdt_overlay_target_offset_v2(fdt, fdto, fragment,
+ &target_path, target_p);
if (ret < 0)
return ret;
target = ret;
@@ -1011,7 +1037,8 @@ static int overlay_symbol_update(void *fdt, void *fdto)
if (!target_path) {
/* again in case setprop_placeholder changed it */
- ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
+ ret = fdt_overlay_target_offset_v2(fdt, fdto, fragment,
+ &target_path, NULL);
if (ret < 0)
return ret;
target = ret;
@@ -1038,6 +1065,11 @@ static int overlay_symbol_update(void *fdt, void *fdto)
}
int fdt_overlay_apply(void *fdt, void *fdto)
+{
+ return fdt_overlay_apply_with_target(fdt, fdto, NULL);
+}
+
+int fdt_overlay_apply_with_target(void *fdt, void *fdto, const char *target)
{
uint32_t delta;
int ret;
@@ -1065,15 +1097,15 @@ int fdt_overlay_apply(void *fdt, void *fdto)
goto err;
/* Don't overwrite phandles in fdt */
- ret = overlay_prevent_phandle_overwrite(fdt, fdto);
+ ret = overlay_prevent_phandle_overwrite(fdt, fdto, target);
if (ret)
goto err;
- ret = overlay_merge(fdt, fdto);
+ ret = overlay_merge(fdt, fdto, target);
if (ret)
goto err;
- ret = overlay_symbol_update(fdt, fdto);
+ ret = overlay_symbol_update(fdt, fdto, target);
if (ret)
goto err;
diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index 9b61215ecd11c8990128c0b523443b83f84b1013..7a8d3903188487890a88920394e715bc23e11784 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -2317,6 +2317,38 @@ int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
*/
int fdt_del_node(void *fdt, int nodeoffset);
+/**
+ * fdt_overlay_apply_with_target - Applies a DT overlay on a base DT
+ * @fdt: pointer to the base device tree blob
+ * @fdto: pointer to the device tree overlay blob
+ * @target: target node path
+ *
+ * fdt_overlay_apply_with_target() will apply the given device tree overlay
+ * on the given node in base device tree.
+ *
+ * Expect the base device tree to be modified, even if the function
+ * returns an error.
+ *
+ * returns:
+ * 0, on success
+ * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
+ * -FDT_ERR_NOTFOUND, the overlay points to some nonexistent nodes or
+ * properties in the base DT
+ * -FDT_ERR_BADPHANDLE,
+ * -FDT_ERR_BADOVERLAY,
+ * -FDT_ERR_NOPHANDLES,
+ * -FDT_ERR_INTERNAL,
+ * -FDT_ERR_BADLAYOUT,
+ * -FDT_ERR_BADMAGIC,
+ * -FDT_ERR_BADOFFSET,
+ * -FDT_ERR_BADPATH,
+ * -FDT_ERR_BADVERSION,
+ * -FDT_ERR_BADSTRUCTURE,
+ * -FDT_ERR_BADSTATE,
+ * -FDT_ERR_TRUNCATED, standard meanings
+ */
+int fdt_overlay_apply_with_target(void *fdt, void *fdto, const char *target);
+
/**
* fdt_overlay_apply - Applies a DT overlay on a base DT
* @fdt: pointer to the base device tree blob
@@ -2348,6 +2380,26 @@ int fdt_del_node(void *fdt, int nodeoffset);
*/
int fdt_overlay_apply(void *fdt, void *fdto);
+/**
+ * fdt_overlay_target_offset_v2 - retrieves the offset of a fragment's target
+ * @fdt: Base device tree blob
+ * @fdto: Device tree overlay blob
+ * @fragment_offset: node offset of the fragment in the overlay
+ * @pathp: pointer which receives the path of the target (or NULL)
+ * @path_prefix: prefix added to any target-path property
+ *
+ * fdt_overlay_target_offset_v2() retrieves the target offset in the base
+ * device tree of a fragment, no matter how the actual targeting is
+ * done (through a phandle or a path)
+ *
+ * returns:
+ * the targeted node offset in the base device tree
+ * Negative error code on error
+ */
+int fdt_overlay_target_offset_v2(const void *fdt, const void *fdto,
+ int fragment_offset, char const **pathp,
+ const char *path_prefix);
+
/**
* fdt_overlay_target_offset - retrieves the offset of a fragment's target
* @fdt: Base device tree blob
diff --git a/libfdt/version.lds b/libfdt/version.lds
index cbfef546de6c7dd2b26a5298be46687be9779233..f9351042ec4ffcabbc14076ddf69115eccde5d9a 100644
--- a/libfdt/version.lds
+++ b/libfdt/version.lds
@@ -68,6 +68,7 @@ LIBFDT_1.2 {
fdt_stringlist_get;
fdt_resize;
fdt_overlay_apply;
+ fdt_overlay_apply_with_target;
fdt_get_string;
fdt_find_max_phandle;
fdt_generate_phandle;
@@ -80,6 +81,7 @@ LIBFDT_1.2 {
fdt_setprop_inplace_namelen_partial;
fdt_create_with_flags;
fdt_overlay_target_offset;
+ fdt_overlay_target_offset_v2;
fdt_get_symbol;
fdt_get_symbol_namelen;
local:
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] tests: Add test for fdtoverlay target argument
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 ` Ayush Singh
2 siblings, 0 replies; 4+ messages in thread
From: Ayush Singh @ 2025-03-12 19:42 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
A simple test that using target argument works for both the base node
overlay contents as well as any additions to subnodes.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
tests/overlay_target.dts | 18 ++++++++++++++++++
tests/run_tests.sh | 14 ++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/tests/overlay_target.dts b/tests/overlay_target.dts
new file mode 100644
index 0000000000000000000000000000000000000000..41b32e2c48e83bda85a3482083a9509e3721a0ba
--- /dev/null
+++ b/tests/overlay_target.dts
@@ -0,0 +1,18 @@
+/dts-v1/;
+/plugin/;
+
+/ {
+ fragment@1 {
+ target-path = "";
+ __overlay__ {
+ test-str-property = "1";
+ };
+ };
+
+ fragment@2 {
+ target-path = "sub-test-node";
+ __overlay__ {
+ test-str-property = "2";
+ };
+ };
+};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 937b128864d03a2aaa8edc171d7ec7bd8fa28569..1b0819271d796a73a73849e192f1af6bde557b1f 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -1057,6 +1057,20 @@ fdtoverlay_tests() {
run_fdtoverlay_test baz "/foonode/barnode/baznode" "baz-property" "-ts" ${stacked_base_nolabeldtb} ${stacked_addlabel_targetdtb} ${stacked_addlabeldtb} ${stacked_bardtb} ${stacked_bazdtb}
+ # test applying overlay to a target
+ overlay_base="$SRCDIR/overlay_base.dts"
+ overlay_basedtb=overlay_base.test.dtb
+ overlay_target="$SRCDIR/overlay_target.dts"
+ overlay_targetdtb=overlay_target.test.dtb
+
+ run_dtc_test -@ -I dts -O dtb -o $overlay_basedtb $overlay_base
+ run_dtc_test -@ -I dts -O dtb -o $overlay_targetdtb $overlay_target
+
+ run_wrap_test $FDTOVERLAY -t "/test-node" -i $overlay_basedtb -o overlay_base0.test.dtb $overlay_targetdtb
+
+ run_fdtget_test "1" overlay_base0.test.dtb "/test-node" "test-str-property"
+ run_fdtget_test "2" overlay_base0.test.dtb "/test-node/sub-test-node" "test-str-property"
+
# verify that phandles are not overwritten
run_dtc_test -@ -I dts -O dtb -o overlay_base_phandle.test.dtb "$SRCDIR/overlay_base_phandle.dts"
run_dtc_test -@ -I dts -O dtb -o overlay_overlay_phandle.test.dtb "$SRCDIR/overlay_overlay_phandle.dts"
--
2.48.1
^ permalink raw reply related [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).