[PATCH v2 07/21] ARM: rpi: add generic Raspberry Pi image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a new image that can be booted on all supported boards. This work by
including DTs for all enabled boards in config and then consulting the
mailbox interface at runtime to deduce which DT to pass to barebox
proper. An alternative would have been to use the existing
barebox-dt-2nd.img with a VideoCore-supplied device tree, but that has
the drawback of requiring barebox to observe the same bindings as the
kernel that's booted later. This approach makes migration
straight-forward, because no difference in VideoCore configuration is
required.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 Documentation/boards/bcm2835.rst              |  8 +-
 arch/arm/boards/raspberry-pi/lowlevel.c       | 87 ++++++++++++++++++-
 arch/arm/mach-bcm283x/include/mach/debug_ll.h |  6 ++
 images/Makefile.bcm283x                       |  4 +
 4 files changed, 99 insertions(+), 6 deletions(-)

diff --git a/Documentation/boards/bcm2835.rst b/Documentation/boards/bcm2835.rst
index 0b5299a34078..a8eed9aec00d 100644
--- a/Documentation/boards/bcm2835.rst
+++ b/Documentation/boards/bcm2835.rst
@@ -15,14 +15,14 @@ Raspberry Pi
      - ``images/barebox-raspberry-pi-2.img`` for the BCM2836/CORTEX-A7 (Raspberry Pi 2)
      - ``images/barebox-raspberry-pi-3.img`` for the BCM2837/CORTEX-A53 (Raspberry Pi 3)
      - ``images/barebox-raspberry-pi-cm3.img`` for the BCM2837/CORTEX-A53 (Raspberry Pi CM3)
+     - ``images/barebox-raspberry-pi.img``, which is a super set of all the other images
 
      Copy the respective image for your model to your SD card and name it
      ``barebox.img``.
 
-     Alternatively, ``images/barebox-dt-2nd.img`` can be used as single bootloader for all
-     supported 32-bit boards. In this case the device tree supplied by the video core
-     is directly used by barebox to probe. The device trees in ``arch/arm/dts/*.dtb``
-     will need to be renamed for alignment with the naming scheme expected by the videocore.
+     The ``images/barebox-raspberry-pi.img`` is expected to replace the other images
+     in the future. It contains the device trees of all supported (and enabled) variants
+     and determines at runtime what board it runs on and does the right thing.
 
   4. Create a text file ``config.txt`` on the SD card with the following content::
 
diff --git a/arch/arm/boards/raspberry-pi/lowlevel.c b/arch/arm/boards/raspberry-pi/lowlevel.c
index 091bfb8f4b14..82b51b5b1594 100644
--- a/arch/arm/boards/raspberry-pi/lowlevel.c
+++ b/arch/arm/boards/raspberry-pi/lowlevel.c
@@ -4,7 +4,10 @@
 #include <asm/cache.h>
 #include <common.h>
 #include <linux/sizes.h>
+#include <asm/unaligned.h>
 #include <mach/platform.h>
+#include <debug_ll.h>
+#include <mach/mbox.h>
 #include <of.h>
 
 #include "lowlevel.h"
@@ -45,8 +48,6 @@ static inline void start_raspberry_pi(unsigned long memsize, void *fdt,
 {
 	unsigned long endmem = rpi_stack_top(memsize);
 
-	arm_cpu_lowlevel_init();
-
 	copy_vc_fdt((void *)endmem, vc_fdt, VIDEOCORE_FDT_SZ);
 
 	fdt += get_runtime_offset();
@@ -64,20 +65,102 @@ extern char __dtb_z_bcm2837_rpi_cm3_start[];
 
 RPI_ENTRY_FUNCTION(start_raspberry_pi1, SZ_128M, r2)
 {
+	arm_cpu_lowlevel_init();
+
 	start_raspberry_pi(SZ_128M, __dtb_z_bcm2835_rpi_start, (void *)r2);
 }
 
 RPI_ENTRY_FUNCTION(start_raspberry_pi2, SZ_512M, r2)
 {
+	arm_cpu_lowlevel_init();
+
 	start_raspberry_pi(SZ_512M, __dtb_z_bcm2836_rpi_2_start, (void *)r2);
 }
 
 RPI_ENTRY_FUNCTION(start_raspberry_pi3, SZ_512M, r2)
 {
+	arm_cpu_lowlevel_init();
+
 	start_raspberry_pi(SZ_512M, __dtb_z_bcm2837_rpi_3_start, (void *)r2);
 }
 
 RPI_ENTRY_FUNCTION(start_raspberry_pi_cm3, SZ_512M, r2)
 {
+	arm_cpu_lowlevel_init();
+
 	start_raspberry_pi(SZ_512M, __dtb_z_bcm2837_rpi_cm3_start, (void *)r2);
 }
+
+#define DT_IF_ENABLED(dt, cfg) \
+	(IS_ENABLED(cfg) ? (dt) : NULL)
+
+static void *rpi_get_board_fdt(int rev)
+{
+	if (!(rev & 0x800000))
+		return DT_IF_ENABLED(__dtb_z_bcm2835_rpi_start, CONFIG_MACH_RPI);
+
+	switch (((rev >> 4) & 0xff)) {
+	case BCM2835_BOARD_REV_A:
+	case BCM2835_BOARD_REV_B:
+	case BCM2835_BOARD_REV_A_PLUS:
+	case BCM2835_BOARD_REV_B_PLUS:
+	case BCM2835_BOARD_REV_CM1:
+	case BCM2835_BOARD_REV_ZERO:
+	case BCM2835_BOARD_REV_ZERO_W:
+		return DT_IF_ENABLED(__dtb_z_bcm2835_rpi_start, CONFIG_MACH_RPI);
+
+	case BCM2836_BOARD_REV_2_B:
+		return DT_IF_ENABLED(__dtb_z_bcm2836_rpi_2_start, CONFIG_MACH_RPI2);
+
+	case BCM2837_BOARD_REV_3_B:
+	case BCM2837B0_BOARD_REV_3B_PLUS:
+	case BCM2837B0_BOARD_REV_3A_PLUS:
+	case BCM2837B0_BOARD_REV_ZERO_2:
+		return DT_IF_ENABLED(__dtb_z_bcm2837_rpi_3_start, CONFIG_MACH_RPI3);
+
+	case BCM2837_BOARD_REV_CM3:
+	case BCM2837B0_BOARD_REV_CM3_PLUS:
+		return DT_IF_ENABLED(__dtb_z_bcm2837_rpi_cm3_start, CONFIG_MACH_RPI_CM3);
+	}
+
+	return NULL;
+}
+
+RPI_ENTRY_FUNCTION(start_raspberry_pi_generic, SZ_128M, vc_fdt)
+{
+	void *fdt = NULL;
+	ssize_t memsize;
+	int rev;
+
+	arm_cpu_lowlevel_init();
+
+	debug_ll_init();
+
+	putc_ll('>');
+
+	relocate_to_current_adr();
+	setup_c();
+
+	memsize = rpi_get_arm_mem();
+	if (memsize < 0) {
+		pr_warn("mbox: failed to query ARM memory size. 128M assumed.\n");
+		memsize = SZ_128M;
+	}
+
+	rev = rpi_get_board_rev();
+	if (rev >= 0) {
+		pr_debug("Detected revision %08x\n", rev);
+		fdt = rpi_get_board_fdt(rev);
+	}
+
+	if (!fdt) {
+		fdt = (void *)vc_fdt;
+
+		pr_warn("Unknown Rpi board with rev %08x.\n", rev);
+
+		if (get_unaligned_be32(fdt) != 0xd00dfeed)
+			panic("No suitable built-in or videocore-supplied DT\n");
+	}
+
+	start_raspberry_pi(memsize, fdt, (void *)vc_fdt);
+}
diff --git a/arch/arm/mach-bcm283x/include/mach/debug_ll.h b/arch/arm/mach-bcm283x/include/mach/debug_ll.h
index 4bfa5abc7c41..db23112aa07e 100644
--- a/arch/arm/mach-bcm283x/include/mach/debug_ll.h
+++ b/arch/arm/mach-bcm283x/include/mach/debug_ll.h
@@ -66,6 +66,12 @@ static inline void debug_ll_init(void)
 	debug_ll_ns16550_init(divisor);
 }
 
+#else
+
+static inline void debug_ll_init(void)
+{
+}
+
 #endif
 
 #endif /* __MACH_BCM2835_DEBUG_LL_H__ */
diff --git a/images/Makefile.bcm283x b/images/Makefile.bcm283x
index 82787f972c2d..b591cd58f563 100644
--- a/images/Makefile.bcm283x
+++ b/images/Makefile.bcm283x
@@ -18,3 +18,7 @@ image-$(CONFIG_MACH_RPI3) += barebox-raspberry-pi-3.img
 pblb-$(CONFIG_MACH_RPI_CM3) += start_raspberry_pi_cm3
 FILE_barebox-raspberry-pi-cm3.img = start_raspberry_pi_cm3.pblb
 image-$(CONFIG_MACH_RPI_CM3) += barebox-raspberry-pi-cm3.img
+
+pblb-$(CONFIG_MACH_RPI_COMMON) += start_raspberry_pi_generic
+FILE_barebox-raspberry-pi.img = start_raspberry_pi_generic.pblb
+image-$(CONFIG_MACH_RPI_COMMON) += barebox-raspberry-pi.img
-- 
2.30.2


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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux