diff options
author | Ye.Li <B37916@freescale.com> | 2014-06-04 17:50:16 +0800 |
---|---|---|
committer | Ye.Li <B37916@freescale.com> | 2014-06-17 11:13:41 +0800 |
commit | 28ae592dc9ec6611e5b7ced1fa4e08b8f930da0f (patch) | |
tree | 7ea25d62abb5bbb17dea13ff16fee1666bb77326 | |
parent | 42b574439e5173bfc0f6e91843de770832a6a4d8 (diff) | |
download | u-boot-imx-28ae592dc9ec6611e5b7ced1fa4e08b8f930da0f.zip u-boot-imx-28ae592dc9ec6611e5b7ced1fa4e08b8f930da0f.tar.gz u-boot-imx-28ae592dc9ec6611e5b7ced1fa4e08b8f930da0f.tar.bz2 |
ENGR00315894-16 env_mmc: add the dynamtic mmc dev support
This patch add the support to load/save env to the slot which
was used as the boot media by dynamic detection.
Signed-off-by: Jason Liu <r64343@freescale.com>
Signed-off-by: Ye.Li <B37916@freescale.com>
-rw-r--r-- | common/env_mmc.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/common/env_mmc.c b/common/env_mmc.c index 045428c..0d4e8a2 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2008-2011 Freescale Semiconductor, Inc. + * (C) Copyright 2008-2014 Freescale Semiconductor, Inc. * * SPDX-License-Identifier: GPL-2.0+ */ @@ -53,6 +53,11 @@ __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr) return 0; } +__weak int mmc_get_env_devno(void) +{ + return CONFIG_SYS_MMC_ENV_DEV; +} + int env_init(void) { /* use default */ @@ -76,7 +81,9 @@ static int init_mmc_for_env(struct mmc *mmc) #ifdef CONFIG_SYS_MMC_ENV_PART if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num) { - if (mmc_switch_part(CONFIG_SYS_MMC_ENV_DEV, + int mmc_env_devno = mmc_get_env_devno(); + + if (mmc_switch_part(mmc_env_devno, CONFIG_SYS_MMC_ENV_PART)) { puts("MMC partition switch failed\n"); return -1; @@ -90,8 +97,10 @@ static int init_mmc_for_env(struct mmc *mmc) static void fini_mmc_for_env(struct mmc *mmc) { #ifdef CONFIG_SYS_MMC_ENV_PART + int mmc_env_devno = mmc_get_env_devno(); + if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num) - mmc_switch_part(CONFIG_SYS_MMC_ENV_DEV, + mmc_switch_part(mmc_env_devno, mmc->part_num); #endif } @@ -101,11 +110,12 @@ static inline int write_env(struct mmc *mmc, unsigned long size, unsigned long offset, const void *buffer) { uint blk_start, blk_cnt, n; + int mmc_env_devno = mmc_get_env_devno(); 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_env_devno, blk_start, blk_cnt, (u_char *)buffer); return (n == blk_cnt) ? 0 : -1; @@ -118,9 +128,10 @@ static unsigned char env_flags; int saveenv(void) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); + int mmc_env_devno = mmc_get_env_devno(); ssize_t len; char *res; - struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); + struct mmc *mmc = find_mmc_device(mmc_env_devno); u32 offset; int ret, copy = 0; @@ -150,7 +161,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; @@ -174,11 +185,12 @@ static inline int read_env(struct mmc *mmc, unsigned long size, unsigned long offset, const void *buffer) { uint blk_start, blk_cnt, n; + int mmc_env_devno = mmc_get_env_devno(); blk_start = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len; blk_cnt = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len; - n = mmc->block_dev.block_read(CONFIG_SYS_MMC_ENV_DEV, blk_start, + n = mmc->block_dev.block_read(mmc_env_devno, blk_start, blk_cnt, (uchar *)buffer); return (n == blk_cnt) ? 0 : -1; @@ -188,7 +200,8 @@ static inline int read_env(struct mmc *mmc, unsigned long size, void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) - 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 offset1, offset2; int read1_fail = 0, read2_fail = 0; int crc1_ok = 0, crc2_ok = 0; @@ -274,7 +287,8 @@ void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); - 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; |