Skip to contentSkip to conversation

remove libfdt

PATCH Superseded Sascha Hauer 2 participants 33 messages Feb 26, 2013 – Feb 27, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remove libfdt

In the beginning we only had libfdt to handle devicetrees. With devicetree probing support we gained two parallel universes for handling devicetrees. This series cleans this up by switching to the internal devicetree completely and removing libfdt.

The dtb format is now only used while flattening/unflattening the tree. All tree manipulation is done on the internal tree format only. This introduces some time overhead (~2ms on a i.MX51) needed for (un)flattening the tree, but actually manipulating the tree is a factor of about 50 faster compared to libfdt. This means the overhead can become more than compensated once we start manipulating the tree in more places.

The overall code and binary size becomes a bit smaller with this due to less duplicated code.

Sascha

The following changes since commit 8c82b1b2021591a8c3537958c7fa60816c584d8a:

OMAP4 USB BOOT: remove double line endings (2013-02-25 09:18:03 +0100)

are available in the git repository at:

git://git.pengutronix.de/git/barebox.git pu/oftree

for you to fetch changes up to 417227b61e2331fa4285aaac42ee22f5db84cbc1:

of_property command: Fix crash with empty property value (2013-02-26 20:42:46 +0100)

----------------------------------------------------------------
Sascha Hauer (29):
of: unflatten: allocate root node explicitly
of: export of_find_child
of: removed unused variables
of: Let of_find_node_by_path iterate over tree
of: remove allnodes list
ARM bootm: Use of_get_fixed_tree
of: Add of_set_property and of_create_node
of_node command: use of_create_node
of: Add root node argument to of_find_node_by_path
of: Add missing prototype for of_device_is_compatible
of: let of_unflatten_dtb return the unflattened tree
of: make unflatten independent of libfdt
of: make flatten independent of libfdt
of/fdt: use optimized endianess conversion
oftree command: Use of_print_nodes
of: move OFTREE Kconfig option to drivers/of/
of: make OFDEVICE a user selectable option
oftree command: retire CMD_OFTREE_PROBE Kconfig option
of: move oftree Kconfig to the top of the drivers menu
of: Pass barebox internal format devicetree to of_get_fixed_tree
bootm: Use of_print_nodes instead of fdt_print
of: move flat devicetree functions to separate file
of: Add of property write functions for u32
of: make value of property in of_new_property optional
of: Add missing prototype for size/address counting functions
of: fixup unflattened devicetree
of: remove unused libfdt
of_* commands: print usage when insufficient arguments are given of_property command: Fix crash with empty property value

 arch/arm/boards/at91sam9m10ihd/hw_version.c |    1 -
 arch/arm/boards/at91sam9x5ek/hw_version.c   |   32 +-
 arch/arm/boards/sama5d3xek/hw_version.c     |    1 -
 arch/arm/lib/bootm.c                        |   13 +-
 arch/ppc/mach-mpc5xxx/cpu.c                 |   26 +-
 commands/Kconfig                            |   10 -
 commands/bootm.c                            |   16 +-
 commands/of_node.c                          |   33 +-
 commands/of_property.c                      |   24 +-
 commands/oftree.c                           |   42 +-
 common/memory.c                             |   49 +-
 common/oftree.c                             |  223 +----
 drivers/Kconfig                             |    2 +-
 drivers/Makefile                            |    2 +-
 drivers/of/Kconfig                          |    6 +-
 drivers/of/Makefile                         |    2 +-
 drivers/of/base.c                           |  319 ++++---
 drivers/of/dtb.c                            |  400 +++++++++
 include/fdt.h                               |   13 +
 include/libfdt.h                            | 1235 ---------------------------
 include/libfdt_env.h                        |   22 -
 include/of.h                                |   68 +-
 lib/Kconfig                                 |    7 -
 lib/Makefile                                |    1 -
 lib/fdt/Makefile                            |    2 -
 lib/fdt/TODO                                |    3 -
 lib/fdt/fdt.c                               |  222 -----
 lib/fdt/fdt_ro.c                            |  574 -------------
 lib/fdt/fdt_rw.c                            |  465 ----------
 lib/fdt/fdt_strerror.c                      |   96 ---
 lib/fdt/fdt_sw.c                            |  256 ------
 lib/fdt/fdt_wip.c                           |  118 ---
 lib/fdt/libfdt_internal.h                   |   95 ---
 33 files changed, 770 insertions(+), 3608 deletions(-)
 create mode 100644 drivers/of/dtb.c
 delete mode 100644 include/libfdt.h
 delete mode 100644 include/libfdt_env.h
 delete mode 100644 lib/fdt/Makefile
 delete mode 100644 lib/fdt/TODO
 delete mode 100644 lib/fdt/fdt.c
 delete mode 100644 lib/fdt/fdt_ro.c
 delete mode 100644 lib/fdt/fdt_rw.c
 delete mode 100644 lib/fdt/fdt_strerror.c
 delete mode 100644 lib/fdt/fdt_sw.c
 delete mode 100644 lib/fdt/fdt_wip.c
 delete mode 100644 lib/fdt/libfdt_internal.h

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/29 of: unflatten: allocate root node explicitly

By doing so of_new_node does not depend on the global root_node anymore.

---
 drivers/of/base.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/of/base.c +12 -5
index eaaeaf4..e853add 100644
@@ -890,7 +890,7 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 	const struct fdt_property *fdt_prop;
 	const char *pathp;
 	int depth = 10000;
-	struct device_node *node = NULL, *n;
+	struct device_node *node = NULL, *n, *root = NULL;
 	struct property *p;
 
 	nodeoffset = fdt_path_offset(fdt, "/");
@@ -903,6 +903,10 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 		return -EINVAL;
 	}
 
+	root = of_new_node(NULL, NULL);
+	if (!root)
+		return -ENOMEM;
+
 	while (1) {
 		tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);
 		switch (tag) {
@@ -912,11 +916,14 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 			if (pathp == NULL)
 				pathp = "/* NULL pointer error */";
 
-			n = of_find_child(node, pathp);
-			if (n) {
-				node = n;
+			if (!node) {
+				node = root;
 			} else {
-				node = of_new_node(node, pathp);
+				if ((n = of_find_child(node, pathp))) {
+					node = n;
+				} else {
+					node = of_new_node(node, pathp);
+				}
 			}
 			break;
 		case FDT_END_NODE:
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/29 of: export of_find_child

In reply to Sascha Hauer

of_find_child is a useful function. Export it and rename it to of_find_child_by_name.

---
 drivers/of/base.c |   16 +++-------------
 include/of.h      |    2 ++
 2 files changed, 5 insertions(+), 13 deletions(-)
drivers/of/base.c +3 -13
index e853add..f016f90 100644
@@ -854,23 +854,13 @@ int of_probe(void)
 	return 0;
 }
 
-static struct device_node *of_find_child(struct device_node *node, const char *name)
+struct device_node *of_find_child_by_name(struct device_node *node, const char *name)
 {
 	struct device_node *_n;
 
-	if (!root_node)
-		return NULL;
-
-	if (!node && !*name)
-		return root_node;
-
-	if (!node)
-		node = root_node;
-
-	list_for_each_entry(_n, &node->children, parent_list) {
+	device_node_for_nach_child(node, _n)
 		if (!strcmp(_n->name, name))
 			return _n;
-	}
 
 	return NULL;
 }
@@ -919,7 +909,7 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 			if (!node) {
 				node = root;
 			} else {
-				if ((n = of_find_child(node, pathp))) {
+				if ((n = of_find_child_by_name(node, pathp))) {
 					node = n;
 				} else {
 					node = of_new_node(node, pathp);
include/of.h +2 -0
index d3a310f..59bdc6e 100644
@@ -58,6 +58,8 @@ struct property *of_find_property(const struct device_node *node, const char *na
 
 struct device_node *of_find_node_by_path(const char *path);
 
+struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
+
 struct fdt_header *fdt_get_tree(void);
 
 #define device_node_for_nach_child(node, child) \
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/29 of: removed unused variables

In reply to Sascha Hauer
---
 drivers/of/base.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/of/base.c +1 -4
index f016f90..704ba8e 100644
@@ -876,10 +876,8 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 	int  nextoffset;	/* next node offset from libfdt */
 	uint32_t tag;		/* tag */
 	int  len;		/* length of the property */
-	int  level = 0;		/* keep track of nesting level */
 	const struct fdt_property *fdt_prop;
 	const char *pathp;
-	int depth = 10000;
 	struct device_node *node = NULL, *n, *root = NULL;
 	struct property *p;
 
@@ -942,8 +940,7 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 			of_alias_scan();
 			return 0;
 		default:
-			if (level <= depth)
-				printf("Unknown tag 0x%08X\n", tag);
+			printf("Unknown tag 0x%08X\n", tag);
 			return -EINVAL;
 		}
 		nodeoffset = nextoffset;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 4/29 of: Let of_find_node_by_path iterate over tree

In reply to Sascha Hauer

of_find_node_by_path iterates over the allnodes list. Depending on where the node we look for is, this can be significantly slower than using the tree structure to look for a node, so iterate over the tree instead.

---
 drivers/of/base.c |   37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/of/base.c +30 -7
index 704ba8e..1c33be1 100644
@@ -490,17 +490,40 @@ EXPORT_SYMBOL(of_machine_is_compatible);
  */
 struct device_node *of_find_node_by_path(const char *path)
 {
-	struct device_node *np;
+	char *slash, *p, *freep;
+	struct device_node *dn = root_node;
+
+	if (!root_node)
+		return NULL;
+
+	if (*path != '/')
+		return NULL;
+
+	path++;
 
-	if (!strcmp(path, "/"))
-		return root_node;
+	freep = p = xstrdup(path);
 
-	list_for_each_entry(np, &allnodes, list) {
-		if (np->full_name && (strcmp(np->full_name, path) == 0))
-			return np;
+	while (1) {
+		if (!*p)
+			goto out;
+
+		slash = strchr(p, '/');
+		if (slash)
+			*slash = 0;
+
+		dn = of_find_child_by_name(dn, p);
+		if (!dn)
+			goto out;
+
+		if (!slash)
+			goto out;
+
+		p = slash + 1;
 	}
+out:
+	free(freep);
 
-	return NULL;
+	return dn;
 }
 EXPORT_SYMBOL(of_find_node_by_path);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 5/29 of: remove allnodes list

In reply to Sascha Hauer

The allnodes list makes it hard to handle multiple devicetrees. Having a list to iterate over all nodes of a tree is still good to have though. This patch uses the list_head of the root node as the head of the list. This way the root node is no longer part of the list, but when iterating over a tree the root node is not interesting anyway.

---
 drivers/of/base.c |   12 +++++-------
 include/of.h      |    8 ++++++++
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/of/base.c +5 -7
index 1c33be1..d6c346d 100644
@@ -50,8 +50,6 @@ static LIST_HEAD(aliases_lookup);
 
 static LIST_HEAD(phandle_list);
 
-static LIST_HEAD(allnodes);
-
 struct device_node *root_node;
 
 struct device_node *of_aliases;
@@ -628,13 +626,13 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
 	if (parent) {
 		node->name = xstrdup(name);
 		node->full_name = asprintf("%s/%s", node->parent->full_name, name);
+		list_add(&node->list, &parent->list);
 	} else {
 		node->name = xstrdup("");
 		node->full_name = xstrdup("");
+		INIT_LIST_HEAD(&node->list);
 	}
 
-	list_add_tail(&node->list, &allnodes);
-
 	return node;
 }
 
@@ -812,8 +810,6 @@ void of_free(struct device_node *node)
 	if (!node)
 		return;
 
-	list_del(&node->list);
-
 	list_for_each_entry_safe(p, pt, &node->properties, list) {
 		list_del(&p->list);
 		free(p->name);
@@ -825,8 +821,10 @@ void of_free(struct device_node *node)
 		of_free(n);
 	}
 
-	if (node->parent)
+	if (node->parent) {
 		list_del(&node->parent_list);
+		list_del(&node->list);
+	}
 
 	if (node->device)
 		node->device->device_node = NULL;
include/of.h +8 -0
index 59bdc6e..933e855 100644
@@ -65,6 +65,14 @@ struct fdt_header *fdt_get_tree(void);
 #define device_node_for_nach_child(node, child) \
 	list_for_each_entry(child, &node->children, parent_list)
 
+/*
+ * Iterate over all nodes of a tree. As a devicetree does not
+ * have a dedicated list head, the start node (usually the root
+ * node) will not be iterated over.
+ */
+#define of_tree_for_each_node(node, root) \
+	list_for_each_entry(node, &root->list, list)
+
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 6/29 ARM bootm: Use of_get_fixed_tree

In reply to Sascha Hauer
---
 arch/arm/lib/bootm.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
arch/arm/lib/bootm.c +1 -7
index dc29004..cf192cf 100644
@@ -181,13 +181,7 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		fdt_open_into(oftree, oftree, end + 0x8000);
-
-		ret = of_fix_tree(oftree);
-		if (ret)
-			return ret;
-
-		data->oftree = oftree;
+		data->oftree = of_get_fixed_tree(oftree);
 	}
 
 	pr_info("zImage: concatenated oftree detected\n");
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 7/29 of: Add of_set_property and of_create_node

In reply to Sascha Hauer

Add functions to create a new device node and to create/set a new property based on the nodepath.

---
 drivers/of/base.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h      |    3 ++
 2 files changed, 82 insertions(+)
drivers/of/base.c +79 -0
index d6c346d..ecc49c4 100644
@@ -662,6 +662,41 @@ void of_delete_property(struct property *pp)
 	free(pp);
 }
 
+/**
+ * of_set_property - create a property for a given node
+ * @node - the node
+ * @name - the name of the property
+ * @val - the value for the property
+ * @len - the length of the properties value
+ * @create - if true, the property is created if not existing already
+ */
+int of_set_property(struct device_node *np, const char *name, const void *val, int len,
+		int create)
+{
+	struct property *pp;
+
+	if (!np)
+		return -ENOENT;
+
+	pp = of_find_property(np, name);
+	if (pp) {
+		void *data;
+
+		free(pp->value);
+		data = xzalloc(len);
+		memcpy(data, val, len);
+		pp->value = data;
+		pp->length = len;
+	} else {
+		if (!create)
+			return -ENOENT;
+
+		pp = of_new_property(np, name, val, len);
+	}
+
+	return 0;
+}
+
 static struct device_d *add_of_device(struct device_node *node)
 {
 	struct device_d *dev;
@@ -886,6 +921,50 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
 	return NULL;
 }
 
+/**
+ * of_create_node - create a new node including its parents
+ * @path - the nodepath to create
+ */
+struct device_node *of_create_node(struct device_node *root, const char *path)
+{
+	char *slash, *p, *freep;
+	struct device_node *tmp, *dn = root;
+
+	if (*path != '/')
+		return NULL;
+
+	path++;
+
+	p = freep = xstrdup(path);
+
+	while (1) {
+		if (!*p)
+			goto out;
+
+		slash = strchr(p, '/');
+		if (slash)
+			*slash = 0;
+
+		tmp = of_find_child_by_name(dn, p);
+		if (tmp)
+			dn = tmp;
+		else
+			dn = of_new_node(dn, p);
+
+		if (!dn)
+			goto out;
+
+		if (!slash)
+			goto out;
+
+		p = slash + 1;
+	}
+out:
+	free(freep);
+
+	return dn;
+}
+
 /*
  * Parse a flat device tree binary blob and store it in the barebox
  * internal tree format,
include/of.h +3 -0
index 933e855..12c5703 100644
@@ -124,6 +124,9 @@ void of_delete_property(struct property *pp);
 
 int of_property_read_string(struct device_node *np, const char *propname,
 				const char **out_string);
+int of_set_property(struct device_node *node, const char *p, const void *val, int len,
+		int create);
+struct device_node *of_create_node(struct device_node *root, const char *path);
 
 #ifdef CONFIG_OFDEVICE
 int of_parse_partitions(const char *cdevname,
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 8/29 of_node command: use of_create_node

In reply to Sascha Hauer
---
 commands/of_node.c |   27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
commands/of_node.c +10 -17
index a370e26..bf9799c 100644
@@ -39,6 +39,7 @@ static int do_of_node(int argc, char *argv[])
 	int create = 0;
 	char *path = NULL;
 	struct device_node *node = NULL;
+	struct device_node *root;
 
 	while ((opt = getopt(argc, argv, "cd")) > 0) {
 		switch (opt) {
@@ -57,27 +58,19 @@ static int do_of_node(int argc, char *argv[])
 		path = argv[optind];
 	}
 
-	if (create) {
-		char *name;
+	root = of_get_root_node();
+	if (!root) {
+		printf("root node not set\n");
+		return -ENOENT;
+	}
 
+	if (create) {
 		if (!path)
 			return COMMAND_ERROR_USAGE;
 
-		name = xstrdup(basename(path));
-		path = dirname(path);
-
-		node = of_find_node_by_path(path);
-		if (!node) {
-			printf("Cannot find nodepath %s\n", path);
-			free(name);
-			return -ENOENT;
-		}
-
-		debug("create node \"%s\" \"%s\"\n", path, name);
-
-		of_new_node(node, name);
-
-		free(name);
+		node = of_create_node(root, path);
+		if (!node)
+			return -EINVAL;
 
 		return 0;
 	}
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 9/29 of: Add root node argument to of_find_node_by_path

In reply to Sascha Hauer

This makes of_find_node_by_path usable with multiple trees.

---
 commands/of_node.c     |    2 +-
 commands/of_property.c |   10 ++++++++--
 commands/oftree.c      |   10 +++++++++-
 drivers/of/base.c      |   16 +++++++---------
 include/of.h           |    2 +-
 5 files changed, 26 insertions(+), 14 deletions(-)
commands/of_node.c +1 -1
index bf9799c..2f6ecae 100644
@@ -79,7 +79,7 @@ static int do_of_node(int argc, char *argv[])
 		if (!path)
 			return COMMAND_ERROR_USAGE;
 
-		node = of_find_node_by_path(path);
+		node = of_find_node_by_path(root, path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
commands/of_property.c +8 -2
index 42b6f11..585522c 100644
@@ -176,7 +176,7 @@ static int do_of_property(int argc, char *argv[])
 	int set = 0;
 	int ret;
 	char *path = NULL, *propname = NULL;
-	struct device_node *node = NULL;
+	struct device_node *root, *node = NULL;
 	struct property *pp = NULL;
 
 	while ((opt = getopt(argc, argv, "ds")) > 0) {
@@ -192,9 +192,15 @@ static int do_of_property(int argc, char *argv[])
 		}
 	}
 
+	root = of_get_root_node();
+	if (!root) {
+		printf("root node not set\n");
+		return -ENOENT;
+	}
+
 	if (optind < argc) {
 		path = argv[optind];
-		node = of_find_node_by_path(path);
+		node = of_find_node_by_path(root, path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
commands/oftree.c +9 -1
index ddbff3e..0ee787e 100644
@@ -146,7 +146,15 @@ static int do_oftree(int argc, char *argv[])
 		if (fdt) {
 			ret = fdt_print(fdt, node);
 		} else {
-			struct device_node *n = of_find_node_by_path(node);
+			struct device_node *root, *n;
+
+			root = of_get_root_node();
+			if (!root) {
+				ret = -ENOENT;
+				goto out;
+			}
+
+			n = of_find_node_by_path(root, node);
 
 			if (!n) {
 				ret = -ENOENT;
drivers/of/base.c +7 -9
index ecc49c4..0eafa39 100644
@@ -144,7 +144,7 @@ void of_alias_scan(void)
 
 	INIT_LIST_HEAD(&aliases_lookup);
 
-	of_aliases = of_find_node_by_path("/aliases");
+	of_aliases = of_find_node_by_path(root_node, "/aliases");
 	if (!of_aliases)
 		return;
 
@@ -161,7 +161,7 @@ void of_alias_scan(void)
 		    !strcmp(pp->name, "linux,phandle"))
 			continue;
 
-		np = of_find_node_by_path(pp->value);
+		np = of_find_node_by_path(root_node, pp->value);
 		if (!np)
 			continue;
 
@@ -481,18 +481,16 @@ EXPORT_SYMBOL(of_machine_is_compatible);
 
 /**
  *	of_find_node_by_path - Find a node matching a full OF path
+ *	@root:	The root node of this tree
  *	@path:	The full path to match
  *
  *	Returns a node pointer with refcount incremented, use
  *	of_node_put() on it when done.
  */
-struct device_node *of_find_node_by_path(const char *path)
+struct device_node *of_find_node_by_path(struct device_node *root, const char *path)
 {
 	char *slash, *p, *freep;
-	struct device_node *dn = root_node;
-
-	if (!root_node)
-		return NULL;
+	struct device_node *dn = root;
 
 	if (*path != '/')
 		return NULL;
@@ -902,7 +900,7 @@ int of_probe(void)
 	if(!root_node)
 		return -ENODEV;
 
-	of_chosen = of_find_node_by_path("/chosen");
+	of_chosen = of_find_node_by_path(root_node, "/chosen");
 	of_property_read_string(root_node, "model", &of_model);
 
 	__of_probe(root_node);
@@ -1122,7 +1120,7 @@ int of_device_is_stdout_path(struct device_d *dev)
 	name = of_get_property(of_chosen, "linux,stdout-path", NULL);
 	if (name == NULL)
 		return 0;
-	dn = of_find_node_by_path(name);
+	dn = of_find_node_by_path(root_node, name);
 
 	if (!dn)
 		return 0;
include/of.h +1 -1
index 12c5703..82475c3 100644
@@ -56,7 +56,7 @@ int of_match(struct device_d *dev, struct driver_d *drv);
 
 struct property *of_find_property(const struct device_node *node, const char *name);
 
-struct device_node *of_find_node_by_path(const char *path);
+struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
 
 struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 10/29 of: Add missing prototype for of_device_is_compatible

In reply to Sascha Hauer
---
 include/of.h |    3 +++
 1 file changed, 3 insertions(+)
include/of.h +3 -0
index 82475c3..c324c74 100644
@@ -107,6 +107,9 @@ int of_get_named_gpio(struct device_node *np,
 struct device_node *of_find_node_by_phandle(phandle phandle);
 void of_print_property(const void *data, int len);
 
+int of_device_is_compatible(const struct device_node *device,
+		const char *compat);
+
 int of_machine_is_compatible(const char *compat);
 
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

PATCH 11/29 of: let of_unflatten_dtb return the unflattened tree

In reply to Sascha Hauer

In order to be able to handle multiple devicetrees, do not assume the tree to be unflattened is the barebox internal one. Instead, just return a pointer to it and assign the barebox internal root_node external to the unflatten function.

---
 commands/oftree.c |   14 ++++++++++++-
 drivers/of/base.c |   57 +++++++++++++++++++++++++++++++++--------------------
 include/of.h      |    3 ++-
 3 files changed, 51 insertions(+), 23 deletions(-)
commands/oftree.c +13 -1
index 0ee787e..83ffe12 100644
@@ -32,6 +32,7 @@
 #include <malloc.h>
 #include <libfdt.h>
 #include <linux/ctype.h>
+#include <linux/err.h>
 #include <asm/byteorder.h>
 #include <errno.h>
 #include <getopt.h>
@@ -52,6 +53,7 @@ static int do_oftree(int argc, char *argv[])
 	int save = 0;
 	int free_of = 0;
 	int ret;
+	struct device_node *n, *root;
 
 	while ((opt = getopt(argc, argv, "dpfn:ls")) > 0) {
 		switch (opt) {
@@ -135,7 +137,17 @@ static int do_oftree(int argc, char *argv[])
 			goto out;
 		}
 
-		ret = of_unflatten_dtb(fdt);
+		n = of_get_root_node();
+
+		root = of_unflatten_dtb(n, fdt);
+		if (IS_ERR(root))
+			ret = PTR_ERR(root);
+		else
+			ret = 0;
+
+		if (!n)
+			ret = of_set_root_node(root);
+
 		if (ret) {
 			printf("parse oftree: %s\n", strerror(-ret));
 			goto out;
drivers/of/base.c +36 -21

119 lines not on this page · raw message

include/of.h +2 -1
index c324c74..89ce64c 100644
@@ -119,7 +119,7 @@ void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
 void of_free(struct device_node *node);
-int of_unflatten_dtb(struct fdt_header *fdt);
+struct device_node *of_unflatten_dtb(struct device_node *root, struct fdt_header *fdt);
 struct device_node *of_new_node(struct device_node *parent, const char *name);
 struct property *of_new_property(struct device_node *node, const char *name,
 		const void *data, int len);
@@ -136,6 +136,7 @@ int of_parse_partitions(const char *cdevname,
 			    struct device_node *node);
 
 struct device_node *of_get_root_node(void);
+int of_set_root_node(struct device_node *);
 int of_alias_get_id(struct device_node *np, const char *stem);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

PATCH 12/29 of: make unflatten independent of libfdt

In reply to Sascha Hauer
---
 drivers/of/base.c |  160 +++++++++++++++++++++++++++++++++++++++++------------
 include/of.h      |    2 +-
 2 files changed, 127 insertions(+), 35 deletions(-)
drivers/of/base.c +126 -34
index 9f1f3cf..d6ca949 100644
@@ -969,92 +969,184 @@ out:
 	return dn;
 }
 
+static inline uint32_t dt_struct_advance(struct fdt_header *f, uint32_t dt, int size)
+{
+	dt += size;
+	dt = ALIGN(dt, 4);
+
+	if (dt > f->off_dt_struct + f->size_dt_struct)
+		return 0;
+
+	return dt;
+}
+
+static inline char *dt_string(struct fdt_header *f, char *strstart, uint32_t ofs)
+{
+	if (ofs > f->size_dt_strings)
+		return NULL;
+	else
+		return strstart + ofs;
+}
+
 /**
- * of_unflatten_dtb - unflatten a fdt blob
+ * of_unflatten_dtb - unflatten a dtb binary blob
  * @root - node in which the fdt blob should be merged into or NULL
- * @fdt - the fdt blob to unflatten
+ * @infdt - the fdt blob to unflatten
  *
  * Parse a flat device tree binary blob and return a pointer to the
  * unflattened tree.
  */
-struct device_node *of_unflatten_dtb(struct device_node *root, struct fdt_header *fdt)
+struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 {
 	const void *nodep;	/* property node pointer */
-	int  nodeoffset;	/* node offset from libfdt */
-	int  nextoffset;	/* next node offset from libfdt */
 	uint32_t tag;		/* tag */
 	int  len;		/* length of the property */
 	const struct fdt_property *fdt_prop;
-	const char *pathp;
+	const char *pathp, *name;
 	struct device_node *node = NULL, *n;
 	struct property *p;
-	int ret;
+	uint32_t dt_struct;
+	struct fdt_node_header *fnh;
+	void *dt_strings;
+	struct fdt_header f;
+	int ret, merge = 0;
+	unsigned int maxlen;
+	struct fdt_header *fdt = infdt;
+
+	if (fdt->magic != cpu_to_fdt32(FDT_MAGIC)) {
+		pr_err("bad magic: 0x%08x\n", fdt32_to_cpu(fdt->magic));
+		return ERR_PTR(-EINVAL);
+	}
 
-	nodeoffset = fdt_path_offset(fdt, "/");
-	if (nodeoffset < 0) {
-		/*
-		 * Not found or something else bad happened.
-		 */
-		printf ("libfdt fdt_path_offset() returned %s\n",
-			fdt_strerror(nodeoffset));
+	if (fdt->version != cpu_to_fdt32(17)) {
+		pr_err("bad dt version: 0x%08x\n", fdt32_to_cpu(fdt->version));
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (!root) {
+	f.totalsize = fdt32_to_cpu(fdt->totalsize);
+	f.off_dt_struct = fdt32_to_cpu(fdt->off_dt_struct);
+	f.size_dt_struct = fdt32_to_cpu(fdt->size_dt_struct);
+	f.off_dt_strings = fdt32_to_cpu(fdt->off_dt_strings);
+	f.size_dt_strings = fdt32_to_cpu(fdt->size_dt_strings);
+
+	if (f.off_dt_struct + f.size_dt_struct > f.totalsize) {
+		pr_err("unflatten: dt size exceeds total size\n");
+		return ERR_PTR(-ESPIPE);
+	}
+
+	if (f.off_dt_strings + f.size_dt_strings > f.totalsize) {
+		pr_err("unflatten: string size exceeds total size\n");
+		return ERR_PTR(-ESPIPE);
+	}
+
+	dt_struct = f.off_dt_struct;
+	dt_strings = (void *)fdt + f.off_dt_strings;
+
+	if (root) {
+		pr_debug("unflatten: merging into existing tree\n");
+		merge = 1;
+	} else {
 		root = of_new_node(NULL, NULL);
 		if (!root)
 			return ERR_PTR(-ENOMEM);
 	}
 
 	while (1) {
-		tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);
+		tag = be32_to_cpu(*(uint32_t *)(infdt + dt_struct));
+
 		switch (tag) {
 		case FDT_BEGIN_NODE:
-			pathp = fdt_get_name(fdt, nodeoffset, NULL);
+			fnh = infdt + dt_struct;
+			pathp = name = fnh->name;
+			maxlen = (unsigned long)fdt + f.off_dt_struct +
+				f.size_dt_struct - (unsigned long)name;
+
+			len = strnlen(name, maxlen + 1);
+			if (len > maxlen) {
+				ret = -ESPIPE;
+				goto err;
+			}
 
-			if (pathp == NULL)
-				pathp = "/* NULL pointer error */";
+			dt_struct = dt_struct_advance(&f, dt_struct,
+					sizeof(struct fdt_node_header) + len + 1);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
 
 			if (!node) {
 				node = root;
 			} else {
-				if ((n = of_find_child_by_name(node, pathp))) {
+				if (merge && (n = of_find_child_by_name(node, pathp)))
 					node = n;
-				} else {
+				else
 					node = of_new_node(node, pathp);
-				}
 			}
+
 			break;
+
 		case FDT_END_NODE:
+			if (!node) {
+				pr_err("unflatten: too many end nodes\n");
+				ret = -EINVAL;
+				goto err;
+			}
+
 			node = node->parent;
+
+			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
 			break;
+
 		case FDT_PROP:
-			fdt_prop = fdt_offset_ptr(fdt, nodeoffset,
-					sizeof(*fdt_prop));
-			pathp    = fdt_string(fdt,
-					fdt32_to_cpu(fdt_prop->nameoff));
-			len      = fdt32_to_cpu(fdt_prop->len);
-			nodep    = fdt_prop->data;
-
-			p = of_find_property(node, pathp);
-			if (p) {
+			fdt_prop = infdt + dt_struct;
+			len = fdt32_to_cpu(fdt_prop->len);
+			nodep = fdt_prop->data;
+
+			name = dt_string(&f, dt_strings, fdt32_to_cpu(fdt_prop->nameoff));
+			if (!name) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
+			dt_struct = dt_struct_advance(&f, dt_struct,
+					sizeof(struct fdt_property) + len);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
+			if (merge && (p = of_find_property(node, name))) {
 				free(p->value);
 				p->value = xzalloc(len);
 				memcpy(p->value, nodep, len);
 			} else {
-				of_new_property(node, pathp, nodep, len);
+				of_new_property(node, name, nodep, len);
 			}
+
 			break;
+
 		case FDT_NOP:
+			dt_struct = dt_struct_advance(&f, dt_struct, FDT_TAGSIZE);
+			if (!dt_struct) {
+				ret = -ESPIPE;
+				goto err;
+			}
+
 			break;
+
 		case FDT_END:
 			return root;
+
 		default:
-			printf("Unknown tag 0x%08X\n", tag);
+			pr_err("unflatten: Unknown tag 0x%08X\n", tag);
 			ret = -EINVAL;
 			goto err;
 		}
-		nodeoffset = nextoffset;
 	}
 err:
 	of_free(root);
include/of.h +1 -1
index 89ce64c..f2fd84b 100644
@@ -119,7 +119,7 @@ void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
 void of_free(struct device_node *node);
-struct device_node *of_unflatten_dtb(struct device_node *root, struct fdt_header *fdt);
+struct device_node *of_unflatten_dtb(struct device_node *root, void *fdt);
 struct device_node *of_new_node(struct device_node *parent, const char *name);
 struct property *of_new_property(struct device_node *node, const char *name,
 		const void *data, int len);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

PATCH 13/29 of: make flatten independent of libfdt

In reply to Sascha Hauer
---
 common/oftree.c   |    8 ++-
 drivers/of/base.c |  180 ++++++++++++++++++++++++++++++++++++++++++++---------
 include/of.h      |    4 +-
 3 files changed, 160 insertions(+), 32 deletions(-)
common/oftree.c +7 -1
index 0df5209..841d2c4 100644
@@ -329,7 +329,13 @@ struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
 	int size, align;
 
 	if (!fdt) {
-		fdt = internalfdt = of_flatten_dtb();
+		struct device_node *root_node;
+
+		root_node = of_get_root_node();
+		if (!root_node)
+			return NULL;
+
+		fdt = internalfdt = of_flatten_dtb(root_node);
 		if (!fdt)
 			return NULL;
 	}
drivers/of/base.c +151 -29

216 lines not on this page · raw message

include/of.h +2 -2
index f2fd84b..e7d74d8 100644
@@ -140,7 +140,7 @@ int of_set_root_node(struct device_node *);
 int of_alias_get_id(struct device_node *np, const char *stem);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
-void *of_flatten_dtb(void);
+void *of_flatten_dtb(struct device_node *node);
 #else
 static inline int of_parse_partitions(const char *cdevname,
 					  struct device_node *node)
@@ -168,7 +168,7 @@ static inline const char *of_get_model(void)
 	return NULL;
 }
 
-static inline void *of_flatten_dtb(void)
+static inline void *of_flatten_dtb(struct device_node *node)
 {
 	return NULL;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#14 lore raw

Re: [PATCH 13/29] of: make flatten independent of libfdt

Hi Sascha,

Quoted 73 lines · Sascha Hauer
---
 common/oftree.c   |    8 ++-
 drivers/of/base.c |  180 ++++++++++++++++++++++++++++++++++++++++++++---------
 include/of.h      |    4 +-
 3 files changed, 160 insertions(+), 32 deletions(-)
common/oftree.c +7 -1
index 0df5209..841d2c4 100644
@@ -329,7 +329,13 @@ struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
 	int size, align;
 
 	if (!fdt) {
-		fdt = internalfdt = of_flatten_dtb();
+		struct device_node *root_node;
+
+		root_node = of_get_root_node();
+		if (!root_node)
+			return NULL;
+
+		fdt = internalfdt = of_flatten_dtb(root_node);
 		if (!fdt)
 			return NULL;
 	}
drivers/of/base.c +38 -1
index d6ca949..cd463e9 100644
@@ -1154,20 +1154,108 @@ err:
 	return ERR_PTR(ret);
 }
 
-static int __of_flatten_dtb(void *fdt, struct device_node *node)
+struct fdt {
+	void *dt;
+	uint32_t dt_nextofs;
+	uint32_t dt_size;
+	char *strings;
+	uint32_t str_nextofs;
+	uint32_t str_size;
+};
+
+static inline uint32_t dt_next_ofs(uint32_t curofs, uint32_t len)
+{
+	return ALIGN(curofs + len, 4);
+}
+
+static int lstrcpy(char *dest, const char *src)
+{
+	int len = 0;
+	int maxlen = 1023;
+
+	while (*src) {
+		*dest++ = *src++;
+		len++;
+		if (!maxlen)
+			return -ENOSPC;
+		maxlen--;
+	}
+
+	return len;
+}
+
+static int fdt_ensure_space(struct fdt *fdt, int dtsize)
+{
+	/*
+	 * We assume strings and names have a maximum length of 1024
+	 * whereas properties can be longer. We allocate new memory
+	 * if we have less than 1024 bytes (+ the property size left.
+	 */
+	if (fdt->str_size - fdt->str_nextofs < 1024) {

drivers/of/base.c err: · line 1204

Quoted 10 lines
drivers/of/base.c +10 -0
+		fdt->strings = realloc(fdt->strings, fdt->str_size * 2);
+		if (!fdt->strings)
+			return -ENOMEM;
+		fdt->str_size *= 2;
+	}
+
+	if (fdt->dt_size - fdt->dt_nextofs < 1024 + dtsize) {
+		fdt->dt = realloc(fdt->dt, fdt->dt_size * 2);
+		if (!fdt->dt)
+			return -ENOMEM;

Leaking memory here. We need to clean fdt->strings.

Regards
Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#15 lore raw

Re: [PATCH 13/29] of: make flatten independent of libfdt

Quoted 80 lines · Alexander Aring

Hi Sascha,

Quoted 77 lines · Sascha Hauer
---
 common/oftree.c   |    8 ++-
 drivers/of/base.c |  180 ++++++++++++++++++++++++++++++++++++++++++++---------
 include/of.h      |    4 +-
 3 files changed, 160 insertions(+), 32 deletions(-)
common/oftree.c +7 -1
index 0df5209..841d2c4 100644
@@ -329,7 +329,13 @@ struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
 	int size, align;
 
 	if (!fdt) {
-		fdt = internalfdt = of_flatten_dtb();
+		struct device_node *root_node;
+
+		root_node = of_get_root_node();
+		if (!root_node)
+			return NULL;
+
+		fdt = internalfdt = of_flatten_dtb(root_node);
 		if (!fdt)
 			return NULL;
 	}
drivers/of/base.c +42 -1
index d6ca949..cd463e9 100644
@@ -1154,20 +1154,108 @@ err:
 	return ERR_PTR(ret);
 }
 
-static int __of_flatten_dtb(void *fdt, struct device_node *node)
+struct fdt {
+	void *dt;
+	uint32_t dt_nextofs;
+	uint32_t dt_size;
+	char *strings;
+	uint32_t str_nextofs;
+	uint32_t str_size;
+};
+
+static inline uint32_t dt_next_ofs(uint32_t curofs, uint32_t len)
+{
+	return ALIGN(curofs + len, 4);
+}
+
+static int lstrcpy(char *dest, const char *src)
+{
+	int len = 0;
+	int maxlen = 1023;
+
+	while (*src) {
+		*dest++ = *src++;
+		len++;
+		if (!maxlen)
+			return -ENOSPC;
+		maxlen--;
+	}
+
+	return len;
+}
+
+static int fdt_ensure_space(struct fdt *fdt, int dtsize)
+{
+	/*
+	 * We assume strings and names have a maximum length of 1024
+	 * whereas properties can be longer. We allocate new memory
+	 * if we have less than 1024 bytes (+ the property size left.
+	 */
+	if (fdt->str_size - fdt->str_nextofs < 1024) {
+		fdt->strings = realloc(fdt->strings, fdt->str_size * 2);
+		if (!fdt->strings)
+			return -ENOMEM;
+		fdt->str_size *= 2;
Quoted 8 lines

drivers/of/base.c err: · line 1204

Quoted 6 lines
drivers/of/base.c +6 -0
+	}
+
+	if (fdt->dt_size - fdt->dt_nextofs < 1024 + dtsize) {
+		fdt->dt = realloc(fdt->dt, fdt->dt_size * 2);
+		if (!fdt->dt)
+			return -ENOMEM;

Leaking memory here. We need to clean fdt->strings.

Nope. When fdt_ensure_space fails we will free both fdt->strings and fdt->dt in the out_free: path in of_flatten_dtb().

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw

Re: [PATCH 13/29] of: make flatten independent of libfdt

Hi Sascha,

Quoted 90 lines · Sascha Hauer
Quoted 80 lines · Alexander Aring

Hi Sascha,

Quoted 77 lines · Sascha Hauer
---
 common/oftree.c   |    8 ++-
 drivers/of/base.c |  180 ++++++++++++++++++++++++++++++++++++++++++++---------
 include/of.h      |    4 +-
 3 files changed, 160 insertions(+), 32 deletions(-)
common/oftree.c +7 -1
index 0df5209..841d2c4 100644
@@ -329,7 +329,13 @@ struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
 	int size, align;
 
 	if (!fdt) {
-		fdt = internalfdt = of_flatten_dtb();
+		struct device_node *root_node;
+
+		root_node = of_get_root_node();
+		if (!root_node)
+			return NULL;
+
+		fdt = internalfdt = of_flatten_dtb(root_node);
 		if (!fdt)
 			return NULL;
 	}
drivers/of/base.c +42 -1
index d6ca949..cd463e9 100644
@@ -1154,20 +1154,108 @@ err:
 	return ERR_PTR(ret);
 }
 
-static int __of_flatten_dtb(void *fdt, struct device_node *node)
+struct fdt {
+	void *dt;
+	uint32_t dt_nextofs;
+	uint32_t dt_size;
+	char *strings;
+	uint32_t str_nextofs;
+	uint32_t str_size;
+};
+
+static inline uint32_t dt_next_ofs(uint32_t curofs, uint32_t len)
+{
+	return ALIGN(curofs + len, 4);
+}
+
+static int lstrcpy(char *dest, const char *src)
+{
+	int len = 0;
+	int maxlen = 1023;
+
+	while (*src) {
+		*dest++ = *src++;
+		len++;
+		if (!maxlen)
+			return -ENOSPC;
+		maxlen--;
+	}
+
+	return len;
+}
+
+static int fdt_ensure_space(struct fdt *fdt, int dtsize)
+{
+	/*
+	 * We assume strings and names have a maximum length of 1024
+	 * whereas properties can be longer. We allocate new memory
+	 * if we have less than 1024 bytes (+ the property size left.
+	 */
+	if (fdt->str_size - fdt->str_nextofs < 1024) {
+		fdt->strings = realloc(fdt->strings, fdt->str_size * 2);
+		if (!fdt->strings)
+			return -ENOMEM;
+		fdt->str_size *= 2;
Quoted 8 lines

drivers/of/base.c err: · line 1204

Quoted 6 lines
drivers/of/base.c +6 -0
+	}
+
+	if (fdt->dt_size - fdt->dt_nextofs < 1024 + dtsize) {
+		fdt->dt = realloc(fdt->dt, fdt->dt_size * 2);
+		if (!fdt->dt)
+			return -ENOMEM;

Leaking memory here. We need to clean fdt->strings.

Quoted 3 lines

Nope. When fdt_ensure_space fails we will free both fdt->strings and fdt->dt in the out_free: path in of_flatten_dtb().

oh, yes you are right. Sorry about that.

Regards
Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#17 lore raw

PATCH 14/29 of/fdt: use optimized endianess conversion

In reply to Sascha Hauer
---
 include/libfdt_env.h |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
include/libfdt_env.h +4 -5
index e83aa96..6486187 100644
@@ -3,13 +3,12 @@
 
 #include <linux/types.h>
 #include <string.h>
+#include <asm/byteorder.h>
 
 #define _B(n)	((unsigned long long)((uint8_t *)&x)[n])
-static inline uint32_t fdt32_to_cpu(uint32_t x)
-{
-	return (_B(0) << 24) | (_B(1) << 16) | (_B(2) << 8) | _B(3);
-}
-#define cpu_to_fdt32(x) fdt32_to_cpu(x)
+
+#define fdt32_to_cpu(x)	be32_to_cpu(x)
+#define cpu_to_fdt32(x) cpu_to_be32(x)
 
 static inline uint64_t fdt64_to_cpu(uint64_t x)
 {
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#18 lore raw

PATCH 15/29 oftree command: Use of_print_nodes

In reply to Sascha Hauer
---
 commands/oftree.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
commands/oftree.c +10 -3
index 83ffe12..612d01a 100644
@@ -156,7 +156,14 @@ static int do_oftree(int argc, char *argv[])
 
 	if (dump) {
 		if (fdt) {
-			ret = fdt_print(fdt, node);
+			root = of_unflatten_dtb(NULL, fdt);
+			if (IS_ERR(root)) {
+				printf("parse oftree: %s\n", strerror(-PTR_ERR(root)));
+				ret = 1;
+				goto out;
+			}
+			of_print_nodes(root, 0);
+			of_free(root);
 		} else {
 			struct device_node *root, *n;
 
@@ -174,10 +181,10 @@ static int do_oftree(int argc, char *argv[])
 			}
 
 			of_print_nodes(n, 0);
-
-			ret = 0;
 		}
 
+		ret = 0;
+
 		goto out;
 	}
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#19 lore raw

PATCH 16/29 of: move OFTREE Kconfig option to drivers/of/

In reply to Sascha Hauer
---
 drivers/of/Kconfig |    4 ++++
 lib/Kconfig        |    4 ----
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/of/Kconfig +4 -0
index 95f10d0..5e53d25 100644
@@ -1,2 +1,6 @@
+config OFTREE
+	select FDT
+	bool
+
 config OFDEVICE
 	bool
lib/Kconfig +0 -4
index 4578353..d58109b 100644
@@ -25,10 +25,6 @@ source lib/lzo/Kconfig
 config FDT
 	bool
 
-config OFTREE
-	select FDT
-	bool
-
 config BCH
 	bool
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#20 lore raw

PATCH 17/29 of: make OFDEVICE a user selectable option

In reply to Sascha Hauer

OFDEVICE decides whether or not we compile in support for probing devices from the devicetree. Let the user decide this explicitly. This makes the oftree, of_node and of_property commands independent of devicetree device support since being able to manipulate devicetrees has nothing to do with probing devices from the devicetree.

---
 commands/Kconfig   |    3 ---
 drivers/Makefile   |    2 +-
 drivers/of/Kconfig |    3 ++-
 include/of.h       |   12 ++++--------
 4 files changed, 7 insertions(+), 13 deletions(-)
commands/Kconfig +0 -3
index c1454c7..c8f06d8 100644
@@ -481,7 +481,6 @@ config CMD_GO
 config CMD_OFTREE
 	tristate
 	select OFTREE
-	select OFDEVICE
 	prompt "oftree"
 	help
 	  The oftree command has support for dumping devicetrees and, if
@@ -497,7 +496,6 @@ config CMD_OFTREE_PROBE
 config CMD_OF_PROPERTY
 	tristate
 	select OFTREE
-	select OFDEVICE
 	prompt "of_property"
 	help
 	  The of_property command allows setting and deleting of properties in
@@ -506,7 +504,6 @@ config CMD_OF_PROPERTY
 config CMD_OF_NODE
 	tristate
 	select OFTREE
-	select OFDEVICE
 	prompt "of_node"
 	help
 	  The of_property command allows adding and removing devicetree nodes.
drivers/Makefile +1 -1
index 1fddee0..0aaae1a 100644
@@ -21,5 +21,5 @@ obj-y	+= misc/
 obj-y	+= dma/
 obj-y  += watchdog/
 obj-y	+= gpio/
-obj-$(CONFIG_OFDEVICE) += of/
+obj-$(CONFIG_OFTREE) += of/
 obj-$(CONFIG_W1) += w1/
drivers/of/Kconfig +2 -1
index 5e53d25..c30b1c1 100644
@@ -3,4 +3,5 @@ config OFTREE
 	bool
 
 config OFDEVICE
-	bool
+	select OFTREE
+	bool "Enable probing of devices from the devicetree"
include/of.h +4 -8
index e7d74d8..2ddbe8d 100644
@@ -131,12 +131,13 @@ int of_set_property(struct device_node *node, const char *p, const void *val, in
 		int create);
 struct device_node *of_create_node(struct device_node *root, const char *path);
 
-#ifdef CONFIG_OFDEVICE
+struct device_node *of_get_root_node(void);
+int of_set_root_node(struct device_node *);
+
+#ifdef CONFIG_OFTREE
 int of_parse_partitions(const char *cdevname,
 			    struct device_node *node);
 
-struct device_node *of_get_root_node(void);
-int of_set_root_node(struct device_node *);
 int of_alias_get_id(struct device_node *np, const char *stem);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
@@ -148,11 +149,6 @@ static inline int of_parse_partitions(const char *cdevname,
 	return -EINVAL;
 }
 
-static inline struct device_node *of_get_root_node(void)
-{
-	return NULL;
-}
-
 static inline int of_alias_get_id(struct device_node *np, const char *stem)
 {
 	return -ENOENT;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#21 lore raw

PATCH 18/29 oftree command: retire CMD_OFTREE_PROBE Kconfig option

In reply to Sascha Hauer

Whether or not the user wishes devicetree probe support can now be decided indepentently of the oftree command, so retire the CMD_OFTREE_PROBE option and use OFDEVICE in the code instead.

---
 commands/Kconfig  |    7 -------
 commands/oftree.c |    2 +-
 2 files changed, 1 insertion(+), 8 deletions(-)
commands/Kconfig +0 -7
index c8f06d8..0062758 100644
@@ -486,13 +486,6 @@ config CMD_OFTREE
 	  The oftree command has support for dumping devicetrees and, if
 	  enabled, to probe devices from the devicetree
 
-config CMD_OFTREE_PROBE
-	bool
-	depends on CMD_OFTREE
-	prompt "oftree probe support"
-	help
-	  This enables the -p option to probe devices from the devicetree
-
 config CMD_OF_PROPERTY
 	tristate
 	select OFTREE
commands/oftree.c +1 -1
index 612d01a..e4f52b8 100644
@@ -64,7 +64,7 @@ static int do_oftree(int argc, char *argv[])
 			dump = 1;
 			break;
 		case 'p':
-			if (IS_ENABLED(CONFIG_CMD_OFTREE_PROBE)) {
+			if (IS_ENABLED(CONFIG_OFDEVICE)) {
 				probe = 1;
 			} else {
 				printf("oftree device probe support disabled\n");
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#22 lore raw

PATCH 19/29 of: move oftree Kconfig to the top of the drivers menu

In reply to Sascha Hauer

Using OFDEVICE is a basic decision, so move it to the top of the driver menu.

---
 drivers/Kconfig |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/Kconfig +1 -1
index 988ec9e..70321ea 100644
@@ -1,5 +1,6 @@
 menu "Drivers"
 
+source "drivers/of/Kconfig"
 source "drivers/serial/Kconfig"
 source "drivers/net/Kconfig"
 source "drivers/spi/Kconfig"
@@ -21,7 +22,6 @@ source "drivers/watchdog/Kconfig"
 source "drivers/pwm/Kconfig"
 source "drivers/dma/Kconfig"
 source "drivers/gpio/Kconfig"
-source "drivers/of/Kconfig"
 source "drivers/w1/Kconfig"
 
 endmenu
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#23 lore raw

PATCH 20/29 of: Pass barebox internal format devicetree to of_get_fixed_tree

In reply to Sascha Hauer

With this every devicetree is first converted to the barebox internal format before it's converted back to dtb again.

---
 arch/arm/lib/bootm.c |   10 +++++++++-
 commands/bootm.c     |    9 ++++++++-
 common/oftree.c      |   19 +++++++++----------
 include/of.h         |    3 ++-
 4 files changed, 28 insertions(+), 13 deletions(-)
arch/arm/lib/bootm.c +9 -1
index cf192cf..234f3e0 100644
@@ -181,7 +181,15 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		data->oftree = of_get_fixed_tree(oftree);
+		struct device_node *node;
+
+		node = of_unflatten_dtb(NULL, oftree);
+		if (!node) {
+			pr_err("unable to unflatten devicetree\n");
+			return -EINVAL;
+		}
+
+		data->oftree = of_get_fixed_tree(node);
 	}
 
 	pr_info("zImage: concatenated oftree detected\n");
commands/bootm.c +8 -1
index 4d3f022..38233e7 100644
@@ -140,6 +140,7 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 	enum filetype ft;
 	struct fdt_header *fdt, *fixfdt;
 	size_t size;
+	struct device_node *node;
 
 	printf("Loading devicetree from '%s'\n", oftree);
 
@@ -187,7 +188,13 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 				file_type_to_string(ft));
 	}
 
-	fixfdt = of_get_fixed_tree(fdt);
+	node = of_unflatten_dtb(NULL, fdt);
+	if (!node) {
+		pr_err("unable to unflatten devicetree\n");
+		return -EINVAL;
+	}
+
+	fixfdt = of_get_fixed_tree(node);
 	if (!fixfdt)
 		return -EINVAL;
 
common/oftree.c +9 -10
index 841d2c4..b616b59 100644
@@ -322,24 +322,23 @@ int of_fix_tree(struct fdt_header *fdt)
  * It increases the size of the tree and applies the registered
  * fixups.
  */
-struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt)
+struct fdt_header *of_get_fixed_tree(struct device_node *node)
 {
 	int ret;
 	void *fixfdt, *internalfdt = NULL;
 	int size, align;
+	struct fdt_header *fdt;
 
-	if (!fdt) {
-		struct device_node *root_node;
-
-		root_node = of_get_root_node();
-		if (!root_node)
-			return NULL;
-
-		fdt = internalfdt = of_flatten_dtb(root_node);
-		if (!fdt)
+	if (!node) {
+		node = of_get_root_node();
+		if (!node)
 			return NULL;
 	}
 
+	fdt = internalfdt = of_flatten_dtb(node);
+	if (!fdt)
+		return NULL;
+
 	size = fdt_totalsize(fdt);
 
 	/*
include/of.h +2 -1
index 2ddbe8d..1db546c 100644
@@ -7,7 +7,6 @@
 
 int fdt_print(struct fdt_header *working_fdt, const char *pathp);
 
-struct fdt_header *of_get_fixed_tree(struct fdt_header *fdt);
 int of_fix_tree(struct fdt_header *fdt);
 int of_register_fixup(int (*fixup)(struct fdt_header *));
 
@@ -62,6 +61,8 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
 
 struct fdt_header *fdt_get_tree(void);
 
+struct fdt_header *of_get_fixed_tree(struct device_node *node);
+
 #define device_node_for_nach_child(node, child) \
 	list_for_each_entry(child, &node->children, parent_list)
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#24 lore raw

PATCH 21/29 bootm: Use of_print_nodes instead of fdt_print

In reply to Sascha Hauer

Now that we use the unflattened tree in bootm we can use of_print_nodes instead of printing the flattened tree.

---
 commands/bootm.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
commands/bootm.c +3 -3
index 38233e7..65a75e2 100644
@@ -194,15 +194,15 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 		return -EINVAL;
 	}
 
+	if (bootm_verbose(data) > 1)
+		of_print_nodes(node, 0);
+
 	fixfdt = of_get_fixed_tree(node);
 	if (!fixfdt)
 		return -EINVAL;
 
 	free(fdt);
 
-	if (bootm_verbose(data) > 1)
-		fdt_print(fixfdt, "/");
-
 	data->oftree = fixfdt;
 
 	return 0;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#25 lore raw

PATCH 22/29 of: move flat devicetree functions to separate file

In reply to Sascha Hauer
---
 drivers/of/Makefile |    2 +-
 drivers/of/base.c   |  372 -----------------------------------------------
 drivers/of/dtb.c    |  401 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 402 insertions(+), 373 deletions(-)
 create mode 100644 drivers/of/dtb.c
drivers/of/Makefile +1 -1
index 5a5960d..fc71962 100644
@@ -1,3 +1,3 @@
-obj-y += base.o
+obj-y += base.o dtb.o
 obj-$(CONFIG_GPIOLIB) += gpio.o
 obj-y += partition.o
drivers/of/base.c +0 -372

378 lines not on this page · raw message

drivers/of/dtb.c new file +401 -0

401 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#26 lore raw

PATCH 23/29 of: Add of property write functions for u32

In reply to Sascha Hauer
---
 drivers/of/base.c |   25 +++++++++++++++++++++++++
 include/of.h      |   11 +++++++++++
 2 files changed, 36 insertions(+)
drivers/of/base.c +25 -0
index 8138a91..6b12979 100644
@@ -349,6 +349,31 @@ int of_property_read_u32_array(const struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
+int of_property_write_u32_array(struct device_node *np,
+				const char *propname, const u32 *values,
+				size_t sz)
+{
+	struct property *prop = of_find_property(np, propname);
+	__be32 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->value = malloc(sizeof(__be32) * sz);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+
+	while (sz--)
+		*val++ = cpu_to_be32(*values++);
+	return 0;
+}
+
 /**
  * of_parse_phandles_with_args - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
include/of.h +11 -0
index 1db546c..b2f9ca7 100644
@@ -94,6 +94,17 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+int of_property_write_u32_array(struct device_node *np,
+				const char *propname, const u32 *values,
+				size_t sz);
+
+static inline int of_property_write_u32(struct device_node *np,
+					const char *propname,
+					u32 value)
+{
+	return of_property_write_u32_array(np, propname, &value, 1);
+}
+
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#27 lore raw

PATCH 24/29 of: make value of property in of_new_property optional

In reply to Sascha Hauer
---
 drivers/of/base.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/of/base.c +4 -2
index 6b12979..c47801a 100644
@@ -676,8 +676,10 @@ struct property *of_new_property(struct device_node *node, const char *name,
 
 	prop->name = strdup(name);
 	prop->length = len;
-	prop->value = xzalloc(len);
-	memcpy(prop->value, data, len);
+	if (len) {
+		prop->value = xzalloc(len);
+		memcpy(prop->value, data, len);
+	}
 
 	list_add_tail(&prop->list, &node->properties);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#28 lore raw

PATCH 25/29 of: Add missing prototype for size/address counting functions

In reply to Sascha Hauer
---
 include/of.h |    3 +++
 1 file changed, 3 insertions(+)
include/of.h +3 -0
index b2f9ca7..21e5687 100644
@@ -53,6 +53,9 @@ struct driver_d;
 
 int of_match(struct device_d *dev, struct driver_d *drv);
 
+int of_n_addr_cells(struct device_node *np);
+int of_n_size_cells(struct device_node *np);
+
 struct property *of_find_property(const struct device_node *node, const char *name);
 
 struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#29 lore raw

PATCH 26/29 of: fixup unflattened devicetree

In reply to Sascha Hauer
---
 arch/arm/boards/at91sam9x5ek/hw_version.c |   31 +++++++------
 arch/ppc/mach-mpc5xxx/cpu.c               |   26 +++++++----
 common/memory.c                           |   48 ++++++--------------
 common/oftree.c                           |   70 +++++++++--------------------
 include/of.h                              |    6 +--
 5 files changed, 72 insertions(+), 109 deletions(-)
arch/arm/boards/at91sam9x5ek/hw_version.c +15 -16
index 47c640a..2695faa 100644
@@ -232,26 +232,25 @@ static void at91sam9x5ek_devices_detect_one(const char *name)
 
 #define NODE_NAME_LEN  128
 
-static int cm_cogent_fixup(struct fdt_header *fdt)
+static int cm_cogent_fixup(struct device_node *root)
 {
-	int off, ret;
-	char node_name[NODE_NAME_LEN];
+	int ret;
+	struct device_node *node;
 
-	off = fdt_node_offset_by_compatible(fdt, -1, "atmel,hsmci");
+	of_tree_for_each_node(node, root) {
+		struct device_node *slotnode;
 
-	while (off != -FDT_ERR_NOTFOUND) {
-		off = fdt_subnode_offset(fdt, off, "slot");
-		fdt_get_path(fdt, off, node_name, NODE_NAME_LEN);
-		ret = fdt_setprop(fdt, off, "broken-cd", NULL, 0);
-		if (ret < 0) {
-			pr_err("error %d while adding broken-cd property to node %s\n",
-				ret, node_name);
-			return ret;
-		} else {
-			pr_debug("add broken-cd property to node %s\n", node_name);
-		}
+		if (!of_device_is_compatible(node, "atmel,hsmci"))
+			continue;
 
-		off = fdt_node_offset_by_compatible(fdt, off, "atmel,hsmci");
+		slotnode = of_find_child_by_name(node, "slot");
+		if (!slotnode)
+			continue;
+
+		ret = of_set_property(slotnode, "broken-cd", NULL, 0, 1);
+		if (ret)
+			pr_err("error %d while adding broken-cd property to node %s\n",
+				ret, slotnode->name);
 	}
 
 	return 0;
arch/ppc/mach-mpc5xxx/cpu.c +18 -8
index 5bbd49a..99f16eb 100644
@@ -77,17 +77,27 @@ void __noreturn reset_cpu (unsigned long addr)
 /* ------------------------------------------------------------------------- */
 
 #ifdef CONFIG_OFTREE
-static int of_mpc5200_fixup(struct fdt_header *fdt)
+static int of_mpc5200_fixup(struct device_node *root)
 {
-	char *cpu_path = "/cpus/PowerPC,5200@0";
+	struct device_node *node;
+
 	int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
 
-	do_fixup_by_path_u32(fdt, cpu_path, "timebase-frequency", get_timebase_clock(), 1);
-	do_fixup_by_path_u32(fdt, cpu_path, "bus-frequency", get_bus_clock(), 1);
-	do_fixup_by_path_u32(fdt, cpu_path, "clock-frequency", get_cpu_clock(), 1);
-	do_fixup_by_path_u32(fdt, "/soc5200@f0000000", "bus-frequency", get_ipb_clock(), 1);
-	do_fixup_by_path_u32(fdt, "/soc5200@f0000000", "system-frequency",
-				get_bus_clock() * div, 1);
+	node = of_find_node_by_path(root, "/cpus/PowerPC,5200@0");
+	if (!node)
+		return -EINVAL;
+
+	of_property_write_u32(node, "timebase-frequency", get_timebase_clock());
+	of_property_write_u32(node, "bus-frequency", get_bus_clock());
+	of_property_write_u32(node, "clock-frequency", get_cpu_clock());
+
+	node = of_find_node_by_path(root, "/soc5200@f0000000");
+	if (!node)
+		return -EINVAL;
+
+	of_property_write_u32(node, "bus-frequency", get_ipb_clock());
+	of_property_write_u32(node, "system-frequency", get_bus_clock() * div);
+
 	return 0;
 }
 
common/memory.c +14 -34

76 lines not on this page · raw message

common/oftree.c +22 -48

117 lines not on this page · raw message

include/of.h +3 -3
index 21e5687..66b9fde 100644
@@ -7,9 +7,6 @@
 
 int fdt_print(struct fdt_header *working_fdt, const char *pathp);
 
-int of_fix_tree(struct fdt_header *fdt);
-int of_register_fixup(int (*fixup)(struct fdt_header *));
-
 int fdt_find_and_setprop(struct fdt_header *fdt, const char *node, const char *prop,
 			 const void *val, int len, int create);
 void do_fixup_by_path(struct fdt_header *fdt, const char *path, const char *prop,
@@ -51,6 +48,9 @@ struct of_device_id {
 
 struct driver_d;
 
+int of_fix_tree(struct device_node *);
+int of_register_fixup(int (*fixup)(struct device_node *));
+
 int of_match(struct device_d *dev, struct driver_d *drv);
 
 int of_n_addr_cells(struct device_node *np);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#30 lore raw

PATCH 27/29 of: remove unused libfdt

In reply to Sascha Hauer

Now that we are completely independent of libfdt remove the unused code.

---
 arch/arm/boards/at91sam9m10ihd/hw_version.c |    1 -
 arch/arm/boards/at91sam9x5ek/hw_version.c   |    1 -
 arch/arm/boards/sama5d3xek/hw_version.c     |    1 -
 arch/arm/lib/bootm.c                        |    1 -
 commands/bootm.c                            |    1 -
 commands/of_node.c                          |    1 -
 commands/of_property.c                      |    1 -
 commands/oftree.c                           |    3 +-
 common/memory.c                             |    1 -
 common/oftree.c                             |  148 ----
 drivers/of/Kconfig                          |    1 -
 drivers/of/base.c                           |    1 -
 drivers/of/dtb.c                            |    1 -
 include/fdt.h                               |   13 +
 include/libfdt.h                            | 1235 ---------------------------
 include/libfdt_env.h                        |   21 -
 include/of.h                                |   10 -
 lib/Kconfig                                 |    3 -
 lib/Makefile                                |    1 -
 lib/fdt/Makefile                            |    2 -
 lib/fdt/TODO                                |    3 -
 lib/fdt/fdt.c                               |  222 -----
 lib/fdt/fdt_ro.c                            |  574 -------------
 lib/fdt/fdt_rw.c                            |  465 ----------
 lib/fdt/fdt_strerror.c                      |   96 ---
 lib/fdt/fdt_sw.c                            |  256 ------
 lib/fdt/fdt_wip.c                           |  118 ---
 lib/fdt/libfdt_internal.h                   |   95 ---
 28 files changed, 14 insertions(+), 3262 deletions(-)
 delete mode 100644 include/libfdt.h
 delete mode 100644 include/libfdt_env.h
 delete mode 100644 lib/fdt/Makefile
 delete mode 100644 lib/fdt/TODO
 delete mode 100644 lib/fdt/fdt.c
 delete mode 100644 lib/fdt/fdt_ro.c
 delete mode 100644 lib/fdt/fdt_rw.c
 delete mode 100644 lib/fdt/fdt_strerror.c
 delete mode 100644 lib/fdt/fdt_sw.c
 delete mode 100644 lib/fdt/fdt_wip.c
 delete mode 100644 lib/fdt/libfdt_internal.h
arch/arm/boards/at91sam9m10ihd/hw_version.c +0 -1
index cd522f7..be910df 100644
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
arch/arm/boards/at91sam9x5ek/hw_version.c +0 -1
index 2695faa..76d4e1b 100644
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
arch/arm/boards/sama5d3xek/hw_version.c +0 -1
index a9fcf7d..79fd63a 100644
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
arch/arm/lib/bootm.c +0 -1
index 234f3e0..92f9e11 100644
@@ -14,7 +14,6 @@
 #include <sizes.h>
 #include <libbb.h>
 #include <magicvar.h>
-#include <libfdt.h>
 #include <binfmt.h>
 
 #include <asm/byteorder.h>
commands/bootm.c +0 -1
index 65a75e2..4acc57f 100644
@@ -34,7 +34,6 @@
 #include <errno.h>
 #include <boot.h>
 #include <of.h>
-#include <libfdt.h>
 #include <rtc.h>
 #include <init.h>
 #include <of.h>
commands/of_node.c +0 -1
index 2f6ecae..27f070d 100644
@@ -24,7 +24,6 @@
 #include <command.h>
 #include <fs.h>
 #include <malloc.h>
-#include <libfdt.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
commands/of_property.c +0 -1
index 585522c..1b968d8 100644
@@ -24,7 +24,6 @@
 #include <command.h>
 #include <fs.h>
 #include <malloc.h>
-#include <libfdt.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
commands/oftree.c +1 -2
index e4f52b8..468235a 100644
@@ -30,7 +30,6 @@
 #include <command.h>
 #include <fs.h>
 #include <malloc.h>
-#include <libfdt.h>
 #include <linux/ctype.h>
 #include <linux/err.h>
 #include <asm/byteorder.h>
@@ -114,7 +113,7 @@ static int do_oftree(int argc, char *argv[])
 			goto out;
 		}
 
-		ret = write_file(file, fdt, fdt_totalsize(fdt));
+		ret = write_file(file, fdt, fdt32_to_cpu(fdt->totalsize));
 
 		goto out;
 	}
common/memory.c +0 -1
index 1d2e3a3..6e59a0a 100644
@@ -21,7 +21,6 @@
 #include <memory.h>
 #include <of.h>
 #include <init.h>
-#include <libfdt.h>
 #include <linux/ioport.h>
 #include <asm-generic/memory_layout.h>
 #include <asm/sections.h>
common/oftree.c +0 -148

160 lines not on this page · raw message

drivers/of/Kconfig +0 -1
index c30b1c1..031bec1 100644
@@ -1,5 +1,4 @@
 config OFTREE
-	select FDT
 	bool
 
 config OFDEVICE
drivers/of/base.c +0 -1
index c47801a..faff883 100644
@@ -20,7 +20,6 @@
 #include <common.h>
 #include <of.h>
 #include <errno.h>
-#include <libfdt.h>
 #include <malloc.h>
 #include <init.h>
 #include <memory.h>
drivers/of/dtb.c +0 -1
index 671ea63..ae4130e 100644
@@ -20,7 +20,6 @@
 #include <common.h>
 #include <of.h>
 #include <errno.h>
-#include <libfdt.h>
 #include <malloc.h>
 #include <init.h>
 #include <memory.h>
include/fdt.h +13 -0
index 48ccfd9..35278e3 100644
@@ -3,6 +3,19 @@
 
 #ifndef __ASSEMBLY__
 
+#define _B(n)	((unsigned long long)((uint8_t *)&x)[n])
+
+#define fdt32_to_cpu(x)	be32_to_cpu(x)
+#define cpu_to_fdt32(x) cpu_to_be32(x)
+
+static inline uint64_t fdt64_to_cpu(uint64_t x)
+{
+	return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32)
+		| (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7);
+}
+#define cpu_to_fdt64(x) fdt64_to_cpu(x)
+#undef _B
+
 struct fdt_header {
 	uint32_t magic;			 /* magic word FDT_MAGIC */
 	uint32_t totalsize;		 /* total size of DT block */
include/libfdt.h deleted +0 -1235

1,235 lines not on this page · raw message

include/libfdt_env.h deleted +0 -21
deleted file mode 100644
index 6486187..0000000
@@ -1,21 +0,0 @@
-#ifndef _LIBFDT_ENV_H
-#define _LIBFDT_ENV_H
-
-#include <linux/types.h>
-#include <string.h>
-#include <asm/byteorder.h>
-
-#define _B(n)	((unsigned long long)((uint8_t *)&x)[n])
-
-#define fdt32_to_cpu(x)	be32_to_cpu(x)
-#define cpu_to_fdt32(x) cpu_to_be32(x)
-
-static inline uint64_t fdt64_to_cpu(uint64_t x)
-{
-	return (_B(0) << 56) | (_B(1) << 48) | (_B(2) << 40) | (_B(3) << 32)
-		| (_B(4) << 24) | (_B(5) << 16) | (_B(6) << 8) | _B(7);
-}
-#define cpu_to_fdt64(x) fdt64_to_cpu(x)
-#undef _B
-
-#endif /* _LIBFDT_ENV_H */
include/of.h +0 -10
index 66b9fde..9d50694 100644
@@ -5,16 +5,6 @@
 #include <errno.h>
 #include <asm/byteorder.h>
 
-int fdt_print(struct fdt_header *working_fdt, const char *pathp);
-
-int fdt_find_and_setprop(struct fdt_header *fdt, const char *node, const char *prop,
-			 const void *val, int len, int create);
-void do_fixup_by_path(struct fdt_header *fdt, const char *path, const char *prop,
-		      const void *val, int len, int create);
-void do_fixup_by_path_u32(struct fdt_header *fdt, const char *path, const char *prop,
-			  u32 val, int create);
-int fdt_get_path_or_create(struct fdt_header *fdt, const char *path);
-
 #define OF_BAD_ADDR      ((u64)-1)
 
 typedef u32 phandle;
lib/Kconfig +0 -3
index d58109b..646fdb7 100644
@@ -22,9 +22,6 @@ config PROCESS_ESCAPE_SEQUENCE
 
 source lib/lzo/Kconfig
 
-config FDT
-	bool
-
 config BCH
 	bool
 
lib/Makefile +0 -1
index 3c94542..7c42537 100644
@@ -31,7 +31,6 @@ obj-y			+= lzo/
 obj-y			+= show_progress.o
 obj-$(CONFIG_LZO_DECOMPRESS)		+= decompress_unlzo.o
 obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE)	+= process_escape_sequence.o
-obj-$(CONFIG_FDT)	+= fdt/
 obj-$(CONFIG_UNCOMPRESS)	+= uncompress.o
 obj-$(CONFIG_BCH)	+= bch.o
 obj-$(CONFIG_BITREV)	+= bitrev.o
lib/fdt/Makefile deleted +0 -2
deleted file mode 100644
index 853bee9..0000000
@@ -1,2 +0,0 @@
-
-obj-y += fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o
lib/fdt/TODO deleted +0 -3
deleted file mode 100644
index 288437e..0000000
@@ -1,3 +0,0 @@
-- Tree traversal functions
-- Graft function
-- Complete libfdt.h documenting comments
lib/fdt/fdt.c deleted +0 -222

222 lines not on this page · raw message

lib/fdt/fdt_ro.c deleted +0 -574

574 lines not on this page · raw message

lib/fdt/fdt_rw.c deleted +0 -465

465 lines not on this page · raw message

lib/fdt/fdt_strerror.c deleted +0 -96

96 lines not on this page · raw message

lib/fdt/fdt_sw.c deleted +0 -256

81 lines not on this page · raw message

lib/fdt/fdt_wip.c deleted +0 -118

118 lines not on this page · raw message

lib/fdt/libfdt_internal.h deleted +0 -95

95 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Part of the diff is not shown here. View the raw message.

#31 lore raw

PATCH 28/29 of_* commands: print usage when insufficient arguments are given

In reply to Sascha Hauer
---
 commands/of_node.c     |    3 +++
 commands/of_property.c |    3 +++
 2 files changed, 6 insertions(+)
commands/of_node.c +3 -0
index 27f070d..0249d97 100644
@@ -53,6 +53,9 @@ static int do_of_node(int argc, char *argv[])
 		}
 	}
 
+	if (optind == argc)
+		return COMMAND_ERROR_USAGE;
+
 	if (optind < argc) {
 		path = argv[optind];
 	}
commands/of_property.c +3 -0
index 1b968d8..5d35bb4 100644
@@ -191,6 +191,9 @@ static int do_of_property(int argc, char *argv[])
 		}
 	}
 
+	if (optind == argc)
+		return COMMAND_ERROR_USAGE;
+
 	root = of_get_root_node();
 	if (!root) {
 		printf("root node not set\n");
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#32 lore raw

PATCH 29/29 of_property command: Fix crash with empty property value

In reply to Sascha Hauer

the of_property command crashes when an empty property value was given. This is because xrealloc is called with a length argument of 0. Fix this.

---
 commands/of_property.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
commands/of_property.c +8 -2
index 5d35bb4..6311b70 100644
@@ -254,9 +254,15 @@ static int do_of_property(int argc, char *argv[])
 
 		if (pp) {
 			free(pp->value);
+
 			/* limit property data to the actual size */
-			data = xrealloc(data, len);
-			pp->value = data;
+			if (len) {
+				pp->value = xrealloc(data, len);
+			} else {
+				pp->value = NULL;
+				free(data);
+			}
+
 			pp->length = len;
 		} else {
 			pp = of_new_property(node, propname, data, len);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox