[next,2/4] board: engicam: imx8mp: boot from the boot device first

Message ID 20261129122015.2496161-3-dario.binacchi@amarulasolutions.com
State New
Headers
Series Add Engicam i.Core MX8M Plus FE C.TOUCH 2.0 board support |

Commit Message

Dario Binacchi Nov. 29, 2026, 12:19 p.m. UTC
The i.Core MX8M Plus SoM boots from the SD card or from the eMMC, but
U-Boot always loads the environment from the SD card and scans it
first. Booting from the eMMC with a card inserted then starts the
system on the card.

Load the environment from the boot device and scan it first, unless
the user has changed the boot order in boot_targets.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 board/engicam/imx8mp/icore_mx8mp.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

-- 
2.43.0
  

Patch

diff --git a/board/engicam/imx8mp/icore_mx8mp.c b/board/engicam/imx8mp/icore_mx8mp.c
index 547cfa3a35f9..88385811803b 100644
--- a/board/engicam/imx8mp/icore_mx8mp.c
+++ b/board/engicam/imx8mp/icore_mx8mp.c
@@ -19,6 +19,7 @@ 
 #include <asm/arch/imx8mp_pins.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/sys_proto.h>
+#include <asm/mach-imx/boot_mode.h>
 #include <asm/mach-imx/gpio.h>
 
 static void setup_fec(void)
@@ -47,7 +48,31 @@  int board_init(void)
 	return 0;
 }
 
+int board_mmc_get_env_dev(int devno)
+{
+	return devno;
+}
+
 int board_late_init(void)
 {
+	const char *targets, *cur_targets, *def_targets;
+
+	switch (get_boot_device()) {
+	case SD2_BOOT:
+		targets = "mmc1 mmc2";
+		break;
+	case MMC3_BOOT:
+		targets = "mmc2 mmc1";
+		break;
+	default:
+		return 0;
+	}
+
+	/* Try the boot device first, unless the boot order was changed */
+	cur_targets = env_get("boot_targets");
+	def_targets = env_get_default("boot_targets");
+	if (cur_targets && def_targets && !strcmp(cur_targets, def_targets))
+		env_set("boot_targets", targets);
+
 	return 0;
 }