mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Add devicetree flatten support
@ 2013-01-09  9:41 Sascha Hauer
  2013-01-09  9:41 ` [PATCH 1/2] of: rename of_parse_dtb to of_unflatten_dtb Sascha Hauer
  2013-01-09  9:41 ` [PATCH 2/2] of: Add support for converting the unflattened tree back to a dtb Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-01-09  9:41 UTC (permalink / raw)
  To: barebox

barebox has its own internal format for the devicetree. If we want to
start a kernel with this tree we have to convert it back to dtb. This
series adds support for it. This is purely for future work as no user
for this code is added currently.

Sascha

----------------------------------------------------------------
Sascha Hauer (2):
      of: rename of_parse_dtb to of_unflatten_dtb
      of: Add support for converting the unflattened tree back to a dtb

 commands/oftree.c |    2 +-
 drivers/of/base.c |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 include/of.h      |    3 ++-
 3 files changed, 65 insertions(+), 3 deletions(-)

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

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

* [PATCH 1/2] of: rename of_parse_dtb to of_unflatten_dtb
  2013-01-09  9:41 [PATCH] Add devicetree flatten support Sascha Hauer
@ 2013-01-09  9:41 ` Sascha Hauer
  2013-01-09  9:41 ` [PATCH 2/2] of: Add support for converting the unflattened tree back to a dtb Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-01-09  9:41 UTC (permalink / raw)
  To: barebox

The process of unflatten the device tree is known from the kernel,
so rename the function, because that's what it does.

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

diff --git a/commands/oftree.c b/commands/oftree.c
index 7404db5..b9d3c7b 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -108,7 +108,7 @@ static int do_oftree(int argc, char *argv[])
 			return 1;
 		}
 
-		ret = of_parse_dtb(fdt);
+		ret = of_unflatten_dtb(fdt);
 		if (ret) {
 			printf("parse oftree: %s\n", strerror(-ret));
 			return 1;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7a41618..3c00fa5 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -816,7 +816,7 @@ int of_probe(void)
  * Parse a flat device tree binary blob and store it in the barebox
  * internal tree format,
  */
-int of_parse_dtb(struct fdt_header *fdt)
+int of_unflatten_dtb(struct fdt_header *fdt)
 {
 	const void *nodep;	/* property node pointer */
 	int  nodeoffset;	/* node offset from libfdt */
diff --git a/include/of.h b/include/of.h
index 58b4590..6b562bd 100644
--- a/include/of.h
+++ b/include/of.h
@@ -106,7 +106,7 @@ int of_machine_is_compatible(const char *compat);
 
 void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
-int of_parse_dtb(struct fdt_header *fdt);
+int of_unflatten_dtb(struct fdt_header *fdt);
 
 int of_property_read_string(struct device_node *np, const char *propname,
 				const char **out_string);
-- 
1.7.10.4


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

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

* [PATCH 2/2] of: Add support for converting the unflattened tree back to a dtb
  2013-01-09  9:41 [PATCH] Add devicetree flatten support Sascha Hauer
  2013-01-09  9:41 ` [PATCH 1/2] of: rename of_parse_dtb to of_unflatten_dtb Sascha Hauer
@ 2013-01-09  9:41 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-01-09  9:41 UTC (permalink / raw)
  To: barebox

We already have support for unflattening the devicetree. This patch
adds support for converting it back to a dtb.

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

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3c00fa5..b584cf2 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -24,6 +24,7 @@
 #include <malloc.h>
 #include <init.h>
 #include <memory.h>
+#include <sizes.h>
 #include <linux/ctype.h>
 
 /**
@@ -892,6 +893,66 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 	return 0;
 }
 
+static int __of_flatten_dtb(void *fdt, struct device_node *node)
+{
+	struct property *p;
+	struct device_node *n;
+	int ret;
+
+	ret = fdt_begin_node(fdt, node->name);
+	if (ret)
+		return ret;
+
+	list_for_each_entry(p, &node->properties, list) {
+		ret = fdt_property(fdt, p->name, p->value, p->length);
+		if (ret)
+			return ret;
+	}
+
+	list_for_each_entry(n, &node->children, parent_list) {
+		ret = __of_flatten_dtb(fdt, n);
+		if (ret)
+			return ret;
+	}
+
+	ret = fdt_end_node(fdt);
+
+	return ret;
+}
+
+#define DTB_SIZE	SZ_128K
+
+void *of_flatten_dtb(void)
+{
+	void *fdt;
+	int ret;
+
+	fdt = malloc(DTB_SIZE);
+	if (!fdt)
+		return NULL;
+
+	ret = fdt_create(fdt, DTB_SIZE);
+	if (ret)
+		goto out_free;
+
+	ret = fdt_finish_reservemap(fdt);
+	if (ret)
+		goto out_free;
+
+	ret = __of_flatten_dtb(fdt, root_node);
+	if (ret)
+		goto out_free;
+
+	fdt_finish(fdt);
+
+	return fdt;
+
+out_free:
+	free(fdt);
+
+	return NULL;
+}
+
 int of_device_is_stdout_path(struct device_d *dev)
 {
 	struct device_node *dn;
diff --git a/include/of.h b/include/of.h
index 6b562bd..303e036 100644
--- a/include/of.h
+++ b/include/of.h
@@ -107,6 +107,7 @@ int of_machine_is_compatible(const char *compat);
 void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_unflatten_dtb(struct fdt_header *fdt);
+void *of_flatten_dtb(void);
 
 int of_property_read_string(struct device_node *np, const char *propname,
 				const char **out_string);
-- 
1.7.10.4


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

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

end of thread, other threads:[~2013-01-09  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-09  9:41 [PATCH] Add devicetree flatten support Sascha Hauer
2013-01-09  9:41 ` [PATCH 1/2] of: rename of_parse_dtb to of_unflatten_dtb Sascha Hauer
2013-01-09  9:41 ` [PATCH 2/2] of: Add support for converting the unflattened tree back to a dtb Sascha Hauer

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