diff mbox series

[U-Boot] arm64: mvebu: armada-8k: support environment in SD/eMMC

Message ID 0278485e06b662d47904d8447a1dbb8945d3f289.1534259146.git.baruch@tkos.co.il
State Accepted
Commit 7e1d32208e035b3014e8dd83dbe41506327f5d40
Delegated to: Stefan Roese
Headers show
Series [U-Boot] arm64: mvebu: armada-8k: support environment in SD/eMMC | expand

Commit Message

Baruch Siach Aug. 14, 2018, 3:05 p.m. UTC
Detect the SD/eMMC boot device at run-time. Load the environment from
the boot deice, as well as save to it.

Leave the environment offset the same as in the SPI flash.

Make SD/eMMC 0 the default environment device when the boot device is
not detected.

Cc: Konstantin Porotchkin <kostap@marvell.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 arch/arm/mach-mvebu/armada8k/cpu.c | 24 ++++++++++++++++++++++++
 include/configs/mvebu_armada-8k.h  |  3 +++
 2 files changed, 27 insertions(+)

Comments

Stefan Roese Sept. 19, 2018, 12:15 p.m. UTC | #1
On 14.08.2018 17:05, Baruch Siach wrote:
> Detect the SD/eMMC boot device at run-time. Load the environment from
> the boot deice, as well as save to it.
> 
> Leave the environment offset the same as in the SPI flash.
> 
> Make SD/eMMC 0 the default environment device when the boot device is
> not detected.
> 
> Cc: Konstantin Porotchkin <kostap@marvell.com>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
>   arch/arm/mach-mvebu/armada8k/cpu.c | 24 ++++++++++++++++++++++++
>   include/configs/mvebu_armada-8k.h  |  3 +++
>   2 files changed, 27 insertions(+)
> 
> diff --git a/arch/arm/mach-mvebu/armada8k/cpu.c b/arch/arm/mach-mvebu/armada8k/cpu.c
> index f8e8e73610d2..959a7cff7641 100644
> --- a/arch/arm/mach-mvebu/armada8k/cpu.c
> +++ b/arch/arm/mach-mvebu/armada8k/cpu.c
> @@ -18,6 +18,10 @@
>   #define RFU_GLOBAL_SW_RST		(MVEBU_RFU_BASE + 0x84)
>   #define RFU_SW_RESET_OFFSET		0
>   
> +#define SAR0_REG			(MVEBU_REGISTER(0x2400200))
> +#define BOOT_MODE_MASK			0x3f
> +#define BOOT_MODE_OFFSET		4
> +
>   /*
>    * The following table includes all memory regions for Armada 7k and
>    * 8k SoCs. The Armada 7k is missing the CP110 slave regions here. Lets
> @@ -125,3 +129,23 @@ u32 mvebu_get_nand_clock(void)
>   	else
>   		return 250 * 1000000;
>   }
> +
> +int mmc_get_env_dev(void)
> +{
> +	u32 reg;
> +	unsigned int boot_mode;
> +
> +	reg = readl(SAR0_REG);
> +	boot_mode = (reg >> BOOT_MODE_OFFSET) & BOOT_MODE_MASK;
> +
> +	switch (boot_mode) {
> +	case 0x28:
> +	case 0x2a:
> +		return 0;
> +	case 0x29:
> +	case 0x2b:
> +		return 1;
> +	}
> +
> +	return CONFIG_SYS_MMC_ENV_DEV;
> +}
> diff --git a/include/configs/mvebu_armada-8k.h b/include/configs/mvebu_armada-8k.h
> index 9205bd9632c3..b84ce670e8b3 100644
> --- a/include/configs/mvebu_armada-8k.h
> +++ b/include/configs/mvebu_armada-8k.h
> @@ -66,6 +66,9 @@
>   #define CONFIG_ENV_SIZE			(64 << 10) /* 64KiB */
>   #define CONFIG_ENV_SECT_SIZE		(64 << 10) /* 64KiB sectors */
>   
> +/* When runtime detection fails this is the default */
> +#define CONFIG_SYS_MMC_ENV_DEV		0
> +
>   #define CONFIG_SYS_MAX_NAND_DEVICE	1
>   #define CONFIG_SYS_NAND_MAX_CHIPS	1
>   #define CONFIG_SYS_NAND_ONFI_DETECTION
> 

Applied to u-boot-marvell/master

Thanks,
Stefan
diff mbox series

Patch

diff --git a/arch/arm/mach-mvebu/armada8k/cpu.c b/arch/arm/mach-mvebu/armada8k/cpu.c
index f8e8e73610d2..959a7cff7641 100644
--- a/arch/arm/mach-mvebu/armada8k/cpu.c
+++ b/arch/arm/mach-mvebu/armada8k/cpu.c
@@ -18,6 +18,10 @@ 
 #define RFU_GLOBAL_SW_RST		(MVEBU_RFU_BASE + 0x84)
 #define RFU_SW_RESET_OFFSET		0
 
+#define SAR0_REG			(MVEBU_REGISTER(0x2400200))
+#define BOOT_MODE_MASK			0x3f
+#define BOOT_MODE_OFFSET		4
+
 /*
  * The following table includes all memory regions for Armada 7k and
  * 8k SoCs. The Armada 7k is missing the CP110 slave regions here. Lets
@@ -125,3 +129,23 @@  u32 mvebu_get_nand_clock(void)
 	else
 		return 250 * 1000000;
 }
+
+int mmc_get_env_dev(void)
+{
+	u32 reg;
+	unsigned int boot_mode;
+
+	reg = readl(SAR0_REG);
+	boot_mode = (reg >> BOOT_MODE_OFFSET) & BOOT_MODE_MASK;
+
+	switch (boot_mode) {
+	case 0x28:
+	case 0x2a:
+		return 0;
+	case 0x29:
+	case 0x2b:
+		return 1;
+	}
+
+	return CONFIG_SYS_MMC_ENV_DEV;
+}
diff --git a/include/configs/mvebu_armada-8k.h b/include/configs/mvebu_armada-8k.h
index 9205bd9632c3..b84ce670e8b3 100644
--- a/include/configs/mvebu_armada-8k.h
+++ b/include/configs/mvebu_armada-8k.h
@@ -66,6 +66,9 @@ 
 #define CONFIG_ENV_SIZE			(64 << 10) /* 64KiB */
 #define CONFIG_ENV_SECT_SIZE		(64 << 10) /* 64KiB sectors */
 
+/* When runtime detection fails this is the default */
+#define CONFIG_SYS_MMC_ENV_DEV		0
+
 #define CONFIG_SYS_MAX_NAND_DEVICE	1
 #define CONFIG_SYS_NAND_MAX_CHIPS	1
 #define CONFIG_SYS_NAND_ONFI_DETECTION