All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal
@ 2017-09-12 20:02 Maxime Ripard
  2017-09-12 20:02 ` [U-Boot] [PATCH v2 1/3] arm: sunxi: Move spl_boot_device in a separate function Maxime Ripard
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Maxime Ripard @ 2017-09-12 20:02 UTC (permalink / raw)
  To: u-boot

Hi,

Here is an attempt at removing the hack in the sunxi code to switch
the MMC indices depending on the boot device.

It's based on Siarhei's suggestion to go through an environment
variable set by the code, and then having a script in our default
bootcmd to change the boot order in order to always favour the boot
device, instead of always picking the external MMC first.

Let me know what you think,
Maxime

Changes from v1:
  - Added the various tags
  - Rebased on top of v2017.09
  - Split the spl_boot_device into a separate function instead of making
    it available in the !spl case

Maxime Ripard (3):
  arm: sunxi: Move spl_boot_device in a separate function
  sunxi: Use sunxi_get_boot_device
  sunxi: Remove the MMC index hack

 arch/arm/include/asm/arch-sunxi/spl.h      |  2 ++-
 arch/arm/mach-sunxi/board.c                | 11 +++++---
 board/sunxi/board.c                        | 26 ++++++++------------
 cmd/fastboot/Kconfig                       |  2 ++-
 configs/A20-OLinuXino-Lime2-eMMC_defconfig |  1 +-
 configs/Sinlinx_SinA33_defconfig           |  1 +-
 configs/parrot_r16_defconfig               |  1 +-
 include/configs/sunxi-common.h             | 30 ++++++++++++++++++-----
 8 files changed, 47 insertions(+), 27 deletions(-)

base-commit: c98ac3487e413c71e5d36322ef3324b21c6f60f9
-- 
git-series 0.9.1

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

* [U-Boot] [PATCH v2 1/3] arm: sunxi: Move spl_boot_device in a separate function
  2017-09-12 20:02 [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard
@ 2017-09-12 20:02 ` Maxime Ripard
  2017-09-12 20:02 ` [U-Boot] [PATCH v2 2/3] sunxi: Use sunxi_get_boot_device Maxime Ripard
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Maxime Ripard @ 2017-09-12 20:02 UTC (permalink / raw)
  To: u-boot

U-Boot itself might need to identify the boot device, for example to be
able to tell where to load the kernel from when several options are
possible.

Move the logic of spl_boot_device to a function that is compiled both for
the SPL and the main binary.

Tested-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 arch/arm/include/asm/arch-sunxi/spl.h |  2 ++
 arch/arm/mach-sunxi/board.c           | 11 ++++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/arm/include/asm/arch-sunxi/spl.h b/arch/arm/include/asm/arch-sunxi/spl.h
index 9358397da27a..a70b1797e5d7 100644
--- a/arch/arm/include/asm/arch-sunxi/spl.h
+++ b/arch/arm/include/asm/arch-sunxi/spl.h
@@ -78,4 +78,6 @@ typedef char boot_file_head_not_multiple_of_32[1 - 2*(sizeof(struct boot_file_he
 
 #define is_boot0_magic(addr)	(memcmp((void *)addr, BOOT0_MAGIC, 8) == 0)
 
+uint32_t sunxi_get_boot_device(void);
+
 #endif
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index 65b1ebd83787..0c60ee04da54 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -14,9 +14,7 @@
 #include <mmc.h>
 #include <i2c.h>
 #include <serial.h>
-#ifdef CONFIG_SPL_BUILD
 #include <spl.h>
-#endif
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -212,11 +210,12 @@ void s_init(void)
 
 #ifdef CONFIG_SPL_BUILD
 DECLARE_GLOBAL_DATA_PTR;
+#endif
 
 /* The sunxi internal brom will try to loader external bootloader
  * from mmc0, nand flash, mmc2.
  */
-u32 spl_boot_device(void)
+uint32_t sunxi_get_boot_device(void)
 {
 	int boot_source;
 
@@ -255,6 +254,12 @@ u32 spl_boot_device(void)
 	return -1;		/* Never reached */
 }
 
+#ifdef CONFIG_SPL_BUILD
+u32 spl_boot_device(void)
+{
+	return sunxi_get_boot_device();
+}
+
 /* No confirmation data available in SPL yet. Hardcode bootmode */
 u32 spl_boot_mode(const u32 boot_device)
 {
-- 
git-series 0.9.1

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

* [U-Boot] [PATCH v2 2/3] sunxi: Use sunxi_get_boot_device
  2017-09-12 20:02 [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard
  2017-09-12 20:02 ` [U-Boot] [PATCH v2 1/3] arm: sunxi: Move spl_boot_device in a separate function Maxime Ripard
@ 2017-09-12 20:02 ` Maxime Ripard
  2017-09-12 20:02 ` [U-Boot] [PATCH v2 3/3] sunxi: Remove the MMC index hack Maxime Ripard
  2017-09-21 19:21 ` [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard
  3 siblings, 0 replies; 5+ messages in thread
From: Maxime Ripard @ 2017-09-12 20:02 UTC (permalink / raw)
  To: u-boot

Our current board code duplicates a bit the sunxi_get_boot_device logic.
Now that we can use that function in the full-flavoured U-Boot, remove that
duplication and call the function instead.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 board/sunxi/board.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 70e01437c4f4..9c7fc4168894 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -32,6 +32,7 @@
 #include <libfdt.h>
 #include <nand.h>
 #include <net.h>
+#include <spl.h>
 #include <sy8106a.h>
 #include <asm/setup.h>
 
@@ -720,11 +721,14 @@ static void setup_environment(const void *fdt)
 int misc_init_r(void)
 {
 	__maybe_unused int ret;
+	uint boot;
 
 	env_set("fel_booted", NULL);
 	env_set("fel_scriptaddr", NULL);
+
+	boot = sunxi_get_boot_device();
 	/* determine if we are running in FEL mode */
-	if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
+	if (boot == BOOT_DEVICE_BOARD) {
 		env_set("fel_booted", "1");
 		parse_spl_header(SPL_ADDR);
 	}
-- 
git-series 0.9.1

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

* [U-Boot] [PATCH v2 3/3] sunxi: Remove the MMC index hack
  2017-09-12 20:02 [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard
  2017-09-12 20:02 ` [U-Boot] [PATCH v2 1/3] arm: sunxi: Move spl_boot_device in a separate function Maxime Ripard
  2017-09-12 20:02 ` [U-Boot] [PATCH v2 2/3] sunxi: Use sunxi_get_boot_device Maxime Ripard
@ 2017-09-12 20:02 ` Maxime Ripard
  2017-09-21 19:21 ` [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard
  3 siblings, 0 replies; 5+ messages in thread
From: Maxime Ripard @ 2017-09-12 20:02 UTC (permalink / raw)
  To: u-boot

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                        | 20 ++++-----------
 cmd/fastboot/Kconfig                       |  2 ++-
 configs/A20-OLinuXino-Lime2-eMMC_defconfig |  1 +-
 configs/Sinlinx_SinA33_defconfig           |  1 +-
 configs/parrot_r16_defconfig               |  1 +-
 include/configs/sunxi-common.h             | 30 ++++++++++++++++++-----
 6 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 9c7fc4168894..feb8d7490d8b 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -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);
diff --git a/cmd/fastboot/Kconfig b/cmd/fastboot/Kconfig
index fb0c5da94cdb..6baea8974690 100644
--- a/cmd/fastboot/Kconfig
+++ b/cmd/fastboot/Kconfig
@@ -69,6 +69,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
diff --git a/configs/A20-OLinuXino-Lime2-eMMC_defconfig b/configs/A20-OLinuXino-Lime2-eMMC_defconfig
index 58aa988b2363..caaa0b9a0d88 100644
--- a/configs/A20-OLinuXino-Lime2-eMMC_defconfig
+++ b/configs/A20-OLinuXino-Lime2-eMMC_defconfig
@@ -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
diff --git a/configs/Sinlinx_SinA33_defconfig b/configs/Sinlinx_SinA33_defconfig
index af00e5434763..471c843e5dcf 100644
--- a/configs/Sinlinx_SinA33_defconfig
+++ b/configs/Sinlinx_SinA33_defconfig
@@ -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
diff --git a/configs/parrot_r16_defconfig b/configs/parrot_r16_defconfig
index 53825eba33c3..c63e7f259f35 100644
--- a/configs/parrot_r16_defconfig
+++ b/configs/parrot_r16_defconfig
@@ -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
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index 02d7be08495d..91751171ec2b 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -148,7 +148,13 @@
 #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) \
-- 
git-series 0.9.1

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

* [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal
  2017-09-12 20:02 [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard
                   ` (2 preceding siblings ...)
  2017-09-12 20:02 ` [U-Boot] [PATCH v2 3/3] sunxi: Remove the MMC index hack Maxime Ripard
@ 2017-09-21 19:21 ` Maxime Ripard
  3 siblings, 0 replies; 5+ messages in thread
From: Maxime Ripard @ 2017-09-21 19:21 UTC (permalink / raw)
  To: u-boot

On Tue, Sep 12, 2017 at 08:02:21PM +0000, Maxime Ripard wrote:
> Hi,
> 
> Here is an attempt at removing the hack in the sunxi code to switch
> the MMC indices depending on the boot device.
> 
> It's based on Siarhei's suggestion to go through an environment
> variable set by the code, and then having a script in our default
> bootcmd to change the boot order in order to always favour the boot
> device, instead of always picking the external MMC first.

Applied all three.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170921/7449b95e/attachment.sig>

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

end of thread, other threads:[~2017-09-21 19:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-12 20:02 [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard
2017-09-12 20:02 ` [U-Boot] [PATCH v2 1/3] arm: sunxi: Move spl_boot_device in a separate function Maxime Ripard
2017-09-12 20:02 ` [U-Boot] [PATCH v2 2/3] sunxi: Use sunxi_get_boot_device Maxime Ripard
2017-09-12 20:02 ` [U-Boot] [PATCH v2 3/3] sunxi: Remove the MMC index hack Maxime Ripard
2017-09-21 19:21 ` [U-Boot] [PATCH v2 0/3] mmc: sunxi: index hack removal Maxime Ripard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.