[U-Boot-Users] using static variables

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

Dear David,
in message 4dd15d180603240833y237b9199lcd4af04a824fff68@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
Correct.
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

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

In message 442786A3.5000909@slb.com you wrote:
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

David Ho davidkwho@gmail.com wrote:
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/
participants (4)
-
David Ho
-
Sam Song
-
Tore Martin Hagen
-
Wolfgang Denk