hwconfig: Utilize getenv_f before relocation to allow for larger buffer
PATCH 1/1 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 he 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]
--- common/hwconfig.c | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-)
common/hwconfig.c +20 -1
@@ -26,6 +26,8 @@#define min (a, b) (((a) < (b)) ? (a) : (b))#endif /* HWCONFIG_TEST */ +DECLARE_GLOBAL_DATA_PTR ; +static const char *hwconfig_parse (const char *opts,size_t maxlen,const char *opt,char *stopchs,char eqch,size_t *arglen)
@@ -69,9 +71,26 @@ next: const char *cpu_hwconfig __attribute__((weak)); const char *board_hwconfig __attribute__((weak)); +#define CONFIG_SYS_HWCONFIG_PRE_RELOC_BUF_SIZE 128 +static const char *__hwconfig (const char *opt,size_t *arglen) { -const char *env_hwconfig =getenv ("hwconfig" ); +const char *env_hwconfig =NULL ; +char buf[CONFIG_SYS_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 +* accesing 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) return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
Signature · 1 line
1.7.2.3
PATCH 1/1 hwconfig: Utilize getenv_f before relocation to allow for larger buffer
Dear Kumar Gala,
Quoted 2 lines · In message <[email protected]> you…
Since we use hwconfig in cases before relocation (like getting DDR params on FSL PPC systems), we can have strings he exceed the early
--------------------------------------------------^^^ Typo?
common/hwconfig.c line 30
Quoted 2 lines
common/hwconfig.c +2
-0+DECLARE_GLOBAL_DATA_PTR ; +
I don't see which part of your new code requires access to the global data, so if that was notneeded before it should not be needed now either.
Review
Quoted 2 lines
(quoted diff) +2
-0+#define CONFIG_SYS_HWCONFIG_PRE_RELOC_BUF_SIZE 128 +
I'm not sure if it's a good idea to use the CONFIG_SYS_ prefix for a strictly local macro name.
common/hwconfig.c next: · line 86
Quoted 6 lines
common/hwconfig.c +6
-0+if (gd->flags &GD_FLG_ENV_READY ) { + env_hwconfig =getenv ("hwconfig" ); + }else { +/* +* Use our own on stack based buffer before relocation to allow +* accesing longer hwconfig strings that might be in the
-----------------------^^^ Typo.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de I program, therefore I am.
PATCH v2 1/1 hwconfig: Utilize getenv_f before relocation to allow for larger buffer
In reply to Kumar GalaSince we use hwconfig in cases before relocation (like getting DDR params on FSL PPC systems), we can have strings he 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]
---
* Removed stray DECLARE_GLOBAL_DATA_PTR
* Renamed define to remove CONFIG_SYS_ prefix
* fixed typo in comment
common/hwconfig.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)
common/hwconfig.c +18 -1
@@ -69,9 +69,26 @@ next: const char *cpu_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) { -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) return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
Signature · 1 line
1.7.2.3
PATCH v2 1/1 hwconfig: Utilize getenv_f before relocation to allow for larger buffer
Dear Kumar Gala,
Quoted 2 lines · In message <[email protected]> you…
Since we use hwconfig in cases before relocation (like getting DDR params on FSL PPC systems), we can have strings he exceed the early
-------------------------------------------------^^^^ Typo?
No need to repost, just let me know what you menat to write, and I will fix when applying.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The high cost of living hasn't affected its popularity.
PATCH v2 1/1 hwconfig: Utilize getenv_f before relocation to allow for larger buffer
Quoted 9 lines · Wolfgang Denk
Dear Kumar Gala,
Quoted 2 lines · In message <[email protected]> you…
Since we use hwconfig in cases before relocation (like getting DDR params on FSL PPC systems), we can have strings he exceed the early
-------------------------------------------------^^^^ Typo?
No need to repost, just let me know what you menat to write, and I will fix when applying.
we can have strings that exceed
PATCH v3 1/1 hwconfig: Utilize getenv_f before relocation to allow for larger buffer
In reply to Kumar GalaSince 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]
---
* Fix typo in commit
* restore DECLARE_GLOBAL_DATA_PTR - we use it for gd->flags
common/hwconfig.c | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-)
common/hwconfig.c +20 -1
@@ -26,6 +26,8 @@#define min (a, b) (((a) < (b)) ? (a) : (b))#endif /* HWCONFIG_TEST */ +DECLARE_GLOBAL_DATA_PTR ; +static const char *hwconfig_parse (const char *opts,size_t maxlen,const char *opt,char *stopchs,char eqch,size_t *arglen)
@@ -69,9 +71,26 @@ next: const char *cpu_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) { -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) return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
Signature · 1 line
1.7.2.3
Wolfgang Denk
AppliedPATCH v3 1/1 hwconfig: Utilize getenv_f before relocation to allow for larger buffer
Dear Kumar Gala,
Quoted 12 lines · In message <[email protected]> you…
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_buftoo small [32]
Quoted 7 lines
Signed-off-by Kumar Gala <[email protected]>---
* Fix typo in commit
* restoreDECLARE_GLOBAL_DATA_PTR- we use it forgd->flagscommon/hwconfig.c | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 7 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de I thought my people would grow tired of killing. But you were right, they see it is easier than trading. And it has its pleasures. I feel it myself. Like the hunt, but with richer rewards. -- Apella, "A Private Little War", stardate 4211.8