summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTerry Lv <r65388@freescale.com>2009-10-29 19:19:00 +0800
committerTerry Lv <r65388@freescale.com>2009-11-03 18:22:03 +0800
commitba816f983f5dac44d9f4461906b9bc0101237ac8 (patch)
tree52d3b83aa1cc146b88933f75b0a65c2dc813ea28 /common
parent3227c278048e6b13397d9d0793e77e703649d7de (diff)
downloadu-boot-imx-ba816f983f5dac44d9f4461906b9bc0101237ac8.zip
u-boot-imx-ba816f983f5dac44d9f4461906b9bc0101237ac8.tar.gz
u-boot-imx-ba816f983f5dac44d9f4461906b9bc0101237ac8.tar.bz2
u-boot v2009.08 sd/mmc support.
Signed-off-by: Terry Lv <r65388@freescale.com>
Diffstat (limited to 'common')
-rw-r--r--common/Makefile2
-rw-r--r--common/cmd_mmc.c7
-rw-r--r--common/env_mmc.c100
3 files changed, 86 insertions, 23 deletions
diff --git a/common/Makefile b/common/Makefile
index 7091eef..f71053e 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -55,6 +55,8 @@ COBJS-$(CONFIG_ENV_IS_EMBEDDED) += env_embedded.o
COBJS-$(CONFIG_ENV_IS_IN_EEPROM) += env_embedded.o
COBJS-$(CONFIG_ENV_IS_IN_FLASH) += env_embedded.o
COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_embedded.o
+COBJS-$(CONFIG_ENV_IS_IN_MMC) += env_embedded.o
+COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_embedded.o
COBJS-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
COBJS-$(CONFIG_ENV_IS_IN_MG_DISK) += env_mgdisk.o
COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index 0e3393b..421482e 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -127,9 +127,10 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
mmc = find_mmc_device(dev_num);
if (mmc) {
- mmc_init(mmc);
-
- print_mmcinfo(mmc);
+ if (mmc_init(mmc))
+ puts("MMC card init failed!\n");
+ else
+ print_mmcinfo(mmc);
}
return 0;
diff --git a/common/env_mmc.c b/common/env_mmc.c
index 74e6c60..180f39c 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -147,45 +147,74 @@ int env_init(void)
int saveenv(void)
{
size_t total;
- int ret = 0;
+ uint blk_start = 0, blk_cnt = 0, n = 0;
+ struct mmc *mmc = find_mmc_device(0);
env_ptr->flags++;
total = CONFIG_ENV_SIZE;
+ if (!mmc) {
+ puts("No MMC card found\n");
+ return;
+ }
+
+ if (mmc_init(mmc)) {
+ puts("MMC init failed\n");
+ return 1;
+ }
+
if (gd->env_valid == 1) {
puts("Writing to redundant MMC... ");
- ret = mmc_write((u_char *)env_ptr,
- CONFIG_ENV_OFFSET_REDUND, total);
+ blk_start = (CONFIG_ENV_OFFSET_REDUND % 512) ? \
+ ((CONFIG_ENV_OFFSET_REDUND / 512) + 1) : (CONFIG_ENV_OFFSET_REDUND / 512);
+ blk_cnt = (total % 512) ? ((total / 512) + 1) : (total / 512);
+ n = mmc->block_dev.block_write(0, blk_start , blk_cnt, (u_char *)env_ptr);
} else {
puts("Writing to MMC... ");
- ret = mmc_write((u_char *)env_ptr,
- CONFIG_ENV_OFFSET, total);
+ blk_start = (CONFIG_ENV_OFFSET % 512) ? \
+ ((CONFIG_ENV_OFFSET / 512) + 1) : (CONFIG_ENV_OFFSET / 512);
+ blk_cnt = (total % 512) ? ((total / 512) + 1) : (total / 512);
+ n = mmc->block_dev.block_write(0, blk_start , blk_cnt, (u_char *)env_ptr);
}
- if (ret || total != CONFIG_ENV_SIZE) {
+ if ((n != blk_cnt) || (total != CONFIG_ENV_SIZE)) {
puts("failed\n");
return 1;
}
puts("done\n");
gd->env_valid = (gd->env_valid == 2 ? 1 : 2);
- return ret;
+ return 0;
}
#else /* ! CONFIG_ENV_OFFSET_REDUND */
int saveenv(void)
{
size_t total;
- int ret = 0;
+ uint blk_start = 0, blk_cnt = 0, n = 0;
+ struct mmc *mmc = find_mmc_device(0);
+
+ if (!mmc) {
+ puts("No MMC card found\n");
+ return;
+ }
+
+ if (mmc_init(mmc)) {
+ puts("MMC init failed\n");
+ return 1;
+ }
puts("Writing to MMC... ");
total = CONFIG_ENV_SIZE;
- ret = mmc_write((u_char *)env_ptr, CONFIG_ENV_OFFSET, total);
- if (ret || total != CONFIG_ENV_SIZE) {
+ blk_start = (CONFIG_ENV_OFFSET % 512) ? \
+ ((CONFIG_ENV_OFFSET / 512) + 1) : (CONFIG_ENV_OFFSET / 512);
+ blk_cnt = (total % 512) ? ((total / 512) + 1) : (total / 512);
+ n = mmc->block_dev.block_write(0, blk_start , blk_cnt, (u_char *)env_ptr);
+ if ((n != blk_cnt) || (total != CONFIG_ENV_SIZE)) {
puts("failed\n");
return 1;
}
puts("done\n");
- return ret;
+ return 0;
}
#endif /* CONFIG_ENV_OFFSET_REDUND */
#endif /* CMD_SAVEENV */
@@ -197,11 +226,16 @@ void env_relocate_spec(void)
size_t total;
int crc1_ok = 0, crc2_ok = 0;
env_t *tmp_env1 = NULL, *tmp_env2 = NULL;
+ uint blk_start = 0, blk_cnt = 0, n = 0;
+ struct mmc *mmc = find_mmc_device(0);
- puts("Initialing MMC card... \n");
-
- if (mmc_init(1) != 0) {
+ if (!mmc) {
puts("No MMC card found\n");
+ return;
+ }
+
+ if (mmc_init(mmc)) {
+ puts("MMC init failed\n");
goto use_default;
}
@@ -222,14 +256,28 @@ void env_relocate_spec(void)
memset(tmp_env2, 0, CONFIG_ENV_SIZE);
puts("Loading environment from mmc... ");
- if (mmc_read(CONFIG_ENV_OFFSET, (uchar *)tmp_env1, total)) {
+
+ blk_start = (CONFIG_ENV_OFFSET % 512) ? \
+ ((CONFIG_ENV_OFFSET / 512) + 1) : (CONFIG_ENV_OFFSET / 512);
+ blk_cnt = (total % 512) ? ((total / 512) + 1) : (total / 512);
+
+ n = mmc->block_dev.block_read(0, blk_start, blk_cnt, (uchar *)tmp_env1);
+
+ if (n != blk_cnt) {
puts("failed\n");
goto use_default;
}
puts("done\n");
puts("Loading redundant environment from mmc... ");
- if (mmc_read(CONFIG_ENV_OFFSET_REDUND, (uchar *)tmp_env2, total)) {
+
+ blk_start = (CONFIG_ENV_OFFSET_REDUND % 512) ? \
+ ((CONFIG_ENV_OFFSET_REDUND / 512) + 1) : (CONFIG_ENV_OFFSET_REDUND / 512);
+ blk_cnt = (total % 512) ? ((total / 512) + 1) : (total / 512);
+
+ n = mmc->block_dev.block_read(0, blk_start, blk_cnt, (uchar *)tmp_env2);
+
+ if (n != blk_cnt) {
puts("failed\n");
goto use_default;
}
@@ -287,16 +335,28 @@ void env_relocate_spec(void)
{
#if !defined(ENV_IS_EMBEDDED)
size_t total;
- int ret;
+ uint blk_start = 0, blk_cnt = 0, n = 0;
+ struct mmc *mmc = find_mmc_device(0);
- if (mmc_init(1) != 0) {
+ if (!mmc) {
puts("No MMC card found\n");
+ return;
+ }
+
+ if (mmc_init(mmc)) {
+ puts("MMC init failed\n");
return;
}
total = CONFIG_ENV_SIZE;
- ret = mmc_read(CONFIG_ENV_OFFSET, (u_char *)env_ptr, total);
- if (ret || total != CONFIG_ENV_SIZE)
+
+ blk_start = (CONFIG_ENV_OFFSET % 512) ? \
+ ((CONFIG_ENV_OFFSET / 512) + 1) : (CONFIG_ENV_OFFSET / 512);
+ blk_cnt = (total % 512) ? ((total / 512) + 1) : (total / 512);
+
+ n = mmc->block_dev.block_read(0, blk_start, blk_cnt, (uchar *)env_ptr);
+
+ if ((n != blk_cnt) || (total != CONFIG_ENV_SIZE))
return use_default();
if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)