Memory initialization (not)

Duane Ellis
Tue Sep 30 23:35:00 GMT 2008

jim> [I have an embedded system with special memory I do not want 

You have the following choices:

(A) Do you control the code at the reset vector?
(B) Or is your program "loaded" by some external boot loader?

If you control the code at the reset vector, you can change that code to 
do what you want.

Typically in a bare-metal application the code sequence at hard reset is:

1)   configure an initial stack pointer

2)   program the clocks, plls, and enable SDRAM
    [all of which is very chip/silicon specific code]

3)   Copy data data from "ROM" to your initialized data area.

4)   zero memory.

5) Call the "C++" constructors and initializers - (if you need C++)

6) Sometimes, call some OS dependent functions.

7) Call some function - example: EtherNut calls it "NutMain()" others - 
just call it "main()"

8)  often you find the above in a file called "crt0.s", other times it 
is called "reset.s" it varies. I've also seen "vectors.s" -

You need to modify the file described above for your target board.

Here is an example from "lostarm" - for an Atmel ARM7 based AT91SAM7X256

Here is an example from "ethernut" - for another ARM cpu.


If your code is: "loaded" - ie: via UBOOT (a boot loader) over TCP/IP, 
you might need to fiddle with the ELF flags that define what gets done 
at load time, that is not always easy, and often one must resort to 
"modifying the boot loader" so that it does not zap memory.


More information about the Gcc-help mailing list