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.fat...@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


Reply via email to