mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: i.MX93: add bootsource detection
@ 2024-02-20 11:45 Sascha Hauer
  2024-02-27 12:57 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2024-02-20 11:45 UTC (permalink / raw)
  To: Barebox List

On i.MX93 the ROM API can be used to detect the bootsource. Implement
support for this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx9.c   |  1 +
 arch/arm/mach-imx/romapi.c | 67 ++++++++++++++++++++++++++++++++++++++
 include/mach/imx/generic.h |  1 +
 3 files changed, 69 insertions(+)

diff --git a/arch/arm/mach-imx/imx9.c b/arch/arm/mach-imx/imx9.c
index bfc248aadf..220951fd19 100644
--- a/arch/arm/mach-imx/imx9.c
+++ b/arch/arm/mach-imx/imx9.c
@@ -172,6 +172,7 @@ int imx93_init(void)
 {
 	imx93_type();
 	imx93_set_arm_clock();
+	imx93_bootsource();
 
 	if (IS_ENABLED(CONFIG_PBL_OPTEE)) {
 		static struct of_optee_fixup_data optee_fixup_data = {
diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
index 797b479c3e..0f1555abad 100644
--- a/arch/arm/mach-imx/romapi.c
+++ b/arch/arm/mach-imx/romapi.c
@@ -10,11 +10,14 @@
 #include <mach/imx/atf.h>
 #include <mach/imx/imx8m-regs.h>
 #include <mach/imx/xload.h>
+#include <mach/imx/generic.h>
 #include <asm/barebox-arm.h>
 #include <zero_page.h>
 #include <memory.h>
 #include <init.h>
 #include <pbl.h>
+#include <mmu.h>
+#include <bootsource.h>
 
 #define BOOTROM_INFO_VERSION		0x1
 #define BOOTROM_INFO_BOOT_DEVICE	0x2
@@ -99,6 +102,41 @@ int imx8mn_romapi_load_image(void *bl33)
 	return imx8mp_romapi_load_image(bl33);
 }
 
+static int imx_romapi_boot_device(struct rom_api *rom_api)
+{
+	uint32_t boot_device_type, boot_instance, boot_device;
+	enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
+	int ret;
+
+	ret = imx_bootrom_query(rom_api, BOOTROM_INFO_BOOT_DEVICE, &boot_device);
+	if (ret)
+		return ret;
+
+	boot_device_type = FIELD_GET(BOOTROM_BOOT_DEVICE_INTERFACE, boot_device);
+	boot_instance = FIELD_GET(BOOTROM_BOOT_DEVICE_INSTANCE, boot_device);
+
+	switch (boot_device_type) {
+	case BT_DEV_TYPE_MMC:
+	case BT_DEV_TYPE_SD:
+		bootsource = BOOTSOURCE_MMC;
+		break;
+	case BT_DEV_TYPE_NAND:
+		bootsource = BOOTSOURCE_NAND;
+		break;
+	case BT_DEV_TYPE_FLEXSPINOR:
+	case BT_DEV_TYPE_SPI_NOR:
+		bootsource = BOOTSOURCE_SPI_NOR;
+		break;
+	case BT_DEV_TYPE_USB:
+		bootsource = BOOTSOURCE_USB;
+		break;
+	}
+
+	bootsource_set(bootsource, boot_instance);
+
+	return 0;
+}
+
 static int imx_romapi_boot_device_seekable(struct rom_api *rom_api)
 {
 	uint32_t boot_device, boot_device_type, boot_device_state;
@@ -242,3 +280,32 @@ void imx8m_save_bootrom_log(void)
 
 	imx8m_scratch_save_bootrom_log(rom_log);
 }
+
+#define IMX93_BOOT_ROM_BASE 0x1000
+#define IMX93_BOOT_ROM_END (0x40000 - 1)
+
+void imx93_bootsource(void)
+{
+	struct rom_api *rom_api = (void *)0x1980;
+	struct resource rom = {
+		.start = IMX93_BOOT_ROM_BASE,
+		.end = IMX93_BOOT_ROM_END,
+	};
+	struct resource *r;
+	int ret;
+
+	r = request_iomem_region("Boot ROM",  rom.start, rom.end);
+	if (IS_ERR(r)) {
+		ret = PTR_ERR(r);
+		goto out;
+	}
+
+	arch_remap_range((void *)rom.start, rom.start, resource_size(&rom), MAP_CACHED);
+
+	OPTIMIZER_HIDE_VAR(rom_api);
+
+	ret = imx_romapi_boot_device(rom_api);
+out:
+	if (ret)
+		pr_err("Failed to get bootsource: %pe\n", ERR_PTR(ret));
+}
diff --git a/include/mach/imx/generic.h b/include/mach/imx/generic.h
index 1dca335fdd..03f3695e60 100644
--- a/include/mach/imx/generic.h
+++ b/include/mach/imx/generic.h
@@ -22,6 +22,7 @@ void imx8mm_boot_save_loc(void);
 void imx8mn_boot_save_loc(void);
 void imx8mp_boot_save_loc(void);
 void imx8mq_boot_save_loc(void);
+void imx93_bootsource(void);
 
 void imx25_get_boot_source(enum bootsource *src, int *instance);
 void imx27_get_boot_source(enum bootsource *src, int *instance);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-27 12:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-20 11:45 [PATCH] ARM: i.MX93: add bootsource detection Sascha Hauer
2024-02-27 12:57 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox