mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/1] arm: boards: support native fdt for raspberry pi
@ 2018-06-08  7:41 Pascal Vizeli
  2018-06-08  7:47 ` Pascal Vizeli
  2018-06-11  6:34 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Pascal Vizeli @ 2018-06-08  7:41 UTC (permalink / raw)
  To: barebox; +Cc: Pascal Vizeli

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

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

end of thread, other threads:[~2018-06-11  6:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08  7:41 [PATCH 1/1] arm: boards: support native fdt for raspberry pi Pascal Vizeli
2018-06-08  7:47 ` Pascal Vizeli
2018-06-11  6:34 ` Sascha Hauer

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