summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Jin <Jason.jin@freescale.com>2009-10-07 15:47:46 -0400
committerJustin Waters <justin.waters@timesys.com>2009-10-07 15:47:46 -0400
commita83e4a111f3e582308f0a3d5481d6d28c6a4c23c (patch)
tree97d707dffc80a24cfd4fc5e0201ad0a4cb77baa0
parent8db78c124a27452c4d196b31b285d7ef34b24c62 (diff)
u-boot-2009.03-p2020rdb-Save-env-to-SDcard-MPC8536DS
Add support for save the env to SDcard This Patch is borrowed from MPC8536DS SD Card Boot. When after booting from SDcard, the environment variables can to be saved on it, this patch add the operation support. Signed-off-by: Jason Jin <Jason.jin@freescale.com> Signed-off-by: Mingkai Hu <Mingkai.hu@freescale.com>
-rw-r--r--common/Makefile1
-rw-r--r--common/cmd_nvedit.c3
-rw-r--r--common/env_common.c3
-rw-r--r--common/env_sdcard.c129
4 files changed, 134 insertions, 2 deletions
diff --git a/common/Makefile b/common/Makefile
index f13cd11b9a..c768344a64 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -57,6 +57,7 @@ COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
+COBJS-$(CONFIG_ENV_IS_IN_SDCARD) += env_sdcard.o
COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
# command
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 68c673e7cc..fb6ba8da2e 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -59,8 +59,9 @@ DECLARE_GLOBAL_DATA_PTR;
!defined(CONFIG_ENV_IS_IN_NAND) && \
!defined(CONFIG_ENV_IS_IN_ONENAND) && \
!defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
+ !defined(CONFIG_ENV_IS_IN_SDCARD) && \
!defined(CONFIG_ENV_IS_NOWHERE)
-# error Define one of CONFIG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|ONENAND|SPI_FLASH|NOWHERE}
+# error Define one of CONFIG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|ONENAND|SPI_FLASH|SDCARD|NOWHERE}
#endif
#define XMK_STR(x) #x
diff --git a/common/env_common.c b/common/env_common.c
index 6be3bb04ac..f1aaed2399 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -140,7 +140,8 @@ uchar default_environment[] = {
};
#if defined(CONFIG_ENV_IS_IN_NAND) /* Environment is in Nand Flash */ \
- || defined(CONFIG_ENV_IS_IN_SPI_FLASH)
+ || defined(CONFIG_ENV_IS_IN_SPI_FLASH) \
+ || defined(CONFIG_ENV_IS_IN_SDCARD)
int default_environment_size = sizeof(default_environment);
#endif
diff --git a/common/env_sdcard.c b/common/env_sdcard.c
new file mode 100644
index 0000000000..1afcbbb5bf
--- /dev/null
+++ b/common/env_sdcard.c
@@ -0,0 +1,129 @@
+ /*
+ * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
+ * Author: Jason.jin <jason.jin@freescale.com>
+ *
+ * Changelog:
+ * July 2008, Intial version.
+ * March 2009, Use the MMC framework's read/write function.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This file is only used for booting from SD card, During the
+ * booting up process, the environments was reading into memory
+ * together with the u-boot images. The environments locate
+ * from the last 8K of the 512k special version u-boot image.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+#include <mmc.h>
+
+#ifdef CONFIG_ENV_IS_IN_SDCARD
+
+#include <environment.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define SD_BLK_SIZE 512
+
+/* references to names in env_common.c */
+extern uchar default_environment[];
+extern int default_environment_size;
+
+char *env_name_spec = "SD CARD";
+env_t *env_ptr;
+
+uchar env_get_char_spec(int index)
+{
+ return *((uchar *)(gd->env_addr + index));
+}
+
+int saveenv(void)
+{
+ int env_blknr, env_blkcnt;
+ int code_offset, code_len, env_addr;
+ uchar tmp_buf[512];
+ int n, tmp_crc;
+ struct mmc *mmc = find_mmc_device(0);
+
+ mmc_init(mmc);
+
+ /* read out the first block, get the config data information */
+ env_blknr = 0;
+ env_blkcnt = 1;
+ n = mmc->block_dev.block_read(0, env_blknr, env_blkcnt, tmp_buf);
+ if (n != env_blkcnt)
+ return 1;
+
+ /* Get the Source Address, from offset 0x50 */
+ code_offset = *(unsigned long *)(tmp_buf + 0x50);
+
+ /* Get the code size from offset 0x48, the size incude the env size 8K */
+ code_len = *(unsigned long *)(tmp_buf + 0x48);
+ env_addr = code_offset + code_len - CONFIG_ENV_SIZE;
+
+ env_blknr = env_addr / SD_BLK_SIZE;
+ env_blkcnt = CONFIG_ENV_SIZE / SD_BLK_SIZE;
+
+ n = mmc->block_dev.block_write(0, env_blknr, env_blkcnt, env_ptr);
+ if (n != env_blkcnt)
+ return 1;
+
+ puts("done\n");
+ return 0;
+}
+
+void env_relocate_spec(void)
+{
+ /*Just copy to relocate place*/
+ memcpy((u8 *)env_ptr, (u8 *)CONFIG_ENV_ADDR_IN_RAM, CONFIG_ENV_SIZE);
+
+ if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) {
+ puts("*** Warning - bad CRC, using default environment\n\n");
+
+ if (default_environment_size > CONFIG_ENV_SIZE) {
+ gd->env_valid = 0;
+ puts("*** Error - default environment is too large\n\n");
+ return;
+ }
+
+ memset(env_ptr, 0, sizeof(env_t));
+ memcpy(env_ptr->data, default_environment, default_environment_size);
+ env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
+ }
+ gd->env_valid = 1;
+}
+
+int env_init(void)
+{
+ /* The ROM code has copied the u-boot and the env to RAM
+ * But we need to know if there're env settings there by crc check
+ */
+
+ env_t *env_ptr_tmp = (env_t *)CONFIG_ENV_ADDR_IN_RAM;
+ if (crc32(0, env_ptr_tmp->data, ENV_SIZE) == env_ptr_tmp->crc) {
+ gd->env_addr = (ulong)&(env_ptr_tmp->data);
+ gd->env_valid = 1;
+ return 0;
+ }
+
+ gd->env_addr = (ulong)&default_environment[0];
+ gd->env_valid = 0;
+ return 0;
+}
+
+#endif /* CONFIG_ENV_IS_IN_SDCARD */