mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] remove libfdt
@ 2013-03-04  9:53 Sascha Hauer
  2013-03-04  9:53 ` [PATCH 01/37] of: unflatten: allocate root node explicitly Sascha Hauer
                   ` (36 more replies)
  0 siblings, 37 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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.

Changes since v1:

- rebase on current master
- add of_write_number helper and use it
- add reserve map handling
- add initrd handling for ARM

Sascha

The following changes since commit 2ecdea32dde307acd5b3f1c49ac666d4c494dfe9:

  switch more boards to lwl-y (2013-03-04 09:23:45 +0100)

are available in the git repository at:

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

for you to fetch changes up to 279b70e19ce9698ab1f8f65cbe32ec9497ce247d:

  of: make locally used functions static (2013-03-04 09:28:12 +0100)

----------------------------------------------------------------
Sascha Hauer (37):
      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 missing prototype for of_device_is_compatible
      of: let of_unflatten_dtb return the unflattened tree
      of: Add root node argument to of_find_node_by_path
      of: Add of_write_number helper
      of: Add initrd helper
      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_* commands: print usage when insufficient arguments are given
      of_property command: Fix crash with empty property value
      ARM: bootm: rework concatenated oftree
      of: memory: Use of_write_number
      of: Add reservemap handling
      bootm: Pass unflattened devicetree to handlers
      ARM bootm: Switch initrd support to unflattened tree
      of: remove unused libfdt
      of: make locally used functions static

 arch/arm/boards/at91sam9m10ihd/hw_version.c |    1 -
 arch/arm/boards/at91sam9x5ek/hw_version.c   |   32 +-
 arch/arm/boards/highbank/init.c             |   49 +-
 arch/arm/boards/sama5d3xek/hw_version.c     |    1 -
 arch/arm/lib/armlinux.c                     |    2 -
 arch/arm/lib/bootm.c                        |   56 +-
 arch/ppc/Kconfig                            |    1 +
 arch/ppc/lib/ppclinux.c                     |    8 +
 arch/ppc/mach-mpc5xxx/cpu.c                 |   26 +-
 commands/Kconfig                            |   10 -
 commands/bootm.c                            |   22 +-
 commands/of_node.c                          |   33 +-
 commands/of_property.c                      |   24 +-
 commands/oftree.c                           |   42 +-
 common/memory.c                             |   70 +-
 common/oftree.c                             |  314 +------
 drivers/Kconfig                             |    2 +-
 drivers/Makefile                            |    2 +-
 drivers/of/Kconfig                          |    6 +-
 drivers/of/Makefile                         |    2 +-
 drivers/of/base.c                           |  364 ++++----
 drivers/of/dtb.c                            |  465 ++++++++++
 include/boot.h                              |    1 +
 include/fdt.h                               |   13 +
 include/libfdt.h                            | 1235 ---------------------------
 include/libfdt_env.h                        |   22 -
 include/of.h                                |  110 ++-
 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 ---
 38 files changed, 971 insertions(+), 3781 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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 01/37] of: unflatten: allocate root node explicitly
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 02/37] of: export of_find_child Sascha Hauer
                   ` (35 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index fd9b8e1..d134f1e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -946,7 +946,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, "/");
@@ -959,6 +959,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) {
@@ -968,11 +972,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:
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 02/37] of: export of_find_child
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
  2013-03-04  9:53 ` [PATCH 01/37] of: unflatten: allocate root node explicitly Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 03/37] of: removed unused variables Sascha Hauer
                   ` (34 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   16 +++-------------
 include/of.h      |    2 ++
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d134f1e..86dca6a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -910,23 +910,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;
 }
@@ -975,7 +965,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);
diff --git a/include/of.h b/include/of.h
index 95d9702..f3fc2ae 100644
--- a/include/of.h
+++ b/include/of.h
@@ -72,6 +72,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) \
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 03/37] of: removed unused variables
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
  2013-03-04  9:53 ` [PATCH 01/37] of: unflatten: allocate root node explicitly Sascha Hauer
  2013-03-04  9:53 ` [PATCH 02/37] of: export of_find_child Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 04/37] of: Let of_find_node_by_path iterate over tree Sascha Hauer
                   ` (33 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 86dca6a..01d4e4f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -932,10 +932,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;
 
@@ -998,8 +996,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;
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 04/37] of: Let of_find_node_by_path iterate over tree
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 03/37] of: removed unused variables Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 05/37] of: remove allnodes list Sascha Hauer
                   ` (32 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 01d4e4f..37d3128 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -491,17 +491,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);
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 05/37] of: remove allnodes list
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 04/37] of: Let of_find_node_by_path iterate over tree Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 06/37] ARM bootm: Use of_get_fixed_tree Sascha Hauer
                   ` (31 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   12 +++++-------
 include/of.h      |    8 ++++++++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 37d3128..ad278ad 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -51,8 +51,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;
@@ -629,13 +627,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;
 }
 
@@ -868,8 +866,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);
@@ -881,8 +877,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;
diff --git a/include/of.h b/include/of.h
index f3fc2ae..8166273 100644
--- a/include/of.h
+++ b/include/of.h
@@ -79,6 +79,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)
 {
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 06/37] ARM bootm: Use of_get_fixed_tree
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (4 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 05/37] of: remove allnodes list Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 07/37] of: Add of_set_property and of_create_node Sascha Hauer
                   ` (30 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootm.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index dc29004..cf192cf 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -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");
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 07/37] of: Add of_set_property and of_create_node
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (5 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 06/37] ARM bootm: Use of_get_fixed_tree Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 08/37] of_node command: use of_create_node Sascha Hauer
                   ` (29 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h      |    3 ++
 2 files changed, 82 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ad278ad..11d17c6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -663,6 +663,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_amba_device(struct device_node *node)
 {
 	struct amba_device *dev;
@@ -942,6 +977,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,
diff --git a/include/of.h b/include/of.h
index 8166273..3305f03 100644
--- a/include/of.h
+++ b/include/of.h
@@ -138,6 +138,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,
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 08/37] of_node command: use of_create_node
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (6 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 07/37] of: Add of_set_property and of_create_node Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 09/37] of: Add missing prototype for of_device_is_compatible Sascha Hauer
                   ` (28 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/of_node.c |   27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/commands/of_node.c b/commands/of_node.c
index a370e26..bf9799c 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -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;
 	}
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 09/37] of: Add missing prototype for of_device_is_compatible
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (7 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 08/37] of_node command: use of_create_node Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 10/37] of: let of_unflatten_dtb return the unflattened tree Sascha Hauer
                   ` (27 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/of.h |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/of.h b/include/of.h
index 3305f03..d780dcf 100644
--- a/include/of.h
+++ b/include/of.h
@@ -121,6 +121,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
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 10/37] of: let of_unflatten_dtb return the unflattened tree
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (8 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 09/37] of: Add missing prototype for of_device_is_compatible Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 11/37] of: Add root node argument to of_find_node_by_path Sascha Hauer
                   ` (26 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/highbank/init.c |   11 +++++---
 commands/oftree.c               |   14 +++++++++-
 drivers/of/base.c               |   57 ++++++++++++++++++++++++---------------
 include/of.h                    |    3 ++-
 4 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index e36674f..0f64fc8 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -17,6 +17,7 @@
 #include <sizes.h>
 #include <io.h>
 #include <libfdt.h>
+#include <of.h>
 
 #define FIRMWARE_DTB_BASE	0x1000
 
@@ -63,19 +64,21 @@ static int hb_fixup(struct fdt_header *fdt)
 
 static int highbank_mem_init(void)
 {
-	struct device_node *np;
+	struct device_node *root, *np;
 	int ret;
 
 	/* load by the firmware at 0x1000 */
 	fdt = IOMEM(FIRMWARE_DTB_BASE);
 
-	ret = of_unflatten_dtb(fdt);
-	if (ret) {
+	root = of_unflatten_dtb(NULL, fdt);
+	if (!root) {
 		pr_warn("no dtb found at 0x1000 use default configuration\n");
 		fdt = NULL;
 		goto not_found;
 	}
 
+	of_set_root_node(root);
+
 	np = of_find_node_by_path("/memory");
 	if (!np) {
 		pr_warn("no memory node use default configuration\n");
@@ -109,7 +112,7 @@ static int highbank_devices_init(void)
 		highbank_register_xgmac(0);
 		highbank_register_xgmac(1);
 	} else {
-		fdt = of_get_fixed_tree(fdt);
+		fdt = of_get_fixed_tree(NULL);
 		add_mem_device("dtb", (unsigned long)fdt, fdt_totalsize(fdt),
 		       IORESOURCE_MEM_WRITEABLE);
 		devfs_add_partition("ram0", FIRMWARE_DTB_BASE, SZ_64K, DEVFS_PARTITION_FIXED, "firmware-dtb");
diff --git a/commands/oftree.c b/commands/oftree.c
index ddbff3e..68e3fb4 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -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;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 11d17c6..ae15524 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -27,6 +27,7 @@
 #include <sizes.h>
 #include <linux/ctype.h>
 #include <linux/amba/bus.h>
+#include <linux/err.h>
 
 /**
  * struct alias_prop - Alias property in 'aliases' node
@@ -561,6 +562,18 @@ struct device_node *of_get_root_node(void)
 	return root_node;
 }
 
+int of_set_root_node(struct device_node *node)
+{
+	if (node && root_node)
+		return -EBUSY;
+
+	root_node = node;
+
+	of_alias_scan();
+
+	return 0;
+}
+
 static int of_node_disabled(struct device_node *node)
 {
 	struct property *p;
@@ -611,15 +624,10 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
 {
 	struct device_node *node;
 
-	if (!parent && root_node)
-		return NULL;
-
 	node = xzalloc(sizeof(*node));
 	node->parent = parent;
 	if (parent)
 		list_add_tail(&node->parent_list, &parent->children);
-	else
-		root_node = node;
 
 	INIT_LIST_HEAD(&node->children);
 	INIT_LIST_HEAD(&node->properties);
@@ -927,9 +935,7 @@ void of_free(struct device_node *node)
 	free(node);
 
 	if (node == root_node)
-		root_node = NULL;
-
-	of_alias_scan();
+		of_set_root_node(NULL);
 }
 
 static void __of_probe(struct device_node *node)
@@ -1021,11 +1027,15 @@ out:
 	return dn;
 }
 
-/*
- * Parse a flat device tree binary blob and store it in the barebox
- * internal tree format,
+/**
+ * of_unflatten_dtb - unflatten a fdt blob
+ * @root - node in which the fdt blob should be merged into or NULL
+ * @fdt - the fdt blob to unflatten
+ *
+ * Parse a flat device tree binary blob and return a pointer to the
+ * unflattened tree.
  */
-int of_unflatten_dtb(struct fdt_header *fdt)
+struct device_node *of_unflatten_dtb(struct device_node *root, struct fdt_header *fdt)
 {
 	const void *nodep;	/* property node pointer */
 	int  nodeoffset;	/* node offset from libfdt */
@@ -1034,8 +1044,9 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 	int  len;		/* length of the property */
 	const struct fdt_property *fdt_prop;
 	const char *pathp;
-	struct device_node *node = NULL, *n, *root = NULL;
+	struct device_node *node = NULL, *n;
 	struct property *p;
+	int ret;
 
 	nodeoffset = fdt_path_offset(fdt, "/");
 	if (nodeoffset < 0) {
@@ -1044,12 +1055,14 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 		 */
 		printf ("libfdt fdt_path_offset() returned %s\n",
 			fdt_strerror(nodeoffset));
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 	}
 
-	root = of_new_node(NULL, NULL);
-	if (!root)
-		return -ENOMEM;
+	if (!root) {
+		root = of_new_node(NULL, NULL);
+		if (!root)
+			return ERR_PTR(-ENOMEM);
+	}
 
 	while (1) {
 		tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);
@@ -1093,16 +1106,18 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 		case FDT_NOP:
 			break;
 		case FDT_END:
-			of_alias_scan();
-			return 0;
+			return root;
 		default:
 			printf("Unknown tag 0x%08X\n", tag);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto err;
 		}
 		nodeoffset = nextoffset;
 	}
+err:
+	of_free(root);
 
-	return 0;
+	return ERR_PTR(ret);
 }
 
 static int __of_flatten_dtb(void *fdt, struct device_node *node)
diff --git a/include/of.h b/include/of.h
index d780dcf..333a7eb 100644
--- a/include/of.h
+++ b/include/of.h
@@ -133,7 +133,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);
@@ -150,6 +150,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);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 11/37] of: Add root node argument to of_find_node_by_path
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (9 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 10/37] of: let of_unflatten_dtb return the unflattened tree Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 12/37] of: Add of_write_number helper Sascha Hauer
                   ` (25 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

This makes of_find_node_by_path usable with multiple trees.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/highbank/init.c |    2 +-
 commands/of_node.c              |    2 +-
 commands/of_property.c          |   10 ++++++++--
 commands/oftree.c               |   10 +++++++++-
 drivers/of/base.c               |   16 +++++++---------
 include/of.h                    |    2 +-
 6 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index 0f64fc8..a689b6a 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -79,7 +79,7 @@ static int highbank_mem_init(void)
 
 	of_set_root_node(root);
 
-	np = of_find_node_by_path("/memory");
+	np = of_find_node_by_path(root, "/memory");
 	if (!np) {
 		pr_warn("no memory node use default configuration\n");
 		goto not_found;
diff --git a/commands/of_node.c b/commands/of_node.c
index bf9799c..2f6ecae 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -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;
diff --git a/commands/of_property.c b/commands/of_property.c
index 42b6f11..585522c 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -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;
diff --git a/commands/oftree.c b/commands/oftree.c
index 68e3fb4..83ffe12 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -158,7 +158,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;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ae15524..721db29 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -146,7 +146,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;
 
@@ -163,7 +163,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;
 
@@ -483,18 +483,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;
@@ -964,7 +962,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);
@@ -1193,7 +1191,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;
diff --git a/include/of.h b/include/of.h
index 333a7eb..63c99b2 100644
--- a/include/of.h
+++ b/include/of.h
@@ -70,7 +70,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);
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 12/37] of: Add of_write_number helper
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (10 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 11/37] of: Add root node argument to of_find_node_by_path Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 13/37] of: Add initrd helper Sascha Hauer
                   ` (24 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

The counterpart to of_read_number: Write a 32bit or 64bit
number to a devicetree.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/of.h |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/of.h b/include/of.h
index 63c99b2..6154490 100644
--- a/include/of.h
+++ b/include/of.h
@@ -96,6 +96,17 @@ static inline u64 of_read_number(const __be32 *cell, int size)
 	return r;
 }
 
+/* Helper to write a big number; size is in cells (not bytes) */
+static inline void of_write_number(void *__cell, u64 val, int size)
+{
+	__be32 *cell = __cell;
+
+	while (size--) {
+		cell[size] = cpu_to_be32(val);
+		val >>= 32;
+	}
+}
+
 int of_property_read_u32_array(const struct device_node *np,
 			       const char *propname, u32 *out_values,
 			       size_t sz);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 13/37] of: Add initrd helper
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (11 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 12/37] of: Add of_write_number helper Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04 12:01   ` Alexander Aring
  2013-03-04  9:53 ` [PATCH 14/37] of: make unflatten independent of libfdt Sascha Hauer
                   ` (23 subsequent siblings)
  36 siblings, 1 reply; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Add a helper to set the initrd properties in the unflattened tree.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   39 +++++++++++++++++++++++++++++++++++++++
 include/of.h      |    3 +++
 2 files changed, 42 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 721db29..4dbe11e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1201,3 +1201,42 @@ int of_device_is_stdout_path(struct device_d *dev)
 
 	return 0;
 }
+
+/**
+ * of_add_initrd - add initrd properties to the devicetree
+ * @root - the root node of the tree
+ * @start - physical start address of the initrd image
+ * @end - physical end address of the initrd image
+ *
+ * Add initrd properties to the devicetree, or, if end is 0,
+ * delete them.
+ */
+int of_add_initrd(struct device_node *root, resource_size_t start,
+		resource_size_t end)
+{
+	struct device_node *chosen;
+	__be32 buf[2];
+
+	chosen = of_find_node_by_path(root, "/chosen");
+	if (!chosen)
+		return -EINVAL;
+
+	if (end) {
+		of_write_number(buf, start, 2);
+		of_set_property(chosen, "linux,initrd-start", buf, 8, 1);
+		of_write_number(buf, end, 2);
+		of_set_property(chosen, "linux,initrd-end", buf, 8, 1);
+	} else {
+		struct property *pp;
+
+		pp = of_find_property(chosen, "linux,initrd-start");
+		if (pp)
+			of_delete_property(pp);
+
+		pp = of_find_property(chosen, "linux,initrd-end");
+		if (pp)
+			of_delete_property(pp);
+	}
+
+	return 0;
+}
diff --git a/include/of.h b/include/of.h
index 6154490..1562f4e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -68,6 +68,9 @@ struct driver_d;
 
 int of_match(struct device_d *dev, struct driver_d *drv);
 
+int of_add_initrd(struct device_node *root, resource_size_t start,
+		resource_size_t end);
+
 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);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 14/37] of: make unflatten independent of libfdt
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (12 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 13/37] of: Add initrd helper Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 15/37] of: make flatten " Sascha Hauer
                   ` (22 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |  160 +++++++++++++++++++++++++++++++++++++++++------------
 include/of.h      |    2 +-
 2 files changed, 127 insertions(+), 35 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4dbe11e..8bb80e6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1025,92 +1025,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);
diff --git a/include/of.h b/include/of.h
index 1562f4e..4622b80 100644
--- a/include/of.h
+++ b/include/of.h
@@ -147,7 +147,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);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 15/37] of: make flatten independent of libfdt
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (13 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 14/37] of: make unflatten independent of libfdt Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 16/37] of/fdt: use optimized endianess conversion Sascha Hauer
                   ` (21 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/oftree.c   |    8 ++-
 drivers/of/base.c |  180 ++++++++++++++++++++++++++++++++++++++++++++---------
 include/of.h      |    6 +-
 3 files changed, 162 insertions(+), 32 deletions(-)

diff --git a/common/oftree.c b/common/oftree.c
index 82e5ddd..555aa0b 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -422,7 +422,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;
 	}
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 8bb80e6..0f842e6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1210,20 +1210,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;
+	}
+
+	if (fdt->dt_size - fdt->dt_nextofs < 1024 + dtsize) {
+		fdt->dt = realloc(fdt->dt, fdt->dt_size * 2);
+		if (!fdt->dt)
+			return -ENOMEM;
+		fdt->dt_size *= 2;
+	}
+
+	return 0;
+}
+
+static inline int dt_add_string(struct fdt *fdt, const char *str)
+{
+	uint32_t ret;
+	int len;
+
+	if (fdt_ensure_space(fdt, 0) < 0)
+		return -ENOMEM;
+
+	len = lstrcpy(fdt->strings + fdt->str_nextofs, str);
+	if (len < 0)
+		return -ENOSPC;
+
+	ret = fdt->str_nextofs;
+
+	fdt->str_nextofs += len + 1;
+
+	return ret;
+}
+
+static int __of_flatten_dtb(struct fdt *fdt, struct device_node *node)
 {
 	struct property *p;
 	struct device_node *n;
 	int ret;
+	unsigned int len;
+	struct fdt_node_header *nh = fdt->dt + fdt->dt_nextofs;
 
-	ret = fdt_begin_node(fdt, node->name);
-	if (ret)
-		return ret;
+	if (fdt_ensure_space(fdt, 0) < 0)
+		return -ENOMEM;
+
+	nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
+	len = lstrcpy(nh->name, node->name);
+	fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs, 4 + len + 1);
 
 	list_for_each_entry(p, &node->properties, list) {
-		ret = fdt_property(fdt, p->name, p->value, p->length);
-		if (ret)
-			return ret;
+		struct fdt_property *fp;
+
+		if (fdt_ensure_space(fdt, p->length) < 0)
+			return -ENOMEM;
+
+		fp = fdt->dt + fdt->dt_nextofs;
+
+		fp->tag = cpu_to_fdt32(FDT_PROP);
+		fp->len = cpu_to_fdt32(p->length);
+		fp->nameoff = cpu_to_fdt32(dt_add_string(fdt, p->name));
+		memcpy(fp->data, p->value, p->length);
+		fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs,
+				sizeof(struct fdt_property) + p->length);
 	}
 
 	list_for_each_entry(n, &node->children, parent_list) {
@@ -1232,45 +1320,79 @@ static int __of_flatten_dtb(void *fdt, struct device_node *node)
 			return ret;
 	}
 
-	ret = fdt_end_node(fdt);
+	nh = fdt->dt + fdt->dt_nextofs;
+	nh->tag = cpu_to_fdt32(FDT_END_NODE);
+	fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs,
+			sizeof(struct fdt_node_header));
 
-	return ret;
-}
+	if (fdt_ensure_space(fdt, 0) < 0)
+		return -ENOMEM;
 
-#define DTB_SIZE	SZ_128K
+	return 0;
+}
 
-void *of_flatten_dtb(void)
+/**
+ * of_flatten_dtb - flatten a barebox internal devicetree to a dtb
+ * @node - the root node of the tree to be unflattened
+ */
+void *of_flatten_dtb(struct device_node *node)
 {
-	void *fdt;
 	int ret;
+	struct fdt_header header = {};
+	struct fdt fdt = {};
+	uint32_t ofs;
+	struct fdt_node_header *nh;
 
-	if (!root_node)
-		return NULL;
+	header.magic = cpu_to_fdt32(FDT_MAGIC);
+	header.version = cpu_to_fdt32(0x11);
+	header.last_comp_version = cpu_to_fdt32(0x10);
 
-	fdt = malloc(DTB_SIZE);
-	if (!fdt)
-		return NULL;
+	fdt.dt = xzalloc(SZ_64K);
+	fdt.dt_size = SZ_64K;
 
-	memset(fdt, 0, DTB_SIZE);
+	fdt.strings = xzalloc(SZ_64K);
+	fdt.str_size = SZ_64K;
 
-	ret = fdt_create(fdt, DTB_SIZE);
-	if (ret)
-		goto out_free;
+	ofs = sizeof(struct fdt_header);
 
-	ret = fdt_finish_reservemap(fdt);
-	if (ret)
-		goto out_free;
+	header.off_mem_rsvmap = cpu_to_fdt32(ofs);
+	ofs += sizeof(struct fdt_reserve_entry) * OF_MAX_RESERVE_MAP;
+
+	fdt.dt_nextofs = ofs;
 
-	ret = __of_flatten_dtb(fdt, root_node);
+	ret = __of_flatten_dtb(&fdt, node);
 	if (ret)
 		goto out_free;
+	nh = fdt.dt + fdt.dt_nextofs;
+	nh->tag = cpu_to_fdt32(FDT_END);
+	fdt.dt_nextofs = dt_next_ofs(fdt.dt_nextofs, sizeof(struct fdt_node_header));
+
+	header.size_dt_strings = cpu_to_fdt32(fdt.str_nextofs);
+	header.size_dt_struct = cpu_to_fdt32(fdt.dt_nextofs);
+
+	header.off_dt_struct = cpu_to_fdt32(ofs);
+
+	header.off_dt_strings = cpu_to_fdt32(fdt.dt_nextofs);
+
+	if (fdt.dt_size - fdt.dt_nextofs < fdt.str_nextofs) {
+		fdt.dt = realloc(fdt.dt, fdt.dt_nextofs + fdt.str_nextofs);
+		if (!fdt.dt)
+			goto out_free;
+	}
+
+	memcpy(fdt.dt + fdt.dt_nextofs, fdt.strings, fdt.str_nextofs);
+
+	header.totalsize = cpu_to_fdt32(fdt.dt_nextofs + fdt.str_nextofs);
+
+	memcpy(fdt.dt, &header, sizeof(header));
 
-	fdt_finish(fdt);
+	free(fdt.strings);
 
-	return fdt;
+	return fdt.dt;
 
 out_free:
-	free(fdt);
+	free(fdt.strings);
+	free(fdt.dt);
 
 	return NULL;
 }
diff --git a/include/of.h b/include/of.h
index 4622b80..2cd55c0 100644
--- a/include/of.h
+++ b/include/of.h
@@ -64,6 +64,8 @@ struct of_device_id {
 	unsigned long data;
 };
 
+#define OF_MAX_RESERVE_MAP	16
+
 struct driver_d;
 
 int of_match(struct device_d *dev, struct driver_d *drv);
@@ -168,7 +170,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);
 int of_add_memory(struct device_node *node, bool dump);
 #else
 static inline int of_parse_partitions(const char *cdevname,
@@ -197,7 +199,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;
 }
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 16/37] of/fdt: use optimized endianess conversion
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (14 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 15/37] of: make flatten " Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 17/37] oftree command: Use of_print_nodes Sascha Hauer
                   ` (20 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/libfdt_env.h |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/libfdt_env.h b/include/libfdt_env.h
index e83aa96..6486187 100644
--- a/include/libfdt_env.h
+++ b/include/libfdt_env.h
@@ -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)
 {
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 17/37] oftree command: Use of_print_nodes
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (15 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 16/37] of/fdt: use optimized endianess conversion Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 18/37] of: move OFTREE Kconfig option to drivers/of/ Sascha Hauer
                   ` (19 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/oftree.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/commands/oftree.c b/commands/oftree.c
index 83ffe12..612d01a 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -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;
 	}
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 18/37] of: move OFTREE Kconfig option to drivers/of/
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (16 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 17/37] oftree command: Use of_print_nodes Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 19/37] of: make OFDEVICE a user selectable option Sascha Hauer
                   ` (18 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/Kconfig |    4 ++++
 lib/Kconfig        |    4 ----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 95f10d0..5e53d25 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -1,2 +1,6 @@
+config OFTREE
+	select FDT
+	bool
+
 config OFDEVICE
 	bool
diff --git a/lib/Kconfig b/lib/Kconfig
index 4578353..d58109b 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -25,10 +25,6 @@ source lib/lzo/Kconfig
 config FDT
 	bool
 
-config OFTREE
-	select FDT
-	bool
-
 config BCH
 	bool
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 19/37] of: make OFDEVICE a user selectable option
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (17 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 18/37] of: move OFTREE Kconfig option to drivers/of/ Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 20/37] oftree command: retire CMD_OFTREE_PROBE Kconfig option Sascha Hauer
                   ` (17 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/Kconfig   |    3 ---
 drivers/Makefile   |    2 +-
 drivers/of/Kconfig |    3 ++-
 include/of.h       |   12 ++++--------
 4 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index c1454c7..c8f06d8 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -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.
diff --git a/drivers/Makefile b/drivers/Makefile
index f81bf99..03a10fb 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -20,5 +20,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/
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 5e53d25..c30b1c1 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -3,4 +3,5 @@ config OFTREE
 	bool
 
 config OFDEVICE
-	bool
+	select OFTREE
+	bool "Enable probing of devices from the devicetree"
diff --git a/include/of.h b/include/of.h
index 2cd55c0..2234dae 100644
--- a/include/of.h
+++ b/include/of.h
@@ -161,12 +161,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);
@@ -179,11 +180,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;
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 20/37] oftree command: retire CMD_OFTREE_PROBE Kconfig option
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (18 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 19/37] of: make OFDEVICE a user selectable option Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 21/37] of: move oftree Kconfig to the top of the drivers menu Sascha Hauer
                   ` (16 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/Kconfig  |    7 -------
 commands/oftree.c |    2 +-
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index c8f06d8..0062758 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -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
diff --git a/commands/oftree.c b/commands/oftree.c
index 612d01a..e4f52b8 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -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");
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 21/37] of: move oftree Kconfig to the top of the drivers menu
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (19 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 20/37] oftree command: retire CMD_OFTREE_PROBE Kconfig option Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 22/37] of: Pass barebox internal format devicetree to of_get_fixed_tree Sascha Hauer
                   ` (15 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/Kconfig |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 16ca5b9..b213849 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -1,5 +1,6 @@
 menu "Drivers"
 
+source "drivers/of/Kconfig"
 source "drivers/amba/Kconfig"
 source "drivers/serial/Kconfig"
 source "drivers/net/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
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 22/37] of: Pass barebox internal format devicetree to of_get_fixed_tree
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (20 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 21/37] of: move oftree Kconfig to the top of the drivers menu Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 23/37] bootm: Use of_print_nodes instead of fdt_print Sascha Hauer
                   ` (14 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 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(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index cf192cf..234f3e0 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -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");
diff --git a/commands/bootm.c b/commands/bootm.c
index 4d3f022..38233e7 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -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;
 
diff --git a/common/oftree.c b/common/oftree.c
index 555aa0b..be9eb28 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -415,24 +415,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);
 
 	/*
diff --git a/include/of.h b/include/of.h
index 2234dae..fe9f65d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -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 *));
 
@@ -81,6 +80,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)
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 23/37] bootm: Use of_print_nodes instead of fdt_print
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (21 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 22/37] of: Pass barebox internal format devicetree to of_get_fixed_tree Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 24/37] of: move flat devicetree functions to separate file Sascha Hauer
                   ` (13 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 38233e7..65a75e2 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -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;
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 24/37] of: move flat devicetree functions to separate file
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (22 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 23/37] bootm: Use of_print_nodes instead of fdt_print Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 25/37] of: Add of property write functions for u32 Sascha Hauer
                   ` (12 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 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

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 5a5960d..fc71962 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,3 +1,3 @@
-obj-y += base.o
+obj-y += base.o dtb.o
 obj-$(CONFIG_GPIOLIB) += gpio.o
 obj-y += partition.o
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 0f842e6..b9db261 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1025,378 +1025,6 @@ 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 dtb binary blob
- * @root - node in which the fdt blob should be merged into or NULL
- * @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, void *infdt)
-{
-	const void *nodep;	/* property node pointer */
-	uint32_t tag;		/* tag */
-	int  len;		/* length of the property */
-	const struct fdt_property *fdt_prop;
-	const char *pathp, *name;
-	struct device_node *node = NULL, *n;
-	struct property *p;
-	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);
-	}
-
-	if (fdt->version != cpu_to_fdt32(17)) {
-		pr_err("bad dt version: 0x%08x\n", fdt32_to_cpu(fdt->version));
-		return ERR_PTR(-EINVAL);
-	}
-
-	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 = be32_to_cpu(*(uint32_t *)(infdt + dt_struct));
-
-		switch (tag) {
-		case FDT_BEGIN_NODE:
-			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;
-			}
-
-			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 (merge && (n = of_find_child_by_name(node, pathp)))
-					node = n;
-				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 = 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, 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:
-			pr_err("unflatten: Unknown tag 0x%08X\n", tag);
-			ret = -EINVAL;
-			goto err;
-		}
-	}
-err:
-	of_free(root);
-
-	return ERR_PTR(ret);
-}
-
-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;
-	}
-
-	if (fdt->dt_size - fdt->dt_nextofs < 1024 + dtsize) {
-		fdt->dt = realloc(fdt->dt, fdt->dt_size * 2);
-		if (!fdt->dt)
-			return -ENOMEM;
-		fdt->dt_size *= 2;
-	}
-
-	return 0;
-}
-
-static inline int dt_add_string(struct fdt *fdt, const char *str)
-{
-	uint32_t ret;
-	int len;
-
-	if (fdt_ensure_space(fdt, 0) < 0)
-		return -ENOMEM;
-
-	len = lstrcpy(fdt->strings + fdt->str_nextofs, str);
-	if (len < 0)
-		return -ENOSPC;
-
-	ret = fdt->str_nextofs;
-
-	fdt->str_nextofs += len + 1;
-
-	return ret;
-}
-
-static int __of_flatten_dtb(struct fdt *fdt, struct device_node *node)
-{
-	struct property *p;
-	struct device_node *n;
-	int ret;
-	unsigned int len;
-	struct fdt_node_header *nh = fdt->dt + fdt->dt_nextofs;
-
-	if (fdt_ensure_space(fdt, 0) < 0)
-		return -ENOMEM;
-
-	nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
-	len = lstrcpy(nh->name, node->name);
-	fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs, 4 + len + 1);
-
-	list_for_each_entry(p, &node->properties, list) {
-		struct fdt_property *fp;
-
-		if (fdt_ensure_space(fdt, p->length) < 0)
-			return -ENOMEM;
-
-		fp = fdt->dt + fdt->dt_nextofs;
-
-		fp->tag = cpu_to_fdt32(FDT_PROP);
-		fp->len = cpu_to_fdt32(p->length);
-		fp->nameoff = cpu_to_fdt32(dt_add_string(fdt, p->name));
-		memcpy(fp->data, p->value, p->length);
-		fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs,
-				sizeof(struct fdt_property) + p->length);
-	}
-
-	list_for_each_entry(n, &node->children, parent_list) {
-		ret = __of_flatten_dtb(fdt, n);
-		if (ret)
-			return ret;
-	}
-
-	nh = fdt->dt + fdt->dt_nextofs;
-	nh->tag = cpu_to_fdt32(FDT_END_NODE);
-	fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs,
-			sizeof(struct fdt_node_header));
-
-	if (fdt_ensure_space(fdt, 0) < 0)
-		return -ENOMEM;
-
-	return 0;
-}
-
-/**
- * of_flatten_dtb - flatten a barebox internal devicetree to a dtb
- * @node - the root node of the tree to be unflattened
- */
-void *of_flatten_dtb(struct device_node *node)
-{
-	int ret;
-	struct fdt_header header = {};
-	struct fdt fdt = {};
-	uint32_t ofs;
-	struct fdt_node_header *nh;
-
-	header.magic = cpu_to_fdt32(FDT_MAGIC);
-	header.version = cpu_to_fdt32(0x11);
-	header.last_comp_version = cpu_to_fdt32(0x10);
-
-	fdt.dt = xzalloc(SZ_64K);
-	fdt.dt_size = SZ_64K;
-
-	fdt.strings = xzalloc(SZ_64K);
-	fdt.str_size = SZ_64K;
-
-	ofs = sizeof(struct fdt_header);
-
-	header.off_mem_rsvmap = cpu_to_fdt32(ofs);
-	ofs += sizeof(struct fdt_reserve_entry) * OF_MAX_RESERVE_MAP;
-
-	fdt.dt_nextofs = ofs;
-
-	ret = __of_flatten_dtb(&fdt, node);
-	if (ret)
-		goto out_free;
-	nh = fdt.dt + fdt.dt_nextofs;
-	nh->tag = cpu_to_fdt32(FDT_END);
-	fdt.dt_nextofs = dt_next_ofs(fdt.dt_nextofs, sizeof(struct fdt_node_header));
-
-	header.size_dt_strings = cpu_to_fdt32(fdt.str_nextofs);
-	header.size_dt_struct = cpu_to_fdt32(fdt.dt_nextofs);
-
-	header.off_dt_struct = cpu_to_fdt32(ofs);
-
-	header.off_dt_strings = cpu_to_fdt32(fdt.dt_nextofs);
-
-	if (fdt.dt_size - fdt.dt_nextofs < fdt.str_nextofs) {
-		fdt.dt = realloc(fdt.dt, fdt.dt_nextofs + fdt.str_nextofs);
-		if (!fdt.dt)
-			goto out_free;
-	}
-
-	memcpy(fdt.dt + fdt.dt_nextofs, fdt.strings, fdt.str_nextofs);
-
-	header.totalsize = cpu_to_fdt32(fdt.dt_nextofs + fdt.str_nextofs);
-
-	memcpy(fdt.dt, &header, sizeof(header));
-
-	free(fdt.strings);
-
-	return fdt.dt;
-
-out_free:
-	free(fdt.strings);
-	free(fdt.dt);
-
-	return NULL;
-}
-
 int of_device_is_stdout_path(struct device_d *dev)
 {
 	struct device_node *dn;
diff --git a/drivers/of/dtb.c b/drivers/of/dtb.c
new file mode 100644
index 0000000..3867128
--- /dev/null
+++ b/drivers/of/dtb.c
@@ -0,0 +1,401 @@
+/*
+ * dtb.c - flat devicetree functions
+ *
+ * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * based on Linux devicetree support
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <common.h>
+#include <of.h>
+#include <errno.h>
+#include <libfdt.h>
+#include <malloc.h>
+#include <init.h>
+#include <memory.h>
+#include <sizes.h>
+#include <linux/ctype.h>
+#include <linux/err.h>
+
+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 dtb binary blob
+ * @root - node in which the fdt blob should be merged into or NULL
+ * @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, void *infdt)
+{
+	const void *nodep;	/* property node pointer */
+	uint32_t tag;		/* tag */
+	int  len;		/* length of the property */
+	const struct fdt_property *fdt_prop;
+	const char *pathp, *name;
+	struct device_node *node = NULL, *n;
+	struct property *p;
+	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);
+	}
+
+	if (fdt->version != cpu_to_fdt32(17)) {
+		pr_err("bad dt version: 0x%08x\n", fdt32_to_cpu(fdt->version));
+		return ERR_PTR(-EINVAL);
+	}
+
+	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 = be32_to_cpu(*(uint32_t *)(infdt + dt_struct));
+
+		switch (tag) {
+		case FDT_BEGIN_NODE:
+			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;
+			}
+
+			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 (merge && (n = of_find_child_by_name(node, pathp)))
+					node = n;
+				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 = 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, 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:
+			pr_err("unflatten: Unknown tag 0x%08X\n", tag);
+			ret = -EINVAL;
+			goto err;
+		}
+	}
+err:
+	of_free(root);
+
+	return ERR_PTR(ret);
+}
+
+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;
+	}
+
+	if (fdt->dt_size - fdt->dt_nextofs < 1024 + dtsize) {
+		fdt->dt = realloc(fdt->dt, fdt->dt_size * 2);
+		if (!fdt->dt)
+			return -ENOMEM;
+		fdt->dt_size *= 2;
+	}
+
+	return 0;
+}
+
+static inline int dt_add_string(struct fdt *fdt, const char *str)
+{
+	uint32_t ret;
+	int len;
+
+	if (fdt_ensure_space(fdt, 0) < 0)
+		return -ENOMEM;
+
+	len = lstrcpy(fdt->strings + fdt->str_nextofs, str);
+	if (len < 0)
+		return -ENOSPC;
+
+	ret = fdt->str_nextofs;
+
+	fdt->str_nextofs += len + 1;
+
+	return ret;
+}
+
+static int __of_flatten_dtb(struct fdt *fdt, struct device_node *node)
+{
+	struct property *p;
+	struct device_node *n;
+	int ret;
+	unsigned int len;
+	struct fdt_node_header *nh = fdt->dt + fdt->dt_nextofs;
+
+	if (fdt_ensure_space(fdt, 0) < 0)
+		return -ENOMEM;
+
+	nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
+	len = lstrcpy(nh->name, node->name);
+	fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs, 4 + len + 1);
+
+	list_for_each_entry(p, &node->properties, list) {
+		struct fdt_property *fp;
+
+		if (fdt_ensure_space(fdt, p->length) < 0)
+			return -ENOMEM;
+
+		fp = fdt->dt + fdt->dt_nextofs;
+
+		fp->tag = cpu_to_fdt32(FDT_PROP);
+		fp->len = cpu_to_fdt32(p->length);
+		fp->nameoff = cpu_to_fdt32(dt_add_string(fdt, p->name));
+		memcpy(fp->data, p->value, p->length);
+		fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs,
+				sizeof(struct fdt_property) + p->length);
+	}
+
+	list_for_each_entry(n, &node->children, parent_list) {
+		ret = __of_flatten_dtb(fdt, n);
+		if (ret)
+			return ret;
+	}
+
+	nh = fdt->dt + fdt->dt_nextofs;
+	nh->tag = cpu_to_fdt32(FDT_END_NODE);
+	fdt->dt_nextofs = dt_next_ofs(fdt->dt_nextofs,
+			sizeof(struct fdt_node_header));
+
+	if (fdt_ensure_space(fdt, 0) < 0)
+		return -ENOMEM;
+
+	return 0;
+}
+
+/**
+ * of_flatten_dtb - flatten a barebox internal devicetree to a dtb
+ * @node - the root node of the tree to be unflattened
+ */
+void *of_flatten_dtb(struct device_node *node)
+{
+	int ret;
+	struct fdt_header header = {};
+	struct fdt fdt = {};
+	uint32_t ofs;
+	struct fdt_node_header *nh;
+
+	header.magic = cpu_to_fdt32(FDT_MAGIC);
+	header.version = cpu_to_fdt32(0x11);
+	header.last_comp_version = cpu_to_fdt32(0x10);
+
+	fdt.dt = xzalloc(SZ_64K);
+	fdt.dt_size = SZ_64K;
+
+	fdt.strings = xzalloc(SZ_64K);
+	fdt.str_size = SZ_64K;
+
+	ofs = sizeof(struct fdt_header);
+
+	header.off_mem_rsvmap = cpu_to_fdt32(ofs);
+	ofs += sizeof(struct fdt_reserve_entry) * OF_MAX_RESERVE_MAP;
+
+	fdt.dt_nextofs = ofs;
+
+	ret = __of_flatten_dtb(&fdt, node);
+	if (ret)
+		goto out_free;
+	nh = fdt.dt + fdt.dt_nextofs;
+	nh->tag = cpu_to_fdt32(FDT_END);
+	fdt.dt_nextofs = dt_next_ofs(fdt.dt_nextofs, sizeof(struct fdt_node_header));
+
+	header.size_dt_strings = cpu_to_fdt32(fdt.str_nextofs);
+	header.size_dt_struct = cpu_to_fdt32(fdt.dt_nextofs);
+
+	header.off_dt_struct = cpu_to_fdt32(ofs);
+
+	header.off_dt_strings = cpu_to_fdt32(fdt.dt_nextofs);
+
+	if (fdt.dt_size - fdt.dt_nextofs < fdt.str_nextofs) {
+		fdt.dt = realloc(fdt.dt, fdt.dt_nextofs + fdt.str_nextofs);
+		if (!fdt.dt)
+			goto out_free;
+	}
+
+	memcpy(fdt.dt + fdt.dt_nextofs, fdt.strings, fdt.str_nextofs);
+
+	header.totalsize = cpu_to_fdt32(fdt.dt_nextofs + fdt.str_nextofs);
+
+	memcpy(fdt.dt, &header, sizeof(header));
+
+	free(fdt.strings);
+
+	return fdt.dt;
+
+out_free:
+	free(fdt.strings);
+	free(fdt.dt);
+
+	return NULL;
+}
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 25/37] of: Add of property write functions for u32
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (23 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 24/37] of: move flat devicetree functions to separate file Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 26/37] of: make value of property in of_new_property optional Sascha Hauer
                   ` (11 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |   25 +++++++++++++++++++++++++
 include/of.h      |   11 +++++++++++
 2 files changed, 36 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index b9db261..9f9d9a0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -350,6 +350,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
diff --git a/include/of.h b/include/of.h
index fe9f65d..eeea016 100644
--- a/include/of.h
+++ b/include/of.h
@@ -124,6 +124,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);
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 26/37] of: make value of property in of_new_property optional
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (24 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 25/37] of: Add of property write functions for u32 Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 27/37] of: Add missing prototype for size/address counting functions Sascha Hauer
                   ` (10 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 9f9d9a0..5891138 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -677,8 +677,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);
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 27/37] of: Add missing prototype for size/address counting functions
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (25 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 26/37] of: make value of property in of_new_property optional Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 28/37] of: fixup unflattened devicetree Sascha Hauer
                   ` (9 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/of.h |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/of.h b/include/of.h
index eeea016..85adc80 100644
--- a/include/of.h
+++ b/include/of.h
@@ -72,6 +72,9 @@ int of_match(struct device_d *dev, struct driver_d *drv);
 int of_add_initrd(struct device_node *root, resource_size_t start,
 		resource_size_t end);
 
+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);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 28/37] of: fixup unflattened devicetree
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (26 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 27/37] of: Add missing prototype for size/address counting functions Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 29/37] of_* commands: print usage when insufficient arguments are given Sascha Hauer
                   ` (8 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/at91sam9x5ek/hw_version.c |   31 +++++++------
 arch/arm/boards/highbank/init.c           |   33 +++++++++-----
 arch/ppc/mach-mpc5xxx/cpu.c               |   26 +++++++----
 common/memory.c                           |   48 ++++++--------------
 common/oftree.c                           |   70 +++++++++--------------------
 include/of.h                              |    6 +--
 6 files changed, 94 insertions(+), 120 deletions(-)

diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 47c640a..2695faa 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -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;
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index a689b6a..bd32c1d 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -25,8 +25,9 @@
 
 struct fdt_header *fdt = NULL;
 
-static int hb_fixup(struct fdt_header *fdt)
+static int hb_fixup(struct device_node *root)
 {
+	struct device_node *node;
 	u32 reg = readl(sregs_base + HB_SREG_A9_PWRDOM_DATA);
 	u32 *opp_table = (u32 *)HB_SYSRAM_OPP_TABLE_BASE;
 	u32 dtb_table[2*10];
@@ -34,17 +35,29 @@ static int hb_fixup(struct fdt_header *fdt)
 	u32 num_opps;
 	__be32 latency;
 
-	if (!(reg & HB_PWRDOM_STAT_SATA))
-		do_fixup_by_compatible_string(fdt, "calxeda,hb-ahci", "status",
-					           "disabled", 1);
+	if (!(reg & HB_PWRDOM_STAT_SATA)) {
+		of_tree_for_each_node(node, root) {
+			if (of_device_is_compatible(node, "calxeda,hb-ahci"))
+				of_set_property(node, "status", "disabled",
+						sizeof("disabled"), 1);
+		}
+	}
 
-	if (!(reg & HB_PWRDOM_STAT_EMMC))
-		do_fixup_by_compatible_string(fdt, "calxeda,hb-sdhci", "status",
-					           "disabled", 1);
+	if (!(reg & HB_PWRDOM_STAT_EMMC)) {
+		of_tree_for_each_node(node, root) {
+			if (of_device_is_compatible(node, "calxeda,hb-sdhci"))
+				of_set_property(node, "status", "disabled",
+						sizeof("disabled"), 1);
+		}
+	}
 
 	if ((opp_table[0] >> 16) != HB_OPP_VERSION)
 		return 0;
 
+	node = of_find_node_by_path(root, "/cpus/cpu@0");
+	if (!node)
+		return 0;
+
 	num_opps = opp_table[0] & 0xff;
 
 	for (i = 0; i < num_opps; i++) {
@@ -54,10 +67,8 @@ static int hb_fixup(struct fdt_header *fdt)
 
 	latency = cpu_to_be32(opp_table[1]);
 
-	fdt_find_and_setprop(fdt, "/cpus/cpu@0", "transition-latency",
-				  &latency, 4, 1);
-	fdt_find_and_setprop(fdt, "/cpus/cpu@0", "operating-points",
-				  dtb_table, 8 * num_opps, 1);
+	of_set_property(node, "transition-latency", &latency, 4, 1);
+	of_set_property(node, "operating-points", dtb_table, 8 * num_opps, 1);
 
 	return 0;
 }
diff --git a/arch/ppc/mach-mpc5xxx/cpu.c b/arch/ppc/mach-mpc5xxx/cpu.c
index 5bbd49a..99f16eb 100644
--- a/arch/ppc/mach-mpc5xxx/cpu.c
+++ b/arch/ppc/mach-mpc5xxx/cpu.c
@@ -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;
 }
 
diff --git a/common/memory.c b/common/memory.c
index 81641f0..1d2e3a3 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -165,22 +165,6 @@ int release_sdram_region(struct resource *res)
 #ifdef CONFIG_OFTREE
 
 /*
- * Get cells len in bytes
- *     if #NNNN-cells property is 2 then len is 8
- *     otherwise len is 4
- */
-static int get_cells_len(struct fdt_header *fdt, char *nr_cells_name)
-{
-	const u32 *cell;
-
-	cell = fdt_getprop(fdt, 0, nr_cells_name, NULL);
-	if (cell && *cell == 2)
-		return 8;
-
-	return 4;
-}
-
-/*
  * Write a 4 or 8 byte big endian cell
  */
 static void write_cell(u8 *addr, u64 val, int size)
@@ -193,28 +177,24 @@ static void write_cell(u8 *addr, u64 val, int size)
 	}
 }
 
-static int of_memory_fixup(struct fdt_header *fdt)
+static int of_memory_fixup(struct device_node *node)
 {
 	struct memory_bank *bank;
-	int err, nodeoffset;
+	int err;
 	int addr_cell_len, size_cell_len, len = 0;
+	struct device_node *memnode;
 	u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
 
-	/* update, or add and update /memory node */
-	nodeoffset = fdt_get_path_or_create(fdt, "/memory");
-	if (nodeoffset < 0)
-		return nodeoffset;
+	memnode = of_create_node(node, "/memory");
+	if (!memnode)
+		return -ENOMEM;
 
-	err = fdt_setprop(fdt, nodeoffset, "device_type", "memory",
-			sizeof("memory"));
-	if (err < 0) {
-		printf("WARNING: could not set %s %s.\n", "device_type",
-				fdt_strerror(err));
+	err = of_set_property(memnode, "device_type", "memory", sizeof("memory"), 1);
+	if (err)
 		return err;
-	}
 
-	addr_cell_len = get_cells_len(fdt, "#address-cells");
-	size_cell_len = get_cells_len(fdt, "#size-cells");
+	addr_cell_len = of_n_addr_cells(memnode) * 4;
+	size_cell_len = of_n_size_cells(memnode) * 4;
 
 	for_each_memory_bank(bank) {
 		write_cell(tmp + len, bank->start, addr_cell_len);
@@ -223,12 +203,12 @@ static int of_memory_fixup(struct fdt_header *fdt)
 		len += size_cell_len;
 	}
 
-	err = fdt_setprop(fdt, nodeoffset, "reg", tmp, len);
-	if (err < 0) {
-		printf("WARNING: could not set %s %s.\n",
-				"reg", fdt_strerror(err));
+	err = of_set_property(memnode, "reg", tmp, len, 1);
+	if (err) {
+		pr_err("could not set reg %s.\n", strerror(-err));
 		return err;
 	}
+
 	return 0;
 }
 
diff --git a/common/oftree.c b/common/oftree.c
index be9eb28..44ffade 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -339,26 +339,24 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 	return 0;
 }
 
-static int of_fixup_bootargs(struct fdt_header *fdt)
+static int of_fixup_bootargs(struct device_node *root)
 {
-	int nodeoffset;
+	struct device_node *node;
 	const char *str;
 	int err;
 
-	nodeoffset = fdt_get_path_or_create(fdt, "/chosen");
-	if (nodeoffset < 0)
-		return nodeoffset;
-
 	str = linux_bootargs_get();
-	if (str) {
-		err = fdt_setprop(fdt, nodeoffset,
-				"bootargs", str, strlen(str)+1);
-		if (err < 0)
-			printf("WARNING: could not set bootargs %s.\n",
-					fdt_strerror(err));
-        }
+	if (!str)
+		return 0;
 
-	return 0;
+	node = of_create_node(root, "/chosen");
+	if (!node)
+		return -ENOMEM;
+
+
+	err = of_set_property(node, "bootargs", str, strlen(str) + 1, 1);
+
+	return err;
 }
 
 static int of_register_bootargs_fixup(void)
@@ -368,13 +366,13 @@ static int of_register_bootargs_fixup(void)
 late_initcall(of_register_bootargs_fixup);
 
 struct of_fixup {
-	int (*fixup)(struct fdt_header *);
+	int (*fixup)(struct device_node *);
 	struct list_head list;
 };
 
 static LIST_HEAD(of_fixup_list);
 
-int of_register_fixup(int (*fixup)(struct fdt_header *))
+int of_register_fixup(int (*fixup)(struct device_node *))
 {
 	struct of_fixup *of_fixup = xzalloc(sizeof(*of_fixup));
 
@@ -389,13 +387,13 @@ int of_register_fixup(int (*fixup)(struct fdt_header *))
  * Apply registered fixups for the given fdt. The fdt must have
  * enough free space to apply the fixups.
  */
-int of_fix_tree(struct fdt_header *fdt)
+int of_fix_tree(struct device_node *node)
 {
 	struct of_fixup *of_fixup;
 	int ret;
 
 	list_for_each_entry(of_fixup, &of_fixup_list, list) {
-		ret = of_fixup->fixup(fdt);
+		ret = of_fixup->fixup(node);
 		if (ret)
 			return ret;
 	}
@@ -418,8 +416,6 @@ int of_fix_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 (!node) {
@@ -428,35 +424,13 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node)
 			return NULL;
 	}
 
-	fdt = internalfdt = of_flatten_dtb(node);
-	if (!fdt)
-		return NULL;
-
-	size = fdt_totalsize(fdt);
-
-	/*
-	 * ARM Linux uses a single 1MiB section (with 1MiB alignment)
-	 * for mapping the devicetree, so we are not allowed to cross
-	 * 1MiB boundaries.
-	 */
-	align = 1 << fls(size + OFTREE_SIZE_INCREASE - 1);
-
-	fixfdt = xmemalign(align, size + OFTREE_SIZE_INCREASE);
-	ret = fdt_open_into(fdt, fixfdt, size + OFTREE_SIZE_INCREASE);
-
-	free(internalfdt);
-
+	ret = of_fix_tree(node);
 	if (ret)
-		goto out_free;
-
-	ret = of_fix_tree(fixfdt);
-	if (ret)
-		goto out_free;
-
-	return fixfdt;
+		return NULL;
 
-out_free:
-	free(fixfdt);
+	fdt = of_flatten_dtb(node);
+	if (!fdt)
+		return NULL;
 
-	return NULL;
+	return fdt;
 }
diff --git a/include/of.h b/include/of.h
index 85adc80..ef6a4ce 100644
--- a/include/of.h
+++ b/include/of.h
@@ -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,
@@ -67,6 +64,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_add_initrd(struct device_node *root, resource_size_t start,
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 29/37] of_* commands: print usage when insufficient arguments are given
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (27 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 28/37] of: fixup unflattened devicetree Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 30/37] of_property command: Fix crash with empty property value Sascha Hauer
                   ` (7 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/of_node.c     |    3 +++
 commands/of_property.c |    3 +++
 2 files changed, 6 insertions(+)

diff --git a/commands/of_node.c b/commands/of_node.c
index 2f6ecae..171ea2c 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -54,6 +54,9 @@ static int do_of_node(int argc, char *argv[])
 		}
 	}
 
+	if (optind == argc)
+		return COMMAND_ERROR_USAGE;
+
 	if (optind < argc) {
 		path = argv[optind];
 	}
diff --git a/commands/of_property.c b/commands/of_property.c
index 585522c..bd9ff72 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -192,6 +192,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");
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 30/37] of_property command: Fix crash with empty property value
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (28 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 29/37] of_* commands: print usage when insufficient arguments are given Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 31/37] ARM: bootm: rework concatenated oftree Sascha Hauer
                   ` (6 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/of_property.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/commands/of_property.c b/commands/of_property.c
index bd9ff72..1567a0f 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -255,9 +255,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);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 31/37] ARM: bootm: rework concatenated oftree
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (29 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 30/37] of_property command: Fix crash with empty property value Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 32/37] of: memory: Use of_write_number Sascha Hauer
                   ` (5 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Without compiled in devicetree support we used to copy the
concatenated devicetree directly behind the zImage. This is
unnecessary, even if we do not have devicetree support we can
copy the devicetree whereever we like and pass the kernel a
pointer to it. This makes the code a bit easier.
While at it, add the missing free calls in the error case.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootm.c |   36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 234f3e0..2a7d0f5 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -131,8 +131,6 @@ struct zimage_header {
 static int do_bootz_linux_fdt(int fd, struct image_data *data)
 {
 	struct fdt_header __header, *header;
-	struct resource *r = data->os_res;
-	struct resource *of_res = data->os_res;
 	void *oftree;
 	int ret;
 
@@ -151,21 +149,10 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 
 	end = be32_to_cpu(header->totalsize);
 
-	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		oftree = malloc(end + 0x8000);
-		if (!oftree) {
-			perror("zImage: oftree malloc");
-			return -ENOMEM;
-		}
-	} else {
-
-		of_res = request_sdram_region("oftree", r->start + resource_size(r), end);
-		if (!of_res) {
-			perror("zImage: oftree request_sdram_region");
-			return -ENOMEM;
-		}
-
-		oftree = (void*)of_res->start;
+	oftree = malloc(end + 0x8000);
+	if (!oftree) {
+		perror("zImage: oftree malloc");
+		return -ENOMEM;
 	}
 
 	memcpy(oftree, header, sizeof(*header));
@@ -174,10 +161,11 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 
 	ret = read_full(fd, oftree + sizeof(*header), end);
 	if (ret < 0)
-		return ret;
+		goto err_free;
 	if (ret < end) {
 		printf("premature end of image\n");
-		return -EIO;
+		ret = -EIO;
+		goto err_free;
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
@@ -186,15 +174,23 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 		node = of_unflatten_dtb(NULL, oftree);
 		if (!node) {
 			pr_err("unable to unflatten devicetree\n");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto err_free;
 		}
 
 		data->oftree = of_get_fixed_tree(node);
+	} else {
+		data->oftree = oftree;
 	}
 
 	pr_info("zImage: concatenated oftree detected\n");
 
 	return 0;
+
+err_free:
+	free(oftree);
+
+	return ret;
 }
 
 static int do_bootz_linux(struct image_data *data)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 32/37] of: memory: Use of_write_number
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (30 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 31/37] ARM: bootm: rework concatenated oftree Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 33/37] of: Add reservemap handling Sascha Hauer
                   ` (4 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/memory.c |   25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 1d2e3a3..61cca0d 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -164,19 +164,6 @@ int release_sdram_region(struct resource *res)
 
 #ifdef CONFIG_OFTREE
 
-/*
- * Write a 4 or 8 byte big endian cell
- */
-static void write_cell(u8 *addr, u64 val, int size)
-{
-	int shift = (size - 1) * 8;
-
-	while (size-- > 0) {
-		*addr++ = (val >> shift) & 0xff;
-		shift -= 8;
-	}
-}
-
 static int of_memory_fixup(struct device_node *node)
 {
 	struct memory_bank *bank;
@@ -193,14 +180,14 @@ static int of_memory_fixup(struct device_node *node)
 	if (err)
 		return err;
 
-	addr_cell_len = of_n_addr_cells(memnode) * 4;
-	size_cell_len = of_n_size_cells(memnode) * 4;
+	addr_cell_len = of_n_addr_cells(memnode);
+	size_cell_len = of_n_size_cells(memnode);
 
 	for_each_memory_bank(bank) {
-		write_cell(tmp + len, bank->start, addr_cell_len);
-		len += addr_cell_len;
-		write_cell(tmp + len, bank->size, size_cell_len);
-		len += size_cell_len;
+		of_write_number(tmp + len, bank->start, addr_cell_len);
+		len += addr_cell_len * 4;
+		of_write_number(tmp + len, bank->size, size_cell_len);
+		len += size_cell_len * 4;
 	}
 
 	err = of_set_property(memnode, "reg", tmp, len, 1);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 33/37] of: Add reservemap handling
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (31 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 32/37] of: memory: Use of_write_number Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 34/37] bootm: Pass unflattened devicetree to handlers Sascha Hauer
                   ` (3 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/dtb.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h     |   10 +++++++++
 2 files changed, 75 insertions(+)

diff --git a/drivers/of/dtb.c b/drivers/of/dtb.c
index 3867128..856b591 100644
--- a/drivers/of/dtb.c
+++ b/drivers/of/dtb.c
@@ -399,3 +399,68 @@ out_free:
 
 	return NULL;
 }
+
+/*
+ * The last entry is the zeroed sentinel, the one before is
+ * reserved for the reservemap entry for the dtb itself.
+ */
+#define OF_MAX_FREE_RESERVE_MAP	(OF_MAX_RESERVE_MAP - 2)
+
+static struct of_reserve_map of_reserve_map;
+
+int of_add_reserve_entry(resource_size_t start, resource_size_t end)
+{
+	int e = of_reserve_map.num_entries;
+
+	if (e >= OF_MAX_FREE_RESERVE_MAP)
+		return -ENOSPC;
+
+	of_reserve_map.start[e] = start;
+	of_reserve_map.end[e] = end;
+	of_reserve_map.num_entries++;
+
+	return 0;
+}
+
+struct of_reserve_map *of_get_reserve_map(void)
+{
+	return &of_reserve_map;
+}
+
+void of_clean_reserve_map(void)
+{
+	of_reserve_map.num_entries = 0;
+}
+
+/**
+ * fdt_add_reserve_map - Add reserve map entries to a devicetree binary
+ * @__fdt: The devicetree blob
+ *
+ * This adds the reservemap entries previously colllected in
+ * of_add_reserve_entry() to a devicetree binary blob. This also
+ * adds the devicetree itself to the reserved list, so after calling
+ * this function the tree should not be relocated anymore.
+ */
+void fdt_add_reserve_map(void *__fdt)
+{
+	struct fdt_header *fdt = __fdt;
+	struct of_reserve_map *res = &of_reserve_map;
+	struct fdt_reserve_entry *fdt_res =
+		__fdt + be32_to_cpu(fdt->off_mem_rsvmap);
+	int i;
+
+	for (i = 0; i < res->num_entries; i++) {
+		of_write_number(&fdt_res->address, res->start[i], 2);
+		of_write_number(&fdt_res->size, res->end[i] - res->start[i] + 1,
+				2);
+		fdt_res++;
+	}
+
+	of_write_number(&fdt_res->address, (unsigned long)__fdt, 2);
+	of_write_number(&fdt_res->size, (unsigned long)__fdt +
+			be32_to_cpu(fdt->totalsize), 2);
+	fdt_res++;
+
+	of_write_number(&fdt_res->address, 0, 2);
+	of_write_number(&fdt_res->size, 0, 2);
+}
diff --git a/include/of.h b/include/of.h
index ef6a4ce..1535694 100644
--- a/include/of.h
+++ b/include/of.h
@@ -61,6 +61,16 @@ struct of_device_id {
 };
 
 #define OF_MAX_RESERVE_MAP	16
+struct of_reserve_map {
+	uint64_t start[OF_MAX_RESERVE_MAP];
+	uint64_t end[OF_MAX_RESERVE_MAP];
+	int num_entries;
+};
+
+int of_add_reserve_entry(resource_size_t start, resource_size_t end);
+struct of_reserve_map *of_get_reserve_map(void);
+void of_clean_reserve_map(void);
+void fdt_add_reserve_map(void *fdt);
 
 struct driver_d;
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 34/37] bootm: Pass unflattened devicetree to handlers
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (32 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 33/37] of: Add reservemap handling Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 35/37] ARM bootm: Switch initrd support to unflattened tree Sascha Hauer
                   ` (2 subsequent siblings)
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

This makes it possible to modify the tree in the handlers.
This is necessary because the initrd addresses are only
known inside the handlers, but not to the generic bootm
code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootm.c    |    8 ++------
 arch/ppc/Kconfig        |    1 +
 arch/ppc/lib/ppclinux.c |    8 ++++++++
 commands/bootm.c        |   24 +++++++++---------------
 include/boot.h          |    1 +
 5 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 2a7d0f5..00c4908 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -169,16 +169,12 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data)
 	}
 
 	if (IS_BUILTIN(CONFIG_OFTREE)) {
-		struct device_node *node;
-
-		node = of_unflatten_dtb(NULL, oftree);
-		if (!node) {
+		data->of_root_node = of_unflatten_dtb(NULL, oftree);
+		if (!data->of_root_node) {
 			pr_err("unable to unflatten devicetree\n");
 			ret = -EINVAL;
 			goto err_free;
 		}
-
-		data->oftree = of_get_fixed_tree(node);
 	} else {
 		data->oftree = oftree;
 	}
diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig
index d124065..db269dd 100644
--- a/arch/ppc/Kconfig
+++ b/arch/ppc/Kconfig
@@ -4,6 +4,7 @@ config PPC
 	select HAS_KALLSYMS
 	select HAS_MODULES
 	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
+	select OFTREE
 	default y
 
 choice
diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
index 95dc83b..ef69ead 100644
--- a/arch/ppc/lib/ppclinux.c
+++ b/arch/ppc/lib/ppclinux.c
@@ -18,6 +18,14 @@ static int do_bootm_linux(struct image_data *data)
 	if (!data->os_res)
 		return -EINVAL;
 
+	data->oftree = of_get_fixed_tree(data->of_root_node);
+	if (!data->oftree) {
+		pr_err("bootm: No devicetree given.\n");
+		return -EINVAL;
+	}
+
+	fdt_add_reserve_map(data->oftree);
+
 	kernel = (void *)(data->os_address + data->os_entry);
 
 	/*
diff --git a/commands/bootm.c b/commands/bootm.c
index 65a75e2..ea5a35b 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -138,9 +138,8 @@ static int bootm_open_initrd_uimage(struct image_data *data)
 static int bootm_open_oftree(struct image_data *data, const char *oftree, int num)
 {
 	enum filetype ft;
-	struct fdt_header *fdt, *fixfdt;
+	struct fdt_header *fdt;
 	size_t size;
-	struct device_node *node;
 
 	printf("Loading devicetree from '%s'\n", oftree);
 
@@ -188,23 +187,14 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 				file_type_to_string(ft));
 	}
 
-	node = of_unflatten_dtb(NULL, fdt);
-	if (!node) {
+	data->of_root_node = of_unflatten_dtb(NULL, fdt);
+	if (!data->of_root_node) {
 		pr_err("unable to unflatten devicetree\n");
 		return -EINVAL;
 	}
 
-	if (bootm_verbose(data) > 1)
-		of_print_nodes(node, 0);
-
-	fixfdt = of_get_fixed_tree(node);
-	if (!fixfdt)
-		return -EINVAL;
-
 	free(fdt);
 
-	data->oftree = fixfdt;
-
 	return 0;
 }
 #endif
@@ -408,10 +398,14 @@ static int do_bootm(int argc, char *argv[])
 		if (ret)
 			goto err_out;
 	} else {
-		data.oftree = of_get_fixed_tree(NULL);
-		if (bootm_verbose(&data) && data.oftree)
+		data.of_root_node = of_get_root_node();
+		if (bootm_verbose(&data) && data.of_root_node)
 			printf("using internal devicetree\n");
 	}
+
+
+	if (bootm_verbose(&data) > 1 && data.of_root_node)
+		of_print_nodes(data.of_root_node, 0);
 #endif
 	if (data.os_address == UIMAGE_SOME_ADDRESS)
 		data.os_address = UIMAGE_INVALID_ADDRESS;
diff --git a/include/boot.h b/include/boot.h
index 3ce0de1..971a403 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -41,6 +41,7 @@ struct image_data {
 
 	unsigned long initrd_address;
 
+	struct device_node *of_root_node;
 	struct fdt_header *oftree;
 
 	int verify;
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 35/37] ARM bootm: Switch initrd support to unflattened tree
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (33 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 34/37] bootm: Pass unflattened devicetree to handlers Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 36/37] of: remove unused libfdt Sascha Hauer
  2013-03-04  9:53 ` [PATCH 37/37] of: make locally used functions static Sascha Hauer
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/armlinux.c |    2 --
 arch/arm/lib/bootm.c    |   11 +++++++-
 common/oftree.c         |   66 -----------------------------------------------
 3 files changed, 10 insertions(+), 69 deletions(-)

diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index 4dd84ed..40a63ea 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -266,8 +266,6 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
 
 	if (oftree) {
 		printf("booting Linux kernel with devicetree\n");
-		fdt_initrd(oftree, initrd_address,
-			initrd_address + initrd_size, 1);
 		params = oftree;
 	} else {
 		setup_tags(initrd_address, initrd_size, swap);
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 00c4908..4decee4 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -26,7 +26,7 @@
 static int __do_bootm_linux(struct image_data *data, int swap)
 {
 	unsigned long kernel;
-	unsigned long initrd_start = 0, initrd_size = 0;
+	unsigned long initrd_start = 0, initrd_size = 0, initrd_end = 0;
 	struct memory_bank *bank;
 	unsigned long load_address;
 
@@ -82,9 +82,18 @@ static int __do_bootm_linux(struct image_data *data, int swap)
 
 	if (data->initrd_res) {
 		initrd_start = data->initrd_res->start;
+		initrd_end = data->initrd_res->end;
 		initrd_size = resource_size(data->initrd_res);
 	}
 
+	if (IS_ENABLED(CONFIG_OFTREE) && data->of_root_node) {
+		of_add_initrd(data->of_root_node, initrd_start, initrd_end);
+		if (initrd_end)
+			of_add_reserve_entry(initrd_start, initrd_end);
+		data->oftree = of_get_fixed_tree(data->of_root_node);
+		fdt_add_reserve_map(data->oftree);
+	}
+
 	if (bootm_verbose(data)) {
 		printf("\nStarting kernel at 0x%08lx", kernel);
 		if (initrd_size)
diff --git a/common/oftree.c b/common/oftree.c
index 44ffade..e6c82d6 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -273,72 +273,6 @@ int fdt_get_path_or_create(struct fdt_header *fdt, const char *path)
 	return nodeoffset;
 }
 
-int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
-{
-	int nodeoffset;
-	int err, j, total;
-	u32 tmp;
-	const char *path;
-	uint64_t addr, size;
-
-	/* Find the "chosen" node */
-	nodeoffset = fdt_path_offset(fdt, "/chosen");
-
-	/* If there is no "chosen" node in the blob return */
-	if (nodeoffset < 0) {
-		printf("fdt_initrd: %s\n", fdt_strerror(nodeoffset));
-		return nodeoffset;
-	}
-
-	/* just return if initrd_start/end aren't valid */
-	if ((initrd_start == 0) || (initrd_end == 0))
-		return 0;
-
-	total = fdt_num_mem_rsv(fdt);
-
-	/*
-	 * Look for an existing entry and update it. If we don't find
-	 * the entry, we will j be the next available slot.
-	 */
-	for (j = 0; j < total; j++) {
-		err = fdt_get_mem_rsv(fdt, j, &addr, &size);
-		if (addr == initrd_start) {
-			fdt_del_mem_rsv(fdt, j);
-			break;
-		}
-	}
-
-	err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start);
-	if (err < 0) {
-		printf("fdt_initrd: %s\n", fdt_strerror(err));
-		return err;
-	}
-
-	path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
-	if (!path || force) {
-		tmp = __cpu_to_be32(initrd_start);
-		err = fdt_setprop(fdt, nodeoffset,
-			"linux,initrd-start", &tmp, sizeof(tmp));
-		if (err < 0) {
-			printf("WARNING: "
-				"could not set linux,initrd-start %s.\n",
-				fdt_strerror(err));
-			return err;
-		}
-		tmp = __cpu_to_be32(initrd_end);
-		err = fdt_setprop(fdt, nodeoffset,
-			"linux,initrd-end", &tmp, sizeof(tmp));
-		if (err < 0) {
-			printf("WARNING: could not set linux,initrd-end %s.\n",
-				fdt_strerror(err));
-
-			return err;
-		}
-	}
-
-	return 0;
-}
-
 static int of_fixup_bootargs(struct device_node *root)
 {
 	struct device_node *node;
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 36/37] of: remove unused libfdt
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (34 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 35/37] ARM bootm: Switch initrd support to unflattened tree Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  2013-03-04  9:53 ` [PATCH 37/37] of: make locally used functions static Sascha Hauer
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/at91sam9m10ihd/hw_version.c |    1 -
 arch/arm/boards/at91sam9x5ek/hw_version.c   |    1 -
 arch/arm/boards/highbank/init.c             |    3 +-
 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                             |  175 ----
 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                                |   24 -
 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 ---
 29 files changed, 15 insertions(+), 3305 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

diff --git a/arch/arm/boards/at91sam9m10ihd/hw_version.c b/arch/arm/boards/at91sam9m10ihd/hw_version.c
index cd522f7..be910df 100644
--- a/arch/arm/boards/at91sam9m10ihd/hw_version.c
+++ b/arch/arm/boards/at91sam9m10ihd/hw_version.c
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 2695faa..76d4e1b 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index bd32c1d..d4a5c5a 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -16,7 +16,6 @@
 #include <partition.h>
 #include <sizes.h>
 #include <io.h>
-#include <libfdt.h>
 #include <of.h>
 
 #define FIRMWARE_DTB_BASE	0x1000
@@ -124,7 +123,7 @@ static int highbank_devices_init(void)
 		highbank_register_xgmac(1);
 	} else {
 		fdt = of_get_fixed_tree(NULL);
-		add_mem_device("dtb", (unsigned long)fdt, fdt_totalsize(fdt),
+		add_mem_device("dtb", (unsigned long)fdt, be32_to_cpu(fdt->totalsize),
 		       IORESOURCE_MEM_WRITEABLE);
 		devfs_add_partition("ram0", FIRMWARE_DTB_BASE, SZ_64K, DEVFS_PARTITION_FIXED, "firmware-dtb");
 	}
diff --git a/arch/arm/boards/sama5d3xek/hw_version.c b/arch/arm/boards/sama5d3xek/hw_version.c
index a9fcf7d..79fd63a 100644
--- a/arch/arm/boards/sama5d3xek/hw_version.c
+++ b/arch/arm/boards/sama5d3xek/hw_version.c
@@ -20,7 +20,6 @@
 #include <libbb.h>
 #include <asm/armlinux.h>
 #include <of.h>
-#include <libfdt.h>
 
 #include "hw_version.h"
 
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 4decee4..e7a0625 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -14,7 +14,6 @@
 #include <sizes.h>
 #include <libbb.h>
 #include <magicvar.h>
-#include <libfdt.h>
 #include <binfmt.h>
 
 #include <asm/byteorder.h>
diff --git a/commands/bootm.c b/commands/bootm.c
index ea5a35b..e5dfc6a 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -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>
diff --git a/commands/of_node.c b/commands/of_node.c
index 171ea2c..0249d97 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -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>
diff --git a/commands/of_property.c b/commands/of_property.c
index 1567a0f..6311b70 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -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>
diff --git a/commands/oftree.c b/commands/oftree.c
index e4f52b8..468235a 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -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;
 	}
diff --git a/common/memory.c b/common/memory.c
index 61cca0d..7ec211b 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -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>
diff --git a/common/oftree.c b/common/oftree.c
index e6c82d6..776d301 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -5,7 +5,6 @@
 #include <command.h>
 #include <fs.h>
 #include <malloc.h>
-#include <libfdt.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
@@ -99,180 +98,6 @@ void of_print_property(const void *data, int len)
 	}
 }
 
-static void printf_indent(int level, const char *fmt, ...)
-{
-	va_list args;
-
-	printf("%*s", level * 8, "");
-
-	va_start (args, fmt);
-	vprintf(fmt, args);
-	va_end (args);
-}
-
-int fdt_print(struct fdt_header *working_fdt, const char *pathp)
-{
-	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 */
-	int  level = 0;		/* keep track of nesting level */
-	const struct fdt_property *fdt_prop;
-
-	nodeoffset = fdt_path_offset(working_fdt, pathp);
-	if (nodeoffset < 0) {
-		/*
-		 * Not found or something else bad happened.
-		 */
-		printf("libfdt fdt_path_offset() returned %s\n",
-			fdt_strerror(nodeoffset));
-		return 1;
-	}
-
-	while (level >= 0) {
-		tag = fdt_next_tag(working_fdt, nodeoffset, &nextoffset);
-		switch (tag) {
-		case FDT_BEGIN_NODE:
-			pathp = fdt_get_name(working_fdt, nodeoffset, NULL);
-			if (pathp == NULL)
-				pathp = "/* NULL pointer error */";
-			if (*pathp == '\0')
-				pathp = "/";	/* root is nameless */
-			printf_indent(level, "%s {\n",pathp);
-			level++;
-			if (level >= MAX_LEVEL) {
-				printf("Nested too deep, aborting.\n");
-				return 1;
-			}
-			break;
-		case FDT_END_NODE:
-			level--;
-			printf_indent(level, "};\n");
-			if (level == 0) {
-				level = -1;		/* exit the loop */
-			}
-			break;
-		case FDT_PROP:
-			fdt_prop = fdt_offset_ptr(working_fdt, nodeoffset,
-					sizeof(*fdt_prop));
-			pathp    = fdt_string(working_fdt,
-					fdt32_to_cpu(fdt_prop->nameoff));
-			len      = fdt32_to_cpu(fdt_prop->len);
-			nodep    = fdt_prop->data;
-			if (len < 0) {
-				printf("libfdt fdt_getprop(): %s\n",
-					fdt_strerror(len));
-				return 1;
-			} else if (len == 0) {
-				/* the property has no value */
-				printf_indent(level, "%s;\n", pathp);
-			} else {
-				printf_indent(level, "%s = ", pathp);
-				of_print_property(nodep, len);
-				printf(";\n");
-			}
-			break;
-		case FDT_NOP:
-			printf_indent(level, "/* NOP */\n");
-			break;
-		case FDT_END:
-			return 1;
-		default:
-			printf("Unknown tag 0x%08X\n", tag);
-			return 1;
-		}
-		nodeoffset = nextoffset;
-	}
-	return 0;
-}
-
-/**
- * fdt_find_and_setprop: Find a node and set it's property
- *
- * @fdt: ptr to device tree
- * @node: path of node
- * @prop: property name
- * @val: ptr to new value
- * @len: length of new property value
- * @create: flag to create the property if it doesn't exist
- *
- * Convenience function to directly set a property given the path to the node.
- */
-int fdt_find_and_setprop(struct fdt_header *fdt, const char *node,
-		const char *prop, const void *val, int len, int create)
-{
-	int nodeoff = fdt_path_offset(fdt, node);
-
-	if (nodeoff < 0)
-		return nodeoff;
-
-	if ((!create) && (fdt_get_property(fdt, nodeoff, prop, NULL) == NULL))
-		return 0; /* create flag not set; so exit quietly */
-
-	return fdt_setprop(fdt, nodeoff, prop, val, len);
-}
-
-void do_fixup_by_path(struct fdt_header *fdt, const char *path,
-		const char *prop, const void *val, int len, int create)
-{
-	int rc = fdt_find_and_setprop(fdt, path, prop, val, len, create);
-	if (rc)
-		printf("Unable to update property %s:%s, err=%s\n",
-			path, prop, fdt_strerror(rc));
-}
-
-void do_fixup_by_path_u32(struct fdt_header *fdt, const char *path,
-		const char *prop, u32 val, int create)
-{
-	val = cpu_to_fdt32(val);
-	do_fixup_by_path(fdt, path, prop, &val, sizeof(val), create);
-}
-
-void do_fixup_by_compatible(struct fdt_header *fdt, const char *compatible,
-			const char *prop, const void *val, int len, int create)
-{
-	int off = -1;
-
-	off = fdt_node_offset_by_compatible(fdt, -1, compatible);
-	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, compatible);
-	}
-}
-
-void do_fixup_by_compatible_u32(struct fdt_header *fdt, const char *compatible,
-				const char *prop, u32 val, int create)
-{
-	val = cpu_to_fdt32(val);
-	do_fixup_by_compatible(fdt, compatible, prop, &val, 4, create);
-}
-
-void do_fixup_by_compatible_string(struct fdt_header *fdt, const char *compatible,
-				const char *prop, const char *val, int create)
-{
-	do_fixup_by_compatible(fdt, compatible, prop, val, strlen(val) + 1,
-				create);
-}
-
-int fdt_get_path_or_create(struct fdt_header *fdt, const char *path)
-{
-	int nodeoffset;
-
-	nodeoffset = fdt_path_offset (fdt, path);
-	if (nodeoffset < 0) {
-		nodeoffset = fdt_add_subnode(fdt, 0, path + 1);
-		if (nodeoffset < 0) {
-			printf("WARNING: could not create %s %s.\n",
-					path, fdt_strerror(nodeoffset));
-                        return -EINVAL;
-                }
-        }
-
-	return nodeoffset;
-}
-
 static int of_fixup_bootargs(struct device_node *root)
 {
 	struct device_node *node;
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index c30b1c1..031bec1 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -1,5 +1,4 @@
 config OFTREE
-	select FDT
 	bool
 
 config OFDEVICE
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 5891138..ada3fc1 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -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>
diff --git a/drivers/of/dtb.c b/drivers/of/dtb.c
index 856b591..6d6b76d 100644
--- a/drivers/of/dtb.c
+++ b/drivers/of/dtb.c
@@ -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>
diff --git a/include/fdt.h b/include/fdt.h
index 48ccfd9..35278e3 100644
--- a/include/fdt.h
+++ b/include/fdt.h
@@ -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 */
diff --git a/include/libfdt.h b/include/libfdt.h
deleted file mode 100644
index 55f3eb3..0000000
diff --git a/include/libfdt_env.h b/include/libfdt_env.h
deleted file mode 100644
index 6486187..0000000
diff --git a/include/of.h b/include/of.h
index 1535694..c10afa7 100644
--- a/include/of.h
+++ b/include/of.h
@@ -5,30 +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);
-void do_fixup_by_compatible(struct fdt_header *fdt, const char *compatible,
-			const char *prop, const void *val, int len, int create);
-void do_fixup_by_compatible_u32(struct fdt_header *fdt, const char *compatible,
-				const char *prop, u32 val, int create);
-void do_fixup_by_compatible_string(struct fdt_header *fdt, const char *compatible,
-				const char *prop, const char *val, int create);
-int fdt_get_path_or_create(struct fdt_header *fdt, const char *path);
-#ifdef CONFIG_FDT
-int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
-#else
-static inline int fdt_initrd(void *fdt, ulong start, ulong end, int force)
-{
-	return 0;
-}
-#endif
-
 #define OF_BAD_ADDR      ((u64)-1)
 
 typedef u32 phandle;
diff --git a/lib/Kconfig b/lib/Kconfig
index d58109b..646fdb7 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -22,9 +22,6 @@ config PROCESS_ESCAPE_SEQUENCE
 
 source lib/lzo/Kconfig
 
-config FDT
-	bool
-
 config BCH
 	bool
 
diff --git a/lib/Makefile b/lib/Makefile
index 3c94542..7c42537 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -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
diff --git a/lib/fdt/Makefile b/lib/fdt/Makefile
deleted file mode 100644
index 853bee9..0000000
diff --git a/lib/fdt/TODO b/lib/fdt/TODO
deleted file mode 100644
index 288437e..0000000
diff --git a/lib/fdt/fdt.c b/lib/fdt/fdt.c
deleted file mode 100644
index e56833a..0000000
diff --git a/lib/fdt/fdt_ro.c b/lib/fdt/fdt_ro.c
deleted file mode 100644
index 02b6d68..0000000
diff --git a/lib/fdt/fdt_rw.c b/lib/fdt/fdt_rw.c
deleted file mode 100644
index 994037b..0000000
diff --git a/lib/fdt/fdt_strerror.c b/lib/fdt/fdt_strerror.c
deleted file mode 100644
index e6c3cee..0000000
diff --git a/lib/fdt/fdt_sw.c b/lib/fdt/fdt_sw.c
deleted file mode 100644
index 55ebebf..0000000
diff --git a/lib/fdt/fdt_wip.c b/lib/fdt/fdt_wip.c
deleted file mode 100644
index 6025fa1..0000000
diff --git a/lib/fdt/libfdt_internal.h b/lib/fdt/libfdt_internal.h
deleted file mode 100644
index 381133b..0000000
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 37/37] of: make locally used functions static
  2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
                   ` (35 preceding siblings ...)
  2013-03-04  9:53 ` [PATCH 36/37] of: remove unused libfdt Sascha Hauer
@ 2013-03-04  9:53 ` Sascha Hauer
  36 siblings, 0 replies; 39+ messages in thread
From: Sascha Hauer @ 2013-03-04  9:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c |    6 +++---
 include/of.h      |    2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ada3fc1..d22031f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -96,7 +96,7 @@ static void of_bus_default_count_cells(struct device_node *dev,
 		*sizec = of_n_size_cells(dev);
 }
 
-void of_bus_count_cells(struct device_node *dev,
+static void of_bus_count_cells(struct device_node *dev,
 			int *addrc, int *sizec)
 {
 	of_bus_default_count_cells(dev, addrc, sizec);
@@ -135,7 +135,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
  * the global lookup table with the properties.  It returns the
  * number of alias_prop found, or error code in error case.
  */
-void of_alias_scan(void)
+static void of_alias_scan(void)
 {
 	struct property *pp;
 	struct alias_prop *app, *tmp;
@@ -814,7 +814,7 @@ static struct device_d *add_of_device(struct device_node *node)
 }
 EXPORT_SYMBOL(add_of_device);
 
-u64 dt_mem_next_cell(int s, const __be32 **cellp)
+static u64 dt_mem_next_cell(int s, const __be32 **cellp)
 {
 	const __be32 *p = *cellp;
 
diff --git a/include/of.h b/include/of.h
index c10afa7..94ccfd8 100644
--- a/include/of.h
+++ b/include/of.h
@@ -143,6 +143,8 @@ int of_device_is_compatible(const struct device_node *device,
 
 int of_machine_is_compatible(const char *compat);
 
+u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
+
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 13/37] of: Add initrd helper
  2013-03-04  9:53 ` [PATCH 13/37] of: Add initrd helper Sascha Hauer
@ 2013-03-04 12:01   ` Alexander Aring
  0 siblings, 0 replies; 39+ messages in thread
From: Alexander Aring @ 2013-03-04 12:01 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi Sascha,

On Mon, Mar 04, 2013 at 10:53:16AM +0100, Sascha Hauer wrote:
> Add a helper to set the initrd properties in the unflattened tree.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/of/base.c |   39 +++++++++++++++++++++++++++++++++++++++
>  include/of.h      |    3 +++
>  2 files changed, 42 insertions(+)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 721db29..4dbe11e 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1201,3 +1201,42 @@ int of_device_is_stdout_path(struct device_d *dev)
>  
>  	return 0;
>  }
> +
> +/**
> + * of_add_initrd - add initrd properties to the devicetree
> + * @root - the root node of the tree
> + * @start - physical start address of the initrd image
> + * @end - physical end address of the initrd image
> + *
> + * Add initrd properties to the devicetree, or, if end is 0,
> + * delete them.
> + */
> +int of_add_initrd(struct device_node *root, resource_size_t start,
> +		resource_size_t end)
> +{
> +	struct device_node *chosen;
> +	__be32 buf[2];
> +
> +	chosen = of_find_node_by_path(root, "/chosen");
> +	if (!chosen)
> +		return -EINVAL;
> +
> +	if (end) {

Perhaps it's better here to check on (start && end) instead of end
address only.

Similar in "[PATCH 35/37] ARM bootm: Switch initrd support to unflattened
tree" at "of_add_reserve_entry(initrd_start, initrd_end);".

Regards
Alex

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2013-03-04 12:03 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-04  9:53 [PATCH v2] remove libfdt Sascha Hauer
2013-03-04  9:53 ` [PATCH 01/37] of: unflatten: allocate root node explicitly Sascha Hauer
2013-03-04  9:53 ` [PATCH 02/37] of: export of_find_child Sascha Hauer
2013-03-04  9:53 ` [PATCH 03/37] of: removed unused variables Sascha Hauer
2013-03-04  9:53 ` [PATCH 04/37] of: Let of_find_node_by_path iterate over tree Sascha Hauer
2013-03-04  9:53 ` [PATCH 05/37] of: remove allnodes list Sascha Hauer
2013-03-04  9:53 ` [PATCH 06/37] ARM bootm: Use of_get_fixed_tree Sascha Hauer
2013-03-04  9:53 ` [PATCH 07/37] of: Add of_set_property and of_create_node Sascha Hauer
2013-03-04  9:53 ` [PATCH 08/37] of_node command: use of_create_node Sascha Hauer
2013-03-04  9:53 ` [PATCH 09/37] of: Add missing prototype for of_device_is_compatible Sascha Hauer
2013-03-04  9:53 ` [PATCH 10/37] of: let of_unflatten_dtb return the unflattened tree Sascha Hauer
2013-03-04  9:53 ` [PATCH 11/37] of: Add root node argument to of_find_node_by_path Sascha Hauer
2013-03-04  9:53 ` [PATCH 12/37] of: Add of_write_number helper Sascha Hauer
2013-03-04  9:53 ` [PATCH 13/37] of: Add initrd helper Sascha Hauer
2013-03-04 12:01   ` Alexander Aring
2013-03-04  9:53 ` [PATCH 14/37] of: make unflatten independent of libfdt Sascha Hauer
2013-03-04  9:53 ` [PATCH 15/37] of: make flatten " Sascha Hauer
2013-03-04  9:53 ` [PATCH 16/37] of/fdt: use optimized endianess conversion Sascha Hauer
2013-03-04  9:53 ` [PATCH 17/37] oftree command: Use of_print_nodes Sascha Hauer
2013-03-04  9:53 ` [PATCH 18/37] of: move OFTREE Kconfig option to drivers/of/ Sascha Hauer
2013-03-04  9:53 ` [PATCH 19/37] of: make OFDEVICE a user selectable option Sascha Hauer
2013-03-04  9:53 ` [PATCH 20/37] oftree command: retire CMD_OFTREE_PROBE Kconfig option Sascha Hauer
2013-03-04  9:53 ` [PATCH 21/37] of: move oftree Kconfig to the top of the drivers menu Sascha Hauer
2013-03-04  9:53 ` [PATCH 22/37] of: Pass barebox internal format devicetree to of_get_fixed_tree Sascha Hauer
2013-03-04  9:53 ` [PATCH 23/37] bootm: Use of_print_nodes instead of fdt_print Sascha Hauer
2013-03-04  9:53 ` [PATCH 24/37] of: move flat devicetree functions to separate file Sascha Hauer
2013-03-04  9:53 ` [PATCH 25/37] of: Add of property write functions for u32 Sascha Hauer
2013-03-04  9:53 ` [PATCH 26/37] of: make value of property in of_new_property optional Sascha Hauer
2013-03-04  9:53 ` [PATCH 27/37] of: Add missing prototype for size/address counting functions Sascha Hauer
2013-03-04  9:53 ` [PATCH 28/37] of: fixup unflattened devicetree Sascha Hauer
2013-03-04  9:53 ` [PATCH 29/37] of_* commands: print usage when insufficient arguments are given Sascha Hauer
2013-03-04  9:53 ` [PATCH 30/37] of_property command: Fix crash with empty property value Sascha Hauer
2013-03-04  9:53 ` [PATCH 31/37] ARM: bootm: rework concatenated oftree Sascha Hauer
2013-03-04  9:53 ` [PATCH 32/37] of: memory: Use of_write_number Sascha Hauer
2013-03-04  9:53 ` [PATCH 33/37] of: Add reservemap handling Sascha Hauer
2013-03-04  9:53 ` [PATCH 34/37] bootm: Pass unflattened devicetree to handlers Sascha Hauer
2013-03-04  9:53 ` [PATCH 35/37] ARM bootm: Switch initrd support to unflattened tree Sascha Hauer
2013-03-04  9:53 ` [PATCH 36/37] of: remove unused libfdt Sascha Hauer
2013-03-04  9:53 ` [PATCH 37/37] of: make locally used functions static Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox