Uboot START process Analysis for s5pv210
BL1 stage, Spl,u-boot-spl.bin
1, first run Arch/arm/cpu/armv7/start. S inside the _start function, make exception vector table settings, then jump to reset Reset handler function, set Processor SVC mode, turn off IRQ and Fiq interrupt. Setting up the CP15 coprocessor
The Sctrl Register V (bit13) is 0, set the exception vector table at 0x00000000-0x0000001c, and set the exception vector table address to _start. Jump to Cpu_init_cp15 initialize coprocessor, clear TLB, close cache,
Close the MMU and open ICACHE if no config_sys_icache_off is defined. Proceed to Cpu_init_crit and jump to Board/samsung/tiny210/lowlevel_init. s inside the Lowlevel_init,
Perform clock initialization, DDR initialization.
2, jump to arch\arm\lib\crt0. s inside the _main, call Copy_bl2_to_ram BL2 from SD card or NAND flash copy to SDRAM 0x20000000, and then jump to SDRAM start running BL2.
BL2 stage, U-boot.bin
1, or run the Arch/arm/cpu/armv7/start. S inside the _start function, then reset, set the exception vector table address again, set CP15, jump to Cpu_init_crit, call Lowlevel_init,
But did not do anything, because BL1 has done initialization, and then jump to _main, set the SP, reserved space for the global variable GD,GD on the SP, the GD pointer is saved inside the R9, jump to board_init_f execution.
2, execute arch\arm\lib\board.c inside of Board_init_f, empty GD, set GD inside variable Mon_len for uboot size, execute init_sequence inside initialization sequence function, initialize timer,
Serial port, environment variable, set DRAM banks and so on. To continue the initialization of GD, if macro config_sys_mem_top_hide is defined, reserve config_sys_mem_top_hide RAM to hide space,
If Config_logbuffer is defined, the Logbuff_reserve space is reserved for kernel logbuffer, the TLB size and space are set, and if CONFIG_LCD is defined, the FB is reserved.
Set Total_malloc_len size to MALLOC space, reserved space for BD, reserved space for GD, get addr_sp as stack pointer, addr for uboot start address. Set the baud rate,
Set the DRAM address address and size, set the Uboot relocation address to addr, the starting stack pointer is addr_sp, set the relocation offset, the GD data from the current R9 copy to the new GD space.
3, set the new GD address to R9, calculate relocation after the address of here is saved in LR, so that after performing relocate_code for Uboot relocation after the return, jump directly to the relocation uboot continue execution.
Set R0 to re-locate the address and call Relocate_code for Uboot relocation.
4, the implementation of Arch\arm\lib\relocater. s inside the Relocate_code for Uboot relocation. Uboot the LD uses-pie and CC does not use-fpic or-fpie, got is not generated in the destination file.
First copy the code between __image_copy_start and __image_copy_end to the relocation address space, in the Adjust. Rel.dyn section inside the address, to __rel_dyn_start and __rel_dyn_end
The entry with the type r_arm_relative (23) plus the offset is adjusted.
5, reposition the code after clearing 0 BSS section, set R0 to R9, that is, R0 point to Gd,r1 to redirect address, and then call Board_init_r.
6, execution arch\arm\lib\board.c inside of Board_init_r continue to initialize, set GD flag for Gd_flg_reloc, enable Ceche, call Board\samsung\tiny210\ TINY210.C inside the Board_init initialization
SROMC set machine type and start parameter address, call Serial_initialize Register serial device, initialize malloc, initialize NAND flash, execute env_relocate set environment variable,
Set the interrupt, initialize the network card, and finally jump to the Main_loop dead loop, in the Main_loop will call Process_boot_delay detect boot phase There is no key press, if there is to enter the Uboot command line,
If the kernel is not loaded by default, the load failure will also go to the Uboot command line.
Some instructions for code relocation
It is important to note that in Uboot's entire relocate_code, Rel.dyn not only has no copy, and no modification, but only for the value +offset the value in Rel.dyn! Check the online information, compiler add-fpic or-fpie option in CC, will generate got (global offset table) in the target file, will need relocate value in got, The label of the tail of the function stores the offset of the got and the offset of the variable, and the variable addressing first finds the got address based on the relative address of the trailing label, and the position of the variable addresses in the Got, thus determining the variable address so that the value in got is uniformly modified for the target file. The relocation is completed by modifying the offset of the variable address. When LD joins the-pie option, the got is incorporated into the Rel.dyn segment, and Uboot is uniformly modified in Relocate_code according to the Rel.dyn segment to relocation values. Uboot the LD uses-pie and CC does not use-fpic or-fpie, the destination file does not generate got, addressing in the function or storing the absolute address of the variable directly in the trailing label. But this label also exists in Rel.dyn, uboot the value on the label according to the Rel.dyn segment, and completes the relocation. This not only saves the got segment of each target file, but also does not need to go to the relative addressing got, directly modifies the function trailing label stored variable address is possible.
Reference blog:
http://blog.csdn.net/skyflying2012/article/details/37660265
http://blog.csdn.net/caiyuqing2001/article/details/7328994
Uboot 2014.04 Running Process record