Skip to content
Snippets Groups Projects
Commit c4b115f5 authored by Kumar Gala's avatar Kumar Gala Committed by Wolfgang Denk
Browse files

hwconfig: Utilize getenv_f before relocation to allow for larger buffer


Since we use hwconfig in cases before relocation (like getting DDR
params on FSL PPC systems), we can have strings that exceed the early
small (32 byte) buffer size that getenv will handle.

So we explicitly allocate our own buffer on the stack and use if to
handle getting the hwconfig env string.  We currently utilize a string
length of 128 bytes.

This allows us to get rid of boot messages like:

env_buf too small [32]

Signed-off-by: default avatarKumar Gala <galak@kernel.crashing.org>
parent 3f7ffa44
Branches
No related tags found
No related merge requests found
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#define min(a, b) (((a) < (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b))
#endif /* HWCONFIG_TEST */ #endif /* HWCONFIG_TEST */
DECLARE_GLOBAL_DATA_PTR;
static const char *hwconfig_parse(const char *opts, size_t maxlen, static const char *hwconfig_parse(const char *opts, size_t maxlen,
const char *opt, char *stopchs, char eqch, const char *opt, char *stopchs, char eqch,
size_t *arglen) size_t *arglen)
...@@ -69,9 +71,26 @@ next: ...@@ -69,9 +71,26 @@ next:
const char *cpu_hwconfig __attribute__((weak)); const char *cpu_hwconfig __attribute__((weak));
const char *board_hwconfig __attribute__((weak)); const char *board_hwconfig __attribute__((weak));
#define HWCONFIG_PRE_RELOC_BUF_SIZE 128
static const char *__hwconfig(const char *opt, size_t *arglen) static const char *__hwconfig(const char *opt, size_t *arglen)
{ {
const char *env_hwconfig = getenv("hwconfig"); const char *env_hwconfig = NULL;
char buf[HWCONFIG_PRE_RELOC_BUF_SIZE];
if (gd->flags & GD_FLG_ENV_READY) {
env_hwconfig = getenv("hwconfig");
} else {
/*
* Use our own on stack based buffer before relocation to allow
* accessing longer hwconfig strings that might be in the
* environment before we've relocated. This is pretty fragile
* on both the use of stack and if the buffer is big enough.
* However we will get a warning from getenv_f for the later.
*/
if ((getenv_f("hwconfig", buf, sizeof(buf))) > 0)
env_hwconfig = buf;
}
if (env_hwconfig) if (env_hwconfig)
return hwconfig_parse(env_hwconfig, strlen(env_hwconfig), return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment