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] arm: boards: support native fdt for raspberry pi
Date: Fri,  8 Jun 2018 07:41:33 +0000	[thread overview]
Message-ID: <20180608074133.30653-1-pvizeli@syshack.ch> (raw)

It store the native device tree from bootloader to '/rpi_native.dtb'.
This device tree is not compatible with barebox but needed to boot the
linux kernel correctly. With new overlay support we can patch this
device tree on runtime.

Now barebox can be the middle bootloader and we have no limitations to
origin bootloader.

Question: How I can share a address between PBL and barebox?

Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch>
---
 arch/arm/boards/raspberry-pi/lowlevel.c   |  4 +++
 arch/arm/boards/raspberry-pi/rpi-common.c | 40 +++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/arch/arm/boards/raspberry-pi/lowlevel.c b/arch/arm/boards/raspberry-pi/lowlevel.c
index cbc6caa4b..07d6f1101 100644
--- a/arch/arm/boards/raspberry-pi/lowlevel.c
+++ b/arch/arm/boards/raspberry-pi/lowlevel.c
@@ -4,10 +4,13 @@
 #include <asm/barebox-arm-head.h>
 #include <mach/platform.h>
 
+extern uint32_t rpi_fdt_addr;
+
 extern char __dtb_bcm2835_rpi_start[];
 ENTRY_FUNCTION(start_raspberry_pi1, r0, r1, r2)
 {
 	void *fdt = __dtb_bcm2835_rpi_start + get_runtime_offset();
+	rpi_fdt_addr = r2;
 
 	arm_cpu_lowlevel_init();
 
@@ -18,6 +21,7 @@ extern char __dtb_bcm2836_rpi_2_start[];
 ENTRY_FUNCTION(start_raspberry_pi2, r0, r1, r2)
 {
 	void *fdt = __dtb_bcm2836_rpi_2_start + get_runtime_offset();
+	rpi_fdt_addr = r2;
 
 	arm_cpu_lowlevel_init();
 
diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c
index 6e375bc98..43326e55d 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -16,11 +16,13 @@
 #include <common.h>
 #include <init.h>
 #include <fs.h>
+#include <of.h>
 #include <linux/stat.h>
 #include <linux/clk.h>
 #include <linux/clkdev.h>
 #include <envfs.h>
 #include <malloc.h>
+#include <libfile.h>
 #include <gpio.h>
 #include <net.h>
 #include <led.h>
@@ -321,12 +323,50 @@ static int rpi_env_init(void)
 	return 0;
 }
 
+uint32_t rpi_fdt_addr;
+
+static int rpi_native_fdt(void)
+{
+	struct fdt_header *oftree;
+	int mode = O_RWSIZE_4 | O_RDONLY;
+	int fd = 0;
+	uint32_t size;
+	void *map;
+
+	fd = open_and_lseek("/dev/mem", mode, rpi_fdt_addr);
+	if (fd < 0) {
+		printf("failed open /dev/mem for fdt");
+		goto end;
+	}
+
+	map = memmap(fd, PROT_READ);
+	if (map == (void *)-1) {
+		printf("failed map memory for fdt");
+		goto end;
+	}
+
+	oftree = map;
+	size = be32_to_cpu(oftree->totalsize);
+	if (!size) {
+		printf("failed read fdt");
+		goto end;
+	}
+
+	if (!write_file("/rpi_native.dtb", map, size))
+		printf("Failed to write rpi_native.dtb");
+
+end:
+	close(fd);
+	return 0;
+}
+
 static int rpi_devices_init(void)
 {
 	rpi_model_init();
 	bcm2835_register_fb();
 	armlinux_set_architecture(MACH_TYPE_BCM2708);
 	rpi_env_init();
+	rpi_native_fdt();
 	return 0;
 }
 late_initcall(rpi_devices_init);
-- 
2.17.1


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

             reply	other threads:[~2018-06-08  7:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08  7:41 Pascal Vizeli [this message]
2018-06-08  7:47 ` Pascal Vizeli
2018-06-11  6:34 ` 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=20180608074133.30653-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