mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de
Subject: [PATCH 2/2] memory: of_fixup: adapt to new memory layout
Date: Mon, 11 Feb 2019 17:20:13 +0100	[thread overview]
Message-ID: <20190211162013.5320-2-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20190211162013.5320-1-m.felsch@pengutronix.de>

Since kernel 4.16 the memory nodes got a @<reg> suffix so the fixup
won't work correctly anymore, because instead of adapting the extisting
one it creates a new node.

To be compatible with the old and new layout delete the found memory
node and create a new one. The new node follows the new @<reg> style.

The patch also renames the node element to root to make it more clear.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 common/memory.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 00fa7c50ff..5402acab8e 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -224,7 +224,7 @@ int memory_bank_first_find_space(resource_size_t *retstart,
 
 #ifdef CONFIG_OFTREE
 
-static int of_memory_fixup(struct device_node *node, void *unused)
+static int of_memory_fixup(struct device_node *root, void *unused)
 {
 	struct memory_bank *bank;
 	int err;
@@ -232,7 +232,23 @@ static int of_memory_fixup(struct device_node *node, void *unused)
 	struct device_node *memnode;
 	u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
 
-	memnode = of_create_node(node, "/memory");
+	/*
+	 * Since kernel 4.16 the memory node got a @<reg> suffix. To support
+	 * the old and the new style delete any found memory node and add it
+	 * again to be sure that the memory node exists only once. It shouldn't
+	 * bother older kernels if the memory node has this suffix so adding it
+	 * following the new style.
+	 */
+
+	memnode = of_find_node_by_name(root, "memory");
+	if (!memnode)
+		memnode = of_find_node_by_type(root, "memory");
+
+	if (memnode)
+		of_delete_node(memnode);
+
+	/* At this moment we don't know the <reg> val */
+	memnode = of_create_node(root, "/memory");
 	if (!memnode)
 		return -ENOMEM;
 
@@ -256,6 +272,10 @@ static int of_memory_fixup(struct device_node *node, void *unused)
 		return err;
 	}
 
+	/* now adapt the node name */
+	of_rename_node(memnode, basprintf("memory@%llx",
+				 of_read_number((u32 *)tmp, addr_cell_len)));
+
 	return 0;
 }
 
-- 
2.20.1


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

  reply	other threads:[~2019-02-11 16:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11 16:20 [PATCH 1/2] of: base: add helper to rename a node Marco Felsch
2019-02-11 16:20 ` Marco Felsch [this message]
2019-02-12  8:03   ` [PATCH 2/2] memory: of_fixup: adapt to new memory layout Sascha Hauer
2019-02-12  8:45     ` Marco Felsch
2019-02-12  8:56       ` Sascha Hauer
2019-02-12  9:01         ` Marco Felsch
2019-02-12  7:32 ` [PATCH 1/2] of: base: add helper to rename a node Sascha Hauer
2019-02-12  8:49   ` Marco Felsch

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=20190211162013.5320-2-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mfe@pengutronix.de \
    /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