Skip to contentSkip to conversation

uboot overlays and FIT image

PATCH Superseded Pantelis Antoniou 7 participants 28 messages Jun 30, 2017 – Jul 28, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover uboot overlays and FIT image

This patch allows uboot to handle overlays in a manner that uses a base DT blob and an arbitrary number of DT overlays blobs.

It is intended to be used with FIT images since handling a multitude of device tree blobs manually is a chore.

The first 3 patches have already been submitted to DTC for review, and provide the plumbing in libfdt.

The next patch adds a unit test for a stacked overlay (in which an overlay refers to a symbol contained in a previously applied overlay).

The last patch contains the FIT FDT blob generation logic as well as documentation about how it all works.

The patchset is available at

https://github.com/pantoniou/u-boot/tree/uboot-overlays

and is against mainline u-boot as pulled today, 30/6/2017.

Pantelis Antoniou (5):
libfdt.h: Introduce FDT_PATH_MAX
libfdt_env.h: Add <malloc.h> in libfdt environment
fdt: Allow stacked overlays phandle references
test: overlay: Add unit test for stacked overlay
fit: Introduce methods for applying overlays on fit-load

 common/image-fdt.c                           |   7 +-
 common/image-fit.c                           | 215 ++++++++++++++++++++++++--
 doc/uImage.FIT/command_syntax_extensions.txt |  12 +-
 doc/uImage.FIT/overlay-fdt-boot.txt          | 221 +++++++++++++++++++++++++++
 doc/uImage.FIT/source_file_format.txt        |   6 +-
 include/image.h                              |  10 ++
 include/libfdt_env.h                         |   1 +
 lib/libfdt/fdt_overlay.c                     | 148 +++++++++++++++++-
 lib/libfdt/libfdt.h                          |   3 +
 test/overlay/Makefile                        |   1 +
 test/overlay/cmd_ut_overlay.c                |  34 ++++-
 test/overlay/test-fdt-overlay-stacked.dts    |  21 +++
 12 files changed, 659 insertions(+), 20 deletions(-)
 create mode 100644 doc/uImage.FIT/overlay-fdt-boot.txt
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/5 libfdt.h: Introduce FDT_PATH_MAX

Introduce FDT_PATH_MAX

---
 lib/libfdt/libfdt.h | 3 +++
 1 file changed, 3 insertions(+)
lib/libfdt/libfdt.h +3 -0
index 2f7ebf8..c369015 100644
@@ -100,6 +100,9 @@
 
 #define FDT_ERR_MAX		18
 
+/* Maximum path size of a node (similar to PATH_MAX in *nix) */
+#define FDT_PATH_MAX	4096
+
 /**********************************************************************/
 /* Low-level functions (you probably don't need these)                */
 /**********************************************************************/
Signature · 1 line
2.1.4
#2 lore raw

PATCH 1/5 libfdt.h: Introduce FDT_PATH_MAX

Quoted 1 line · Pantelis Antoniou

Introduce FDT_PATH_MAX

Because ... why ? The commit message is crap, please fix.

Quoted 20 lines
---
 lib/libfdt/libfdt.h | 3 +++
 1 file changed, 3 insertions(+)
lib/libfdt/libfdt.h +3 -0
index 2f7ebf8..c369015 100644
@@ -100,6 +100,9 @@
 
 #define FDT_ERR_MAX		18
 
+/* Maximum path size of a node (similar to PATH_MAX in *nix) */
+#define FDT_PATH_MAX	4096
+
 /**********************************************************************/
 /* Low-level functions (you probably don't need these)                */
 /**********************************************************************/
Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw

PATCH 1/5 libfdt.h: Introduce FDT_PATH_MAX

Hi,

Quoted 4 lines · Marek Vasut
Quoted 1 line · Pantelis Antoniou

Introduce FDT_PATH_MAX

Because ... why ? The commit message is crap, please fix.

A better way of saying this is, please add a motivation to the commit message :-)

Apart from that:

We can just pick it from upstream if it is applied there first.

Quoted 14 lines
Quoted 14 lines
---
 lib/libfdt/libfdt.h | 3 +++
 1 file changed, 3 insertions(+)
lib/libfdt/libfdt.h +0 -0
index 2f7ebf8..c369015 100644
@@ -100,6 +100,9 @@
 
 #define FDT_ERR_MAX          18
 
Quoted 12 lines

lib/libfdt/libfdt.h line 108

Quoted 7 lines
lib/libfdt/libfdt.h +3 -0
+/* Maximum path size of a node (similar to PATH_MAX in *nix) */
+#define FDT_PATH_MAX 4096
+
 /**********************************************************************/
 /* Low-level functions (you probably don't need these)                */
 /**********************************************************************/

--
Best regards,
Marek Vasut

Regards,
Simon

#4 lore raw

PATCH 1/5 libfdt.h: Introduce FDT_PATH_MAX

Hi Simon,

Quoted 11 lines · Simon Glass

Hi,

Quoted 4 lines · Marek Vasut
Quoted 1 line · Pantelis Antoniou

Introduce FDT_PATH_MAX

Because ... why ? The commit message is crap, please fix.

A better way of saying this is, please add a motivation to the commit message :-)

Err, will do, but it's part of a patchset and it's so similar to what PATH_MAX does. Yeah I guess :)

Quoted 6 lines

Apart from that:

We can just pick it from upstream if it is applied there first.

Regards

-- Pantelis

Quoted 29 lines
Quoted 14 lines
Quoted 14 lines
---
 lib/libfdt/libfdt.h | 3 +++
 1 file changed, 3 insertions(+)
lib/libfdt/libfdt.h +0 -0
index 2f7ebf8..c369015 100644
@@ -100,6 +100,9 @@
 
 #define FDT_ERR_MAX          18
 
Quoted 12 lines

lib/libfdt/libfdt.h line 108

Quoted 7 lines
lib/libfdt/libfdt.h +3 -0
+/* Maximum path size of a node (similar to PATH_MAX in *nix) */
+#define FDT_PATH_MAX 4096
+
 /**********************************************************************/
 /* Low-level functions (you probably don't need these)                */
 /**********************************************************************/

--
Best regards,
Marek Vasut

Regards,
Simon

#5 lore raw

PATCH 2/5 libfdt_env.h: Add <malloc.h> in libfdt environment

In reply to Pantelis Antoniou

Overlays require malloc so add it in the libfdt environment.

---
 include/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
include/libfdt_env.h +1 -0
index 6c6845f..59463c0 100644
@@ -27,6 +27,7 @@ typedef __be64 fdt64_t;
 #include <vsprintf.h>
 
 #define strtoul(cp, endp, base)	simple_strtoul(cp, endp, base)
+#include <malloc.h>
 #endif
 
 /* adding a ramdisk needs 0x44 bytes in version 2008.10 */
Signature · 1 line
2.1.4
#6 lore raw

PATCH 2/5 libfdt_env.h: Add <malloc.h> in libfdt environment

Quoted 1 line · Pantelis Antoniou

Overlays require malloc so add it in the libfdt environment.

Include this where it's actually used, not in some header.

Quoted 18 lines
---
 include/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
include/libfdt_env.h +1 -0
index 6c6845f..59463c0 100644
@@ -27,6 +27,7 @@ typedef __be64 fdt64_t;
 #include <vsprintf.h>
 
 #define strtoul(cp, endp, base)	simple_strtoul(cp, endp, base)
+#include <malloc.h>
 #endif
 
 /* adding a ramdisk needs 0x44 bytes in version 2008.10 */
Signature · 2 lines
Best regards,
Marek Vasut
#7 lore raw

PATCH 2/5 libfdt_env.h: Add <malloc.h> in libfdt environment

Hi Marek,

Quoted 5 lines · Marek Vasut
Quoted 1 line · Pantelis Antoniou

Overlays require malloc so add it in the libfdt environment.

Include this where it's actually used, not in some header.

This follows the same method of libfdt adaption layer, that all required headers are placed in the libfdt_env.h file so that upreving to a new libfdt version is less painful.

Sorry, libfdt is not normal u-boot code :)

Quoted 12 lines
Quoted 12 lines
---
 include/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
include/libfdt_env.h +0 -0
index 6c6845f..59463c0 100644
@@ -27,6 +27,7 @@ typedef __be64 fdt64_t;
 #include <vsprintf.h>
 
Quoted 8 lines

include/libfdt_env.h typedef __be64 fdt64_t; · line 33

Quoted 6 lines
include/libfdt_env.h +1 -0
 #define strtoul(cp, endp, base)	simple_strtoul(cp, endp, base)
+#include <malloc.h>
 #endif
 
 /* adding a ramdisk needs 0x44 bytes in version 2008.10 */

Regards

-- Pantelis

#8 lore raw

PATCH 2/5 libfdt_env.h: Add <malloc.h> in libfdt environment

In reply to Pantelis Antoniou
Quoted 20 lines · Pantelis Antoniou

Overlays require malloc so add it in the libfdt environment.

---
 include/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
include/libfdt_env.h +1 -1
index 6c6845f..59463c0 100644
@@ -27,6 +27,7 @@ typedef __be64 fdt64_t;
 #include <vsprintf.h>
 
 #define strtoul(cp, endp, base)        simple_strtoul(cp, endp, base)
+#include <malloc.h>
 #endif
 
 /* adding a ramdisk needs 0x44 bytes in version 2008.10 */
--
Quoted 2 lines

2.1.4

#9 lore raw

PATCH 3/5 fdt: Allow stacked overlays phandle references

In reply to Pantelis Antoniou

This patch enables an overlay to refer to a previous overlay's labels by performing a merge of symbol information at application time.

In a nutshell it allows an overlay to refer to a symbol that a previous overlay has defined. It requires both the base and all the overlays to be compiled with the -@ command line switch so that symbol information is included.

base.dts
--------

	/dts-v1/;
	/ {
		foo: foonode {
			foo-property;
		};
	};

	$ dtc -@ -I dts -O dtb -o base.dtb base.dts

bar.dts
-------

	/dts-v1/;
	/plugin/;
	/ {
		fragment at 1 {
			target = <&foo>;
			__overlay__ {
				overlay-1-property;
				bar: barnode {
					bar-property;
				};
			};
		};
	};

	$ dtc -@ -I dts -O dtb -o bar.dtb bar.dts

baz.dts
-------

	/dts-v1/;
	/plugin/;
	/ {
		fragment at 1 {
			target = <&bar>;
			__overlay__ {
				overlay-2-property;
				baz: baznode {
					baz-property;
				};
			};
		};
	};

	$ dtc -@ -I dts -O dtb -o baz.dtb baz.dts

Applying the overlays:

	$ fdtoverlay -i base.dtb -o target.dtb bar.dtb baz.dtb

Dumping:

	$ fdtdump target.dtb
	/ {
            foonode {
                overlay-1-property;
                foo-property;
                linux,phandle = <0x00000001>;
                phandle = <0x00000001>;
                barnode {
                    overlay-2-property;
                    phandle = <0x00000002>;
                    linux,phandle = <0x00000002>;
                    bar-property;
                    baznode {
                        phandle = <0x00000003>;
                        linux,phandle = <0x00000003>;
                        baz-property;
                    };
                };
            };
            __symbols__ {
                baz = "/foonode/barnode/baznode";
                bar = "/foonode/barnode";
                foo = "/foonode";
            };
	};
---
 lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 147 insertions(+), 1 deletion(-)
lib/libfdt/fdt_overlay.c +147 -1
index ceb9687..59fd7f3 100644
@@ -590,7 +590,7 @@ static int overlay_apply_node(void *fdt, int target,
  *
  * overlay_merge() merges an overlay into its base device tree.
  *
- * This is the final step in the device tree overlay application
+ * This is the next to last step in the device tree overlay application
  * process, when all the phandles have been adjusted and resolved and
  * you just have to merge overlay into the base device tree.
  *
@@ -630,6 +630,148 @@ static int overlay_merge(void *fdt, void *fdto)
 	return 0;
 }
 
+/**
+ * overlay_symbol_update - Update the symbols of base tree after a merge
+ * @fdt: Base Device Tree blob
+ * @fdto: Device tree overlay blob
+ *
+ * overlay_symbol_update() updates the symbols of the base tree with the
+ * symbols of the applied overlay
+ *
+ * This is the last step in the device tree overlay application
+ * process, allowing the reference of overlay symbols by subsequent
+ * overlay operations.
+ *
+ * returns:
+ *      0 on success
+ *      Negative error code on failure
+ */
+static int overlay_symbol_update(void *fdt, void *fdto)
+{
+	int root_sym, ov_sym, prop, path_len, fragment, target;
+	int len, frag_name_len, ret, rel_path_len;
+	const char *s;
+	const char *path;
+	const char *name;
+	const char *frag_name;
+	const char *rel_path;
+	char *buf = NULL;
+
+	root_sym = fdt_subnode_offset(fdt, 0, "__symbols__");
+	ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__");
+
+	/* if neither exist we can't update symbols, but that's OK */
+	if (root_sym < 0 || ov_sym < 0)
+		return 0;
+
+	buf = malloc(FDT_PATH_MAX);
+	if (!buf)
+		return -FDT_ERR_NOSPACE;
+
+	/* iterate over each overlay symbol */
+	fdt_for_each_property_offset(prop, fdto, ov_sym) {
+
+		path = fdt_getprop_by_offset(fdto, prop, &name, &path_len);
+		if (!path) {
+			ret = path_len;
+			goto out;
+		}
+
+		/* skip autogenerated properties */
+		if (!strcmp(name, "name"))
+			continue;
+
+		/* format: /<fragment-name>/__overlay__/<relative-subnode-path> */
+
+		if (*path != '/') {
+			ret = -FDT_ERR_BADVALUE;
+			goto out;
+		}
+
+		/* get frag name first */
+		s = strchr(path + 1, '/');
+		if (!s) {
+			ret = -FDT_ERR_BADVALUE;
+			goto out;
+		}
+		frag_name = path + 1;
+		frag_name_len = s - path - 1;
+
+		/* verify format */
+		len = strlen("/__overlay__/");
+		if (strncmp(s, "/__overlay__/", len)) {
+			ret = -FDT_ERR_NOTFOUND;
+			goto out;
+		}
+
+		rel_path = s + len;
+		rel_path_len = strlen(rel_path);
+
+		/* find the fragment index in which the symbol lies */
+		fdt_for_each_subnode(fragment, fdto, 0) {
+
+			s = fdt_get_name(fdto, fragment, &len);
+			if (!s)
+				continue;
+
+			/* name must match */
+			if (len == frag_name_len && !memcmp(s, frag_name, len))
+				break;
+		}
+
+		/* not found? */
+		if (fragment < 0) {
+			ret = -FDT_ERR_NOTFOUND;
+			goto out;
+		}
+
+		/* an __overlay__ subnode must exist */
+		ret = fdt_subnode_offset(fdto, fragment, "__overlay__");
+		if (ret < 0)
+			goto out;
+
+		/* get the target of the fragment */
+		ret = overlay_get_target(fdt, fdto, fragment);
+		if (ret < 0)
+			goto out;
+		target = ret;
+
+		/* get the path of the target */
+		ret = fdt_get_path(fdt, target, buf, FDT_PATH_MAX);
+		if (ret < 0)
+			goto out;
+
+		len = strlen(buf);
+
+		/* if the target is root strip leading / */
+		if (len == 1 && buf[0] == '/')
+			len = 0;
+
+		/* make sure we have enough space */
+		if (len + 1 + rel_path_len + 1 > FDT_PATH_MAX) {
+			ret = -FDT_ERR_NOSPACE;
+			goto out;
+		}
+
+		/* create new symbol path in place */
+		buf[len] = '/';
+		memcpy(buf + len + 1, rel_path, rel_path_len);
+		buf[len + 1 + rel_path_len] = '\0';
+
+		ret = fdt_setprop_string(fdt, root_sym, name, buf);
+		if (ret < 0)
+			goto out;
+	}
+
+	ret = 0;
+
+out:
+	if (buf)
+		free(buf);
+
+	return ret;
+}
+
 int fdt_overlay_apply(void *fdt, void *fdto)
 {
 	uint32_t delta = fdt_get_max_phandle(fdt);
@@ -654,6 +796,10 @@ int fdt_overlay_apply(void *fdt, void *fdto)
 	if (ret)
 		goto err;
 
+	ret = overlay_symbol_update(fdt, fdto);
+	if (ret)
+		goto err;
+
 	/*
 	 * The overlay has been damaged, erase its magic.
 	 */
Signature · 1 line
2.1.4
#10 lore raw

PATCH 3/5 fdt: Allow stacked overlays phandle references

On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:

[...]

Quoted 7 lines
lib/libfdt/fdt_overlay.c +7 -0
+static int overlay_symbol_update(void *fdt, void *fdto)
+{
+	int root_sym, ov_sym, prop, path_len, fragment, target;
+	int len, frag_name_len, ret, rel_path_len;
+	const char *s;
+	const char *path;
+	const char *name;

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 665

Quoted 10 lines
lib/libfdt/fdt_overlay.c +10 -0
+	const char *frag_name;
+	const char *rel_path;
+	char *buf = NULL;
+
+	root_sym = fdt_subnode_offset(fdt, 0, "__symbols__");
+	ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__");
+
+	/* if neither exist we can't update symbols, but that's OK */
+	if (root_sym < 0 || ov_sym < 0)
+		return 0;

If you have symbol table in either the DTO or the base DT, but not in the other one, wouldn't it make sense to use that one symbol table instead of bailing out ?

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 669

Quoted 3 lines
lib/libfdt/fdt_overlay.c +3 -0
+	buf = malloc(FDT_PATH_MAX);
+	if (!buf)
+		return -FDT_ERR_NOSPACE;

Would it make sense to allocate this on stack ?

Quoted 11 lines
lib/libfdt/fdt_overlay.c +11 -0
+	/* iterate over each overlay symbol */
+	fdt_for_each_property_offset(prop, fdto, ov_sym) {
+
+		path = fdt_getprop_by_offset(fdto, prop, &name, &path_len);
+		if (!path) {
+			ret = path_len;
+			goto out;
+		}
+
+		/* skip autogenerated properties */
+		if (!strcmp(name, "name"))

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 691

Quoted 10 lines
lib/libfdt/fdt_overlay.c +10 -0
+			continue;
+
+		/* format: /<fragment-name>/__overlay__/<relative-subnode-path> */
+
+		if (*path != '/') {
+			ret = -FDT_ERR_BADVALUE;
+			goto out;
+		}
+
+		/* get frag name first */

"frag name" ? What is this now, Unreal Tournament ? :)

Quoted 58 lines
lib/libfdt/fdt_overlay.c +58 -0
+		s = strchr(path + 1, '/');
+		if (!s) {
+			ret = -FDT_ERR_BADVALUE;
+			goto out;
+		}
+		frag_name = path + 1;
+		frag_name_len = s - path - 1;
+
+		/* verify format */
+		len = strlen("/__overlay__/");
+		if (strncmp(s, "/__overlay__/", len)) {
+			ret = -FDT_ERR_NOTFOUND;
+			goto out;
+		}
+
+		rel_path = s + len;
+		rel_path_len = strlen(rel_path);
+
+		/* find the fragment index in which the symbol lies */
+		fdt_for_each_subnode(fragment, fdto, 0) {
+
+			s = fdt_get_name(fdto, fragment, &len);
+			if (!s)
+				continue;
+
+			/* name must match */
+			if (len == frag_name_len && !memcmp(s, frag_name, len))
+				break;
+		}
+
+		/* not found? */
+		if (fragment < 0) {
+			ret = -FDT_ERR_NOTFOUND;
+			goto out;
+		}
+
+		/* an __overlay__ subnode must exist */
+		ret = fdt_subnode_offset(fdto, fragment, "__overlay__");
+		if (ret < 0)
+			goto out;
+
+		/* get the target of the fragment */
+		ret = overlay_get_target(fdt, fdto, fragment);
+		if (ret < 0)
+			goto out;
+		target = ret;
+
+		/* get the path of the target */
+		ret = fdt_get_path(fdt, target, buf, FDT_PATH_MAX);
+		if (ret < 0)
+			goto out;
+
+		len = strlen(buf);
+
+		/* if the target is root strip leading / */
+		if (len == 1 && buf[0] == '/')
+			len = 0;
+

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 759

Quoted 10 lines
lib/libfdt/fdt_overlay.c +10 -0
+		/* make sure we have enough space */
+		if (len + 1 + rel_path_len + 1 > FDT_PATH_MAX) {
+			ret = -FDT_ERR_NOSPACE;
+			goto out;
+		}
+
+		/* create new symbol path in place */
+		buf[len] = '/';
+		memcpy(buf + len + 1, rel_path, rel_path_len);
+		buf[len + 1 + rel_path_len] = '\0';

Can snprintf() help somewhere here instead of the memcpy() ?

Quoted 29 lines
lib/libfdt/fdt_overlay.c +18 -0
+		ret = fdt_setprop_string(fdt, root_sym, name, buf);
+		if (ret < 0)
+			goto out;
+	}
+
+	ret = 0;
+
+out:
+	if (buf)
+		free(buf);
+
+	return ret;
+}
+
 int fdt_overlay_apply(void *fdt, void *fdto)
 {
 	uint32_t delta = fdt_get_max_phandle(fdt);
@@ -654,6 +796,10 @@ int fdt_overlay_apply(void *fdt, void *fdto)
 	if (ret)
 		goto err;
 
+	ret = overlay_symbol_update(fdt, fdto);
+	if (ret)
+		goto err;
+
 	/*
 	 * The overlay has been damaged, erase its magic.
 	 */
Signature · 2 lines
Best regards,
Marek Vasut
#11 lore raw

PATCH 3/5 fdt: Allow stacked overlays phandle references

Hi Marek,

Quoted 17 lines · Marek Vasut

On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:

[...]

Quoted 13 lines
lib/libfdt/fdt_overlay.c +13 -0
+static int overlay_symbol_update(void *fdt, void *fdto)
+{
+	int root_sym, ov_sym, prop, path_len, fragment, target;
+	int len, frag_name_len, ret, rel_path_len;
+	const char *s;
+	const char *path;
+	const char *name;
+	const char *frag_name;
+	const char *rel_path;
+	char *buf = NULL;
+
+	root_sym = fdt_subnode_offset(fdt, 0, "__symbols__");
+	ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__");
Quoted 9 lines

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 665

Quoted 4 lines
lib/libfdt/fdt_overlay.c +4 -0
+
+	/* if neither exist we can't update symbols, but that's OK */
+	if (root_sym < 0 || ov_sym < 0)
+		return 0;

If you have symbol table in either the DTO or the base DT, but not in the other one, wouldn't it make sense to use that one symbol table instead of bailing out ?

It's bailing out without an error.

The logic is simple; if there's no symbol table in the base tree, that means that there's no symbols in the base device tree, i.e. not compiled with the option to generate it. No point in inserting overlay symbols.

If there's no symbol table in the overlay that perfectly fine, no symbol work then.

Quoted 6 lines

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 669

Quoted 3 lines
lib/libfdt/fdt_overlay.c +3 -0
+	buf = malloc(FDT_PATH_MAX);
+	if (!buf)
+		return -FDT_ERR_NOSPACE;

Would it make sense to allocate this on stack ?

FDT_PATH_MAX = 4K, dubious if the u-boot stack will have enough space. Especially in SPL cases.

Quoted 15 lines
Quoted 15 lines
lib/libfdt/fdt_overlay.c +15 -0
+	/* iterate over each overlay symbol */
+	fdt_for_each_property_offset(prop, fdto, ov_sym) {
+
+		path = fdt_getprop_by_offset(fdto, prop, &name, &path_len);
+		if (!path) {
+			ret = path_len;
+			goto out;
+		}
+
+		/* skip autogenerated properties */
+		if (!strcmp(name, "name"))
+			continue;
+
+		/* format: /<fragment-name>/__overlay__/<relative-subnode-path> */
+
Quoted 9 lines

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 691

Quoted 6 lines
lib/libfdt/fdt_overlay.c +6 -0
+		if (*path != '/') {
+			ret = -FDT_ERR_BADVALUE;
+			goto out;
+		}
+
+		/* get frag name first */

"frag name" ? What is this now, Unreal Tournament ? :)

Fragment. There were computers before first person shooters.

Quoted 62 lines
Quoted 62 lines
lib/libfdt/fdt_overlay.c +62 -0
+		s = strchr(path + 1, '/');
+		if (!s) {
+			ret = -FDT_ERR_BADVALUE;
+			goto out;
+		}
+		frag_name = path + 1;
+		frag_name_len = s - path - 1;
+
+		/* verify format */
+		len = strlen("/__overlay__/");
+		if (strncmp(s, "/__overlay__/", len)) {
+			ret = -FDT_ERR_NOTFOUND;
+			goto out;
+		}
+
+		rel_path = s + len;
+		rel_path_len = strlen(rel_path);
+
+		/* find the fragment index in which the symbol lies */
+		fdt_for_each_subnode(fragment, fdto, 0) {
+
+			s = fdt_get_name(fdto, fragment, &len);
+			if (!s)
+				continue;
+
+			/* name must match */
+			if (len == frag_name_len && !memcmp(s, frag_name, len))
+				break;
+		}
+
+		/* not found? */
+		if (fragment < 0) {
+			ret = -FDT_ERR_NOTFOUND;
+			goto out;
+		}
+
+		/* an __overlay__ subnode must exist */
+		ret = fdt_subnode_offset(fdto, fragment, "__overlay__");
+		if (ret < 0)
+			goto out;
+
+		/* get the target of the fragment */
+		ret = overlay_get_target(fdt, fdto, fragment);
+		if (ret < 0)
+			goto out;
+		target = ret;
+
+		/* get the path of the target */
+		ret = fdt_get_path(fdt, target, buf, FDT_PATH_MAX);
+		if (ret < 0)
+			goto out;
+
+		len = strlen(buf);
+
+		/* if the target is root strip leading / */
+		if (len == 1 && buf[0] == '/')
+			len = 0;
+
+		/* make sure we have enough space */
+		if (len + 1 + rel_path_len + 1 > FDT_PATH_MAX) {
+			ret = -FDT_ERR_NOSPACE;
+			goto out;
Quoted 9 lines

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 759

Quoted 6 lines
lib/libfdt/fdt_overlay.c +6 -0
+		}
+
+		/* create new symbol path in place */
+		buf[len] = '/';
+		memcpy(buf + len + 1, rel_path, rel_path_len);
+		buf[len + 1 + rel_path_len] = '\0';

Can snprintf() help somewhere here instead of the memcpy() ?

It is going to be considerably slower (although that doesn't matter much). We still need to do the space check before so it's not going to be worth the change IMO.

Quoted 21 lines
Quoted 21 lines
lib/libfdt/fdt_overlay.c +14 -0
+		ret = fdt_setprop_string(fdt, root_sym, name, buf);
+		if (ret < 0)
+			goto out;
+	}
+
+	ret = 0;
+
+out:
+	if (buf)
+		free(buf);
+
+	return ret;
+}
+
 int fdt_overlay_apply(void *fdt, void *fdto)
 {
 	uint32_t delta = fdt_get_max_phandle(fdt);
@@ -654,6 +796,10 @@ int fdt_overlay_apply(void *fdt, void *fdto)
 	if (ret)
 		goto err;
 
Quoted 10 lines

lib/libfdt/fdt_overlay.c int fdt_overlay_apply(void *fdt, void *fdto) · line 805

Quoted 8 lines
lib/libfdt/fdt_overlay.c +4 -0
+	ret = overlay_symbol_update(fdt, fdto);
+	if (ret)
+		goto err;
+
 	/*
 	 * The overlay has been damaged, erase its magic.
 	 */

Regards

-- Pantelis

#12 lore raw

PATCH 3/5 fdt: Allow stacked overlays phandle references

In reply to Marek Vasut

Hi,

Quoted 2 lines · On Sat, 1 Jul 2017 16:07:47 +0200 Marek Vasut wrote:

On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:

[...]

Quoted 6 lines

lib/libfdt/fdt_overlay.c static int overlay_merge(void *fdt, void *fdto) · line 669

Quoted 3 lines
lib/libfdt/fdt_overlay.c +3 -0
+	buf = malloc(FDT_PATH_MAX);
+	if (!buf)
+		return -FDT_ERR_NOSPACE;

Would it make sense to allocate this on stack ?

buffers on stack are a disatrous stack overflow waiting to happen.

Lothar Waßmann

#13 lore raw

PATCH 3/5 fdt: Allow stacked overlays phandle references

In reply to Pantelis Antoniou
Quoted 91 lines · Pantelis Antoniou

This patch enables an overlay to refer to a previous overlay's labels by performing a merge of symbol information at application time.

In a nutshell it allows an overlay to refer to a symbol that a previous overlay has defined. It requires both the base and all the overlays to be compiled with the -@ command line switch so that symbol information is included.

base.dts
--------

        /dts-v1/;
        / {
                foo: foonode {
                        foo-property;
                };
        };

        $ dtc -@ -I dts -O dtb -o base.dtb base.dts

bar.dts
-------

        /dts-v1/;
        /plugin/;
        / {
                fragment at 1 {
                        target = <&foo>;
                        __overlay__ {
                                overlay-1-property;
                                bar: barnode {
                                        bar-property;
                                };
                        };
                };
        };

        $ dtc -@ -I dts -O dtb -o bar.dtb bar.dts

baz.dts
-------

        /dts-v1/;
        /plugin/;
        / {
                fragment at 1 {
                        target = <&bar>;
                        __overlay__ {
                                overlay-2-property;
                                baz: baznode {
                                        baz-property;
                                };
                        };
                };
        };

        $ dtc -@ -I dts -O dtb -o baz.dtb baz.dts

Applying the overlays:

        $ fdtoverlay -i base.dtb -o target.dtb bar.dtb baz.dtb

Dumping:

        $ fdtdump target.dtb
        / {
            foonode {
                overlay-1-property;
                foo-property;
                linux,phandle = <0x00000001>;
                phandle = <0x00000001>;
                barnode {
                    overlay-2-property;
                    phandle = <0x00000002>;
                    linux,phandle = <0x00000002>;
                    bar-property;
                    baznode {
                        phandle = <0x00000003>;
                        linux,phandle = <0x00000003>;
                        baz-property;
                    };
                };
            };
            __symbols__ {
                baz = "/foonode/barnode/baznode";
                bar = "/foonode/barnode";
                foo = "/foonode";
            };
        };
Quoted 4 lines
---
 lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 147 insertions(+), 1 deletion(-)

I suppose that the upstream version has tests?

Does it make sense to implement this in the live tree instead, or do you need to modify the DT before relocation?

- Simon

#14 lore raw

PATCH 3/5 fdt: Allow stacked overlays phandle references

Hi Simon,

Quoted 93 lines · Simon Glass
Quoted 91 lines · Pantelis Antoniou

This patch enables an overlay to refer to a previous overlay's labels by performing a merge of symbol information at application time.

In a nutshell it allows an overlay to refer to a symbol that a previous overlay has defined. It requires both the base and all the overlays to be compiled with the -@ command line switch so that symbol information is included.

base.dts
--------

        /dts-v1/;
        / {
                foo: foonode {
                        foo-property;
                };
        };

        $ dtc -@ -I dts -O dtb -o base.dtb base.dts

bar.dts
-------

        /dts-v1/;
        /plugin/;
        / {
                fragment at 1 {
                        target = <&foo>;
                        __overlay__ {
                                overlay-1-property;
                                bar: barnode {
                                        bar-property;
                                };
                        };
                };
        };

        $ dtc -@ -I dts -O dtb -o bar.dtb bar.dts

baz.dts
-------

        /dts-v1/;
        /plugin/;
        / {
                fragment at 1 {
                        target = <&bar>;
                        __overlay__ {
                                overlay-2-property;
                                baz: baznode {
                                        baz-property;
                                };
                        };
                };
        };

        $ dtc -@ -I dts -O dtb -o baz.dtb baz.dts

Applying the overlays:

        $ fdtoverlay -i base.dtb -o target.dtb bar.dtb baz.dtb

Dumping:

        $ fdtdump target.dtb
        / {
            foonode {
                overlay-1-property;
                foo-property;
                linux,phandle = <0x00000001>;
                phandle = <0x00000001>;
                barnode {
                    overlay-2-property;
                    phandle = <0x00000002>;
                    linux,phandle = <0x00000002>;
                    bar-property;
                    baznode {
                        phandle = <0x00000003>;
                        linux,phandle = <0x00000003>;
                        baz-property;
                    };
                };
            };
            __symbols__ {
                baz = "/foonode/barnode/baznode";
                bar = "/foonode/barnode";
                foo = "/foonode";
            };
        };
Quoted 9 lines
Quoted 4 lines
---
 lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 147 insertions(+), 1 deletion(-)

I suppose that the upstream version has tests?

Yes, and I could use a couple reviewers in the dtc mailing list.

Quoted 3 lines

Does it make sense to implement this in the live tree instead, or do you need to modify the DT before relocation?

There is a port of a patch that works on the live tree; I guess I can port it to u-boot's live tree as well.

Speaking of which I've done quite a bit of work on a different live tree implementation as well. I would propose we split off u-boot's one in a library and port my changes there. That way we can have a definitive live tree implementation, and in the future move dtc's internal live tree to it as well. We keep on implementing the same functionality in different flavors for years, let's consolidate, and start working on ideas for the future.

Quoted 1 line

- Simon

Regards

-- Pantelis

#15 lore raw

PATCH 3/5 fdt: Allow stacked overlays phandle references

Hi Pantelis,

Quoted 101 lines · Pantelis Antoniou

Hi Simon,

Quoted 98 lines · Simon Glass
Quoted 95 lines · Pantelis Antoniou

This patch enables an overlay to refer to a previous overlay's labels by performing a merge of symbol information at application time.

In a nutshell it allows an overlay to refer to a symbol that a previous overlay has defined. It requires both the base and all the overlays to be compiled with the -@ command line switch so that symbol information is included.

base.dts
--------

        /dts-v1/;
        / {
                foo: foonode {
                        foo-property;
                };
        };

        $ dtc -@ -I dts -O dtb -o base.dtb base.dts

bar.dts
-------

        /dts-v1/;
        /plugin/;
        / {
                fragment at 1 {
                        target = <&foo>;
                        __overlay__ {
                                overlay-1-property;
                                bar: barnode {
                                        bar-property;
                                };
                        };
                };
        };

        $ dtc -@ -I dts -O dtb -o bar.dtb bar.dts

baz.dts
-------

        /dts-v1/;
        /plugin/;
        / {
                fragment at 1 {
                        target = <&bar>;
                        __overlay__ {
                                overlay-2-property;
                                baz: baznode {
                                        baz-property;
                                };
                        };
                };
        };

        $ dtc -@ -I dts -O dtb -o baz.dtb baz.dts

Applying the overlays:

        $ fdtoverlay -i base.dtb -o target.dtb bar.dtb baz.dtb

Dumping:

        $ fdtdump target.dtb
        / {
            foonode {
                overlay-1-property;
                foo-property;
                linux,phandle = <0x00000001>;
                phandle = <0x00000001>;
                barnode {
                    overlay-2-property;
                    phandle = <0x00000002>;
                    linux,phandle = <0x00000002>;
                    bar-property;
                    baznode {
                        phandle = <0x00000003>;
                        linux,phandle = <0x00000003>;
                        baz-property;
                    };
                };
            };
            __symbols__ {
                baz = "/foonode/barnode/baznode";
                bar = "/foonode/barnode";
                foo = "/foonode";
            };
        };
---
 lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 147 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 4 lines

I suppose that the upstream version has tests?

Yes, and I could use a couple reviewers in the dtc mailing list.

Ah OK, I will take a look.

Quoted 7 lines
Quoted 4 lines

Does it make sense to implement this in the live tree instead, or do you need to modify the DT before relocation?

There is a port of a patch that works on the live tree; I guess I can port it to u-boot's live tree as well.

Do you mean 'as well'? I am wondering if we can get away with only supporting the live tree for overlays. Or do you think that will be too limiting?

Obviously the live and flat tree versions do essentially the same thing, so if we can it would be good to include only one version of the code.

Quoted 8 lines

Speaking of which I've done quite a bit of work on a different live tree implementation as well. I would propose we split off u-boot's one in a library and port my changes there. That way we can have a definitive live tree implementation, and in the future move dtc's internal live tree to it as well. We keep on implementing the same functionality in different flavors for years, let's consolidate, and start working on ideas for the future.

What about the kernel? I took most of the of_access.c code from there and trying to avoid changing it as much as possible. The extra bits for U-Boot are the ofnode implementation (to permit transparent use of live/flat trees) and of course dev_read_...().

I think it would be great to have a live tree upstream in dtc that we can pull into U-Boot. But I'm keen to line it up with Linux.

Regards,
Simon

#16 lore raw

PATCH 4/5 test: overlay: Add unit test for stacked overlay

In reply to Pantelis Antoniou

Verify that stacked overlays work.

---
 test/overlay/Makefile                     |  1 +
 test/overlay/cmd_ut_overlay.c             | 34 ++++++++++++++++++++++++++++++-
 test/overlay/test-fdt-overlay-stacked.dts | 21 +++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts
test/overlay/Makefile +1 -0
index 907f085..416645c 100644
@@ -13,3 +13,4 @@ DTC_FLAGS += -@
 # DT overlays
 obj-y += test-fdt-base.dtb.o
 obj-y += test-fdt-overlay.dtb.o
+obj-y += test-fdt-overlay-stacked.dtb.o
test/overlay/cmd_ut_overlay.c +33 -1
index cbef720..d8f5c8f 100644
@@ -20,6 +20,7 @@
 
 extern u32 __dtb_test_fdt_base_begin;
 extern u32 __dtb_test_fdt_overlay_begin;
+extern u32 __dtb_test_fdt_overlay_stacked_begin;
 
 static int fdt_getprop_u32_by_index(void *fdt, const char *path,
 				    const char *name, int index,
@@ -201,6 +202,19 @@ static int fdt_overlay_local_phandles(struct unit_test_state *uts)
 }
 OVERLAY_TEST(fdt_overlay_local_phandles, 0);
 
+static int fdt_overlay_stacked(struct unit_test_state *uts)
+{
+	void *fdt = uts->priv;
+	u32 val = 0;
+
+	ut_assertok(fdt_getprop_u32(fdt, "/new-local-node", "stacked-test-int-property",
+				    &val));
+	ut_asserteq(43, val);
+
+	return CMD_RET_SUCCESS;
+}
+OVERLAY_TEST(fdt_overlay_stacked, 0);
+
 int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	struct unit_test *tests = ll_entry_start(struct unit_test,
@@ -210,7 +224,8 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct unit_test *test;
 	void *fdt_base = &__dtb_test_fdt_base_begin;
 	void *fdt_overlay = &__dtb_test_fdt_overlay_begin;
-	void *fdt_base_copy, *fdt_overlay_copy;
+	void *fdt_overlay_stacked = &__dtb_test_fdt_overlay_stacked_begin;
+	void *fdt_base_copy, *fdt_overlay_copy, *fdt_overlay_stacked_copy;
 
 	uts = calloc(1, sizeof(*uts));
 	if (!uts)
@@ -228,6 +243,10 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (!fdt_overlay_copy)
 		return -ENOMEM;
 
+	fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE);
+	if (!fdt_overlay_stacked_copy)
+		return -ENOMEM;
+
 	/*
 	 * Resize the FDT to 4k so that we have room to operate on
 	 *
@@ -245,9 +264,21 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy,
 				  FDT_COPY_SIZE));
 
+	/*
+	 * Resize the stacked overlay to 4k so that we have room to operate on
+	 *
+	 * (and relocate it since the memory might be mapped
+	 * read-only)
+	 */
+	ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy,
+				  FDT_COPY_SIZE));
+
 	/* Apply the overlay */
 	ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_copy));
 
+	/* Apply the stacked overlay */
+	ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_stacked_copy));
+
 	if (argc == 1)
 		printf("Running %d environment tests\n", n_ents);
 
@@ -263,6 +294,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	printf("Failures: %d\n", uts->fail_count);
 
+	free(fdt_overlay_stacked_copy);
 	free(fdt_overlay_copy);
 	free(fdt_base_copy);
 	free(uts);
test/overlay/test-fdt-overlay-stacked.dts new file +21 -0
new file mode 100644
index 0000000..9fb7c7b
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2016 NextThing Co
+ * Copyright (c) 2016 Free Electrons
+ * Copyright (c) 2018 Konsulko Group
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+/dts-v1/;
+/plugin/;
+
+/ {
+	/* Test that we can reference an overlay symbol */
+	fragment at 0 {
+		target = <&local>;
+
+		__overlay__ {
+			stacked-test-int-property = <43>;
+		};
+	};
+};
Signature · 1 line
2.1.4
#17 lore raw

PATCH 4/5 test: overlay: Add unit test for stacked overlay

Hi,

Quoted 9 lines · Pantelis Antoniou

Verify that stacked overlays work.

---
 test/overlay/Makefile                     |  1 +
 test/overlay/cmd_ut_overlay.c             | 34 ++++++++++++++++++++++++++++++-
 test/overlay/test-fdt-overlay-stacked.dts | 21 +++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts
#18 lore raw

PATCH 4/5 test: overlay: Add unit test for stacked overlay

In reply to Pantelis Antoniou

Hi Pantelis,

nit inline

Quoted 3 lines · Pantelis Antoniou

Verify that stacked overlays work.

Quoted 105 lines
---
 test/overlay/Makefile                     |  1 +
 test/overlay/cmd_ut_overlay.c             | 34 ++++++++++++++++++++++++++++++-
 test/overlay/test-fdt-overlay-stacked.dts | 21 +++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts
test/overlay/Makefile +1 -0
index 907f085..416645c 100644
@@ -13,3 +13,4 @@ DTC_FLAGS += -@
 # DT overlays
 obj-y += test-fdt-base.dtb.o
 obj-y += test-fdt-overlay.dtb.o
+obj-y += test-fdt-overlay-stacked.dtb.o
test/overlay/cmd_ut_overlay.c +33 -1
index cbef720..d8f5c8f 100644
@@ -20,6 +20,7 @@
 
 extern u32 __dtb_test_fdt_base_begin;
 extern u32 __dtb_test_fdt_overlay_begin;
+extern u32 __dtb_test_fdt_overlay_stacked_begin;
 
 static int fdt_getprop_u32_by_index(void *fdt, const char *path,
                                    const char *name, int index,
@@ -201,6 +202,19 @@ static int fdt_overlay_local_phandles(struct unit_test_state *uts)
 }
 OVERLAY_TEST(fdt_overlay_local_phandles, 0);
 
+static int fdt_overlay_stacked(struct unit_test_state *uts)
+{
+       void *fdt = uts->priv;
+       u32 val = 0;
+
+       ut_assertok(fdt_getprop_u32(fdt, "/new-local-node", "stacked-test-int-property",
+                                   &val));
+       ut_asserteq(43, val);
+
+       return CMD_RET_SUCCESS;
+}
+OVERLAY_TEST(fdt_overlay_stacked, 0);
+
 int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        struct unit_test *tests = ll_entry_start(struct unit_test,
@@ -210,7 +224,8 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        struct unit_test *test;
        void *fdt_base = &__dtb_test_fdt_base_begin;
        void *fdt_overlay = &__dtb_test_fdt_overlay_begin;
-       void *fdt_base_copy, *fdt_overlay_copy;
+       void *fdt_overlay_stacked = &__dtb_test_fdt_overlay_stacked_begin;
+       void *fdt_base_copy, *fdt_overlay_copy, *fdt_overlay_stacked_copy;
 
        uts = calloc(1, sizeof(*uts));
        if (!uts)
@@ -228,6 +243,10 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        if (!fdt_overlay_copy)
                return -ENOMEM;
 
+       fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE);
+       if (!fdt_overlay_stacked_copy)
+               return -ENOMEM;
+
        /*
         * Resize the FDT to 4k so that we have room to operate on
         *
@@ -245,9 +264,21 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy,
                                  FDT_COPY_SIZE));
 
+       /*
+        * Resize the stacked overlay to 4k so that we have room to operate on
+        *
+        * (and relocate it since the memory might be mapped
+        * read-only)
+        */
+       ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy,
+                                 FDT_COPY_SIZE));
+
        /* Apply the overlay */
        ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_copy));
 
+       /* Apply the stacked overlay */
+       ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_stacked_copy));
+
        if (argc == 1)
                printf("Running %d environment tests\n", n_ents);
 
@@ -263,6 +294,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        printf("Failures: %d\n", uts->fail_count);
 
+       free(fdt_overlay_stacked_copy);
        free(fdt_overlay_copy);
        free(fdt_base_copy);
        free(uts);
test/overlay/test-fdt-overlay-stacked.dts new file +0 -0
new file mode 100644
index 0000000..9fb7c7b

test/overlay/test-fdt-overlay-stacked.dts line 4

Quoted 4 lines
test/overlay/test-fdt-overlay-stacked.dts new file +4 -0
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2016 NextThing Co
+ * Copyright (c) 2016 Free Electrons
+ * Copyright (c) 2018 Konsulko Group

Are you time-traveling or anticipating a long review process ;-)

Quoted 20 lines
test/overlay/test-fdt-overlay-stacked.dts new file +17 -1
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/dts-v1/;
+/plugin/;
+
+/ {
+       /* Test that we can reference an overlay symbol */
+       fragment at 0 {
+               target = <&local>;
+
+               __overlay__ {
+                       stacked-test-int-property = <43>;
+               };
+       };
+};
--

2.1.4

#19 lore raw

PATCH 4/5 test: overlay: Add unit test for stacked overlay

Quoted 106 lines · Moritz Fischer

Hi Pantelis,

nit inline

Quoted 3 lines · Pantelis Antoniou

Verify that stacked overlays work.

Quoted 95 lines
---
 test/overlay/Makefile                     |  1 +
 test/overlay/cmd_ut_overlay.c             | 34 ++++++++++++++++++++++++++++++-
 test/overlay/test-fdt-overlay-stacked.dts | 21 +++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts
test/overlay/Makefile +1 -0
index 907f085..416645c 100644
@@ -13,3 +13,4 @@ DTC_FLAGS += -@
 # DT overlays
 obj-y += test-fdt-base.dtb.o
 obj-y += test-fdt-overlay.dtb.o
+obj-y += test-fdt-overlay-stacked.dtb.o
test/overlay/cmd_ut_overlay.c +32 -1
index cbef720..d8f5c8f 100644
@@ -20,6 +20,7 @@
 
 extern u32 __dtb_test_fdt_base_begin;
 extern u32 __dtb_test_fdt_overlay_begin;
+extern u32 __dtb_test_fdt_overlay_stacked_begin;
 
 static int fdt_getprop_u32_by_index(void *fdt, const char *path,
                                    const char *name, int index,
@@ -201,6 +202,19 @@ static int fdt_overlay_local_phandles(struct unit_test_state *uts)
 }
 OVERLAY_TEST(fdt_overlay_local_phandles, 0);
 
+static int fdt_overlay_stacked(struct unit_test_state *uts)
+{
+       void *fdt = uts->priv;
+       u32 val = 0;
+
+       ut_assertok(fdt_getprop_u32(fdt, "/new-local-node", "stacked-test-int-property",
+                                   &val));
+       ut_asserteq(43, val);
+
+       return CMD_RET_SUCCESS;
+}
+OVERLAY_TEST(fdt_overlay_stacked, 0);
+
 int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        struct unit_test *tests = ll_entry_start(struct unit_test,
@@ -210,7 +224,8 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        struct unit_test *test;
        void *fdt_base = &__dtb_test_fdt_base_begin;
        void *fdt_overlay = &__dtb_test_fdt_overlay_begin;
-       void *fdt_base_copy, *fdt_overlay_copy;
+       void *fdt_overlay_stacked = &__dtb_test_fdt_overlay_stacked_begin;
+       void *fdt_base_copy, *fdt_overlay_copy, *fdt_overlay_stacked_copy;
 
        uts = calloc(1, sizeof(*uts));
        if (!uts)
@@ -228,6 +243,10 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        if (!fdt_overlay_copy)
                return -ENOMEM;
 
+       fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE);
+       if (!fdt_overlay_stacked_copy)
+               return -ENOMEM;
+
        /*
         * Resize the FDT to 4k so that we have room to operate on
         *
@@ -245,9 +264,21 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy,
                                  FDT_COPY_SIZE));
 
+       /*
+        * Resize the stacked overlay to 4k so that we have room to operate on
+        *
+        * (and relocate it since the memory might be mapped
+        * read-only)
+        */
+       ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy,
+                                 FDT_COPY_SIZE));
+
        /* Apply the overlay */
        ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_copy));
 
+       /* Apply the stacked overlay */
+       ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_stacked_copy));
+
        if (argc == 1)
                printf("Running %d environment tests\n", n_ents);
 
@@ -263,6 +294,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        printf("Failures: %d\n", uts->fail_count);
 
Quoted 16 lines
Quoted 10 lines
test/overlay/cmd_ut_overlay.c +1 -0
+       free(fdt_overlay_stacked_copy);
        free(fdt_overlay_copy);
        free(fdt_base_copy);
        free(uts);
test/overlay/test-fdt-overlay-stacked.dts new file +0 -0
new file mode 100644
index 0000000..9fb7c7b

test/overlay/test-fdt-overlay-stacked.dts line 4

Quoted 4 lines
test/overlay/test-fdt-overlay-stacked.dts new file +4 -0
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2016 NextThing Co
+ * Copyright (c) 2016 Free Electrons
+ * Copyright (c) 2018 Konsulko Group

Are you time-traveling or anticipating a long review process ;-)

After the configfs stuff in Linux, I think the later ;-)

Signature · 2 lines
Best regards,
Marek Vasut
#20 lore raw

PATCH 4/5 test: overlay: Add unit test for stacked overlay

In reply to Moritz Fischer
Quoted 106 lines · Moritz Fischer

Hi Pantelis,

nit inline

Quoted 3 lines · Pantelis Antoniou

Verify that stacked overlays work.

Quoted 95 lines
---
 test/overlay/Makefile                     |  1 +
 test/overlay/cmd_ut_overlay.c             | 34 ++++++++++++++++++++++++++++++-
 test/overlay/test-fdt-overlay-stacked.dts | 21 +++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts
test/overlay/Makefile +1 -0
index 907f085..416645c 100644
@@ -13,3 +13,4 @@ DTC_FLAGS += -@
 # DT overlays
 obj-y += test-fdt-base.dtb.o
 obj-y += test-fdt-overlay.dtb.o
+obj-y += test-fdt-overlay-stacked.dtb.o
test/overlay/cmd_ut_overlay.c +32 -1
index cbef720..d8f5c8f 100644
@@ -20,6 +20,7 @@
 
 extern u32 __dtb_test_fdt_base_begin;
 extern u32 __dtb_test_fdt_overlay_begin;
+extern u32 __dtb_test_fdt_overlay_stacked_begin;
 
 static int fdt_getprop_u32_by_index(void *fdt, const char *path,
                                    const char *name, int index,
@@ -201,6 +202,19 @@ static int fdt_overlay_local_phandles(struct unit_test_state *uts)
 }
 OVERLAY_TEST(fdt_overlay_local_phandles, 0);
 
+static int fdt_overlay_stacked(struct unit_test_state *uts)
+{
+       void *fdt = uts->priv;
+       u32 val = 0;
+
+       ut_assertok(fdt_getprop_u32(fdt, "/new-local-node", "stacked-test-int-property",
+                                   &val));
+       ut_asserteq(43, val);
+
+       return CMD_RET_SUCCESS;
+}
+OVERLAY_TEST(fdt_overlay_stacked, 0);
+
 int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        struct unit_test *tests = ll_entry_start(struct unit_test,
@@ -210,7 +224,8 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        struct unit_test *test;
        void *fdt_base = &__dtb_test_fdt_base_begin;
        void *fdt_overlay = &__dtb_test_fdt_overlay_begin;
-       void *fdt_base_copy, *fdt_overlay_copy;
+       void *fdt_overlay_stacked = &__dtb_test_fdt_overlay_stacked_begin;
+       void *fdt_base_copy, *fdt_overlay_copy, *fdt_overlay_stacked_copy;
 
        uts = calloc(1, sizeof(*uts));
        if (!uts)
@@ -228,6 +243,10 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        if (!fdt_overlay_copy)
                return -ENOMEM;
 
+       fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE);
+       if (!fdt_overlay_stacked_copy)
+               return -ENOMEM;
+
        /*
         * Resize the FDT to 4k so that we have room to operate on
         *
@@ -245,9 +264,21 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy,
                                  FDT_COPY_SIZE));
 
+       /*
+        * Resize the stacked overlay to 4k so that we have room to operate on
+        *
+        * (and relocate it since the memory might be mapped
+        * read-only)
+        */
+       ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy,
+                                 FDT_COPY_SIZE));
+
        /* Apply the overlay */
        ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_copy));
 
+       /* Apply the stacked overlay */
+       ut_assertok(fdt_overlay_apply(fdt_base_copy, fdt_overlay_stacked_copy));
+
        if (argc == 1)
                printf("Running %d environment tests\n", n_ents);
 
@@ -263,6 +294,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        printf("Failures: %d\n", uts->fail_count);
 
Quoted 16 lines
Quoted 10 lines
test/overlay/cmd_ut_overlay.c +1 -0
+       free(fdt_overlay_stacked_copy);
        free(fdt_overlay_copy);
        free(fdt_base_copy);
        free(uts);
test/overlay/test-fdt-overlay-stacked.dts new file +0 -0
new file mode 100644
index 0000000..9fb7c7b

test/overlay/test-fdt-overlay-stacked.dts line 4

Quoted 4 lines
test/overlay/test-fdt-overlay-stacked.dts new file +4 -0
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2016 NextThing Co
+ * Copyright (c) 2016 Free Electrons
+ * Copyright (c) 2018 Konsulko Group

Are you time-traveling or anticipating a long review process ;-)

It is a file that's been copied and modified so I'm keeping the copyright lines.

Long review process? In my open source? It's more likely than you think.

Quoted 12 lines
Quoted 12 lines
test/overlay/test-fdt-overlay-stacked.dts new file +12 -0
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/dts-v1/;
+/plugin/;
+
+/ {
+       /* Test that we can reference an overlay symbol */
+       fragment at 0 {
+               target = <&local>;
+
Quoted 8 lines
Quoted 8 lines
test/overlay/test-fdt-overlay-stacked.dts new file +5 -1
+               __overlay__ {
+                       stacked-test-int-property = <43>;
+               };
+       };
+};
--

2.1.4

Regards

-- Pantelis

#21 lore raw

PATCH 5/5 fit: Introduce methods for applying overlays on fit-load

In reply to Pantelis Antoniou

Introduce an overlay based method for constructing a base DT blob to pass to the kernel.

Both canned and runtime feature selection is supported.

---
 common/image-fdt.c                           |   7 +-
 common/image-fit.c                           | 215 ++++++++++++++++++++++++--
 doc/uImage.FIT/command_syntax_extensions.txt |  12 +-
 doc/uImage.FIT/overlay-fdt-boot.txt          | 221 +++++++++++++++++++++++++++
 doc/uImage.FIT/source_file_format.txt        |   6 +-
 include/image.h                              |  10 ++
 6 files changed, 453 insertions(+), 18 deletions(-)
 create mode 100644 doc/uImage.FIT/overlay-fdt-boot.txt
common/image-fdt.c +3 -4
index c6e8832..a59134c 100644
@@ -356,17 +356,16 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 			if (fit_check_format(buf)) {
 				ulong load, len;
 
-				fdt_noffset = fit_image_load(images,
+				fdt_noffset = boot_get_fdt_fit(images,
 					fdt_addr, &fit_uname_fdt,
 					&fit_uname_config,
-					arch, IH_TYPE_FLATDT,
-					BOOTSTAGE_ID_FIT_FDT_START,
-					FIT_LOAD_OPTIONAL, &load, &len);
+					arch, &load, &len);
 
 				images->fit_hdr_fdt = map_sysmem(fdt_addr, 0);
 				images->fit_uname_fdt = fit_uname_fdt;
 				images->fit_noffset_fdt = fdt_noffset;
 				fdt_addr = load;
+
 				break;
 			} else
 #endif
common/image-fit.c +204 -11

304 lines not on this page · raw message

doc/uImage.FIT/command_syntax_extensions.txt +11 -1
index 6c99b1c..676f992 100644
@@ -36,7 +36,7 @@ Old uImage:
 New uImage:
 8.  bootm <addr1>
 9.  bootm [<addr1>]:<subimg1>
-10. bootm [<addr1>]#<conf>
+10. bootm [<addr1>]#<conf>[#<extra-conf[#...]]
 11. bootm [<addr1>]:<subimg1> [<addr2>]:<subimg2>
 12. bootm [<addr1>]:<subimg1> [<addr2>]:<subimg2> [<addr3>]:<subimg3>
 13. bootm [<addr1>]:<subimg1> [<addr2>]:<subimg2> <addr3>
@@ -129,6 +129,12 @@ following syntax:
 - new uImage configuration specification
 <addr>#<configuration unit_name>
 
+- new uImage configuration specification with extra configuration components
+<addr>#<configuration unit_name>[#<extra configuration unit_name>[#..]]
+
+The extra configuration currently is supported only for additional device tree
+overlays to apply on the base device tree supplied by the first configuration
+unit.
 
 Examples:
 
@@ -138,6 +144,10 @@ bootm 200000:kernel at 1
 - boot configuration "cfg at 1" from a new uImage located at 200000:
 bootm 200000#cfg at 1
 
+- boot configuration "cfg at 1" with extra "cfg at 2" from a new uImage located
+  at 200000:
+bootm 200000#cfg at 1#cfg at 2
+
 - boot "kernel at 1" from a new uImage at 200000 with initrd "ramdisk at 2" found in
   some other new uImage stored at address 800000:
 bootm 200000:kernel at 1 800000:ramdisk at 2
doc/uImage.FIT/overlay-fdt-boot.txt new file +221 -0

221 lines not on this page · raw message

doc/uImage.FIT/source_file_format.txt +4 -2
index afff301..966b244 100644
@@ -235,7 +235,7 @@ o config at 1
   |- description = "configuration description"
   |- kernel = "kernel sub-node unit name"
   |- ramdisk = "ramdisk sub-node unit name"
-  |- fdt = "fdt sub-node unit-name"
+  |- fdt = "fdt sub-node unit-name" [, "fdt overlay sub-node unit-name", ...]
   |- fpga = "fpga sub-node unit-name"
   |- loadables = "loadables sub-node unit-name"
 
@@ -249,7 +249,9 @@ o config at 1
   - ramdisk : Unit name of the corresponding ramdisk image (component image
     node of a "ramdisk" type).
   - fdt : Unit name of the corresponding fdt blob (component image node of a
-    "fdt type").
+    "fdt type"). Additional fdt overlay nodes can be supplied which signify
+    that the resulting device tree blob is generated by the first base fdt
+    blob with all subsequent overlays applied.
   - setup : Unit name of the corresponding setup binary (used for booting
     an x86 kernel). This contains the setup.bin file built by the kernel.
   - fpga : Unit name of the corresponding fpga bitstream blob
include/image.h +10 -0
index fcfe730..bf35197 100644
@@ -592,6 +592,10 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
 int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
 		       ulong *setup_start, ulong *setup_len);
 
+int boot_get_fdt_fit(bootm_headers_t *images, ulong addr,
+		   const char **fit_unamep, const char **fit_uname_configp,
+		   int arch, ulong *datap, ulong *lenp);
+
 /**
  * fit_image_load() - load an image from a FIT
  *
@@ -657,6 +661,8 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
  */
 int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
 			ulong addr);
+int fit_get_node_from_config_index(bootm_headers_t *images, const char *prop_name,
+			ulong addr, int index);
 
 int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 		 bootm_headers_t *images,
@@ -986,6 +992,10 @@ int fit_check_format(const void *fit);
 int fit_conf_find_compat(const void *fit, const void *fdt);
 int fit_conf_get_node(const void *fit, const char *conf_uname);
 
+int fit_conf_get_prop_node_count(const void *fit, int noffset,
+		const char *prop_name);
+int fit_conf_get_prop_node_index(const void *fit, int noffset,
+		const char *prop_name, int index);
 /**
  * fit_conf_get_prop_node() - Get node refered to by a configuration
  * @fit:	FIT to check
Signature · 1 line
2.1.4
#22 lore raw

PATCH 5/5 fit: Introduce methods for applying overlays on fit-load

Quoted 6 lines · Pantelis Antoniou

Introduce an overlay based method for constructing a base DT blob to pass to the kernel.

Both canned and runtime feature selection is supported.

[...]

Quoted 4 lines
common/image-fit.c +0 -0
@@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const char *conf_uname)
 		debug("Found default configuration: '%s'\n", conf_uname);
 	}
 

common/image-fit.c int fit_conf_get_node(const void *fit, const char *conf_uname) · line 1494

Quoted 10 lines
common/image-fit.c +10 -0
+	s = strchr(conf_uname, '#');
+	if (s) {
+		len = s - conf_uname;
+		conf_uname_copy = malloc(len + 1);
+		if (!conf_uname_copy) {
+			debug("Can't allocate uname copy: '%s'\n",
+					conf_uname);
+			return -ENOMEM;
+		}
+		memcpy(conf_uname_copy, conf_uname, len);

Is that like strdup() here ?

Quoted 15 lines
common/image-fit.c +7 -0
+		conf_uname_copy[len] = '\0';
+		conf_uname = conf_uname_copy;
+	}
+
 	noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname);
 	if (noffset < 0) {
 		debug("Can't get node offset for configuration unit name: '%s' (%s)\n",
 		      conf_uname, fdt_strerror(noffset));
 	}
 
+	if (conf_uname_copy)
+		free(conf_uname_copy);
+
 	return noffset;
 }

[...]

Signature · 2 lines
Best regards,
Marek Vasut
#23 lore raw

PATCH 5/5 fit: Introduce methods for applying overlays on fit-load

Hi Marek,

Quoted 14 lines · Marek Vasut
Quoted 6 lines · Pantelis Antoniou

Introduce an overlay based method for constructing a base DT blob to pass to the kernel.

Both canned and runtime feature selection is supported.

[...]

Quoted 4 lines
common/image-fit.c +0 -0
@@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const char *conf_uname)
 		debug("Found default configuration: '%s'\n", conf_uname);
 	}
 
Quoted 13 lines

common/image-fit.c int fit_conf_get_node(const void *fit, const char *conf_uname) · line 1494

Quoted 10 lines
common/image-fit.c +10 -0
+	s = strchr(conf_uname, '#');
+	if (s) {
+		len = s - conf_uname;
+		conf_uname_copy = malloc(len + 1);
+		if (!conf_uname_copy) {
+			debug("Can't allocate uname copy: '%s'\n",
+					conf_uname);
+			return -ENOMEM;
+		}
+		memcpy(conf_uname_copy, conf_uname, len);

Is that like strdup() here ?

No. The space allocated is not the full string, just the span until the next #.

Quoted 10 lines
Quoted 10 lines
common/image-fit.c +4 -0
+		conf_uname_copy[len] = '\0';
+		conf_uname = conf_uname_copy;
+	}
+
 	noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname);
 	if (noffset < 0) {
 		debug("Can't get node offset for configuration unit name: '%s' (%s)\n",
 		      conf_uname, fdt_strerror(noffset));
 	}
 
Quoted 9 lines
Quoted 5 lines
common/image-fit.c +3 -0
+	if (conf_uname_copy)
+		free(conf_uname_copy);
+
 	return noffset;
 }

[...]

Regards

-- Pantelis

#24 lore raw

PATCH 5/5 fit: Introduce methods for applying overlays on fit-load

Quoted 32 lines · On Dienstag, 4. Juli 2017 19:05:25 CEST Pantelis Antoniou wrote:

Hi Marek,

Quoted 16 lines · Marek Vasut
Quoted 6 lines · Pantelis Antoniou

Introduce an overlay based method for constructing a base DT blob to pass to the kernel.

Both canned and runtime feature selection is supported.

[...]

Quoted 6 lines
(quoted diff) +0 -0
@@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const

char *conf_uname)> >

common/image-fit.c +0 -0
 		debug("Found default configuration: '%s'\n", conf_uname);
 
 	}
Quoted 12 lines

common/image-fit.c int fit_conf_get_node(const void *fit, const char *conf_uname) · line 1494

Quoted 10 lines
common/image-fit.c +10 -0
+	s = strchr(conf_uname, '#');
+	if (s) {
+		len = s - conf_uname;
+		conf_uname_copy = malloc(len + 1);
+		if (!conf_uname_copy) {
+			debug("Can't allocate uname copy: '%s'\n",
+					conf_uname);
+			return -ENOMEM;
+		}
+		memcpy(conf_uname_copy, conf_uname, len);

Is that like strdup() here ?

Quoted 2 lines

No. The space allocated is not the full string, just the span until the next #.

You could use strndup() to copy only the first n characters.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
common/image-fit.c +4 -0
+		conf_uname_copy[len] = '\0';
+		conf_uname = conf_uname_copy;
+	}
+
 
 	noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname);
 	if (noffset < 0) {
Quoted 8 lines
Quoted 8 lines

common/image-fit.c int fit_conf_get_node(const void *fit, const char *conf_uname)

Quoted 8 lines
common/image-fit.c +1 -0
 		debug("Can't get node offset for configuration unit name: '%s'
 		(%s)\n",
 
 		      conf_uname, fdt_strerror(noffset));
 
 	}
 
+	if (conf_uname_copy)

No need for a null ptr check, IIRC.

Quoted 18 lines
Quoted 8 lines
Quoted 6 lines
common/image-fit.c +2 -0
+		free(conf_uname_copy);
+
 
 	return noffset;
 
 }

[...]

Regards

-- Pantelis

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#25 lore raw

PATCH 5/5 fit: Introduce methods for applying overlays on fit-load

Hi,

Quoted 33 lines · On Wed, 5 Jul 2017 00:19:28 +0200 stefan.bruens at rwth-aachen.de wrote:
Quoted 32 lines · On Dienstag, 4. Juli 2017 19:05:25 CEST Pantelis Antoniou wrote:

Hi Marek,

Quoted 28 lines · Marek Vasut
Quoted 6 lines · Pantelis Antoniou

Introduce an overlay based method for constructing a base DT blob to pass to the kernel.

Both canned and runtime feature selection is supported.

[...]

Quoted 6 lines
(quoted diff) +0 -0
@@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const

char *conf_uname)> >

common/image-fit.c +0 -0
 		debug("Found default configuration: '%s'\n", conf_uname);
 
 	}
 

common/image-fit.c int fit_conf_get_node(const void *fit, const char *conf_uname) · line 1494

Quoted 10 lines
common/image-fit.c +10 -0
+	s = strchr(conf_uname, '#');
+	if (s) {
+		len = s - conf_uname;
+		conf_uname_copy = malloc(len + 1);
+		if (!conf_uname_copy) {
+			debug("Can't allocate uname copy: '%s'\n",
+					conf_uname);
+			return -ENOMEM;
+		}
+		memcpy(conf_uname_copy, conf_uname, len);

Is that like strdup() here ?

Quoted 5 lines
Quoted 2 lines

No. The space allocated is not the full string, just the span until the next #.

You could use strndup() to copy only the first n characters.

or strsep() to tokenize (a copy of) the original string. IMO using strdup() and strsep() makes the intent of this function clearer, than the current code.

Lothar Waßmann

#26 lore raw

cover uboot overlays and FIT image

In reply to Pantelis Antoniou

Hi Pantelis,

Quoted 28 lines · Pantelis Antoniou

This patch allows uboot to handle overlays in a manner that uses a base DT blob and an arbitrary number of DT overlays blobs.

It is intended to be used with FIT images since handling a multitude of device tree blobs manually is a chore.

The first 3 patches have already been submitted to DTC for review, and provide the plumbing in libfdt.

The next patch adds a unit test for a stacked overlay (in which an overlay refers to a symbol contained in a previously applied overlay).

The last patch contains the FIT FDT blob generation logic as well as documentation about how it all works.

The patchset is available at

https://github.com/pantoniou/u-boot/tree/uboot-overlays

and is against mainline u-boot as pulled today, 30/6/2017.

Pantelis Antoniou (5):
libfdt.h: Introduce FDT_PATH_MAX
libfdt_env.h: Add <malloc.h> in libfdt environment
fdt: Allow stacked overlays phandle references
test: overlay: Add unit test for stacked overlay
fit: Introduce methods for applying overlays on fit-load

Quoted 15 lines
 common/image-fdt.c                           |   7 +-
 common/image-fit.c                           | 215 ++++++++++++++++++++++++--
 doc/uImage.FIT/command_syntax_extensions.txt |  12 +-
 doc/uImage.FIT/overlay-fdt-boot.txt          | 221 +++++++++++++++++++++++++++
 doc/uImage.FIT/source_file_format.txt        |   6 +-
 include/image.h                              |  10 ++
 include/libfdt_env.h                         |   1 +
 lib/libfdt/fdt_overlay.c                     | 148 +++++++++++++++++-
 lib/libfdt/libfdt.h                          |   3 +
 test/overlay/Makefile                        |   1 +
 test/overlay/cmd_ut_overlay.c                |  34 ++++-
 test/overlay/test-fdt-overlay-stacked.dts    |  21 +++
 12 files changed, 659 insertions(+), 20 deletions(-)
 create mode 100644 doc/uImage.FIT/overlay-fdt-boot.txt
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts

Will there be a v2 of this series? I'm not sure whether the plan is to apply it in the current merge window or not?

Regards,
Simon

#27 lore raw

cover uboot overlays and FIT image

Quoted 48 lines · Simon Glass

Hi Pantelis,

Quoted 28 lines · Pantelis Antoniou

This patch allows uboot to handle overlays in a manner that uses a base DT blob and an arbitrary number of DT overlays blobs.

It is intended to be used with FIT images since handling a multitude of device tree blobs manually is a chore.

The first 3 patches have already been submitted to DTC for review, and provide the plumbing in libfdt.

The next patch adds a unit test for a stacked overlay (in which an overlay refers to a symbol contained in a previously applied overlay).

The last patch contains the FIT FDT blob generation logic as well as documentation about how it all works.

The patchset is available at

https://github.com/pantoniou/u-boot/tree/uboot-overlays

and is against mainline u-boot as pulled today, 30/6/2017.

Pantelis Antoniou (5):
libfdt.h: Introduce FDT_PATH_MAX
libfdt_env.h: Add <malloc.h> in libfdt environment
fdt: Allow stacked overlays phandle references
test: overlay: Add unit test for stacked overlay
fit: Introduce methods for applying overlays on fit-load

Quoted 15 lines
 common/image-fdt.c                           |   7 +-
 common/image-fit.c                           | 215 ++++++++++++++++++++++++--
 doc/uImage.FIT/command_syntax_extensions.txt |  12 +-
 doc/uImage.FIT/overlay-fdt-boot.txt          | 221 +++++++++++++++++++++++++++
 doc/uImage.FIT/source_file_format.txt        |   6 +-
 include/image.h                              |  10 ++
 include/libfdt_env.h                         |   1 +
 lib/libfdt/fdt_overlay.c                     | 148 +++++++++++++++++-
 lib/libfdt/libfdt.h                          |   3 +
 test/overlay/Makefile                        |   1 +
 test/overlay/cmd_ut_overlay.c                |  34 ++++-
 test/overlay/test-fdt-overlay-stacked.dts    |  21 +++
 12 files changed, 659 insertions(+), 20 deletions(-)
 create mode 100644 doc/uImage.FIT/overlay-fdt-boot.txt
 create mode 100644 test/overlay/test-fdt-overlay-stacked.dts
Quoted 2 lines

Will there be a v2 of this series? I'm not sure whether the plan is to apply it in the current merge window or not?

There's a certain level of churn and then what will be accepted in upstream libfdt that's happening before another iteration of this happens, unfortunately.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170728/62159ff0/attachment.sig>