From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 7/9] ARM: OMAP: add am33xx_hsmmc_start_image for PBL
Date: Tue, 22 Apr 2025 07:26:33 +0200 [thread overview]
Message-ID: <20250422052635.3423961-8-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250422052635.3423961-1-a.fatoum@pengutronix.de>
We have had a separate am335x_mlo_defconfig for a long time, but it
frequently breaks, because barebox keeps getting bigger and then is
slimmed down a bit again.
To counteract that, there is a am335x_mlo_sdmmc_defconfig, but the
downside is that this still requires two barebox builds: One for MLO
and one for barebox proper, because the MLO needs to fit into the
on-chip SRAM.
Reworking drivers for all supported boot media, including raw flash,
to be usable in PBL is a big undertaking, but supporting just SD is easy
enough, so add an entry point exclusively for that.
The end goal is to allow an easier integration for a future
beaglebone-yocto support in openembedded-core.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/mach-omap/Makefile | 1 +
arch/arm/mach-omap/am33xx_generic.c | 38 ++++++++---------
arch/arm/mach-omap/am33xx_xload.c | 66 +++++++++++++++++++++++++++++
include/mach/omap/am33xx-generic.h | 2 +
include/mach/omap/xload.h | 14 ++++++
5 files changed, 102 insertions(+), 19 deletions(-)
create mode 100644 arch/arm/mach-omap/am33xx_xload.c
create mode 100644 include/mach/omap/xload.h
diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 6b42196b2373..83722dfa9ca1 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_ARCH_OMAP3) += omap3_generic.o auxcr.o
pbl-$(CONFIG_ARCH_OMAP3) += omap3_generic.o auxcr.o
obj-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o
pbl-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o
+pbl-$(CONFIG_MCI_OMAP_HSMMC_PBL) += am33xx_xload.o
obj-pbl-$(CONFIG_ARCH_AM33XX) += am33xx_generic.o am33xx_clock.o am33xx_mux.o am3xxx.o emif4.o
obj-pbl-$(CONFIG_ARCH_AM35XX) += am3xxx.o emif4.o
obj-$(CONFIG_ARCH_AM33XX) += am33xx_scrm.o
diff --git a/arch/arm/mach-omap/am33xx_generic.c b/arch/arm/mach-omap/am33xx_generic.c
index bcafc0677e38..007daccdfbe1 100644
--- a/arch/arm/mach-omap/am33xx_generic.c
+++ b/arch/arm/mach-omap/am33xx_generic.c
@@ -120,40 +120,40 @@ u32 am33xx_running_in_sdram(void)
return 0; /* running in SRAM or FLASH */
}
-static int am33xx_bootsource(void)
+enum bootsource am33xx_get_bootsource(int *instance)
{
- enum bootsource src;
- int instance = 0;
uint32_t *am33xx_bootinfo = (void *)AM33XX_SRAM_SCRATCH_SPACE;
switch (am33xx_bootinfo[2] & 0xFF) {
case 0x05:
- src = BOOTSOURCE_NAND;
- break;
+ return BOOTSOURCE_NAND;
case 0x08:
- src = BOOTSOURCE_MMC;
instance = 0;
- break;
+ return BOOTSOURCE_MMC;
case 0x09:
- src = BOOTSOURCE_MMC;
- instance = 1;
- break;
+ *instance = 1;
+ return BOOTSOURCE_MMC;
case 0x0b:
- src = BOOTSOURCE_SPI;
- break;
+ return BOOTSOURCE_SPI;
case 0x41:
- src = BOOTSOURCE_SERIAL;
- break;
+ return BOOTSOURCE_SERIAL;
case 0x44:
- src = BOOTSOURCE_USB;
- break;
+ return BOOTSOURCE_USB;
case 0x46:
- src = BOOTSOURCE_NET;
- break;
+ return BOOTSOURCE_NET;
default:
- src = BOOTSOURCE_UNKNOWN;
+ return BOOTSOURCE_UNKNOWN;
}
+}
+
+static int am33xx_bootsource(void)
+{
+ enum bootsource src;
+ int instance = 0;
+
+ src = am33xx_get_bootsource(&instance);
bootsource_set_raw(src, instance);
+
return 0;
}
diff --git a/arch/arm/mach-omap/am33xx_xload.c b/arch/arm/mach-omap/am33xx_xload.c
new file mode 100644
index 000000000000..f0c8b451b308
--- /dev/null
+++ b/arch/arm/mach-omap/am33xx_xload.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <filetype.h>
+#include <mach/omap/generic.h>
+#include <mach/omap/xload.h>
+#include <mach/omap/am33xx-silicon.h>
+#include <mach/omap/am33xx-generic.h>
+#include <mach/omap/am33xx-clock.h>
+#include <bootsource.h>
+#include <linux/sizes.h>
+#include <asm/cache.h>
+#include <pbl/bio.h>
+
+struct xload_instance {
+ void __iomem *base;
+};
+
+static void omap_hsmmc_fat_start_image(struct pbl_bio *bio, void *buf)
+{
+ int ret;
+
+ ret = pbl_fat_load(bio, "barebox.bin", buf, SZ_2M);
+ if (ret < 0) {
+ pr_err("pbl_fat_load: error %d\n", ret);
+ return;
+ }
+
+ sync_caches_for_execution();
+
+ asm volatile ("bx %0\n" : : "r"(buf) :);
+ __builtin_unreachable();
+}
+
+static const struct xload_instance am35xx_hsmmc_instances[] = {
+ [0] = { .base = IOMEM(AM33XX_MMCHS0_BASE), },
+ [1] = { .base = IOMEM(AM33XX_MMC1_BASE), },
+ [2] = { .base = IOMEM(AM33XX_MMCHS2_BASE), },
+};
+
+void __noreturn am33xx_hsmmc_start_image(void)
+{
+ void *buf = (void *)OMAP_DRAM_ADDR_SPACE_START;
+ const struct xload_instance *instance;
+ enum bootsource src;
+ struct pbl_bio bio;
+ int id = 0, ret;
+
+ omap_dmtimer_init(IOMEM(AM33XX_DMTIMER0_BASE),
+ am33xx_get_osc_clock() * 1000);
+
+ src = am33xx_get_bootsource(&id);
+ if (src != BOOTSOURCE_MMC)
+ panic("This MLO was configured only for SD/MMC\n");
+
+ instance = &am35xx_hsmmc_instances[id];
+
+ ret = omap_hsmmc_bio_init(&bio, instance->base, 0x100);
+ if (ret)
+ goto out_panic;
+
+ omap_hsmmc_fat_start_image(&bio, buf);
+
+out_panic:
+ panic("FAT chainloading failed\n");
+}
diff --git a/include/mach/omap/am33xx-generic.h b/include/mach/omap/am33xx-generic.h
index 30aa13974111..a1ede96a30ff 100644
--- a/include/mach/omap/am33xx-generic.h
+++ b/include/mach/omap/am33xx-generic.h
@@ -30,6 +30,8 @@ u32 am33xx_running_in_flash(void);
u32 am33xx_running_in_sram(void);
u32 am33xx_running_in_sdram(void);
+enum bootsource am33xx_get_bootsource(int *instance);
+
void am33xx_enable_per_clocks(void);
int am33xx_init(void);
int am33xx_devices_init(void);
diff --git a/include/mach/omap/xload.h b/include/mach/omap/xload.h
new file mode 100644
index 000000000000..d820d2602c22
--- /dev/null
+++ b/include/mach/omap/xload.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __MACH_OMAP_XLOAD_H
+#define __MACH_OMAP_XLOAD_H
+
+#include <linux/compiler.h>
+#include <pbl/bio.h>
+
+void __noreturn am33xx_hsmmc_start_image(void);
+
+int omap_hsmmc_bio_init(struct pbl_bio *bio, void __iomem *base,
+ unsigned reg_ofs);
+
+#endif /* __MACH_OMAP_XLOAD_H */
--
2.39.5
next prev parent reply other threads:[~2025-04-22 5:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 5:26 [PATCH 0/9] ARM: OMAP: beaglebone: add PBL SD xload support Ahmad Fatoum
2025-04-22 5:26 ` [PATCH 1/9] clocksource: make available in PBL Ahmad Fatoum
2025-04-22 5:26 ` [PATCH 2/9] clocksource: ti-dm: " Ahmad Fatoum
2025-04-22 5:26 ` [PATCH 3/9] mci: move mci_setup_cmd definition into header Ahmad Fatoum
2025-04-22 5:26 ` [PATCH 4/9] mci: add common PBL helper for chainloading after BootROM initialization Ahmad Fatoum
2025-04-22 5:26 ` [PATCH 5/9] mci: pbl: add autodetection of BootROM-initialized standard capacity cards Ahmad Fatoum
2025-04-22 5:26 ` [PATCH 6/9] mci: omap_hsmmc: split out common code Ahmad Fatoum
2025-04-22 5:26 ` Ahmad Fatoum [this message]
2025-04-22 5:26 ` [PATCH 8/9] mci: omap_hsmmc: add xload implementation for PBL Ahmad Fatoum
2025-04-22 5:26 ` [PATCH 9/9] ARM: OMAP: beaglebone: add PBL SD xload support Ahmad Fatoum
2025-04-22 10:55 ` [PATCH 0/9] " Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250422052635.3423961-8-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox