[U-Boot] [PATCH] imx: spl: inject 'u-boot, spl-boot-device' for next-stage

André Draszik git at andred.net
Wed Oct 16 15:48:55 UTC 2019


This implements the 'spl_perform_fixups' hook for i.MX-based
boards and injects the /chosen/u-boot,spl-boot-device with a string
representation corresponding to the boot device used.

The intended usage is for the full U-Boot stage to evaluate this in
scripts and then adapt its boot-order as needed.

This change is heavily based on commit e5f2ecc75001
("rockchip: rk3399: inject 'u-boot, spl-boot-device' for next-stage")

A string representation of the boot device was chosen
here (as opposed to an ofpath in the rockchip commit),
so as to make this less hardware dependent.

Signed-off-by: André Draszik <git at andred.net>
Cc: Stefano Babic <sbabic at denx.de>
Cc: Fabio Estevam <festevam at gmail.com>
Cc: "NXP i.MX U-Boot Team" <uboot-imx at nxp.com>
Cc: Albert Aribaud <albert.u.boot at aribaud.net>
---
 arch/arm/mach-imx/spl.c | 49 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index f025c4b301..42ca719cd8 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -176,6 +176,55 @@ u32 spl_boot_device(void)
 }
 #endif /* CONFIG_MX7 || CONFIG_IMX8M || CONFIG_IMX8 */
 
+static const char *imx_decode_boot_device(u32 boot_device)
+{
+	int i;
+	static const struct {
+		u32 boot_device;
+		const char *ofpath;
+	} spl_boot_devices_tbl[] = {
+		{ BOOT_DEVICE_MMC1, "mmc1" },
+		{ BOOT_DEVICE_MMC2, "mmc2" },
+		{ BOOT_DEVICE_SPI, "spi" },
+		{ BOOT_DEVICE_NAND, "nand" },
+	};
+
+	for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+		if (spl_boot_devices_tbl[i].boot_device == boot_device)
+			return spl_boot_devices_tbl[i].ofpath;
+
+	return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+	void *blob = spl_image->fdt_addr;
+	const char *boot_ofpath;
+	int chosen;
+
+	/*
+	 * Inject the ofpath of the device the full U-Boot (or Linux in
+	 * Falcon-mode) was booted from into the FDT, if a FDT has been
+	 * loaded at the same time.
+	 */
+	if (!blob)
+		return;
+	boot_ofpath = imx_decode_boot_device(spl_image->boot_device);
+	if (!boot_ofpath) {
+		pr_err("%s: could not map boot_device to ofpath\n", __func__);
+		return;
+	}
+
+	chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+	if (chosen < 0) {
+		pr_err("%s: could not find/create '/chosen'\n", __func__);
+		return;
+	}
+	fdt_setprop_string(blob, chosen,
+			   "u-boot,spl-boot-device", boot_ofpath);
+}
+
+
 #ifdef CONFIG_SPL_USB_GADGET
 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
 {
-- 
2.23.0.rc1



More information about the U-Boot mailing list