[U-Boot-Users] [PATCH] Add additional fdt fixup helper functions

Kumar Gala galak at kernel.crashing.org
Wed Nov 21 21:17:26 CET 2007


Added the following fdt fixup helpers:
 * do_fixup_by_prop{_u32} - Find matching nodes by property name/value
 * do_fixup_by_compat{_u32} - Find matching nodes by compat

The _u32 variants work the same only the property they are setting
is know to be a 32-bit integer instead of a byte buffer.

Signed-off-by: Kumar Gala <galak at kernel.crashing.org>
---
 common/fdt_support.c  |   80 ++++++++++++++++++++++++++++++++++++++++++++-----
 include/fdt_support.h |   11 +++++++
 2 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 0e61f6d..b50f064 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -160,6 +160,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 			printf("WARNING: could not set linux,initrd-end %s.\n",
 				fdt_strerror(err));
 	}
+
 #ifdef OF_STDOUT_PATH
 	err = fdt_setprop(fdt, nodeoffset,
 		"linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1);
@@ -386,6 +387,61 @@ void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
 	do_fixup_by_path(fdt, path, prop, &val, sizeof(val), create);
 }

+void do_fixup_by_prop(void *fdt,
+		      const char *pname, const void *pval, int plen,
+		      const char *prop, const void *val, int len,
+		      int create)
+{
+	int off;
+#if defined(DEBUG)
+	int i;
+	debug("Updating property '%s/%s' = ", node, prop);
+	for (i = 0; i < len; i++)
+		debug(" %.2x", *(u8*)(val+i));
+	debug("\n");
+#endif
+	off = fdt_node_offset_by_prop_value(fdt, -1, pname, pval, plen);
+	while (off != -FDT_ERR_NOTFOUND) {
+		if (create || (fdt_get_property(fdt, off, prop, 0) != NULL))
+			fdt_setprop(fdt, off, prop, val, len);
+		off = fdt_node_offset_by_prop_value(fdt, off, pname, pval, plen);
+	}
+}
+
+void do_fixup_by_prop_u32(void *fdt,
+			  const char *pname, const void *pval, int plen,
+			  const char *prop, u32 val, int create)
+{
+	val = cpu_to_fdt32(val);
+	do_fixup_by_prop(fdt, pname, pval, plen, prop, &val, 4, create);
+}
+
+void do_fixup_by_compat(void *fdt, const char *compat,
+			const char *prop, const void *val, int len, int create)
+{
+	int off = -1;
+#if defined(DEBUG)
+	int i;
+	debug("Updating property '%s/%s' = ", node, prop);
+	for (i = 0; i < len; i++)
+		debug(" %.2x", *(u8*)(val+i));
+	debug("\n");
+#endif
+	off = fdt_node_offset_by_compatible(fdt, -1, compat);
+	while (off != -FDT_ERR_NOTFOUND) {
+		if (create || (fdt_get_property(fdt, off, prop, 0) != NULL))
+			fdt_setprop(fdt, off, prop, val, len);
+		off = fdt_node_offset_by_compatible(fdt, off, compat);
+	}
+}
+
+void do_fixup_by_compat_u32(void *fdt, const char *compat,
+			    const char *prop, u32 val, int create)
+{
+	val = cpu_to_fdt32(val);
+	do_fixup_by_compat(fdt, compat, prop, &val, 4, create);
+}
+
 void fdt_fixup_ethernet(void *fdt, bd_t *bd)
 {
 	int node;
@@ -396,29 +452,37 @@ void fdt_fixup_ethernet(void *fdt, bd_t *bd)
 #if defined(CONFIG_HAS_ETH0)
                 path = fdt_getprop(fdt, node, "ethernet0", NULL);
 		if (path) {
-			do_fixup_by_path(fdt, path, "mac-address", bd->bi_enetaddr, 6, 0);
-			do_fixup_by_path(fdt, path, "local-mac-address", bd->bi_enetaddr, 6, 1);
+			do_fixup_by_path(fdt, path, "mac-address",
+				bd->bi_enetaddr, 6, 0);
+			do_fixup_by_path(fdt, path, "local-mac-address",
+				bd->bi_enetaddr, 6, 1);
 		}
 #endif
 #if defined(CONFIG_HAS_ETH1)
                 path = fdt_getprop(fdt, node, "ethernet1", NULL);
 		if (path) {
-			do_fixup_by_path(fdt, path, "mac-address", bd->bi_enet1addr, 6, 0);
-			do_fixup_by_path(fdt, path, "local-mac-address", bd->bi_enet1addr, 6, 1);
+			do_fixup_by_path(fdt, path, "mac-address",
+				bd->bi_enet1addr, 6, 0);
+			do_fixup_by_path(fdt, path, "local-mac-address",
+				bd->bi_enet1addr, 6, 1);
 		}
 #endif
 #if defined(CONFIG_HAS_ETH2)
                 path = fdt_getprop(fdt, node, "ethernet2", NULL);
 		if (path) {
-			do_fixup_by_path(fdt, path, "mac-address", bd->bi_enet2addr, 6, 0);
-			do_fixup_by_path(fdt, path, "local-mac-address", bd->bi_enet2addr, 6, 1);
+			do_fixup_by_path(fdt, path, "mac-address",
+				bd->bi_enet2addr, 6, 0);
+			do_fixup_by_path(fdt, path, "local-mac-address",
+				bd->bi_enet2addr, 6, 1);
 		}
 #endif
 #if defined(CONFIG_HAS_ETH3)
                 path = fdt_getprop(fdt, node, "ethernet3", NULL);
 		if (path) {
-			do_fixup_by_path(fdt, path, "mac-address", bd->bi_enet3addr, 6, 0);
-			do_fixup_by_path(fdt, path, "local-mac-address", bd->bi_enet3addr, 6, 1);
+			do_fixup_by_path(fdt, path, "mac-address",
+				bd->bi_enet3addr, 6, 0);
+			do_fixup_by_path(fdt, path, "local-mac-address",
+				bd->bi_enet3addr, 6, 1);
 		}
 #endif
         }
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 150dd2b..8f781d4 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -33,6 +33,17 @@ void do_fixup_by_path(void *fdt, const char *path, const char *prop,
 		      const void *val, int len, int create);
 void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
 			  u32 val, int create);
+void do_fixup_by_prop(void *fdt,
+		      const char *pname, const void *pval, int plen,
+		      const char *prop, const void *val, int len,
+		      int create);
+void do_fixup_by_prop_u32(void *fdt,
+			  const char *pname, const void *pval, int plen,
+			  const char *prop, u32 val, int create);
+void do_fixup_by_compat(void *fdt, const char *compat,
+			const char *prop, const void *val, int len, int create);
+void do_fixup_by_compat_u32(void *fdt, const char *compat,
+			    const char *prop, u32 val, int create);
 void fdt_fixup_ethernet(void *fdt, bd_t *bd);

 #ifdef CONFIG_OF_HAS_UBOOT_ENV
-- 
1.5.3.4





More information about the U-Boot mailing list