imx: imx6ul: kontron-sl-mx6ul: Select correct boot and env device

Instead of checking both, SPI NOR and MMC for loading U-Boot proper
and the environment, implement a way to detect the actual boot
device even if the BootROM doesn't report it and we can't rely
solely on the fuse settings, as by default we use MMC as primary
boot device and boot from SPI NOR via the secondary fallback device
(EEPROM Recovery Mode).

Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
diff --git a/board/kontron/sl-mx6ul/sl-mx6ul-common.c b/board/kontron/sl-mx6ul/sl-mx6ul-common.c
new file mode 100644
index 0000000..1f24acd
--- /dev/null
+++ b/board/kontron/sl-mx6ul/sl-mx6ul-common.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Kontron Electronics GmbH
+ */
+
+#include <asm/types.h>
+#include <asm/arch/sys_proto.h>
+
+#include <sl-mx6ul-common.h>
+
+bool sl_mx6ul_is_spi_nor_boot(void)
+{
+	u32 bmode = imx6_src_get_boot_mode();
+
+	/*
+	 * Check if "EEPROM Recovery" enabled and ECSPI2_CONREG not 0x0.
+	 * If this is the case and U-Boot didn't initialize the SPI bus
+	 * yet, we can safely assume that we are booting from SPI NOR.
+	 */
+	if ((bmode & 0x40000000) && readl(0x0200c008))
+		return true;
+
+	return false;
+}