From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Andr=C3=A9=20Draszik?= Date: Wed, 16 Oct 2019 16:48:55 +0100 Subject: [U-Boot] [PATCH] imx: spl: inject 'u-boot, spl-boot-device' for next-stage Message-ID: <20191016154855.40276-1-git@andred.net> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de 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=C3=A9 Draszik Cc: Stefano Babic Cc: Fabio Estevam Cc: "NXP i.MX U-Boot Team" Cc: Albert Aribaud --- 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 */ =20 +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[] =3D { + { BOOT_DEVICE_MMC1, "mmc1" }, + { BOOT_DEVICE_MMC2, "mmc2" }, + { BOOT_DEVICE_SPI, "spi" }, + { BOOT_DEVICE_NAND, "nand" }, + }; + + for (i =3D 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i) + if (spl_boot_devices_tbl[i].boot_device =3D=3D boot_device) + return spl_boot_devices_tbl[i].ofpath; + + return NULL; +} + +void spl_perform_fixups(struct spl_image_info *spl_image) +{ + void *blob =3D 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 =3D 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 =3D 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) { --=20 2.23.0.rc1