[U-Boot] [PATCH v1 3/3] mpc8536: Get the address of env on the SDCard

Mingkai Hu Mingkai.hu at freescale.com
Fri Sep 11 05:40:45 CEST 2009


Both the save env and load env operation will call this function
to get the address of env on the SDCard, so the user can control
where to put the env freely.

Also enable the functionlity of saving env variable to SDCard on
mpc8536

Signed-off-by: Mingkai Hu <Mingkai.hu at freescale.com>
---
 board/freescale/mpc8536ds/mpc8536ds.c |   46 +++++++++++++++++++++++++++++++++
 include/configs/MPC8536DS.h           |    5 +++-
 2 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/board/freescale/mpc8536ds/mpc8536ds.c b/board/freescale/mpc8536ds/mpc8536ds.c
index da72916..85a3dc3 100644
--- a/board/freescale/mpc8536ds/mpc8536ds.c
+++ b/board/freescale/mpc8536ds/mpc8536ds.c
@@ -38,6 +38,8 @@
 #include <tsec.h>
 #include <netdev.h>
 #include <sata.h>
+#include <mmc.h>
+#include <malloc.h>
 
 #include "../common/pixis.h"
 #include "../common/sgmii_riser.h"
@@ -681,3 +683,47 @@ void ft_board_setup(void *blob, bd_t *bd)
 #endif
 }
 #endif
+
+#if defined(CONFIG_MMC)
+/*
+ * The environment variables are written to just after the u-boot image
+ * on SDCard, so we must read the MBR to get the start address and code
+ * length of the u-boot image, then calculate the address of the env.
+ */
+#define ESDHC_BOOT_IMAGE_SIZE	0x48
+#define ESDHC_BOOT_IMAGE_ADDR	0x50
+
+int mmc_get_env_addr(int dev, u32 *env_addr)
+{
+	int ret;
+	u8 *tmp_buf;
+	u32 blklen, code_offset, code_len;
+	struct mmc *mmc = find_mmc_device(dev);
+
+	mmc_init(mmc);
+
+	blklen = mmc->read_bl_len;
+	tmp_buf = malloc(blklen);
+	if (!tmp_buf)
+		return 1;
+
+	/* read out the first block, get the config data information */
+	ret = mmc_read(mmc, 0, tmp_buf, blklen);
+	if (ret) {
+		free(tmp_buf);
+		return 1;
+	}
+
+	/* Get the Source Address, from offset 0x50 */
+	code_offset = *(u32 *)(tmp_buf + ESDHC_BOOT_IMAGE_ADDR);
+
+	/* Get the code size from offset 0x48 */
+	code_len = *(u32 *)(tmp_buf + ESDHC_BOOT_IMAGE_SIZE);
+
+	*env_addr = code_offset + code_len;
+
+	free(tmp_buf);
+
+	return 0;
+}
+#endif
diff --git a/include/configs/MPC8536DS.h b/include/configs/MPC8536DS.h
index 580d66f..6ffa894 100644
--- a/include/configs/MPC8536DS.h
+++ b/include/configs/MPC8536DS.h
@@ -633,7 +633,10 @@ extern unsigned long get_board_ddr_clk(unsigned long dummy);
 	#define CONFIG_ENV_IS_IN_NAND	1
 	#define CONFIG_ENV_SIZE		CONFIG_SYS_NAND_BLOCK_SIZE
 	#define CONFIG_ENV_OFFSET	((512 * 1024) + CONFIG_SYS_NAND_BLOCK_SIZE)
-#elif defined(CONFIG_RAMBOOT_SPIFLASH) || defined(CONFIG_RAMBOOT_SDCARD)
+#elif defined(CONFIG_RAMBOOT_SDCARD)
+        #define CONFIG_ENV_IS_IN_SDCARD         1
+        #define CONFIG_ENV_SIZE                 0x2000
+#elif defined(CONFIG_RAMBOOT_SPIFLASH)
 	#define CONFIG_ENV_IS_NOWHERE	1	/* Store ENV in memory only */
 	#define CONFIG_ENV_ADDR		(CONFIG_SYS_MONITOR_BASE - 0x1000)
 	#define CONFIG_ENV_SIZE		0x2000
-- 
1.6.4



More information about the U-Boot mailing list