mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 11/16] of: unflatten: allow overlay dtbs
Date: Fri, 11 Jan 2013 14:24:31 +0100	[thread overview]
Message-ID: <1357910676-4231-12-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1357910676-4231-1-git-send-email-s.hauer@pengutronix.de>

This implements overlaying a currently loaded dtb with another dtb.
We used to return -EBUSY when a oftree is currently loaded. Instead
of doing this, check if a node already exists before creating a new
one. Similarly, if a property already exists, just overwrite the
value instead of creating a new property.

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

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3307f41..527121d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -845,13 +845,11 @@ 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;
+	struct device_node *node = NULL, *n;
+	struct property *p;
 	char buf[1024];
 	int ret;
 
-	if (root_node)
-		return -EBUSY;
-
 	nodeoffset = fdt_path_offset(fdt, "/");
 	if (nodeoffset < 0) {
 		/*
@@ -875,12 +873,17 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 			if (ret)
 				return -EINVAL;
 
-			node = new_device_node(node);
-			if (!node->parent)
-				root_node = node;
-			node->full_name = xstrdup(buf);
-			node->name = xstrdup(pathp);
-			list_add_tail(&node->list, &allnodes);
+			n = of_find_node_by_path(buf);
+			if (n) {
+				node = n;
+			} else {
+				node = new_device_node(node);
+				if (!node->parent)
+					root_node = node;
+				node->full_name = xstrdup(buf);
+				node->name = xstrdup(pathp);
+				list_add_tail(&node->list, &allnodes);
+			}
 			break;
 		case FDT_END_NODE:
 			node = node->parent;
@@ -892,7 +895,15 @@ int of_unflatten_dtb(struct fdt_header *fdt)
 					fdt32_to_cpu(fdt_prop->nameoff));
 			len      = fdt32_to_cpu(fdt_prop->len);
 			nodep    = fdt_prop->data;
-			new_property(node, pathp, nodep, len);
+
+			p = of_find_property(node, pathp);
+			if (p) {
+				free(p->value);
+				p->value = xzalloc(len);
+				memcpy(p->value, nodep, len);
+			} else {
+				new_property(node, pathp, nodep, len);
+			}
 			break;
 		case FDT_NOP:
 			break;
-- 
1.7.10.4


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

  parent reply	other threads:[~2013-01-11 13:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-11 13:24 [PATCH] devicetree improvements Sascha Hauer
2013-01-11 13:24 ` [PATCH 01/16] of: make of_get_fixed_tree more universally usable Sascha Hauer
2013-01-11 13:24 ` [PATCH 02/16] of: Fix invalid path for of_find_node_by_path Sascha Hauer
2013-01-11 13:24 ` [PATCH 03/16] ARM android image: remove double of_fix_tree Sascha Hauer
2013-01-11 13:24 ` [PATCH 04/16] of: of_free fixes Sascha Hauer
2013-01-11 13:24 ` [PATCH 05/16] of of_free: remove old node from allnodes list Sascha Hauer
2013-01-11 13:24 ` [PATCH 06/16] of: return root node when looking for a node with path / Sascha Hauer
2013-01-11 13:24 ` [PATCH 07/16] of: rename of_parse_dtb to of_unflatten_dtb Sascha Hauer
2013-01-11 13:24 ` [PATCH 08/16] of: Add support for converting the unflattened tree back to a dtb Sascha Hauer
2013-01-11 13:24 ` [PATCH 09/16] of: remove unused barebox_fdt Sascha Hauer
2013-01-11 13:24 ` [PATCH 10/16] ARM bootm: only use concatenated oftree when no other is available Sascha Hauer
2013-01-11 13:24 ` Sascha Hauer [this message]
2013-01-11 13:24 ` [PATCH 12/16] oftree command: refactor Sascha Hauer
2013-01-11 13:24 ` [PATCH 13/16] of: add of_delete_property Sascha Hauer
2013-01-11 13:24 ` [PATCH 14/16] of: rename new_device_node to of_new_node and export it Sascha Hauer
2013-01-11 13:24 ` [PATCH 15/16] commands: Add of_property command Sascha Hauer
2013-01-11 13:24 ` [PATCH 16/16] commands: Add of_node command Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357910676-4231-12-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox