[U-Boot] [PATCH 10/10] Get the address of env on the SDCard

Mingkai Hu Mingkai.hu at freescale.com
Tue Aug 18 09:37:22 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.

Signed-off-by: Mingkai Hu <Mingkai.hu at freescale.com>
---
 board/freescale/mpc8536ds/mpc8536ds.c |   43 +++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/board/freescale/mpc8536ds/mpc8536ds.c b/board/freescale/mpc8536ds/mpc8536ds.c
index 8c5984b..b32b84b 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"
@@ -705,3 +707,44 @@ 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.
+ */
+int mmc_get_env_addr(int dev, u32 *env_addr)
+{
+	uint blklen;
+	int ret, code_offset, code_len;
+	uchar *tmp_buf;
+	struct mmc *mmc = find_mmc_device(dev);
+
+	mmc_init(mmc);
+
+	blklen = mmc->read_bl_len;
+	tmp_buf = (uchar *)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 = *(unsigned long *)(tmp_buf + 0x50);
+
+	/* Get the code size from offset 0x48 */
+	code_len = *(unsigned long *)(tmp_buf + 0x48);
+
+	*env_addr = code_offset + code_len;
+
+	free(tmp_buf);
+
+	return 0;
+}
+#endif
-- 
1.5.4



More information about the U-Boot mailing list