Skip to contentSkip to conversation

arm: boards: support native fdt for raspberry pi

PATCH In review Pascal Vizeli 2 participants 3 messages Jun 8, 2018 – Jun 11, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: boards: support native fdt for raspberry pi

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?

---
 arch/arm/boards/raspberry-pi/lowlevel.c   |  4 +++
 arch/arm/boards/raspberry-pi/rpi-common.c | 40 +++++++++++++++++++++++
 2 files changed, 44 insertions(+)
arch/arm/boards/raspberry-pi/lowlevel.c +4 -0
index cbc6caa4b..07d6f1101 100644
@@ -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();
 
arch/arm/boards/raspberry-pi/rpi-common.c +40 -0
index 6e375bc98..43326e55d 100644
@@ -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);
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

That is a RFC, the command --subject-prefix="RFC" had not work...

2018-06-08 9:41 GMT+02:00 Pascal Vizeli <[email protected]>:

Quoted 112 lines

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?

---
 arch/arm/boards/raspberry-pi/lowlevel.c   |  4 +++
 arch/arm/boards/raspberry-pi/rpi-common.c | 40 +++++++++++++++++++++++
 2 files changed, 44 insertions(+)
arch/arm/boards/raspberry-pi/lowlevel.c +4 -0
index cbc6caa4b..07d6f1101 100644
@@ -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();
 
arch/arm/boards/raspberry-pi/rpi-common.c +40 -1
index 6e375bc98..43326e55d 100644
@@ -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);
--
Quoted 2 lines

2.17.1

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw
In reply to Pascal Vizeli
Quoted 9 lines · 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?

See other mail I just sent you.

Quoted 9 lines
arch/arm/boards/raspberry-pi/rpi-common.c +9 -0
+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);

arch/arm/boards/raspberry-pi/rpi-common.c static int rpi_env_init(void) · line 346

Quoted 10 lines
arch/arm/boards/raspberry-pi/rpi-common.c +10 -0
+	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;
+	}

No need to open/memmap /dev/mem. Just dereference the memory location.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox