summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-06-09 07:59:08 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-06-17 08:28:55 +0200
commit40160e667be7db8e4fa91d89b7f9ed52a44a4618 (patch)
tree4de51a1be9113a3de64f50dc25fb98990b90a67c
parent9949ba5b6e49c56d7428d603d2101af1e993c0a7 (diff)
downloadbarebox-40160e667be7db8e4fa91d89b7f9ed52a44a4618.tar.gz
barebox-40160e667be7db8e4fa91d89b7f9ed52a44a4618.tar.xz
ARM: rpi: add generic Raspberry Pi image
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@pengutronix.de> Link: https://lore.barebox.org/20220609055922.667016-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--Documentation/boards/bcm2835.rst8
-rw-r--r--arch/arm/boards/raspberry-pi/lowlevel.c87
-rw-r--r--arch/arm/mach-bcm283x/include/mach/debug_ll.h6
-rw-r--r--images/Makefile.bcm283x4
4 files changed, 99 insertions, 6 deletions
diff --git a/Documentation/boards/bcm2835.rst b/Documentation/boards/bcm2835.rst
index 0b5299a340..a8eed9aec0 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 091bfb8f4b..82b51b5b15 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 4bfa5abc7c..db23112aa0 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 82787f972c..b591cd58f5 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