public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards
@ 2015-12-15  8:26 Peng Fan
  2015-12-15  8:26 ` [U-Boot] [PATCH 2/5] imx: mx6sabresd: implement mmc_get_env_devno Peng Fan
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Peng Fan @ 2015-12-15  8:26 UTC (permalink / raw)
  To: u-boot

Some boards support booting from different SD card slots.
For example, mx6dpsabresd board supports booting from SD2,
SD3, EMMC4, using different boot switch. And the index
numbers are SD2(0), SD3(1), EMMC4(2).
But CONFIG_SYS_MMC_ENV_DEV is hardcoded to 1(for SD3), so when
booting from SD2(using 0), uboot complains "MMC: no card present",
since there is no card in SD3 slot.

This patch introduces a weak function which still returns
CONFIG_SYS_MMC_ENV_DEV to avoid break other boards. Then
different boards can implement mmc_get_env_devno to read
env from the correct sd/emmc.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Hans de Goede <hdegoede@redhat.com>
---
 common/env_mmc.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/common/env_mmc.c b/common/env_mmc.c
index 9639822..d2e2a40 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -63,6 +63,11 @@ int env_init(void)
 	return 0;
 }
 
+__weak uint mmc_get_env_devno(void)
+{
+	return CONFIG_SYS_MMC_ENV_DEV;
+}
+
 #ifdef CONFIG_SYS_MMC_ENV_PART
 __weak uint mmc_get_env_part(struct mmc *mmc)
 {
@@ -72,7 +77,7 @@ __weak uint mmc_get_env_part(struct mmc *mmc)
 static int mmc_set_env_part(struct mmc *mmc)
 {
 	uint part = mmc_get_env_part(mmc);
-	int dev = CONFIG_SYS_MMC_ENV_DEV;
+	int dev = mmc_get_env_devno();
 	int ret = 0;
 
 #ifdef CONFIG_SPL_BUILD
@@ -108,7 +113,7 @@ static const char *init_mmc_for_env(struct mmc *mmc)
 static void fini_mmc_for_env(struct mmc *mmc)
 {
 #ifdef CONFIG_SYS_MMC_ENV_PART
-	int dev = CONFIG_SYS_MMC_ENV_DEV;
+	int dev = mmc_get_env_devno();
 
 #ifdef CONFIG_SPL_BUILD
 	dev = 0;
@@ -127,7 +132,7 @@ static inline int write_env(struct mmc *mmc, unsigned long size,
 	blk_start	= ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
 	blk_cnt		= ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
 
-	n = mmc->block_dev.block_write(CONFIG_SYS_MMC_ENV_DEV, blk_start,
+	n = mmc->block_dev.block_write(mmc_get_env_devno(), blk_start,
 					blk_cnt, (u_char *)buffer);
 
 	return (n == blk_cnt) ? 0 : -1;
@@ -140,7 +145,8 @@ static unsigned char env_flags;
 int saveenv(void)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
-	struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
+	int mmc_env_devno = mmc_get_env_devno();
+	struct mmc *mmc = find_mmc_device(mmc_env_devno);
 	u32	offset;
 	int	ret, copy = 0;
 	const char *errmsg;
@@ -168,7 +174,7 @@ int saveenv(void)
 	}
 
 	printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "",
-	       CONFIG_SYS_MMC_ENV_DEV);
+	       mmc_env_devno);
 	if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) {
 		puts("failed\n");
 		ret = 1;
@@ -192,7 +198,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
 			   unsigned long offset, const void *buffer)
 {
 	uint blk_start, blk_cnt, n;
-	int dev = CONFIG_SYS_MMC_ENV_DEV;
+	int dev = mmc_get_env_devno();
 
 #ifdef CONFIG_SPL_BUILD
 	dev = 0;
@@ -216,7 +222,7 @@ void env_relocate_spec(void)
 	int crc1_ok = 0, crc2_ok = 0;
 	env_t *ep;
 	int ret;
-	int dev = CONFIG_SYS_MMC_ENV_DEV;
+	int dev = mmc_get_env_devno();
 	const char *errmsg = NULL;
 
 	ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
@@ -302,7 +308,7 @@ void env_relocate_spec(void)
 	struct mmc *mmc;
 	u32 offset;
 	int ret;
-	int dev = CONFIG_SYS_MMC_ENV_DEV;
+	int dev = mmc_get_env_devno();
 	const char *errmsg;
 
 #ifdef CONFIG_SPL_BUILD
-- 
2.6.2

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

* [U-Boot] [PATCH 2/5] imx: mx6sabresd: implement mmc_get_env_devno
  2015-12-15  8:26 [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Peng Fan
@ 2015-12-15  8:26 ` Peng Fan
  2015-12-15  8:26 ` [U-Boot] [PATCH 3/5] imx: mx6qarm2: " Peng Fan
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Peng Fan @ 2015-12-15  8:26 UTC (permalink / raw)
  To: u-boot

Implement mmc_get_env_devno, support loading env successfully
when booting from different slots.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 board/freescale/mx6sabresd/mx6sabresd.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/board/freescale/mx6sabresd/mx6sabresd.c b/board/freescale/mx6sabresd/mx6sabresd.c
index 581c9d5..22ed331 100644
--- a/board/freescale/mx6sabresd/mx6sabresd.c
+++ b/board/freescale/mx6sabresd/mx6sabresd.c
@@ -234,6 +234,35 @@ struct fsl_esdhc_cfg usdhc_cfg[3] = {
 #define USDHC2_CD_GPIO	IMX_GPIO_NR(2, 2)
 #define USDHC3_CD_GPIO	IMX_GPIO_NR(2, 0)
 
+int mmc_get_env_devno(void)
+{
+	struct src *src_regs = (struct src *)SRC_BASE_ADDR;
+	u32 soc_sbmr = readl(&src_regs->sbmr1);
+	u32 dev_no;
+	u32 bootsel;
+
+	/*
+	 * Refer to
+	 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
+	 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
+	 */
+	bootsel = (soc_sbmr & 0x000000FF) >> 6 ;
+
+	/* If not boot from sd/mmc, use default value */
+	if (bootsel != 1)
+		return CONFIG_SYS_MMC_ENV_DEV;
+
+	/* BOOT_CFG2[3] and BOOT_CFG2[4] */
+	dev_no = (soc_sbmr & 0x00001800) >> 11;
+
+	/*
+	 * need ubstract 1 to map to the mmc device id
+	 * see the comments in board_mmc_init function
+	 */
+
+	return --dev_no;
+}
+
 int board_mmc_getcd(struct mmc *mmc)
 {
 	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
-- 
2.6.2

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

* [U-Boot] [PATCH 3/5] imx: mx6qarm2: implement mmc_get_env_devno
  2015-12-15  8:26 [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Peng Fan
  2015-12-15  8:26 ` [U-Boot] [PATCH 2/5] imx: mx6sabresd: implement mmc_get_env_devno Peng Fan
@ 2015-12-15  8:26 ` Peng Fan
  2015-12-15  8:26 ` [U-Boot] [PATCH 4/5] imx: mx6slevk: " Peng Fan
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Peng Fan @ 2015-12-15  8:26 UTC (permalink / raw)
  To: u-boot

Implement mmc_get_env_devno, support loading env successfully
when booting from different slots.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 board/freescale/mx6qarm2/mx6qarm2.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/board/freescale/mx6qarm2/mx6qarm2.c b/board/freescale/mx6qarm2/mx6qarm2.c
index 98ccdb7..245ac47 100644
--- a/board/freescale/mx6qarm2/mx6qarm2.c
+++ b/board/freescale/mx6qarm2/mx6qarm2.c
@@ -110,6 +110,29 @@ struct fsl_esdhc_cfg usdhc_cfg[2] = {
 	{USDHC4_BASE_ADDR},
 };
 
+int mmc_get_env_devno(void)
+{
+	struct src *src_regs = (struct src *)SRC_BASE_ADDR;
+	u32 soc_sbmr = readl(&src_regs->sbmr1);
+	u32 dev_no;
+	u32 bootsel;
+
+	bootsel = (soc_sbmr & 0x000000FF) >> 6 ;
+
+	/* If not boot from sd/mmc, use default value */
+	if (bootsel != 1)
+		return CONFIG_SYS_MMC_ENV_DEV;
+
+	/* BOOT_CFG2[3] and BOOT_CFG2[4] */
+	dev_no = (soc_sbmr & 0x00001800) >> 11;
+
+	/*
+	 * need ubstract 2 to map to the mmc device id
+	 * see the comments in board_mmc_init function
+	 */
+	return dev_no - 2;
+}
+
 int board_mmc_getcd(struct mmc *mmc)
 {
 	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
-- 
2.6.2

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

* [U-Boot] [PATCH 4/5] imx: mx6slevk: implement mmc_get_env_devno
  2015-12-15  8:26 [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Peng Fan
  2015-12-15  8:26 ` [U-Boot] [PATCH 2/5] imx: mx6sabresd: implement mmc_get_env_devno Peng Fan
  2015-12-15  8:26 ` [U-Boot] [PATCH 3/5] imx: mx6qarm2: " Peng Fan
@ 2015-12-15  8:26 ` Peng Fan
  2015-12-15  8:26 ` [U-Boot] [PATCH 5/5] imx: mx6sxsabresd: " Peng Fan
  2015-12-15 14:58 ` [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Stefano Babic
  4 siblings, 0 replies; 7+ messages in thread
From: Peng Fan @ 2015-12-15  8:26 UTC (permalink / raw)
  To: u-boot

Implement mmc_get_env_devno, support loading env successfully
when booting from different slots.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 board/freescale/mx6slevk/mx6slevk.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/board/freescale/mx6slevk/mx6slevk.c b/board/freescale/mx6slevk/mx6slevk.c
index 5eab4b5..7617c76 100644
--- a/board/freescale/mx6slevk/mx6slevk.c
+++ b/board/freescale/mx6slevk/mx6slevk.c
@@ -170,6 +170,22 @@ static struct fsl_esdhc_cfg usdhc_cfg[3] = {
 	{USDHC3_BASE_ADDR, 0, 4},
 };
 
+int mmc_get_env_devno(void)
+{
+	struct src *src_regs = (struct src *)SRC_BASE_ADDR;
+	u32 soc_sbmr = readl(&src_regs->sbmr1);
+	u32 bootsel;
+
+	bootsel = (soc_sbmr & 0x000000FF) >> 6 ;
+
+	/* If not boot from sd/mmc, use default value */
+	if (bootsel != 1)
+		return CONFIG_SYS_MMC_ENV_DEV;
+
+	/* BOOT_CFG2[3] and BOOT_CFG2[4] */
+	return (soc_sbmr & 0x00001800) >> 11;
+}
+
 int board_mmc_getcd(struct mmc *mmc)
 {
 	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
-- 
2.6.2

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

* [U-Boot] [PATCH 5/5] imx: mx6sxsabresd: implement mmc_get_env_devno
  2015-12-15  8:26 [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Peng Fan
                   ` (2 preceding siblings ...)
  2015-12-15  8:26 ` [U-Boot] [PATCH 4/5] imx: mx6slevk: " Peng Fan
@ 2015-12-15  8:26 ` Peng Fan
  2015-12-15 14:58 ` [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Stefano Babic
  4 siblings, 0 replies; 7+ messages in thread
From: Peng Fan @ 2015-12-15  8:26 UTC (permalink / raw)
  To: u-boot

Implement mmc_get_env_devno, support loading env successfully
when booting from different slots.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 board/freescale/mx6sxsabresd/mx6sxsabresd.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/board/freescale/mx6sxsabresd/mx6sxsabresd.c b/board/freescale/mx6sxsabresd/mx6sxsabresd.c
index 3ee4662..f524e71 100644
--- a/board/freescale/mx6sxsabresd/mx6sxsabresd.c
+++ b/board/freescale/mx6sxsabresd/mx6sxsabresd.c
@@ -309,6 +309,30 @@ static struct fsl_esdhc_cfg usdhc_cfg[3] = {
 #define USDHC3_PWR_GPIO	IMX_GPIO_NR(2, 11)
 #define USDHC4_CD_GPIO	IMX_GPIO_NR(6, 21)
 
+int mmc_get_env_devno(void)
+{
+	struct src *src_regs = (struct src *)SRC_BASE_ADDR;
+	u32 soc_sbmr = readl(&src_regs->sbmr1);
+	int dev_no;
+	u32 bootsel;
+
+	bootsel = (soc_sbmr & 0x000000FF) >> 6 ;
+
+	/* If not boot from sd/mmc, use default value */
+	if (bootsel != 1)
+		return CONFIG_SYS_MMC_ENV_DEV;
+
+	/* BOOT_CFG2[3] and BOOT_CFG2[4] */
+	dev_no = (soc_sbmr & 0x00001800) >> 11;
+
+	/*
+	 * need ubstract 1 to map to the mmc device id
+	 * see the comments in board_mmc_init function
+	 */
+
+	return --dev_no;
+}
+
 int board_mmc_getcd(struct mmc *mmc)
 {
 	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
-- 
2.6.2

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

* [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards
  2015-12-15  8:26 [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Peng Fan
                   ` (3 preceding siblings ...)
  2015-12-15  8:26 ` [U-Boot] [PATCH 5/5] imx: mx6sxsabresd: " Peng Fan
@ 2015-12-15 14:58 ` Stefano Babic
  2015-12-16  2:04   ` Peng Fan
  4 siblings, 1 reply; 7+ messages in thread
From: Stefano Babic @ 2015-12-15 14:58 UTC (permalink / raw)
  To: u-boot

Hi Peng,

On 15/12/2015 09:26, Peng Fan wrote:
> Some boards support booting from different SD card slots.
> For example, mx6dpsabresd board supports booting from SD2,
> SD3, EMMC4, using different boot switch. And the index
> numbers are SD2(0), SD3(1), EMMC4(2).
> But CONFIG_SYS_MMC_ENV_DEV is hardcoded to 1(for SD3), so when
> booting from SD2(using 0), uboot complains "MMC: no card present",
> since there is no card in SD3 slot.
> 
> This patch introduces a weak function which still returns
> CONFIG_SYS_MMC_ENV_DEV to avoid break other boards. Then
> different boards can implement mmc_get_env_devno to read
> env from the correct sd/emmc.
> 
> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tim Harvey <tharvey@gateworks.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
> ---
>  common/env_mmc.c | 22 ++++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/common/env_mmc.c b/common/env_mmc.c
> index 9639822..d2e2a40 100644
> --- a/common/env_mmc.c
> +++ b/common/env_mmc.c
> @@ -63,6 +63,11 @@ int env_init(void)
>  	return 0;
>  }
>  
> +__weak uint mmc_get_env_devno(void)
> +{
> +	return CONFIG_SYS_MMC_ENV_DEV;
> +}
> +
>  #ifdef CONFIG_SYS_MMC_ENV_PART
>  __weak uint mmc_get_env_part(struct mmc *mmc)
>  {
> @@ -72,7 +77,7 @@ __weak uint mmc_get_env_part(struct mmc *mmc)
>  static int mmc_set_env_part(struct mmc *mmc)
>  {
>  	uint part = mmc_get_env_part(mmc);
> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
> +	int dev = mmc_get_env_devno();
>  	int ret = 0;

mmc_get_env_devno() is moved inside the board file. Anyway, for i.MX6
this means to check in the SRC register to get which is the boot device.
Your board functions differ just for the number they return, depending
how many controllers are initialized.

The check routine can be factorized and moved to imx-common. The devnum
could then be extracted from a table (maybe usdhc_cfg present in all
boards).

>  
>  #ifdef CONFIG_SPL_BUILD
> @@ -108,7 +113,7 @@ static const char *init_mmc_for_env(struct mmc *mmc)
>  static void fini_mmc_for_env(struct mmc *mmc)
>  {
>  #ifdef CONFIG_SYS_MMC_ENV_PART
> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
> +	int dev = mmc_get_env_devno();
>  
>  #ifdef CONFIG_SPL_BUILD
>  	dev = 0;
> @@ -127,7 +132,7 @@ static inline int write_env(struct mmc *mmc, unsigned long size,
>  	blk_start	= ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
>  	blk_cnt		= ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
>  
> -	n = mmc->block_dev.block_write(CONFIG_SYS_MMC_ENV_DEV, blk_start,
> +	n = mmc->block_dev.block_write(mmc_get_env_devno(), blk_start,
>  					blk_cnt, (u_char *)buffer);
>  
>  	return (n == blk_cnt) ? 0 : -1;
> @@ -140,7 +145,8 @@ static unsigned char env_flags;
>  int saveenv(void)
>  {
>  	ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
> -	struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
> +	int mmc_env_devno = mmc_get_env_devno();
> +	struct mmc *mmc = find_mmc_device(mmc_env_devno);
>  	u32	offset;
>  	int	ret, copy = 0;
>  	const char *errmsg;
> @@ -168,7 +174,7 @@ int saveenv(void)
>  	}
>  
>  	printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "",
> -	       CONFIG_SYS_MMC_ENV_DEV);
> +	       mmc_env_devno);
>  	if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) {
>  		puts("failed\n");
>  		ret = 1;
> @@ -192,7 +198,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
>  			   unsigned long offset, const void *buffer)
>  {
>  	uint blk_start, blk_cnt, n;
> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
> +	int dev = mmc_get_env_devno();
>  
>  #ifdef CONFIG_SPL_BUILD
>  	dev = 0;
> @@ -216,7 +222,7 @@ void env_relocate_spec(void)
>  	int crc1_ok = 0, crc2_ok = 0;
>  	env_t *ep;
>  	int ret;
> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
> +	int dev = mmc_get_env_devno();
>  	const char *errmsg = NULL;
>  
>  	ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
> @@ -302,7 +308,7 @@ void env_relocate_spec(void)
>  	struct mmc *mmc;
>  	u32 offset;
>  	int ret;
> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
> +	int dev = mmc_get_env_devno();
>  	const char *errmsg;
>  
>  #ifdef CONFIG_SPL_BUILD
> 

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

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

* [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards
  2015-12-15 14:58 ` [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Stefano Babic
@ 2015-12-16  2:04   ` Peng Fan
  0 siblings, 0 replies; 7+ messages in thread
From: Peng Fan @ 2015-12-16  2:04 UTC (permalink / raw)
  To: u-boot

Hi Stefano,

On Tue, Dec 15, 2015 at 03:58:47PM +0100, Stefano Babic wrote:
>Hi Peng,
>
>On 15/12/2015 09:26, Peng Fan wrote:
>> Some boards support booting from different SD card slots.
>> For example, mx6dpsabresd board supports booting from SD2,
>> SD3, EMMC4, using different boot switch. And the index
>> numbers are SD2(0), SD3(1), EMMC4(2).
>> But CONFIG_SYS_MMC_ENV_DEV is hardcoded to 1(for SD3), so when
>> booting from SD2(using 0), uboot complains "MMC: no card present",
>> since there is no card in SD3 slot.
>> 
>> This patch introduces a weak function which still returns
>> CONFIG_SYS_MMC_ENV_DEV to avoid break other boards. Then
>> different boards can implement mmc_get_env_devno to read
>> env from the correct sd/emmc.
>> 
>> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
>> Cc: Stefano Babic <sbabic@denx.de>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Tim Harvey <tharvey@gateworks.com>
>> Cc: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  common/env_mmc.c | 22 ++++++++++++++--------
>>  1 file changed, 14 insertions(+), 8 deletions(-)
>> 
>> diff --git a/common/env_mmc.c b/common/env_mmc.c
>> index 9639822..d2e2a40 100644
>> --- a/common/env_mmc.c
>> +++ b/common/env_mmc.c
>> @@ -63,6 +63,11 @@ int env_init(void)
>>  	return 0;
>>  }
>>  
>> +__weak uint mmc_get_env_devno(void)
>> +{
>> +	return CONFIG_SYS_MMC_ENV_DEV;
>> +}
>> +
>>  #ifdef CONFIG_SYS_MMC_ENV_PART
>>  __weak uint mmc_get_env_part(struct mmc *mmc)
>>  {
>> @@ -72,7 +77,7 @@ __weak uint mmc_get_env_part(struct mmc *mmc)
>>  static int mmc_set_env_part(struct mmc *mmc)
>>  {
>>  	uint part = mmc_get_env_part(mmc);
>> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
>> +	int dev = mmc_get_env_devno();
>>  	int ret = 0;
>
>mmc_get_env_devno() is moved inside the board file. Anyway, for i.MX6
>this means to check in the SRC register to get which is the boot device.
>Your board functions differ just for the number they return, depending
>how many controllers are initialized.
>
>The check routine can be factorized and moved to imx-common. The devnum
>could then be extracted from a table (maybe usdhc_cfg present in all
>boards).

Thanks for comments. How about the following way:

Add the weak function in imx-common/cpu.c:
__weak int board_mmc_get_env_devno(int devno)
{
	return CONFIG_SYS_MMC_ENV_DEV;
}

Add add in arch/arm/cpu/armv7/mx6/soc.c
int mmc_get_env_devno(void)
{
	devno = [ check src smbr1 ]

	return board_mmc_get_env_devno(devno)
}
For i.MX7, it's different, and need to fix it in arch/arm/cpu/armv7/mx7/soc.c

And final in board file,implement
int board_mmc_get_env_devno(int devno)
{	
   following is example for different boot slot used by different boards:
	sd1/sd2/sd3, return devno;
	sd2/sd3, return devno - 1;
	sd3/sd4, return devno - 2;
	sd1/sd4, if (devno == 3) return devno - 2; return devno
}

Thanks,
Peng.
>
>>  
>>  #ifdef CONFIG_SPL_BUILD
>> @@ -108,7 +113,7 @@ static const char *init_mmc_for_env(struct mmc *mmc)
>>  static void fini_mmc_for_env(struct mmc *mmc)
>>  {
>>  #ifdef CONFIG_SYS_MMC_ENV_PART
>> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
>> +	int dev = mmc_get_env_devno();
>>  
>>  #ifdef CONFIG_SPL_BUILD
>>  	dev = 0;
>> @@ -127,7 +132,7 @@ static inline int write_env(struct mmc *mmc, unsigned long size,
>>  	blk_start	= ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
>>  	blk_cnt		= ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len;
>>  
>> -	n = mmc->block_dev.block_write(CONFIG_SYS_MMC_ENV_DEV, blk_start,
>> +	n = mmc->block_dev.block_write(mmc_get_env_devno(), blk_start,
>>  					blk_cnt, (u_char *)buffer);
>>  
>>  	return (n == blk_cnt) ? 0 : -1;
>> @@ -140,7 +145,8 @@ static unsigned char env_flags;
>>  int saveenv(void)
>>  {
>>  	ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
>> -	struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
>> +	int mmc_env_devno = mmc_get_env_devno();
>> +	struct mmc *mmc = find_mmc_device(mmc_env_devno);
>>  	u32	offset;
>>  	int	ret, copy = 0;
>>  	const char *errmsg;
>> @@ -168,7 +174,7 @@ int saveenv(void)
>>  	}
>>  
>>  	printf("Writing to %sMMC(%d)... ", copy ? "redundant " : "",
>> -	       CONFIG_SYS_MMC_ENV_DEV);
>> +	       mmc_env_devno);
>>  	if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)env_new)) {
>>  		puts("failed\n");
>>  		ret = 1;
>> @@ -192,7 +198,7 @@ static inline int read_env(struct mmc *mmc, unsigned long size,
>>  			   unsigned long offset, const void *buffer)
>>  {
>>  	uint blk_start, blk_cnt, n;
>> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
>> +	int dev = mmc_get_env_devno();
>>  
>>  #ifdef CONFIG_SPL_BUILD
>>  	dev = 0;
>> @@ -216,7 +222,7 @@ void env_relocate_spec(void)
>>  	int crc1_ok = 0, crc2_ok = 0;
>>  	env_t *ep;
>>  	int ret;
>> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
>> +	int dev = mmc_get_env_devno();
>>  	const char *errmsg = NULL;
>>  
>>  	ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
>> @@ -302,7 +308,7 @@ void env_relocate_spec(void)
>>  	struct mmc *mmc;
>>  	u32 offset;
>>  	int ret;
>> -	int dev = CONFIG_SYS_MMC_ENV_DEV;
>> +	int dev = mmc_get_env_devno();
>>  	const char *errmsg;
>>  
>>  #ifdef CONFIG_SPL_BUILD
>> 
>
>Best regards,
>Stefano Babic
>
>-- 
>=====================================================================
>DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
>HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
>=====================================================================

-- 

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

end of thread, other threads:[~2015-12-16  2:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-15  8:26 [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Peng Fan
2015-12-15  8:26 ` [U-Boot] [PATCH 2/5] imx: mx6sabresd: implement mmc_get_env_devno Peng Fan
2015-12-15  8:26 ` [U-Boot] [PATCH 3/5] imx: mx6qarm2: " Peng Fan
2015-12-15  8:26 ` [U-Boot] [PATCH 4/5] imx: mx6slevk: " Peng Fan
2015-12-15  8:26 ` [U-Boot] [PATCH 5/5] imx: mx6sxsabresd: " Peng Fan
2015-12-15 14:58 ` [U-Boot] [PATCH 1/5] common: env_mmc: support loading env from different cards Stefano Babic
2015-12-16  2:04   ` Peng Fan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox