All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/5] uboot overlays and FIT image
@ 2017-06-30 16:22 Pantelis Antoniou
  2017-06-30 16:22 ` [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX Pantelis Antoniou
                   ` (5 more replies)
  0 siblings, 6 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-06-30 16:22 UTC (permalink / raw)
  To: u-boot

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

-- 
2.1.4

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

* [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX
  2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
@ 2017-06-30 16:22 ` Pantelis Antoniou
  2017-07-01 14:01   ` Marek Vasut
  2017-06-30 16:22 ` [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment Pantelis Antoniou
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 28+ messages in thread
From: Pantelis Antoniou @ 2017-06-30 16:22 UTC (permalink / raw)
  To: u-boot

Introduce FDT_PATH_MAX

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
 lib/libfdt/libfdt.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/libfdt/libfdt.h b/lib/libfdt/libfdt.h
index 2f7ebf8..c369015 100644
--- a/lib/libfdt/libfdt.h
+++ b/lib/libfdt/libfdt.h
@@ -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)                */
 /**********************************************************************/
-- 
2.1.4

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

* [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment
  2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
  2017-06-30 16:22 ` [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX Pantelis Antoniou
@ 2017-06-30 16:22 ` Pantelis Antoniou
  2017-07-01 14:02   ` Marek Vasut
  2017-07-07  3:58   ` Simon Glass
  2017-06-30 16:23 ` [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references Pantelis Antoniou
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-06-30 16:22 UTC (permalink / raw)
  To: u-boot

Overlays require malloc so add it in the libfdt environment.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
 include/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/libfdt_env.h b/include/libfdt_env.h
index 6c6845f..59463c0 100644
--- a/include/libfdt_env.h
+++ b/include/libfdt_env.h
@@ -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 */
-- 
2.1.4

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

* [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
  2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
  2017-06-30 16:22 ` [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX Pantelis Antoniou
  2017-06-30 16:22 ` [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment Pantelis Antoniou
@ 2017-06-30 16:23 ` Pantelis Antoniou
  2017-07-01 14:07   ` Marek Vasut
  2017-07-07  3:58   ` Simon Glass
  2017-06-30 16:23 ` [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay Pantelis Antoniou
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-06-30 16:23 UTC (permalink / raw)
  To: u-boot

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";
            };
	};

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
 lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 147 insertions(+), 1 deletion(-)

diff --git a/lib/libfdt/fdt_overlay.c b/lib/libfdt/fdt_overlay.c
index ceb9687..59fd7f3 100644
--- a/lib/libfdt/fdt_overlay.c
+++ b/lib/libfdt/fdt_overlay.c
@@ -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.
 	 */
-- 
2.1.4

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

* [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay
  2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
                   ` (2 preceding siblings ...)
  2017-06-30 16:23 ` [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references Pantelis Antoniou
@ 2017-06-30 16:23 ` Pantelis Antoniou
  2017-07-07  3:58   ` Simon Glass
  2017-07-07  7:48   ` Moritz Fischer
  2017-06-30 16:23 ` [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load Pantelis Antoniou
  2017-07-28 18:48 ` [U-Boot] [PATCH 0/5] uboot overlays and FIT image Simon Glass
  5 siblings, 2 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-06-30 16:23 UTC (permalink / raw)
  To: u-boot

Verify that stacked overlays work.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
 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

diff --git a/test/overlay/Makefile b/test/overlay/Makefile
index 907f085..416645c 100644
--- a/test/overlay/Makefile
+++ b/test/overlay/Makefile
@@ -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
diff --git a/test/overlay/cmd_ut_overlay.c b/test/overlay/cmd_ut_overlay.c
index cbef720..d8f5c8f 100644
--- a/test/overlay/cmd_ut_overlay.c
+++ b/test/overlay/cmd_ut_overlay.c
@@ -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);
diff --git a/test/overlay/test-fdt-overlay-stacked.dts b/test/overlay/test-fdt-overlay-stacked.dts
new file mode 100644
index 0000000..9fb7c7b
--- /dev/null
+++ b/test/overlay/test-fdt-overlay-stacked.dts
@@ -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>;
+		};
+	};
+};
-- 
2.1.4

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

* [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load
  2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
                   ` (3 preceding siblings ...)
  2017-06-30 16:23 ` [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay Pantelis Antoniou
@ 2017-06-30 16:23 ` Pantelis Antoniou
  2017-07-01 14:11   ` Marek Vasut
  2017-07-28 18:48 ` [U-Boot] [PATCH 0/5] uboot overlays and FIT image Simon Glass
  5 siblings, 1 reply; 28+ messages in thread
From: Pantelis Antoniou @ 2017-06-30 16:23 UTC (permalink / raw)
  To: u-boot

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

Both canned and runtime feature selection is supported.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
 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

diff --git a/common/image-fdt.c b/common/image-fdt.c
index c6e8832..a59134c 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -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
diff --git a/common/image-fit.c b/common/image-fit.c
index 109ecfa..f78c5cf 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <mapmem.h>
 #include <asm/io.h>
+#include <malloc.h>
 DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
 
@@ -434,6 +435,10 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
 			printf("0x%08lx\n", load);
 	}
 
+	/* optional load address for FDT */
+	if (type == IH_TYPE_FLATDT && !fit_image_get_load(fit, image_noffset, &load))
+		printf("%s  Load Address: 0x%08lx\n", p, load);
+
 	if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
 	    (type == IH_TYPE_RAMDISK)) {
 		ret = fit_image_get_entry(fit, image_noffset, &entry);
@@ -1454,6 +1459,8 @@ int fit_conf_get_node(const void *fit, const char *conf_uname)
 {
 	int noffset, confs_noffset;
 	int len;
+	const char *s;
+	char *conf_uname_copy = NULL;
 
 	confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
 	if (confs_noffset < 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);
 	}
 
+	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);
+		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;
 }
 
-int fit_conf_get_prop_node(const void *fit, int noffset,
+int fit_conf_get_prop_node_count(const void *fit, int noffset,
 		const char *prop_name)
 {
-	char *uname;
+	return fdt_stringlist_count(fit, noffset, prop_name);
+}
+
+int fit_conf_get_prop_node_index(const void *fit, int noffset,
+		const char *prop_name, int index)
+{
+	const char *uname;
 	int len;
 
 	/* get kernel image unit name from configuration kernel property */
-	uname = (char *)fdt_getprop(fit, noffset, prop_name, &len);
+	uname = fdt_stringlist_get(fit, noffset, prop_name, index, &len);
 	if (uname == NULL)
 		return len;
 
 	return fit_image_get_node(fit, uname);
 }
 
+int fit_conf_get_prop_node(const void *fit, int noffset,
+		const char *prop_name)
+{
+	return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0);
+}
+
 /**
  * fit_conf_print - prints out the FIT configuration details
  * @fit: pointer to the FIT format image header
@@ -1515,7 +1551,7 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
 	char *desc;
 	const char *uname;
 	int ret;
-	int loadables_index;
+	int fdt_index, loadables_index;
 
 	/* Mandatory properties */
 	ret = fit_get_desc(fit, noffset, &desc);
@@ -1537,9 +1573,17 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
 	if (uname)
 		printf("%s  Init Ramdisk: %s\n", p, uname);
 
-	uname = fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
-	if (uname)
-		printf("%s  FDT:          %s\n", p, uname);
+	for (fdt_index = 0;
+	     uname = fdt_stringlist_get(fit, noffset, FIT_FDT_PROP,
+					fdt_index, NULL), uname;
+	     fdt_index++) {
+
+		if (fdt_index == 0)
+			printf("%s  FDT:          ", p);
+		else
+			printf("%s                ", p);
+		printf("%s\n", uname);
+	}
 
 	uname = fdt_getprop(fit, noffset, FIT_FPGA_PROP, NULL);
 	if (uname)
@@ -1575,8 +1619,8 @@ static int fit_image_select(const void *fit, int rd_noffset, int verify)
 	return 0;
 }
 
-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 cfg_noffset;
 	void *fit_hdr;
@@ -1593,7 +1637,8 @@ int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
 		return -EINVAL;
 	}
 
-	noffset = fit_conf_get_prop_node(fit_hdr, cfg_noffset, prop_name);
+	noffset = fit_conf_get_prop_node_index(fit_hdr, cfg_noffset, prop_name,
+					       index);
 	if (noffset < 0) {
 		debug("*  %s: no '%s' in config\n", prop_name, prop_name);
 		return -ENOENT;
@@ -1602,6 +1647,12 @@ int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
 	return noffset;
 }
 
+int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
+			ulong addr)
+{
+	return fit_get_node_from_config_index(images, prop_name, addr, 0);
+}
+
 /**
  * fit_get_image_type_property() - get property name for IH_TYPE_...
  *
@@ -1689,7 +1740,8 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
 					BOOTSTAGE_SUB_NO_UNIT_NAME);
 			return -ENOENT;
 		}
-		fit_uname_config = fdt_get_name(fit, cfg_noffset, NULL);
+		if (!fit_uname_config)
+			fit_uname_config = fdt_get_name(fit, cfg_noffset, NULL);
 		printf("   Using '%s' configuration\n", fit_uname_config);
 		if (image_type == IH_TYPE_KERNEL) {
 			/* Remember (and possibly verify) this config */
@@ -1841,6 +1893,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
 		dst = map_sysmem(load, len);
 		memmove(dst, buf, len);
 		data = load;
+
 	}
 	bootstage_mark(bootstage_id + BOOTSTAGE_SUB_LOAD);
 
@@ -1873,3 +1926,143 @@ int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
 
 	return ret;
 }
+
+#ifndef USE_HOSTCC
+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)
+{
+	int fdt_noffset, cfg_noffset, count;
+	const void *fit;
+	const char *fit_uname = NULL;
+	const char *fit_uname_config = NULL;
+	char *fit_uname_config_copy = NULL;
+	char *next_config = NULL;
+	ulong load, len;
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	ulong ovload, ovlen, image_start, image_end;
+	const char *uconfig;
+	const char *uname;
+	void *base, *ov;
+	int i, err, noffset, ov_noffset;
+#endif
+
+	fit_uname = fit_unamep ? *fit_unamep : NULL;
+
+	if (fit_uname_configp && *fit_uname_configp) {
+		fit_uname_config_copy = strdup(*fit_uname_configp);
+		if (!fit_uname_config_copy)
+			return -ENOMEM;
+
+		next_config = strchr(fit_uname_config_copy, '#');
+		if (next_config)
+			*next_config++ = '\0';
+		if (next_config - 1 > fit_uname_config_copy)
+			fit_uname_config = fit_uname_config_copy;
+	}
+
+	fdt_noffset = fit_image_load(images,
+		addr, &fit_uname, &fit_uname_config,
+		arch, IH_TYPE_FLATDT,
+		BOOTSTAGE_ID_FIT_FDT_START,
+		FIT_LOAD_OPTIONAL, &load, &len);
+
+	if (fdt_noffset < 0)
+		goto out;
+
+	debug("fit_uname=%s, fit_uname_config=%s\n",
+			fit_uname ? fit_uname : "<NULL>",
+			fit_uname_config ? fit_uname_config : "<NULL>");
+
+	fit = map_sysmem(addr, 0);
+	image_start = addr;
+	image_end = addr + fit_get_size(fit);
+
+	cfg_noffset = fit_conf_get_node(fit, fit_uname_config);
+
+	/* single blob, or error just return as well */
+	count = fit_conf_get_prop_node_count(fit, cfg_noffset, FIT_FDT_PROP);
+	if (count <= 1 && !next_config)
+		goto out;
+
+	/* we need to apply overlays */
+
+#ifdef CONFIG_OF_LIBFDT_OVERLAY
+	/* verify that relocation took place by load address not being in fit */
+	if (load >= image_start && load < image_end) {
+		/* check is simplified; fit load checks for overlaps */
+		printf("Overlayed FDT requires relocation\n");
+		fdt_noffset = -EBADF;
+		goto out;
+	}
+
+	base = map_sysmem(load, len);
+
+	/* apply extra configs in FIT first, followed by args */
+	for (i = 1; ; i++) {
+		if (i < count) {
+			noffset = fit_conf_get_prop_node_index(fit, cfg_noffset,
+							       FIT_FDT_PROP, i);
+			uname = fit_get_name(fit, noffset, NULL);
+			uconfig = NULL;
+		} else {
+			if (!next_config)
+				break;
+			uconfig = next_config;
+			next_config = strchr(next_config, '#');
+			if (next_config)
+				*next_config++ = '\0';
+			uname = NULL;
+		}
+
+		debug("%d: using uname=%s uconfig=%s\n", i, uname, uconfig);
+
+		ov_noffset = fit_image_load(images,
+			addr, &uname, &uconfig,
+			arch, IH_TYPE_FLATDT,
+			BOOTSTAGE_ID_FIT_FDT_START,
+			FIT_LOAD_REQUIRED, &ovload, &ovlen);
+		if (ov_noffset < 0) {
+			printf("load of %s failed\n", uname);
+			continue;
+		}
+		debug("%s loaded@0x%08lx len=0x%08lx\n",
+				uname, ovload, ovlen);
+		ov = map_sysmem(ovload, ovlen);
+
+		base = map_sysmem(load, len + ovlen);
+		err = fdt_open_into(base, base, len + ovlen);
+		if (err < 0) {
+			printf("failed on fdt_open_into\n");
+			fdt_noffset = err;
+			goto out;
+		}
+		err = fdt_overlay_apply(base, ov);
+		if (err < 0) {
+			printf("failed on fdt_overlay_apply\n");
+			fdt_noffset = err;
+			goto out;
+		}
+		fdt_pack(base);
+		len = fdt_totalsize(base);
+	}
+#else
+	printf("config with overlays but CONFIG_OF_LIBFDT_OVERLAY not set\n");
+	fdt_noffset = -EBADF;
+#endif
+
+out:
+	if (datap)
+		*datap = load;
+	if (lenp)
+		*lenp = len;
+	if (fit_unamep)
+		*fit_unamep = fit_uname;
+	if (fit_uname_configp)
+		*fit_uname_configp = fit_uname_config;
+
+	if (fit_uname_config_copy)
+		free(fit_uname_config_copy);
+	return fdt_noffset;
+}
+#endif
diff --git a/doc/uImage.FIT/command_syntax_extensions.txt b/doc/uImage.FIT/command_syntax_extensions.txt
index 6c99b1c..676f992 100644
--- a/doc/uImage.FIT/command_syntax_extensions.txt
+++ b/doc/uImage.FIT/command_syntax_extensions.txt
@@ -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
diff --git a/doc/uImage.FIT/overlay-fdt-boot.txt b/doc/uImage.FIT/overlay-fdt-boot.txt
new file mode 100644
index 0000000..dbdf2a1
--- /dev/null
+++ b/doc/uImage.FIT/overlay-fdt-boot.txt
@@ -0,0 +1,221 @@
+U-Boot FDT Overlay usage
+========================
+
+Introduction
+------------
+In many cases it is desirable to have a single FIT image support a multitude
+of similar boards and their expansion options. The same kernel on DT enabled
+platforms can support this easily enough by providing a DT blob upon boot
+that matches the desired configuration.
+
+Configuration without overlays
+------------------------------
+
+Take a hypothetical board named 'foo' where there are different supported
+revisions, reva and revb. Assume that both board revisions can use add a bar
+add-on board, while only the revb board can use a baz add-on board.
+
+Without using overlays the configuration would be as follows for every case.
+
+	/dts-v1/;
+	/ {
+		images {
+			kernel at 1 {
+				data = /incbin/("./zImage");
+				type = "kernel";
+				arch = "arm";
+				os = "linux";
+				load = <0x82000000>;
+				entry = <0x82000000>;
+			};
+			fdt at 1 {
+				data = /incbin/("./foo-reva.dtb");
+				type = "flat_dt";
+				arch = "arm";
+			};
+			fdt at 2 {
+				data = /incbin/("./foo-revb.dtb");
+				type = "flat_dt";
+				arch = "arm";
+			};
+			fdt at 3 {
+				data = /incbin/("./foo-reva-bar.dtb");
+				type = "flat_dt";
+				arch = "arm";
+			};
+			fdt at 4 {
+				data = /incbin/("./foo-revb-bar.dtb");
+				type = "flat_dt";
+				arch = "arm";
+			};
+			fdt at 5 {
+				data = /incbin/("./foo-revb-baz.dtb");
+				type = "flat_dt";
+				arch = "arm";
+			};
+			fdt at 6 {
+				data = /incbin/("./foo-revb-bar-baz.dtb");
+				type = "flat_dt";
+				arch = "arm";
+			};
+		};
+
+		configurations {
+			default = "foo-reva.dtb;
+			foo-reva.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 1";
+			};
+			foo-revb.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 2";
+			};
+			foo-reva-bar.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 3";
+			};
+			foo-revb-bar.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 4";
+			};
+			foo-revb-baz.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 5";
+			};
+			foo-revb-bar-baz.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 6";
+			};
+		};
+	};
+
+Note the blob needs to be compiled for each case and the combinatorial explosion of
+configurations. A typical device tree blob is in the low hunderds of kbytes so a
+multitude of configuration grows the image quite a bit.
+
+Booting this image is done by using
+
+	# bootm <addr>#<config>
+
+Where config is one of:
+	foo-reva.dtb, foo-revb.dtb, foo-reva-bar.dtb, foo-revb-bar.dtb,
+	foo-revb-baz.dtb, foo-revb-bar-baz.dtb
+
+This selects the DTB to use when booting.
+
+Configuration using overlays
+----------------------------
+
+Device tree overlays can be applied to a base DT and result in the same blob
+being passed to the booting kernel. This saves on space and avoid the combinatorial
+explosion problem.
+
+	/dts-v1/;
+	/ {
+		images {
+			kernel at 1 {
+				data = /incbin/("./zImage");
+				type = "kernel";
+				arch = "arm";
+				os = "linux";
+				load = <0x82000000>;
+				entry = <0x82000000>;
+			};
+			fdt at 1 {
+				data = /incbin/("./foo.dtb");
+				type = "flat_dt";
+				arch = "arm";
+				load = <0x87f00000>;
+			};
+			fdt at 2 {
+				data = /incbin/("./reva.dtbo");
+				type = "flat_dt";
+				arch = "arm";
+				load = <0x87fc0000>;
+			};
+			fdt at 3 {
+				data = /incbin/("./revb.dtbo");
+				type = "flat_dt";
+				arch = "arm";
+				load = <0x87fc0000>;
+			};
+			fdt at 4 {
+				data = /incbin/("./bar.dtbo");
+				type = "flat_dt";
+				arch = "arm";
+				load = <0x87fc0000>;
+			};
+			fdt at 5 {
+				data = /incbin/("./baz.dtbo");
+				type = "flat_dt";
+				arch = "arm";
+				load = <0x87fc0000>;
+			};
+		};
+
+		configurations {
+			default = "foo-reva.dtb;
+			foo-reva.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 1", "fdt at 2";
+			};
+			foo-revb.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 1", "fdt at 3";
+			};
+			foo-reva-bar.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 1", "fdt at 2", "fdt at 4";
+			};
+			foo-revb-bar.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 1", "fdt at 3", "fdt at 4";
+			};
+			foo-revb-baz.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 1", "fdt at 3", "fdt at 5";
+			};
+			foo-revb-bar-baz.dtb {
+				kernel = "kernel at 1";
+				fdt = "fdt at 1", "fdt at 3", "fdt at 4", "fdt at 5";
+			};
+			bar {
+				fdt = "fdt at 4";
+			};
+			baz {
+				fdt = "fdt at 5";
+			};
+		};
+	};
+
+Booting this image is exactly the same as the non-overlay example.
+u-boot will retrieve the base blob and apply the overlays in sequence as
+they are declared in the configuration.
+
+Note the minimum amount of different DT blobs, as well as the requirement for
+the DT blobs to have a load address; the overlay application requires the blobs
+to be writeable.
+
+Configuration using overlays and feature selection
+--------------------------------------------------
+
+Although the configuration in the previous section works is a bit inflexible
+since it requires all possible configuration options to be laid out before
+hand in the FIT image. For the add-on boards the extra config selection method
+might make sense.
+
+Note the two bar & baz configuration nodes. To boot a reva board with
+the bar add-on board enabled simply use:
+
+	# bootm <addr>#foo-reva.dtb#bar
+
+While booting a revb with bar and baz is as follows:
+
+	# bootm <addr>#foo-revb.dtb#bar#baz
+
+The limitation for a feature selection configuration node is that a single
+fdt option is currently supported.
+
+Pantelis Antoniou
+pantelis.antoniou at konsulko.com
+12/6/2017
diff --git a/doc/uImage.FIT/source_file_format.txt b/doc/uImage.FIT/source_file_format.txt
index afff301..966b244 100644
--- a/doc/uImage.FIT/source_file_format.txt
+++ b/doc/uImage.FIT/source_file_format.txt
@@ -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
diff --git a/include/image.h b/include/image.h
index fcfe730..bf35197 100644
--- a/include/image.h
+++ b/include/image.h
@@ -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
-- 
2.1.4

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

* [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX
  2017-06-30 16:22 ` [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX Pantelis Antoniou
@ 2017-07-01 14:01   ` Marek Vasut
  2017-07-07  3:58     ` Simon Glass
  0 siblings, 1 reply; 28+ messages in thread
From: Marek Vasut @ 2017-07-01 14:01 UTC (permalink / raw)
  To: u-boot

On 06/30/2017 06:22 PM, Pantelis Antoniou wrote:
> Introduce FDT_PATH_MAX

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

> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
>  lib/libfdt/libfdt.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/libfdt/libfdt.h b/lib/libfdt/libfdt.h
> index 2f7ebf8..c369015 100644
> --- a/lib/libfdt/libfdt.h
> +++ b/lib/libfdt/libfdt.h
> @@ -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)                */
>  /**********************************************************************/
> 


-- 
Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment
  2017-06-30 16:22 ` [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment Pantelis Antoniou
@ 2017-07-01 14:02   ` Marek Vasut
  2017-07-04 16:53     ` Pantelis Antoniou
  2017-07-07  3:58   ` Simon Glass
  1 sibling, 1 reply; 28+ messages in thread
From: Marek Vasut @ 2017-07-01 14:02 UTC (permalink / raw)
  To: u-boot

On 06/30/2017 06:22 PM, Pantelis Antoniou wrote:
> Overlays require malloc so add it in the libfdt environment.

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

> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
>  include/libfdt_env.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/libfdt_env.h b/include/libfdt_env.h
> index 6c6845f..59463c0 100644
> --- a/include/libfdt_env.h
> +++ b/include/libfdt_env.h
> @@ -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 */
> 


-- 
Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
  2017-06-30 16:23 ` [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references Pantelis Antoniou
@ 2017-07-01 14:07   ` Marek Vasut
  2017-07-04 17:03     ` Pantelis Antoniou
  2017-07-05  6:25     ` Lothar Waßmann
  2017-07-07  3:58   ` Simon Glass
  1 sibling, 2 replies; 28+ messages in thread
From: Marek Vasut @ 2017-07-01 14:07 UTC (permalink / raw)
  To: u-boot

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

[...]

> +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;

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 ?

> +	buf = malloc(FDT_PATH_MAX);
> +	if (!buf)
> +		return -FDT_ERR_NOSPACE;

Would it make sense to allocate this on stack ?

> +	/* 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 */

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

> +		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';

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

> +		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.
>  	 */
> 


-- 
Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load
  2017-06-30 16:23 ` [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load Pantelis Antoniou
@ 2017-07-01 14:11   ` Marek Vasut
  2017-07-04 17:05     ` Pantelis Antoniou
  0 siblings, 1 reply; 28+ messages in thread
From: Marek Vasut @ 2017-07-01 14:11 UTC (permalink / raw)
  To: u-boot

On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:
> Introduce an overlay based method for constructing a base DT blob
> to pass to the kernel.
> 
> Both canned and runtime feature selection is supported.
> 
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

[...]

> @@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const char *conf_uname)
>  		debug("Found default configuration: '%s'\n", conf_uname);
>  	}
>  
> +	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 ?

> +		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;
>  }

[...]


-- 
Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment
  2017-07-01 14:02   ` Marek Vasut
@ 2017-07-04 16:53     ` Pantelis Antoniou
  0 siblings, 0 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-07-04 16:53 UTC (permalink / raw)
  To: u-boot

Hi Marek,

On Sat, 2017-07-01 at 16:02 +0200, Marek Vasut wrote:
> On 06/30/2017 06:22 PM, Pantelis Antoniou wrote:
> > 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 :)

> > Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> > ---
> >  include/libfdt_env.h | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/include/libfdt_env.h b/include/libfdt_env.h
> > index 6c6845f..59463c0 100644
> > --- a/include/libfdt_env.h
> > +++ b/include/libfdt_env.h
> > @@ -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 */
> > 
> 
> 

Regards

-- Pantelis

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

* [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
  2017-07-01 14:07   ` Marek Vasut
@ 2017-07-04 17:03     ` Pantelis Antoniou
  2017-07-05  6:25     ` Lothar Waßmann
  1 sibling, 0 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-07-04 17:03 UTC (permalink / raw)
  To: u-boot

Hi Marek,

On Sat, 2017-07-01 at 16:07 +0200, Marek Vasut wrote:
> On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:
> 
> [...]
> 
> > +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;
> 
> 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.

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

> > +	/* 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 */
> 
> "frag name" ? What is this now, Unreal Tournament ? :)
> 

Fragment. There were computers before first person shooters.

> > +		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';
> 
> 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.
 
> > +		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.
> >  	 */
> > 
> 
> 

Regards

-- Pantelis

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

* [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load
  2017-07-01 14:11   ` Marek Vasut
@ 2017-07-04 17:05     ` Pantelis Antoniou
  2017-07-04 22:19       ` stefan.bruens at rwth-aachen.de
  0 siblings, 1 reply; 28+ messages in thread
From: Pantelis Antoniou @ 2017-07-04 17:05 UTC (permalink / raw)
  To: u-boot

Hi Marek,

On Sat, 2017-07-01 at 16:11 +0200, Marek Vasut wrote:
> On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:
> > Introduce an overlay based method for constructing a base DT blob
> > to pass to the kernel.
> > 
> > Both canned and runtime feature selection is supported.
> > 
> > Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> 
> [...]
> 
> > @@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const char *conf_uname)
> >  		debug("Found default configuration: '%s'\n", conf_uname);
> >  	}
> >  
> > +	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 #.

> > +		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;
> >  }
> 
> [...]
> 
> 

Regards

-- Pantelis

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

* [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load
  2017-07-04 17:05     ` Pantelis Antoniou
@ 2017-07-04 22:19       ` stefan.bruens at rwth-aachen.de
  2017-07-05  6:32         ` Lothar Waßmann
  0 siblings, 1 reply; 28+ messages in thread
From: stefan.bruens at rwth-aachen.de @ 2017-07-04 22:19 UTC (permalink / raw)
  To: u-boot

On Dienstag, 4. Juli 2017 19:05:25 CEST Pantelis Antoniou wrote:
> Hi Marek,
> 
> On Sat, 2017-07-01 at 16:11 +0200, Marek Vasut wrote:
> > On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:
> > > Introduce an overlay based method for constructing a base DT blob
> > > to pass to the kernel.
> > > 
> > > Both canned and runtime feature selection is supported.
> > > 
> > > Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> > 
> > [...]
> > 
> > > @@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const
> > > char *conf_uname)> > 
> > >  		debug("Found default configuration: '%s'\n", conf_uname);
> > >  	
> > >  	}
> > > 
> > > +	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 #.

You could use strndup() to copy only the first n characters.
 
> > > +		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)

No need for a null ptr check, IIRC.

> > > +		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

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

* [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
  2017-07-01 14:07   ` Marek Vasut
  2017-07-04 17:03     ` Pantelis Antoniou
@ 2017-07-05  6:25     ` Lothar Waßmann
  1 sibling, 0 replies; 28+ messages in thread
From: Lothar Waßmann @ 2017-07-05  6:25 UTC (permalink / raw)
  To: u-boot

Hi,

On Sat, 1 Jul 2017 16:07:47 +0200 Marek Vasut wrote:
> On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:
> 
[...]
> > +	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

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

* [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load
  2017-07-04 22:19       ` stefan.bruens at rwth-aachen.de
@ 2017-07-05  6:32         ` Lothar Waßmann
  0 siblings, 0 replies; 28+ messages in thread
From: Lothar Waßmann @ 2017-07-05  6:32 UTC (permalink / raw)
  To: u-boot

Hi,

On Wed, 5 Jul 2017 00:19:28 +0200 stefan.bruens at rwth-aachen.de wrote:
> On Dienstag, 4. Juli 2017 19:05:25 CEST Pantelis Antoniou wrote:
> > Hi Marek,
> > 
> > On Sat, 2017-07-01 at 16:11 +0200, Marek Vasut wrote:
> > > On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:
> > > > Introduce an overlay based method for constructing a base DT blob
> > > > to pass to the kernel.
> > > > 
> > > > Both canned and runtime feature selection is supported.
> > > > 
> > > > Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> > > 
> > > [...]
> > > 
> > > > @@ -1475,29 +1482,58 @@ int fit_conf_get_node(const void *fit, const
> > > > char *conf_uname)> > 
> > > >  		debug("Found default configuration: '%s'\n", conf_uname);
> > > >  	
> > > >  	}
> > > > 
> > > > +	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 #.
> 
> 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

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

* [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX
  2017-07-01 14:01   ` Marek Vasut
@ 2017-07-07  3:58     ` Simon Glass
  2017-07-07  7:03       ` Pantelis Antoniou
  0 siblings, 1 reply; 28+ messages in thread
From: Simon Glass @ 2017-07-07  3:58 UTC (permalink / raw)
  To: u-boot

Hi,

On 1 July 2017 at 08:01, Marek Vasut <marex@denx.de> wrote:
> On 06/30/2017 06:22 PM, Pantelis Antoniou wrote:
>> 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:

Reviewed-by: Simon Glass <sjg@chromium.org>

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

>
>> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
>> ---
>>  lib/libfdt/libfdt.h | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/lib/libfdt/libfdt.h b/lib/libfdt/libfdt.h
>> index 2f7ebf8..c369015 100644
>> --- a/lib/libfdt/libfdt.h
>> +++ b/lib/libfdt/libfdt.h
>> @@ -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)                */
>>  /**********************************************************************/
>>
>
>
> --
> Best regards,
> Marek Vasut

Regards,
Simon

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

* [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment
  2017-06-30 16:22 ` [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment Pantelis Antoniou
  2017-07-01 14:02   ` Marek Vasut
@ 2017-07-07  3:58   ` Simon Glass
  1 sibling, 0 replies; 28+ messages in thread
From: Simon Glass @ 2017-07-07  3:58 UTC (permalink / raw)
  To: u-boot

On 30 June 2017 at 10:22, Pantelis Antoniou
<pantelis.antoniou@konsulko.com> wrote:
> Overlays require malloc so add it in the libfdt environment.
>
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
>  include/libfdt_env.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/include/libfdt_env.h b/include/libfdt_env.h
> index 6c6845f..59463c0 100644
> --- a/include/libfdt_env.h
> +++ b/include/libfdt_env.h
> @@ -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 */
> --
> 2.1.4
>

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
  2017-06-30 16:23 ` [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references Pantelis Antoniou
  2017-07-01 14:07   ` Marek Vasut
@ 2017-07-07  3:58   ` Simon Glass
  2017-07-07  7:02     ` Pantelis Antoniou
  1 sibling, 1 reply; 28+ messages in thread
From: Simon Glass @ 2017-07-07  3:58 UTC (permalink / raw)
  To: u-boot

On 30 June 2017 at 10:23, Pantelis Antoniou
<pantelis.antoniou@konsulko.com> wrote:
> 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";
>             };
>         };
>
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
>  lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 147 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

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

* [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay
  2017-06-30 16:23 ` [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay Pantelis Antoniou
@ 2017-07-07  3:58   ` Simon Glass
  2017-07-07  7:48   ` Moritz Fischer
  1 sibling, 0 replies; 28+ messages in thread
From: Simon Glass @ 2017-07-07  3:58 UTC (permalink / raw)
  To: u-boot

Hi,

On 30 June 2017 at 10:23, Pantelis Antoniou
<pantelis.antoniou@konsulko.com> wrote:
> Verify that stacked overlays work.
>
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
>  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

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
  2017-07-07  3:58   ` Simon Glass
@ 2017-07-07  7:02     ` Pantelis Antoniou
  2017-07-14 13:51       ` Simon Glass
  0 siblings, 1 reply; 28+ messages in thread
From: Pantelis Antoniou @ 2017-07-07  7:02 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Thu, 2017-07-06 at 21:58 -0600, Simon Glass wrote:
> On 30 June 2017 at 10:23, Pantelis Antoniou
> <pantelis.antoniou@konsulko.com> wrote:
> > 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";
> >             };
> >         };
> >
> > Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> > ---
> >  lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 147 insertions(+), 1 deletion(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> I suppose that the upstream version has tests?
> 

Yes, and I could use a couple reviewers in the dtc mailing list.
 
> 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.

> - Simon

Regards

-- Pantelis

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

* [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX
  2017-07-07  3:58     ` Simon Glass
@ 2017-07-07  7:03       ` Pantelis Antoniou
  0 siblings, 0 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-07-07  7:03 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Thu, 2017-07-06 at 21:58 -0600, Simon Glass wrote:
> Hi,
> 
> On 1 July 2017 at 08:01, Marek Vasut <marex@denx.de> wrote:
> > On 06/30/2017 06:22 PM, Pantelis Antoniou wrote:
> >> 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 :)

> Apart from that:
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> We can just pick it from upstream if it is applied there first.
> 

Regards

-- Pantelis

> >
> >> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> >> ---
> >>  lib/libfdt/libfdt.h | 3 +++
> >>  1 file changed, 3 insertions(+)
> >>
> >> diff --git a/lib/libfdt/libfdt.h b/lib/libfdt/libfdt.h
> >> index 2f7ebf8..c369015 100644
> >> --- a/lib/libfdt/libfdt.h
> >> +++ b/lib/libfdt/libfdt.h
> >> @@ -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)                */
> >>  /**********************************************************************/
> >>
> >
> >
> > --
> > Best regards,
> > Marek Vasut
> 
> Regards,
> Simon

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

* [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay
  2017-06-30 16:23 ` [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay Pantelis Antoniou
  2017-07-07  3:58   ` Simon Glass
@ 2017-07-07  7:48   ` Moritz Fischer
  2017-07-07  8:32     ` Marek Vasut
  2017-07-07 10:33     ` Pantelis Antoniou
  1 sibling, 2 replies; 28+ messages in thread
From: Moritz Fischer @ 2017-07-07  7:48 UTC (permalink / raw)
  To: u-boot

Hi Pantelis,

nit inline

On Fri, Jun 30, 2017 at 9:23 AM, Pantelis Antoniou
<pantelis.antoniou@konsulko.com> wrote:
> Verify that stacked overlays work.
>
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

Reviewed-by: Moritz Fischer <moritz.fischer@ettus.com>
> ---
>  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
>
> diff --git a/test/overlay/Makefile b/test/overlay/Makefile
> index 907f085..416645c 100644
> --- a/test/overlay/Makefile
> +++ b/test/overlay/Makefile
> @@ -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
> diff --git a/test/overlay/cmd_ut_overlay.c b/test/overlay/cmd_ut_overlay.c
> index cbef720..d8f5c8f 100644
> --- a/test/overlay/cmd_ut_overlay.c
> +++ b/test/overlay/cmd_ut_overlay.c
> @@ -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);
> diff --git a/test/overlay/test-fdt-overlay-stacked.dts b/test/overlay/test-fdt-overlay-stacked.dts
> new file mode 100644
> index 0000000..9fb7c7b
> --- /dev/null
> +++ b/test/overlay/test-fdt-overlay-stacked.dts
> @@ -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 ;-)
> + *
> + * 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
>

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

* [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay
  2017-07-07  7:48   ` Moritz Fischer
@ 2017-07-07  8:32     ` Marek Vasut
  2017-07-07 10:33     ` Pantelis Antoniou
  1 sibling, 0 replies; 28+ messages in thread
From: Marek Vasut @ 2017-07-07  8:32 UTC (permalink / raw)
  To: u-boot

On 07/07/2017 09:48 AM, Moritz Fischer wrote:
> Hi Pantelis,
> 
> nit inline
> 
> On Fri, Jun 30, 2017 at 9:23 AM, Pantelis Antoniou
> <pantelis.antoniou@konsulko.com> wrote:
>> Verify that stacked overlays work.
>>
>> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> 
> Reviewed-by: Moritz Fischer <moritz.fischer@ettus.com>
>> ---
>>  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
>>
>> diff --git a/test/overlay/Makefile b/test/overlay/Makefile
>> index 907f085..416645c 100644
>> --- a/test/overlay/Makefile
>> +++ b/test/overlay/Makefile
>> @@ -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
>> diff --git a/test/overlay/cmd_ut_overlay.c b/test/overlay/cmd_ut_overlay.c
>> index cbef720..d8f5c8f 100644
>> --- a/test/overlay/cmd_ut_overlay.c
>> +++ b/test/overlay/cmd_ut_overlay.c
>> @@ -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);
>> diff --git a/test/overlay/test-fdt-overlay-stacked.dts b/test/overlay/test-fdt-overlay-stacked.dts
>> new file mode 100644
>> index 0000000..9fb7c7b
>> --- /dev/null
>> +++ b/test/overlay/test-fdt-overlay-stacked.dts
>> @@ -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 ;-)

-- 
Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay
  2017-07-07  7:48   ` Moritz Fischer
  2017-07-07  8:32     ` Marek Vasut
@ 2017-07-07 10:33     ` Pantelis Antoniou
  1 sibling, 0 replies; 28+ messages in thread
From: Pantelis Antoniou @ 2017-07-07 10:33 UTC (permalink / raw)
  To: u-boot

On Fri, 2017-07-07 at 00:48 -0700, Moritz Fischer wrote:
> Hi Pantelis,
> 
> nit inline
> 
> On Fri, Jun 30, 2017 at 9:23 AM, Pantelis Antoniou
> <pantelis.antoniou@konsulko.com> wrote:
> > Verify that stacked overlays work.
> >
> > Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> 
> Reviewed-by: Moritz Fischer <moritz.fischer@ettus.com>
> > ---
> >  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
> >
> > diff --git a/test/overlay/Makefile b/test/overlay/Makefile
> > index 907f085..416645c 100644
> > --- a/test/overlay/Makefile
> > +++ b/test/overlay/Makefile
> > @@ -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
> > diff --git a/test/overlay/cmd_ut_overlay.c b/test/overlay/cmd_ut_overlay.c
> > index cbef720..d8f5c8f 100644
> > --- a/test/overlay/cmd_ut_overlay.c
> > +++ b/test/overlay/cmd_ut_overlay.c
> > @@ -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);
> > diff --git a/test/overlay/test-fdt-overlay-stacked.dts b/test/overlay/test-fdt-overlay-stacked.dts
> > new file mode 100644
> > index 0000000..9fb7c7b
> > --- /dev/null
> > +++ b/test/overlay/test-fdt-overlay-stacked.dts
> > @@ -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.

> > + *
> > + * 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
> >

Regards

-- Pantelis

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

* [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
  2017-07-07  7:02     ` Pantelis Antoniou
@ 2017-07-14 13:51       ` Simon Glass
  0 siblings, 0 replies; 28+ messages in thread
From: Simon Glass @ 2017-07-14 13:51 UTC (permalink / raw)
  To: u-boot

Hi Pantelis,

On 7 July 2017 at 01:02, Pantelis Antoniou
<pantelis.antoniou@konsulko.com> wrote:
> Hi Simon,
>
> On Thu, 2017-07-06 at 21:58 -0600, Simon Glass wrote:
>> On 30 June 2017 at 10:23, Pantelis Antoniou
>> <pantelis.antoniou@konsulko.com> wrote:
>> > 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";
>> >             };
>> >         };
>> >
>> > Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
>> > ---
>> >  lib/libfdt/fdt_overlay.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-
>> >  1 file changed, 147 insertions(+), 1 deletion(-)
>>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>
>> 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.

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

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

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

* [U-Boot] [PATCH 0/5] uboot overlays and FIT image
  2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
                   ` (4 preceding siblings ...)
  2017-06-30 16:23 ` [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load Pantelis Antoniou
@ 2017-07-28 18:48 ` Simon Glass
  2017-07-28 19:20   ` Tom Rini
  5 siblings, 1 reply; 28+ messages in thread
From: Simon Glass @ 2017-07-28 18:48 UTC (permalink / raw)
  To: u-boot

Hi Pantelis,

On 30 June 2017 at 10:22, Pantelis Antoniou
<pantelis.antoniou@konsulko.com> wrote:
> 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

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

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

* [U-Boot] [PATCH 0/5] uboot overlays and FIT image
  2017-07-28 18:48 ` [U-Boot] [PATCH 0/5] uboot overlays and FIT image Simon Glass
@ 2017-07-28 19:20   ` Tom Rini
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Rini @ 2017-07-28 19:20 UTC (permalink / raw)
  To: u-boot

On Fri, Jul 28, 2017 at 12:48:22PM -0600, Simon Glass wrote:
> Hi Pantelis,
> 
> On 30 June 2017 at 10:22, Pantelis Antoniou
> <pantelis.antoniou@konsulko.com> wrote:
> > 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
> 
> 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.

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

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

end of thread, other threads:[~2017-07-28 19:20 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
2017-06-30 16:22 ` [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX Pantelis Antoniou
2017-07-01 14:01   ` Marek Vasut
2017-07-07  3:58     ` Simon Glass
2017-07-07  7:03       ` Pantelis Antoniou
2017-06-30 16:22 ` [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment Pantelis Antoniou
2017-07-01 14:02   ` Marek Vasut
2017-07-04 16:53     ` Pantelis Antoniou
2017-07-07  3:58   ` Simon Glass
2017-06-30 16:23 ` [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references Pantelis Antoniou
2017-07-01 14:07   ` Marek Vasut
2017-07-04 17:03     ` Pantelis Antoniou
2017-07-05  6:25     ` Lothar Waßmann
2017-07-07  3:58   ` Simon Glass
2017-07-07  7:02     ` Pantelis Antoniou
2017-07-14 13:51       ` Simon Glass
2017-06-30 16:23 ` [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay Pantelis Antoniou
2017-07-07  3:58   ` Simon Glass
2017-07-07  7:48   ` Moritz Fischer
2017-07-07  8:32     ` Marek Vasut
2017-07-07 10:33     ` Pantelis Antoniou
2017-06-30 16:23 ` [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load Pantelis Antoniou
2017-07-01 14:11   ` Marek Vasut
2017-07-04 17:05     ` Pantelis Antoniou
2017-07-04 22:19       ` stefan.bruens at rwth-aachen.de
2017-07-05  6:32         ` Lothar Waßmann
2017-07-28 18:48 ` [U-Boot] [PATCH 0/5] uboot overlays and FIT image Simon Glass
2017-07-28 19:20   ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.