Make flash protection work, when the environment is in EEPROM
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
From: Eric Schumann <[email protected]>
On the pcm030 the environment is located in the onboard EEPROM. But we want to handle flash sector protection in a safe manner. So we must read the unlock environment variable from EEPROM instead from flash.
This patch is required as long the evironment is saved into the EEPROM.
---
0 files changed, 0 insertions(+), 0 deletions(-)
drivers/mtd/cfi_flash.c +3 -1
@@ -2009,7 +2009,9 @@ unsigned long flash_init (void)#endif #ifdef CONFIG_SYS_FLASH_PROTECTION -char *s =getenv ("unlock" ); +/* read environment from EEPROM */ +char s[4 ]; +getenv_r ("unlock" , s,sizeof (s));#endif #define BANK_BASE (i) (((phys_addr_t [CFI_MAX_FLASH_BANKS])CONFIG_SYS_FLASH_BANKS_LIST)[i])
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
Dear Jon,
Quoted 18 lines · In message <20090321135934.12464.65400.stgit@localhost> you wrote:
From: Eric Schumann <[email protected]>
On the pcm030 the environment is located in the onboard EEPROM. But we want to handle flash sector protection in a safe manner. So we must read the unlock environment variable from EEPROM instead from flash.
This patch is required as long the evironment is saved into the EEPROM.
Signed-off-by Eric Schumann <[email protected]>Signed-off-by Sascha Hauer <[email protected]>---
0 files changed, 0 insertions(+), 0 deletions(-)drivers/mtd/cfi_flash.c +0
-0
drivers/mtd/cfi_flash.c unsigned long flash_init (void) · line 2015
Quoted 8 lines
drivers/mtd/cfi_flash.c +3
-1@@ -2009,7 +2009,9 @@ unsigned long flash_init (void)#endif #ifdef CONFIG_SYS_FLASH_PROTECTION -char *s =getenv ("unlock" ); +/* read environment from EEPROM */ +char s[4 ]; +getenv_r ("unlock" , s,sizeof (s));#endif
This patch doesn't really make sense to me. The flash_init() code is only being run after relocation to RAM, so standard getenv() is supposed to work, and there should be no reason why we would have to fall back on getenv_r().
Please explain which issues you are observing.
Best regards,
Wolfgang Denk
Signature · 5 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 "Who is the oldest inhabitant of this village?" "We haven't got one; we had one, but he died three weeks ago."
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
Quoted 23 lines · Wolfgang Denk
Dear Jon,
Quoted 20 lines · In message <20090321135934.12464.65400.stgit@localhost> you wrote:
From: Eric Schumann <[email protected]>
On the pcm030 the environment is located in the onboard EEPROM. But we want to handle flash sector protection in a safe manner. So we must read the unlock environment variable from EEPROM instead from flash.
This patch is required as long the evironment is saved into the EEPROM.
Signed-off-by Eric Schumann <[email protected]>Signed-off-by Sascha Hauer <[email protected]>---
?0 files changed, 0 insertions(+), 0 deletions(-)drivers/mtd/cfi_flash.c +0
-0@@ -2009,7 +2009,9 @@ unsigned long flash_init (void)?#endif
Quoted 11 lines
Quoted 6 lines
?#ifdef
CONFIG_SYS_FLASH_PROTECTION
- ? ? char *s =getenv("unlock");
+ ? ? /* read environment from EEPROM */
+ ? ? char s[4];
+ ? ?getenv_r("unlock", s, sizeof(s));
?#endifThis patch doesn't really make sense to me. The
flash_init()code ?is only ?being ?run ?after ?relocation ?to ?RAM, so standardgetenv()is supposed to work, and there should be no reason why we would have ?to fall back ongetenv_r().
I didn't write these, these are the Phytex pcm030 board support patches from Pengutronix that have never been submitted to mainline. They're all working on my hardware but of course there may be better ways to do things.
My guess is getenv() returns a pointer to the environment variable, not a copy of the environment variable. getenv_r() returns a copy. How can you return a pointer to the variable if the variable is in something not directly addressable like EEPROM? Does getenv("unlock"); do what you want when the environment is in EEPROM?
Quoted 15 lines
Please explain which issues you are observing.
Best regards,
Wolfgang Denk
--
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 "Who is the oldest inhabitant of this village?"
"We haven't got one; we had one, but he died three weeks ago."
Signature · 2 lines
Jon Smirl jonsmirl at gmail.com
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
Dear Jon Smirl,
Quoted 5 lines · In message <[email protected]> you…
My guess is
getenv()returns a pointer to the environment variable, not a copy of the environment variable.getenv_r()returns a copy. How can you return a pointer to the variable if the variable is in something not directly addressable like EEPROM? Does
The environment always gets copied to RAM. And it's a perfectly simple thing to return an adress pointing to some memory in RAM :-)
Quoted 1 line
getenv("unlock"); do what you want when the environment is in EEPROM?
getenv() always works that way, no matter which actual media is used for the persistent storage of the environment.
Best regards,
Wolfgang Denk
Signature · 5 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 only person who always got his work done by Friday
was Robinson Crusoe.PATCH 1/1 Make flash protection work, when the environment is in EEPROM
Quoted 9 lines · Wolfgang Denk
Dear Jon Smirl,
Quoted 5 lines · In message <[email protected]> you…
My guess is
getenv()returns a pointer to the environment variable, not a copy of the environment variable.getenv_r()returns a copy. How can you return a pointer to the variable if the variable is in something not directly addressable like EEPROM? ?Does
Quoted 7 lines
The environment always gets copied to RAM. And it's a perfectly simple thing to return an adress pointing to some memory in RAM :-)
Quoted 1 line
getenv("unlock"); do what you want when the environment is in EEPROM?
getenv()always works that way, no matter which actual media is used for the persistent storage of the environment.
This one can be dropped. It looks like a misunderstanding in how the API worked.
Quoted 12 lines
Best regards,
Wolfgang Denk
--
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 only person who always got his work done by Friday
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? was Robinson Crusoe.
Signature · 2 lines
Jon Smirl jonsmirl at gmail.com
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
In reply to Wolfgang DenkHi Wolgang,
Quoted 9 lines · Wolfgang Denk
Dear Jon Smirl,
Quoted 5 lines · In message <[email protected]> you…
My guess is
getenv()returns a pointer to the environment variable, not a copy of the environment variable.getenv_r()returns a copy. How can you return a pointer to the variable if the variable is in something not directly addressable like EEPROM? Does
Quoted 7 lines
The environment always gets copied to RAM. And it's a perfectly simple thing to return an adress pointing to some memory in RAM :-)
Quoted 1 line
getenv("unlock"); do what you want when the environment is in EEPROM?
getenv()always works that way, no matter which actual media is used for the persistent storage of the environment.
This is not quite true. In the PPC init sequence flash_init() is called before env_relocate() and thus getenv is not available in flash_init(). Please note that this was just a quick way for us to make things work and I never considered this a fix for mainline.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
Quoted 17 lines · Sascha Hauer
Hi Wolgang,
Quoted 14 lines · Wolfgang Denk
Dear Jon Smirl,
Quoted 5 lines · In message <[email protected]> you…
My guess is
getenv()returns a pointer to the environment variable, not a copy of the environment variable.getenv_r()returns a copy. How can you return a pointer to the variable if the variable is in something not directly addressable like EEPROM? ?DoesThe environment always gets copied to RAM. And it's a perfectly simple thing to return an adress pointing to some memory in RAM :-)
Quoted 1 line
getenv("unlock"); do what you want when the environment is in EEPROM?
Quoted 7 lines
Quoted 2 lines
getenv()always works that way, no matter which actual media is used for the persistent storage of the environment.This is not quite true. In the PPC init sequence
flash_init()is called beforeenv_relocate()and thus getenv is not available inflash_init(). Please note that this was just a quick way for us to make things work and I never considered this a fix for mainline.
What is your fix for mainline?
Quoted 9 lines
Sascha
--
Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? | Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?| Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?| Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
Signature · 2 lines
Jon Smirl jonsmirl at gmail.com
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
Quoted 21 lines · Jon Smirl
Quoted 20 lines · Sascha Hauer
Hi Wolgang,
Quoted 16 lines · Wolfgang Denk
Dear Jon Smirl,
Quoted 5 lines · In message <[email protected]> you…
My guess is
getenv()returns a pointer to the environment variable, not a copy of the environment variable.getenv_r()returns a copy. How can you return a pointer to the variable if the variable is in something not directly addressable like EEPROM? ?DoesThe environment always gets copied to RAM. And it's a perfectly simple thing to return an adress pointing to some memory in RAM :-)
Quoted 1 line
getenv("unlock"); do what you want when the environment is in EEPROM?
getenv()always works that way, no matter which actual media is used for the persistent storage of the environment.
Quoted 6 lines
Quoted 4 lines
This is not quite true. In the PPC init sequence
flash_init()is called beforeenv_relocate()and thus getenv is not available inflash_init(). Please note that this was just a quick way for us to make things work and I never considered this a fix for mainline.What is your fix for mainline?
I have none.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
In reply to Jon SmirlDear Jon,
Quoted 8 lines · in message <[email protected]> you…
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
getenv("unlock"); do what you want when the environment is in EEPROM?
getenv()always works that way, no matter which actual media is used for the persistent storage of the environment.This is not quite true. In the PPC init sequence
flash_init()is called beforeenv_relocate()and thus getenv is not available inflash_init().
I see. You are right.
Quoted 4 lines
Quoted 2 lines
Please note that this was just a quick way for us to make things work and I never considered this a fix for mainline.
What is your fix for mainline?
We cannot run env_relocate() before flash_init(), as (with environ- ment stored in flash) we need an initialized flash memory to do so. Consequently, we indeed have to use getenv_r() instead of getenv().
Stefan, will you pick up the original patch, please:
http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/56275
Hm, you might want to change "char s[4];" into "char s[256];" or similar, though, to make buffer overflows less likely.
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 used to be indecisive, now I'm not sure.
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
In reply to JonDear Stefan,
Quoted 18 lines · In message <20090321135934.12464.65400.stgit@localhost> Jon Smirl wrote:
From: Eric Schumann <[email protected]>
On the pcm030 the environment is located in the onboard EEPROM. But we want to handle flash sector protection in a safe manner. So we must read the unlock environment variable from EEPROM instead from flash.
This patch is required as long the evironment is saved into the EEPROM.
Signed-off-by Eric Schumann <[email protected]>Signed-off-by Sascha Hauer <[email protected]>---
0 files changed, 0 insertions(+), 0 deletions(-)drivers/mtd/cfi_flash.c +0
-0
drivers/mtd/cfi_flash.c unsigned long flash_init (void) · line 2017
Quoted 10 lines
drivers/mtd/cfi_flash.c +3
-1@@ -2009,7 +2009,9 @@ unsigned long flash_init (void)#endif #ifdef CONFIG_SYS_FLASH_PROTECTION -char *s =getenv ("unlock" ); +/* read environment from EEPROM */ +char s[4 ]; +getenv_r ("unlock" , s,sizeof (s));#endif #define BANK_BASE (i) (((phys_addr_t [CFI_MAX_FLASH_BANKS])CONFIG_SYS_FLASH_BANKS_LIST)[i])
Please change "char s[4];" into "char s[256];", otherwise:
Best regards,
Wolfgang Denk
Signature · 5 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 don't see any direct evidence ... but, then, my crystal ball is in dire need of an ectoplasmic upgrade. :-) -- Howard Smith
PATCH 1/1 Make flash protection work, when the environment is in EEPROM
Hi Wolfgang,
Quoted 11 lines · Wolfgang Denk
Quoted 11 lines
+++
b/drivers/mtd/cfi_flash.cdrivers/mtd/cfi_flash.c +3
-1@@ -2009,7 +2009,9 @@ unsigned long flash_init (void)#endif #ifdef CONFIG_SYS_FLASH_PROTECTION -char *s =getenv ("unlock" ); +/* read environment from EEPROM */ +char s[4 ]; +getenv_r ("unlock" , s,sizeof (s));#endif
Quoted 6 lines
Quoted 2 lines
(quoted diff) +0
-0#define BANK_BASE(i) (((phys_addr_t[CFI_MAX_FLASH_BANKS])CONFIG_SYS_FLASH_BANKS_LIST)[i])
Please change "char s[4];" into "char s[256];", otherwise:
Acked-by Wolfgang Denk <[email protected]>
OK, I changed the array to 64 (256 is a bit high without "real" stack) and will push this patch quickly to the cfi repository.
Best regards,
Stefan
=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================