Discussion:
[U-Boot-Users] using static variables
David Ho
2006-03-24 16:33:42 UTC
Permalink
Hi,

I would appreciate if an u-boot expert can explain the use of static
variables in u-boot.

My understanding is that when u-boot is still running in flash static
variables are not modifiable. Once u-boot moves to RAM, what will
happen to static variables? I don't quite understand how the
mechanism work before and after relocation.

I asked this question because I need a saved copy of a write only
latch/register, which I have to initialize early.

I have added a field in the global_data struct previously for this.
Seeing that introduced changes in the common code I would like to
choose a method I can use to localize it in my board specific code.

Will I be able to use static variables in board_early_init_r?

Are there some other mehods I have not noticed?

Regards,
David
Wolfgang Denk
2006-03-24 17:16:20 UTC
Permalink
Dear David,
Post by David Ho
My understanding is that when u-boot is still running in flash static
variables are not modifiable. Once u-boot moves to RAM, what will
Correct.
Post by David Ho
happen to static variables? I don't quite understand how the
mechanism work before and after relocation.
Static variables with nonzero initialial values (the data segment)
are copied to RAM, too, and magicly become writable. Static variables
with (implicit or explicit) zero initialial values (the bss segment)
will have space allocated in the new created and zeroed bss segment.
Post by David Ho
I asked this question because I need a saved copy of a write only
latch/register, which I have to initialize early.
I have added a field in the global_data struct previously for this.
Thisi s discouraged. If each board would do this we'd have a terrible
mess soon.
Post by David Ho
Seeing that introduced changes in the common code I would like to
choose a method I can use to localize it in my board specific code.
Good idea.
Post by David Ho
Will I be able to use static variables in board_early_init_r?
No, as this is still running from ROM.
Post by David Ho
Are there some other mehods I have not noticed?
Use free registers, on chip memory, etc.

Best regards,

Wolfgang Denk
--
Software Engineering: Embedded and Realtime Systems, Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Use the Force, Luke.
David Ho
2006-03-27 20:11:52 UTC
Permalink
Thanks guys,

Using a pre-initialized static variable, I have managed to set the the
write only latch early with the initialized value while running in
flash (board_early_init_f) and only modify the latch and static
variable in (board_early_init_r), by then the variable is modifable.

Thanks again, David

Tore Martin Hagen
2006-03-27 06:30:59 UTC
Permalink
Post by David Ho
Hi,
Are there some other mehods I have not noticed?
Since your flash is up and running the easyest is probably to erase a
flash sector before starting up and then write directly to that address.

/Tore Martin Hagen
Wolfgang Denk
2006-03-27 07:30:29 UTC
Permalink
Post by Tore Martin Hagen
Since your flash is up and running the easyest is probably to erase a
flash sector before starting up and then write directly to that address.
This does not work, because you cannot run any flash driver code
(which will set the flash into programming mode and thus prevent
reading normal data) while you are still running from flash (so you
need to be able to fetch instructions and data from flash).

And it is a very bad idea anyway as each reset would reduce the
filetime of your product.

Best regards,

Wolfgang Denk
--
Software Engineering: Embedded and Realtime Systems, Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I wish Captain Vimes were here. He wouldn't have known what to do
either, but he's got a much better vocabulary to be baffled in.
- Terry Pratchett, _Guards! Guards!_
Sam Song
2006-03-27 08:42:31 UTC
Permalink
Post by David Ho
Are there some other mehods I have not noticed?
Seems you could use Alarm registers in RTC chip
if had. I tried it on DS1337 and worked.

Regards,

Sam






___________________________________________________________
??1G???????????
http://cn.mail.yahoo.com/
Loading...