sunxi: Remove the MMC index hack
authorMaxime Ripard <maxime.ripard@free-electrons.com>
Wed, 23 Aug 2017 08:12:22 +0000 (10:12 +0200)
committerMaxime Ripard <maxime.ripard@free-electrons.com>
Tue, 3 Oct 2017 17:12:06 +0000 (19:12 +0200)
The current code, if there's both an eMMC and an MMC slot available on the
board, will swap the MMC indices based on whether we booted from the eMMC
or the MMC. This way, the MMC we're supposed to boot on will always have
the index 0.

However, this causes various issues, for example when using other
components that base their behaviour on the MMC index, such as fastboot.

Let's remove that hack, and take the opposite approach. The MMC will always
have the same index, but the bootcmd will pick the same device than the one
we booted from. This is done through the introduction of the mmc_bootdev
environment variable that will be filled by the board code based on the
boot device informations we can get from the SoC.

In order to not introduce regressions, we also need to adjust the fastboot
MMC device and the environment device in order to set it to the eMMC, over
the MMC, like it used to be the case.

Tested-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
board/sunxi/board.c
cmd/fastboot/Kconfig
configs/A20-OLinuXino-Lime2-eMMC_defconfig
configs/Sinlinx_SinA33_defconfig
configs/parrot_r16_defconfig
include/configs/sunxi-common.h

index 7fdcc4a..cb42742 100644 (file)
@@ -492,20 +492,6 @@ int board_mmc_init(bd_t *bis)
                return -1;
 #endif
 
-#if !defined(CONFIG_SPL_BUILD) && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
-       /*
-        * On systems with an emmc (mmc2), figure out if we are booting from
-        * the emmc and if we are make it "mmc dev 0" so that boot.scr, etc.
-        * are searched there first. Note we only do this for u-boot proper,
-        * not for the SPL, see spl_boot_device().
-        */
-       if (readb(SPL_ADDR + 0x28) == SUNXI_BOOTED_FROM_MMC2) {
-               /* Booting from emmc / mmc2, swap */
-               mmc0->block_dev.devnum = 1;
-               mmc1->block_dev.devnum = 0;
-       }
-#endif
-
        return 0;
 }
 #endif
@@ -725,12 +711,18 @@ int misc_init_r(void)
 
        env_set("fel_booted", NULL);
        env_set("fel_scriptaddr", NULL);
+       env_set("mmc_bootdev", NULL);
 
        boot = sunxi_get_boot_device();
        /* determine if we are running in FEL mode */
        if (boot == BOOT_DEVICE_BOARD) {
                env_set("fel_booted", "1");
                parse_spl_header(SPL_ADDR);
+       /* or if we booted from MMC, and which one */
+       } else if (boot == BOOT_DEVICE_MMC1) {
+               env_set("mmc_bootdev", "0");
+       } else if (boot == BOOT_DEVICE_MMC2) {
+               env_set("mmc_bootdev", "1");
        }
 
        setup_environment(gd->fdt_blob);
index 7330da2..214bbc2 100644 (file)
@@ -74,6 +74,8 @@ config FASTBOOT_FLASH
 config FASTBOOT_FLASH_MMC_DEV
        int "Define FASTBOOT MMC FLASH default device"
        depends on FASTBOOT_FLASH && MMC
+       default 0 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1
+       default 1 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1
        help
          The fastboot "flash" command requires additional information
          regarding the non-volatile storage device. Define this to
index a04037e..b89c505 100644 (file)
@@ -14,7 +14,6 @@ CONFIG_AHCI=y
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 # CONFIG_CMD_IMLS is not set
 CONFIG_CMD_DFU=y
 # CONFIG_CMD_FLASH is not set
index d726b40..32c8872 100644 (file)
@@ -15,7 +15,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-a33-sinlinx-sina33"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL=y
 CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 # CONFIG_CMD_IMLS is not set
 CONFIG_CMD_DFU=y
 # CONFIG_CMD_FLASH is not set
index 6be57e6..d6bc89c 100644 (file)
@@ -13,7 +13,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-r16-parrot"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL=y
 CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_FPGA is not set
index 02d7be0..9175117 100644 (file)
 #endif
 
 #if defined(CONFIG_ENV_IS_IN_MMC)
-#define CONFIG_SYS_MMC_ENV_DEV         0       /* first detected MMC controller */
+#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
+/* If we have two devices (most likely eMMC + MMC), favour the eMMC */
+#define CONFIG_SYS_MMC_ENV_DEV         1
+#else
+/* Otherwise, use the only device we have */
+#define CONFIG_SYS_MMC_ENV_DEV         0
+#endif
 #define CONFIG_SYS_MMC_MAX_DEVICE      4
 #elif defined(CONFIG_ENV_IS_NOWHERE)
 #define CONFIG_ENV_SIZE                        (128 << 10)
@@ -382,15 +388,28 @@ extern int soft_i2c_gpio_scl;
        "ramdisk ram " RAMDISK_ADDR_R " 0x4000000\0"
 
 #ifdef CONFIG_MMC
-#define BOOT_TARGET_DEVICES_MMC(func) func(MMC, mmc, 0)
 #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
-#define BOOT_TARGET_DEVICES_MMC_EXTRA(func) func(MMC, mmc, 1)
+#define BOOTENV_DEV_MMC_AUTO(devtypeu, devtypel, instance)             \
+       BOOTENV_DEV_MMC(MMC, mmc, 0)                                    \
+       BOOTENV_DEV_MMC(MMC, mmc, 1)                                    \
+       "bootcmd_mmc_auto="                                             \
+               "if test ${mmc_bootdev} -eq 1; then "                   \
+                       "run bootcmd_mmc1; "                            \
+                       "run bootcmd_mmc0; "                            \
+               "elif test ${mmc_bootdev} -eq 0; then "                 \
+                       "run bootcmd_mmc0; "                            \
+                       "run bootcmd_mmc1; "                            \
+               "fi\0"
+
+#define BOOTENV_DEV_NAME_MMC_AUTO(devtypeu, devtypel, instance) \
+       "mmc_auto "
+
+#define BOOT_TARGET_DEVICES_MMC(func) func(MMC_AUTO, mmc_auto, na)
 #else
-#define BOOT_TARGET_DEVICES_MMC_EXTRA(func)
+#define BOOT_TARGET_DEVICES_MMC(func) func(MMC, mmc, 0)
 #endif
 #else
 #define BOOT_TARGET_DEVICES_MMC(func)
-#define BOOT_TARGET_DEVICES_MMC_EXTRA(func)
 #endif
 
 #ifdef CONFIG_AHCI
@@ -418,7 +437,6 @@ extern int soft_i2c_gpio_scl;
 #define BOOT_TARGET_DEVICES(func) \
        func(FEL, fel, na) \
        BOOT_TARGET_DEVICES_MMC(func) \
-       BOOT_TARGET_DEVICES_MMC_EXTRA(func) \
        BOOT_TARGET_DEVICES_SCSI(func) \
        BOOT_TARGET_DEVICES_USB(func) \
        func(PXE, pxe, na) \