Flow of Startup code in an embedded system , concept of boot loader?

Renjith G picture Renjith G · Aug 3, 2010 · Viewed 23.1k times · Source

I am working with an embedded board , but i don't know the flow of the start up code(C/assembly) of the same.

Can we discuss the general modules/steps acted upon by the start up action in the case of an embedded system.

Just a high level overview(algorithmic) is enough.All examples are welcome.

/Kanu__

Answer

Yann Ramin picture Yann Ramin · Aug 3, 2010
  1. CPU gets a power on reset, and jumps to a defined point: the reset vector, beginning of flash, ROM, etc.
  2. The startup code (crt - C runtime) is run. This is an important piece of code generated by your compiler/libc, which performs:
    1. Configure and turn on any external memory (if absolutely required, otherwise left for later user code).
    2. Establish a stack pointer
    3. Clear the .bss segment (usually). .bss is the name for the uninitialized (or zeroed) global memory region. Global variables, arrays, etc which don't have an initializing value (beyond 0) are located here. The general practice on a microcontroller is to loop over this region and set all bytes to 0 at startup.
    4. Copy from the end of .text the non-const .data. As most microcontrollers run from flash, they cannot store variable data there. For statements such as int thisGlobal = 5;, the value of thisGlobal must be copied from a persistent area (usually after the program in flash, as generated by your linker) to RAM. This applies to static values, and static values in functions. Values which are left undefined are not copied but instead cleared as part of step 2.
    5. Perform other static initializers.
    6. Call main()

From here, your code is run. Generally, the CPU is left in an interrupts-off state (platform dependent).