mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 07/21] ARM: rpi: add generic Raspberry Pi image
Date: Thu,  9 Jun 2022 07:59:08 +0200	[thread overview]
Message-ID: <20220609055922.667016-8-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220609055922.667016-1-a.fatoum@pengutronix.de>

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>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2022-06-09  6:04 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09  5:59 [PATCH v2 00/21] ARM: rpi: add basic Raspberry Pi 4 support Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 01/21] ARM64: asm: implement read_cpuid_id() Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 02/21] dma: add dma_sync nop stubs for PBL Ahmad Fatoum
2022-06-14  8:49   ` Sascha Hauer
2022-06-14  9:00     ` Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 03/21] ARM: rpi: move bcm2835_add_device_sdram() into header Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 04/21] ARM: rpi: support PBL use of mbox Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 05/21] ARM: rpi: split out mbox helpers to share code with PBL Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 06/21] ARM: rpi: switch to ARM_USE_COMPRESSED_DTB Ahmad Fatoum
2022-06-09  5:59 ` Ahmad Fatoum [this message]
2022-06-09  5:59 ` [PATCH v2 08/21] ARM: rpi: support FDT in x0 for 64bit configurations Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 09/21] serial: ns16550: rpi: remove ungating now done by proper clk driver Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 10/21] ARM: cpu: prevent recursive dependencies via CPU_SUPPORTS_64BIT_KERNEL Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 11/21] ARM: cpu: remove unnecessary CONFIG_SYS_SUPPORTS_64BIT_KERNEL Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 12/21] ARM: cpu: remove unused SYS_SUPPORTS_32BIT_KERNEL Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 13/21] ARM: rpi: add Raspberry Pi 3 64-bit build support Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 14/21] ARM: rpi: rpi3: disallow MMU_EARLY && 64BIT Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 15/21] clk: rpi: add Raspberry Pi 4 support Ahmad Fatoum
2022-06-09 13:58   ` Sascha Hauer
2022-06-09 14:15     ` Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 16/21] mci: bcm2835: add bcm2711-emmc2 (Rpi4) support Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 17/21] clocksource: bcm2835: bump below architeced timer for AArch64 Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 18/21] ARM: rpi: add Raspberry Pi 4 support Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 19/21] ARM: rpi: add debug_ll support for Raspberry Pi 4 Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 20/21] doc: bcm283x: reference newer firmware Ahmad Fatoum
2022-06-09  5:59 ` [PATCH v2 21/21] ARM: rpi: use correct kernel8.img as name for 64-bit Ahmad Fatoum
2022-06-10  8:33 ` [PATCH v2 00/21] ARM: rpi: add basic Raspberry Pi 4 support 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=20220609055922.667016-8-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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