Template Information

Trang

Control Flow in U-boot

Thứ Tư, 29 tháng 6, 2011 / 22:52

u-boot startup process

system startup entry point. Since we now have to analyze the process of u-boot startup, you must first find the u-boot, which code the first realization, the first completed what tasks. On the other hand an executable image must have an entry point, and only a global entry point, so to inform the compiler where the entrance. From this we can find the entry point is in / board/lpc2210/u-boot.lds specified, which ENTRY (_start) _start start running from that program, and he points to the cpu/arm7tdmi/start.o file. Because we are using the cpu ARM7TDMI architecture, from the address 0x00000000 after reset to take its first instruction, so we will Flash map to this address, so that the system is powered up, cpu will be the first implementation of u-boot process.

u-boot startup process is multi-stage implementation, divided in two stages. Architecture depends on the cpu code (such as device initialization code, etc.) are usually placed in stage1, but also usually implemented in assembly language in order to achieve the purpose of short and pithy. The stage2 is usually implemented with C language, so that complex functions can be achieved, and the code has better readability and portability.

following detailed analysis of our first under the stage1 code shown in Figure 2:





Figure 2 Start.s program flow

code really started in _start, set the exception vector table, so that when an exception occurs in the cpu to jump to / cpu/arm7tdmi / interrupts in the code to execute the appropriate service routine. Most of the document in the interrupts are not implemented exception code specific functions, but only print some exception message, which is the key to reset the interrupt code, skip to the reset entry address.

reset reset before the entrance of some segments of the statement. In the reset, the first is the cpu is set to svc32 mode, and block all irq and fiq. In addition to the u-boot using the timer interrupt, the other is basically no need to use interrupts, such as serial communications and network communications, as long as the u-boot to complete some simple communication can be, so here mask out all interrupts.

initialize the external bus. This part of the first set of I / O port features, including serial, network interface settings, and other I / O port is set to GPIO. Then set BCFG0 ~ BCFG3, the external bus controller. Here bank0 corresponding Flash, set to 16-bit width, the slowest bus speed is set to achieve stable operation; Bank1 corresponding DRAM, the same settings and Flash; Bank2 corresponding RTL8019.

Next is the key to set the cpu, including system re-mapping (to tell the processor when the interrupt occurs in the system to the external memory to read the interrupt vector table) and the system frequency.

lowlevel_init, set the RAM timing, and interrupt controller cleared. The relevant part of the platform-specific, but generally the process is the same.

Here is the code of the move phase. In order to obtain faster execution, usually stage2 is loaded into RAM space to run, it is necessary to load the stage2 ready for Boot Loader section of the scope of available RAM space. Space is best memory page size (usually 4KB) multiple of, in general, 1M of RAM space is enough. stored in flash u-boot executable file, the code segment, data segment, and BSS segments are stored end to end, so when calculating the size of the move is to use the first address with the BSS segment minus the first address code, This is actually calculated using the space. Program uses a loop to move the code 0x81180000, that is the bottom 1M RAM space used to store code. And the program continues to move to RAM interrupt vector table top. Stage2 is usually the C language implementation of the code, therefore I have to build the stack. Even before the stack area allocated to malloc space and the space required for global data space down, and their size is given by the macro definition can be modified in the appropriate location. Basic memory map:




Figure 3, the distribution of moving, memory map

Next is the u-boot start of the second phase, is written in c code, which is of relatively little change in some part of the board that we change it for different number of initialization function call, and by setting Some macro to change the initialization process, so the code in the process of transplantation does not need to modify is the file the error appears relatively small. In the beginning of the file first defines a function pointer array, the array, the program through a loop initialization routine in order, and thereafter through a number of macros to initialize a specific device. In the final program enters a loop, main_loop. This loop receives user input commands to set the parameters or the boot.

of this article will focus on the front of the start.s on, because this part of both the transplant or in the debugging process is the most error-prone places on the need for procedures to solve the problem staff to modify the code, so heres a brief introduction about the basic process start.s, hoping to help.

0 nhận xét:

Đăng nhận xét