From: Lei Wen <leiwen@marvell.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [U-BOOT] [PATCH] env: reduce the stack footprint for the env buf
Date: Fri, 4 Feb 2011 11:08:23 +0800 [thread overview]
Message-ID: <1296788903-7604-1-git-send-email-leiwen@marvell.com> (raw)
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@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
next reply other threads:[~2011-02-04 3:08 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-04 3:08 Lei Wen [this message]
2011-02-04 20:31 ` [U-Boot] [U-BOOT] [PATCH] env: reduce the stack footprint for the env buf Scott Wood
2011-02-04 21:18 ` Wolfgang Denk
2011-02-05 1:21 ` Lei Wen
2011-02-05 8:30 ` Wolfgang Denk
2011-02-05 9:33 ` Graeme Russ
2011-02-05 14:11 ` Wolfgang Denk
2011-02-06 15:25 ` Lei Wen
2011-02-06 16:08 ` Wolfgang Denk
2011-02-07 4:38 ` Lei Wen
2011-02-07 5:04 ` Graeme Russ
2011-02-07 7:06 ` Wolfgang Denk
2011-02-07 6:58 ` Wolfgang Denk
2011-02-07 8:17 ` Lei Wen
2011-02-07 8:59 ` Wolfgang Denk
2011-02-07 9:01 ` Lei Wen
2011-02-07 9:43 ` [U-Boot] Compiler Question Maik Hänig
2011-02-07 10:17 ` Wolfgang Denk
2011-02-07 10:24 ` Maik Hänig
2011-02-07 11:41 ` Wolfgang Denk
2011-02-07 12:03 ` Maik Hänig
2011-02-07 13:10 ` Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1296788903-7604-1-git-send-email-leiwen@marvell.com \
--to=leiwen@marvell.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox