[U-Boot] [PATCH] env_mmc: avoid stack allocation for env

Tim Harvey tharvey at gateworks.com
Fri May 8 23:51:36 CEST 2015


Allocating space for temporary env on the stack makes env_relocate_spec()
unsuitable for SPL environments which have very little stack.

Signed-off-by: Tim Harvey <tharvey at gateworks.com>
---
 common/env_mmc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/common/env_mmc.c b/common/env_mmc.c
index 6c4ce2f..19a28da 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -213,13 +213,19 @@ void env_relocate_spec(void)
 	u32 offset1, offset2;
 	int read1_fail = 0, read2_fail = 0;
 	int crc1_ok = 0, crc2_ok = 0;
-	env_t *ep;
+	env_t *ep, *tmp_env1, *tmp_env2;
 	int ret;
 	int dev = CONFIG_SYS_MMC_ENV_DEV;
 	const char *errmsg = NULL;
 
-	ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
-	ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env2, 1);
+	tmp_env1 = memalign(CONFIG_SYS_CACHELINE_SIZE, CONFIG_ENV_SIZE);
+	tmp_env2 = memalign(CONFIG_SYS_CACHELINE_SIZE, CONFIG_ENV_SIZE);
+	if (tmp_env1 == NULL || tmp_env2 == NULL) {
+		puts("Can't allocate buffers for environment\n");
+		ret = 1;
+		errmsg = "!malloc() failed";
+		goto err;
+	}
 
 #ifdef CONFIG_SPL_BUILD
 	dev = 0;
@@ -287,6 +293,8 @@ void env_relocate_spec(void)
 	ret = 0;
 
 fini:
+	free(tmp_env1);
+	free(tmp_env2);
 	fini_mmc_for_env(mmc);
 err:
 	if (ret)
-- 
1.9.1



More information about the U-Boot mailing list