[PATCH] board: ti: am43xx: pass boot device information from SPL to U-Boot proper

Josef Lusticky josef at lusticky.cz
Fri Nov 26 10:56:46 CET 2021


TI AM43xx SoC supports various boot devices (peripherals).
There is already handoff mechanism prepared to allow passing
the information which boot device was used to load the SPL.

Use the handoff mechanism to pass this information to U-Boot proper
and set the "boot_device" environment variable in board_late_init.

Signed-off-by: Josef Lusticky <josef at lusticky.cz>
Cc: Tom Rini <trini at konsulko.com>
Cc: Lokesh Vutla <lokeshvutla at ti.com>
Cc: Michael Trimarchi <michael at amarulasolutions.com>
---

I use the boot_device variable later in U-Boot scripting - e.g. to avoid running
bootcmd when the SPL was loaded from UART but run it when loaded from MMC.
Only AM43xx is supported by this patch, but for other TI SoCs
the procedure should be the same:
- figure out supported boot devices from arch/arm/include/asm/arch-am33xx/spl.h
or arch/arm/include/asm/arch-omapX/spl.h
- implement setting the boot_device env variable in board_late_init()

You'll need to enable the following in the config:
CONFIG_BLOBLIST=y (required by CONFIG_HANDOFF)
CONFIG_HANDOFF=y
CONFIG_BLOBLIST_ADDR=0x87000000 (i set this based on other values defined by
the DEFAULT_LINUX_BOOT_ENV macro in include/configs/ti_armv7_common.h, you
may want to use a different address)

 arch/arm/include/asm/handoff.h    |  3 +++
 arch/arm/mach-omap2/boot-common.c |  9 ++++++++
 board/ti/am43xx/board.c           | 38 +++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)

diff --git a/arch/arm/include/asm/handoff.h b/arch/arm/include/asm/handoff.h
index 0790d2ab1e..1b7aa432a2 100644
--- a/arch/arm/include/asm/handoff.h
+++ b/arch/arm/include/asm/handoff.h
@@ -16,6 +16,9 @@
  */
 struct arch_spl_handoff {
 	ulong usable_ram_top;
+#ifdef CONFIG_ARCH_OMAP2PLUS
+	u32 omap_boot_device;
+#endif
 };
 
 #endif
diff --git a/arch/arm/mach-omap2/boot-common.c b/arch/arm/mach-omap2/boot-common.c
index 1268a32503..191bb2a42d 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -236,3 +236,12 @@ void arch_preboot_os(void)
 	ahci_reset((void __iomem *)DWC_AHSATA_BASE);
 }
 #endif
+
+#if CONFIG_IS_ENABLED(HANDOFF)
+int handoff_arch_save(struct spl_handoff *ho)
+{
+	ho->arch.omap_boot_device = spl_boot_device();
+
+	return 0;
+}
+#endif
diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
index a71b588efc..8c5834fc25 100644
--- a/board/ti/am43xx/board.c
+++ b/board/ti/am43xx/board.c
@@ -726,6 +726,44 @@ static int device_okay(const char *path)
 int board_late_init(void)
 {
 	struct udevice *dev;
+
+#if CONFIG_IS_ENABLED(HANDOFF)
+	/* Read peripheral SPL was loaded from */
+	if (gd->spl_handoff) {
+		switch (gd->spl_handoff->arch.omap_boot_device) {
+		case BOOT_DEVICE_CPGMAC:
+			env_set("boot_device", "cpgmac");
+			break;
+		case BOOT_DEVICE_MMC1:
+			env_set("boot_device", "mmc1");
+			break;
+		case BOOT_DEVICE_MMC2:
+			env_set("boot_device", "mmc2");
+			break;
+		case BOOT_DEVICE_NAND:
+			env_set("boot_device", "nand");
+			break;
+		case BOOT_DEVICE_NOR:
+			env_set("boot_device", "nor");
+			break;
+		case BOOT_DEVICE_SPI:
+			env_set("boot_device", "spi");
+			break;
+		case BOOT_DEVICE_UART:
+			env_set("boot_device", "uart");
+			break;
+		case BOOT_DEVICE_USB:
+			env_set("boot_device", "usb");
+			break;
+		case BOOT_DEVICE_USBETH:
+			env_set("boot_device", "usbeth");
+			break;
+		default:
+			env_set("boot_device", "unknown");
+		}
+	}
+#endif
+
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 	set_board_info_env(NULL);
 
-- 
2.30.2



More information about the U-Boot mailing list