[U-Boot-Users] using static variables

Wolfgang Denk wd at denx.de
Fri Mar 24 18:16:20 CET 2006

Dear David,

in message <4dd15d180603240833y237b9199lcd4af04a824fff68 at mail.gmail.com> you wrote:
> 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.

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.

> 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.

> 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.

> Will I be able to use static variables in board_early_init_r?

No, as this is still running from ROM.

> 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.

More information about the U-Boot mailing list