[U-Boot] [U-BOOT] [PATCH] env: reduce the stack footprint for the env buf
Lei Wen
leiwen at marvell.com
Fri Feb 4 04:08:23 CET 2011
Original env buf directly locate at stack lead large stack footprint
when call those env functions. It is not good when the system memory
is critical or only want the uboot run at restrict range, that is not
to touch the memory of other place at its best.
So now this patch move the env buf to the heap area, which reduce the
area uboot need to touch.
Signed-off-by: Lei Wen <leiwen at marvell.com>
---
common/env_dataflash.c | 8 +++++++-
common/env_eeprom.c | 8 +++++++-
common/env_mgdisk.c | 10 +++++++++-
common/env_mmc.c | 9 ++++++++-
common/env_nand.c | 10 +++++++++-
common/env_nvram.c | 9 ++++++++-
common/env_sf.c | 9 ++++++++-
7 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/common/env_dataflash.c b/common/env_dataflash.c
index 1d57079..a5a409a 100644
--- a/common/env_dataflash.c
+++ b/common/env_dataflash.c
@@ -50,11 +50,17 @@ uchar env_get_char_spec(int index)
void env_relocate_spec(void)
{
- char buf[CONFIG_ENV_SIZE];
+ char *buf;
+ buf = malloc(CONFIG_ENV_SIZE);
+ if (!buf) {
+ set_default_env("!dataflash env buf malloc failed");
+ return;
+ }
read_dataflash(CONFIG_ENV_ADDR, CONFIG_ENV_SIZE, buf);
env_import(buf, 1);
+ free(buf);
}
#ifdef CONFIG_ENV_OFFSET_REDUND
diff --git a/common/env_eeprom.c b/common/env_eeprom.c
index 0a179ad..ed7d2d7 100644
--- a/common/env_eeprom.c
+++ b/common/env_eeprom.c
@@ -113,9 +113,14 @@ uchar env_get_char_spec (int index)
void env_relocate_spec (void)
{
- char buf[CONFIG_ENV_SIZE];
+ char *buf;
unsigned int off = CONFIG_ENV_OFFSET;
+ buf = malloc(CONFIG_ENV_SIZE);
+ if (!buf) {
+ set_default_env("!eeprom env buf malloc failed");
+ return;
+ }
#ifdef CONFIG_ENV_OFFSET_REDUND
if (gd->env_valid == 2)
off = CONFIG_ENV_OFFSET_REDUND;
@@ -126,6 +131,7 @@ void env_relocate_spec (void)
CONFIG_ENV_SIZE);
env_import(buf, 1);
+ free(buf);
}
int saveenv(void)
diff --git a/common/env_mgdisk.c b/common/env_mgdisk.c
index a69923b..7638ac3 100644
--- a/common/env_mgdisk.c
+++ b/common/env_mgdisk.c
@@ -43,22 +43,30 @@ uchar env_get_char_spec(int index)
void env_relocate_spec(void)
{
- char buf[CONFIG_ENV_SIZE];
+ char *buf;
unsigned int err, rc;
+ buf = malloc(CONFIG_ENV_SIZE);
+ if (!buf) {
+ set_default_env("!mgdisk env buf malloc failed");
+ return;
+ }
err = mg_disk_init();
if (err) {
set_default_env("!mg_disk_init error");
+ free(buf);
return;
}
err = mg_disk_read(CONFIG_ENV_ADDR, buf, CONFIG_ENV_SIZE);
if (err) {
set_default_env("!mg_disk_read error");
+ free(buf);
return;
}
env_import(buf, 1);
+ free(buf);
}
int saveenv(void)
diff --git a/common/env_mmc.c b/common/env_mmc.c
index 71dcc4c..2eb2953 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -141,7 +141,7 @@ inline int read_env(struct mmc *mmc, unsigned long size,
void env_relocate_spec(void)
{
#if !defined(ENV_IS_EMBEDDED)
- char buf[CONFIG_ENV_SIZE];
+ char *buf;
struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
@@ -150,12 +150,19 @@ void env_relocate_spec(void)
return;
}
+ buf = malloc(CONFIG_ENV_SIZE);
+ if (!buf) {
+ set_default_env("!mmc env buf malloc failed");
+ return;
+ }
if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) {
use_default();
+ free(buf);
return;
}
env_import(buf, 1);
+ free(buf);
#endif
}
diff --git a/common/env_nand.c b/common/env_nand.c
index 2682f07..3efc23d 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -416,8 +416,13 @@ void env_relocate_spec (void)
{
#if !defined(ENV_IS_EMBEDDED)
int ret;
- char buf[CONFIG_ENV_SIZE];
+ char *buf;
+ buf = malloc(CONFIG_ENV_SIZE);
+ if (!buf) {
+ set_default_env("!nand env buf malloc failed");
+ return;
+ }
#if defined(CONFIG_ENV_OFFSET_OOB)
ret = get_nand_env_oob(&nand_info[0], &nand_env_oob_offset);
/*
@@ -428,6 +433,7 @@ void env_relocate_spec (void)
printf("Found Environment offset in OOB..\n");
} else {
set_default_env("!no env offset in OOB");
+ free(buf);
return;
}
#endif
@@ -435,10 +441,12 @@ void env_relocate_spec (void)
ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
if (ret) {
set_default_env("!readenv() failed");
+ free(buf);
return;
}
env_import(buf, 1);
+ free(buf);
#endif /* ! ENV_IS_EMBEDDED */
}
#endif /* CONFIG_ENV_OFFSET_REDUND */
diff --git a/common/env_nvram.c b/common/env_nvram.c
index 544ce47..7619039 100644
--- a/common/env_nvram.c
+++ b/common/env_nvram.c
@@ -76,14 +76,21 @@ uchar env_get_char_spec(int index)
void env_relocate_spec(void)
{
- char buf[CONFIG_ENV_SIZE];
+ char *buf;
+ buf = malloc(CONFIG_ENV_SIZE);
+ if (!buf) {
+ set_default_env("!nvram env buf malloc failed");
+ return;
+ }
+#if defined(CONFIG_ENV_OFFSET_OOB)
#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE)
nvram_read(buf, CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
#else
memcpy(buf, (void*)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
#endif
env_import(buf, 1);
+ free(buf);
}
int saveenv(void)
diff --git a/common/env_sf.c b/common/env_sf.c
index 41cc00a..a26865d 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -345,13 +345,19 @@ int saveenv(void)
void env_relocate_spec(void)
{
- char buf[CONFIG_ENV_SIZE];
+ char *buf;
int ret;
+ buf = malloc(CONFIG_ENV_SIZE);
+ if (!buf) {
+ set_default_env("!sf env buf malloc failed");
+ return;
+ }
env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
if (!env_flash) {
set_default_env("!spi_flash_probe() failed");
+ free(buf);
return;
}
@@ -369,6 +375,7 @@ void env_relocate_spec(void)
out:
spi_flash_free(env_flash);
env_flash = NULL;
+ free(buf);
}
#endif
--
1.7.0.4
More information about the U-Boot
mailing list