星期四, 3月 02, 2006

[note] boot code

Linker
‧takes obj file as input and produces exectable image or a larger relocable obj file
‧linker command file instructs the linker on how to combine the obj file and where to place the binary code and data in the target embedded system
‧symbol resolution: resolve all of the external symbol in which file are defined
‧symbol relocation:
boot image
‧prepares the system to execute the loader
loader
‧download image from host(ROM/flash) to target(RAM)

Boot scenarios
target image contain various program section, each section has designated location in memory map
  1. power on
  2. fetch & exec code from predefined & hard-wired add offset(ROM, 0x0000h)
  3. code named Reset Vector @ ROM, mapped to location 0x0h, a jump instruction, must be small(due to memory space)
  4. reset vector jump to 0x00040h, code named bootstrap, startup initialization code @ flash, contains target image loader program & default system exception vector, bootstrap put system into known state, set processor register, set stack pointer with value @ ROM
  5. loader @ flash disable interrupt, initialize RAM & caches, copy code from flash to RAM, initial HW, putting system into a known state
  6. replace image into RAM
initial value @ ROM required by processor on reset: reset vector, initial stack pointer, usable RAM add

Program execution is faster in RAM than flash memory
For enable runtime debugging, program need to execute out of RAM to insert breakpoint.

program section has
load add: the program section reside
run add: the loader copy the program section to/the program section execution

executable image contains:
initialized data section: .data & .sdata, contain initial value for global & static variables. transferred by loader
uninitialized data section: .bss .sbss, is empty. loader reserve space in memory map.

The allocalation info for sections(section size/run add) is part of the section header. loader need to retrieve this info from header and allocate the amount of memory in RAM during load process.

executable image has constants, which is part of the .const section, read only, can be placed in ROM. But freq accessed constant(lookup table) should be transferred into RAM.

initial system device, majoyily I/O system

execute from ROM while using RAM for data

The CPU's IP is hardwired to execute the first instruction in memory(reset vector)
reset vector jump to .text section @ ROM, CPU use IP to execture, initializes memory system(ROM/RAM)
.data section(read/write-able)is copied to RAM
reserve RAM space for .bss section(read/write-able)
stack space is reserved in RAM
CPU's SP register is set to point the to the beginning of the newly created stack
boot complete, CPU execute .text code