]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
sunxi: When we've both mmc0 and mmc2, detect from which one we're booting
authorHans de Goede <hdegoede@redhat.com>
Thu, 2 Oct 2014 19:13:54 +0000 (21:13 +0200)
committerHans de Goede <hdegoede@redhat.com>
Fri, 24 Oct 2014 07:35:38 +0000 (09:35 +0200)
sunxi SOCs can boot from both mmc0 and mmc2, detect from which one we're
booting, and make that one "mmc dev 0" so that a single u-boot binary can
be used for both the onboard eMMC and for external sdcards.

When we're booting from mmc2, we make it dev 0 because that is where the SPL
will load the tertiary payload (the actual u-boot binary in our case) from,
see: common/spl/spl_mmc.c, which has dev 0 hardcoded everywhere.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
arch/arm/include/asm/arch-sunxi/mmc.h
board/sunxi/board.c
drivers/mmc/sunxi_mmc.c

index 6a3118402f4d60a7dbaf04b9d7aeded6e84f2789..70d787567c1964e3e4b7668eadf4ebfb5bce8491 100644 (file)
@@ -123,5 +123,5 @@ struct sunxi_mmc {
 #define SUNXI_MMC_IDIE_TXIRQ           (0x1 << 0)
 #define SUNXI_MMC_IDIE_RXIRQ           (0x1 << 1)
 
-int sunxi_mmc_init(int sdc_no);
+struct mmc *sunxi_mmc_init(int sdc_no);
 #endif /* _SUNXI_MMC_H */
index cfe22b61388319ccb152eef263a273c3c82a33c6..f310e8dbff28273d6231b24f60c69b56be71841f 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <mmc.h>
 #ifdef CONFIG_AXP152_POWER
 #include <axp152.h>
 #endif
@@ -104,11 +105,36 @@ static void mmc_pinmux_setup(int sdc)
 
 int board_mmc_init(bd_t *bis)
 {
+       __maybe_unused struct mmc *mmc0, *mmc1;
+       __maybe_unused char buf[512];
+
        mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
-       sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
+       mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
+       if (!mmc0)
+               return -1;
+
 #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
        mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
-       sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
+       mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
+       if (!mmc1)
+               return -1;
+#endif
+
+#if CONFIG_MMC_SUNXI_SLOT == 0 && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
+       /*
+        * Both mmc0 and mmc2 are bootable, figure out where we're booting
+        * from. Try mmc0 first, just like the brom does.
+        */
+       if (mmc_getcd(mmc0) && mmc_init(mmc0) == 0 &&
+           mmc0->block_dev.block_read(0, 16, 1, buf) == 1) {
+               buf[12] = 0;
+               if (strcmp(&buf[4], "eGON.BT0") == 0)
+                       return 0;
+       }
+
+       /* no bootable card in mmc0, so we must be booting from mmc2, swap */
+       mmc0->block_dev.dev = 1;
+       mmc1->block_dev.dev = 0;
 #endif
 
        return 0;
index b47376a79383fb38de3ad6fee033850274046845..d3b1039cfe9f82b4430f413ead5cd85201402950 100644 (file)
@@ -373,7 +373,7 @@ static const struct mmc_ops sunxi_mmc_ops = {
        .getcd          = sunxi_mmc_getcd,
 };
 
-int sunxi_mmc_init(int sdc_no)
+struct mmc *sunxi_mmc_init(int sdc_no)
 {
        struct mmc_config *cfg = &mmc_host[sdc_no].cfg;
 
@@ -396,8 +396,5 @@ int sunxi_mmc_init(int sdc_no)
        mmc_resource_init(sdc_no);
        mmc_clk_io_on(sdc_no);
 
-       if (mmc_create(cfg, &mmc_host[sdc_no]) == NULL)
-               return -1;
-
-       return 0;
+       return mmc_create(cfg, &mmc_host[sdc_no]);
 }