The u-boot/README gives a high level understanding of it’s internals. Now I have to concentrate on a particular hardware (CPU + Board configuration) and I understood that a thorough reading of CPU and MCU peripheral initialization is required. Further in this series I will write based on my ATngw100 board which is having an AVR32 cpu core (AT32AP7000 Processor).
I found the AP7000 specific files under u-boot-1.3.4/cpu/at32ap/. Here it is, start.S – the very initial few instructions where AP7000 kicks off. The exception vector is defined under the label _evba. I will mention few line below,
rjmp unknown_exception /* Unrecoverable exception */
rjmp unknown_exception /* TLB multiple hit */
After the exception vector definition we have the exception handler instructions,
csrfcz SYSREG_M1_OFFSET /* copy status register (SR) flag to C and Z */
brcc at32ap_cpu_bootstrap /* Branch if carry cleared to at32ap_cpu_bootstrap */
The SR(M1, M2) bits are cleared by reset and M0 is set so that the processor is in supervisor mode after reset. The default value of SR(M1, M2) bits are also 0. This is utilized in the above instruction. If M1 flag is cleared, CPU continues booting by jumping to ‘at32ap_cpu_bootstrap’.
./include/configs/atngw100.h:160:#define CFG_INIT_SP_ADDR (CFG_INTRAM_BASE + CFG_INTRAM_SIZE)
There is something interesting here, ./cpu/at32ap/start.S:167: lddpc pc, 1f
lddpc pc, 1f /* Where does this instruction branch to? */
1: .long at32ap_low_level_init
.size _start, . – _start
.section .text.avr32ap_low_level_init, “ax”, @progbits
.type at32ap_low_level_init, @function
lddpc sp, sp_init /* Instruction 1 */
lddpc r6, got_init /* Instruction 2 */
3: rsub r6, pc /* Instruction 3 */
rjmp board_init_f /* Instruction 4 */
The ‘lddpc’ implement PC relative loading of register from a constant address in program memory short distant from current instruction. In our case ‘lddpc pc, 1f ‘ cause CPU to execute the 4th instruction ahead of current PC, ie ‘rjmp board_init_f ‘. And we got the first function call to a C implementation in u-boot!