mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Pascal Vizeli <pvizeli@syshack.ch>
To: barebox@lists.infradead.org
Cc: Pascal Vizeli <pvizeli@syshack.ch>
Subject: [PATCH 1/1] command: oftree: support load device tree from memory
Date: Wed,  6 Jun 2018 15:16:02 +0000	[thread overview]
Message-ID: <20180606151602.11094-1-pvizeli@syshack.ch> (raw)

DON'T MERGE: this is only a concept patch.

On some device, barebox is the second bootloader. The first bootloader provide
some times allready a better device tree as the linux kernel own.
Mostly barebox can't boot from this device tree but the linux kernel can.

This patch allow to load a device tree from memory from first bootloader.

For implementation:

Not sure what is the best. Maybe we can create a of_unflatten_file_dtb() and
of_unflatten_memory_dtb() they return fdt. There are a lot place they load
a fdt from a file and repeat the same code.

Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch>
---
 commands/oftree.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/commands/oftree.c b/commands/oftree.c
index 8a47c0be5..831b6c280 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -40,9 +40,40 @@
 #include <fcntl.h>
 #include <complete.h>
 
+struct fdt_header* read_memory_dtb(loff_t mem_start)
+{
+	struct fdt_header *oftree = NULL;
+	struct fdt_header *memtree;
+	int mode = O_RWSIZE_4 | O_RDONLY;
+	int fd;
+	uint32_t size;
+	void *map;
+
+	fd = open_and_lseek("/dev/mem", mode,mem_start);
+	if (fd < 0)
+		return NULL;
+
+	map = memmap(fd, PROT_READ);
+	if (map == (void *)-1)
+		goto end;
+	memtree = map;
+
+	size = be32_to_cpu(memtree->totalsize);
+	if (!size)
+		goto end;
+
+	oftree = malloc(size);
+	memcpy((void *)oftree, map, size);
+
+end:
+	close(fd);
+	return oftree;
+}
+
 static int do_oftree(int argc, char *argv[])
 {
 	struct fdt_header *fdt = NULL;
+	loff_t mem_start;
 	size_t size;
 	int opt;
 	int probe = 0;
@@ -102,7 +133,13 @@ static int do_oftree(int argc, char *argv[])
 	}
 
 	if (load) {
-		fdt = read_file(load, &size);
+		if (file_name_detect_type(load) == filetype_oftree) {
+			fdt = read_file(load, &size);
+		} else {
+			mem_start = simple_strtoull(load, NULL, 0);
+			fdt = read_memory_dtb(mem_start);
+		}
+
 		if (!fdt) {
 			printf("unable to read %s\n", load);
 			return 1;
-- 
2.17.1


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

             reply	other threads:[~2018-06-06 15:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-06 15:16 Pascal Vizeli [this message]
2018-06-06 19:57 ` Andrey Smirnov
2018-06-07  7:20 ` Sascha Hauer
2018-06-07  8:29   ` Pascal Vizeli
2018-06-07  8:53     ` Sascha Hauer
2018-06-07 10:42       ` Pascal Vizeli
2018-06-07 12:45         ` Pascal Vizeli

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=20180606151602.11094-1-pvizeli@syshack.ch \
    --to=pvizeli@syshack.ch \
    --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