After running bare metal recently, I started to run the system. But I thought that there was a bootloader between the bare metal and the system. I didn't do any further research before, so I said it would take one or two weeks to start U-boot.
Referring to fzb and Zhao chunjiang, I also studied two classic versions of version 2010.06 and version 2011.06, and compared TQ (the board I bought was embedded in the sky) I wrote U-BOOT, learned a lot, also found a lot of things, the following will record the following of your own experience, so that you can refer to it later.
Two phases of U-BOOT startup process: (2010.06 classic edition)
Stage 1:The path of start. S is arch \ Arm \ CPU \ ARM920T \. This assembly code is generally called the first-stage initialization code. The main function is to initialize the runtime environment; initialize the memory; Re-place the uboot code into the memory; jump into the memory to execute the second initialization code.
1. Close the opening dog and block all interruptions
2. Set the frequency division ratio
3. Bl cpu_init_crit () off MMU and initialize memory
BL lowlevel_init () configures memory and modifies memory update rate parameters.
4. Relocate to determine whether the current code is in norflash or RAM
Copy the flash code to ram in a copy_loop Loop
5. stack_setup stack settings
Clear data between clear_bss _ bss_start and _ bss_end 0
6. ldr pc and start_armboot jump to the second stage
// ================================================ ====================================
Stage 2: The Path to board. C is arch/ARM/lib/board. C, which is the second-stage initialization code for the U-BOOT. The main function is to initialize two important data structures, configure the memory allocation for the SDRAM, initialize various peripherals to be used, and finally cyclically jump into the main_loop () function.
Stage 2 start_armboot consists of board_init_f and board_init_r.
First executedBoard_init_fPart:
1. Allocate the address for the GD data structure and clear it
2. execute various initialization functions in the init_fnc_ptr function pointer array, as shown below:
Board_early_init_f, timer_init, env_init init_baudrate serial_init
Lele_init_f display_banner dram_init
3, A, the allocation of SDRAM high 64 kB TLB, for U-BOOT
B. Assign the U-BOOT code segment, data segment, and BSS segment to the next module of SDRAM.
(The original BSS segment is used to store uninitialized global and static variables)
C. Then open up the malloc space, and store BD, Gd, and 3 abnormal heap space characters.
4. Assign the relorate address value to the corresponding variable of the GD struct (version 2011.06, used to return start. s)
ExecutedBoard_init_rPart:
1. initialize the value assignment for the GD and BD Data Structures
2. Various peripheral initialization:
Initialize norflash, nandflash, and onenand flash
Initialize environment variables initialize PCI settings IP address initialize various peripherals: IIC, LCD, keyboard, USB initialization console create IRQ interrupt stack initialize Ethernet
Initialize the jump table (which defines common function libraries in U-boot ).. This is not a peripherals
3. Execute the main_loop () function in an endless loop.
/**********************************
Two versions of U-BOOT startup comparison:
************************************/
In fact, it is almost the same in general, but compared with the classic version (version 2010.06), the new version has become disgusting.
The main differences are as follows:
1. The stack settings in step 1 of the first phase of the original version are placed before step 2 relorate (this is nothing)
2. The second phase of the original versionBoard_init_fPut it before relorate in step 1 of Stage 1, that is, the execution is complete.
Stack_setup stack settings change to the second stage of initialization, and then through 4, The relorate address value is assigned to the corresponding variable of the GD struct (version 2011.06, used to return start. s) returns the first stage... I feel that the new version is messy and unorganized after the change (the annual change of open source is annoying, haha)
// ================================================ ==============
The following lists the paths of functions that may be used in two phases for future convenience: (Press Version 2011.06)
Phase 1:
Lowlevel_init function, which is defined in the lowlevel_init.s file under the directory of board/Samsung/smdk2410
Stage 2:
GD is a pointer to the gd_t struct In the R8 register of arm. It is defined in the global_data.h file under the/include/ASM directory.
The data prototype of the BD struct is the bd_t data structure, which represents the "board-level information" struct, which is defined in the u-boot.h file under the/include/ASM directory.
Various initialization functions in the init_fnc_ptr function pointer array:
The board_early_init_f function is in the timer_init function of the smdk2410.c file under the directory of board/Samsung/smdk2410 In the timer. c file under the arch/ARM/CPU/ARM920T/s3c24x0 directory.
The env_init function is in the env_flash.c file under the common directory.
The init_baudrate function is in the board. c file under the arch/ARM/lib directory.
The serial_init function defines config_s3c24x0_serial in the include/configs/smdk2410.h file in the serial_s3c24x0.c file under the drivers/serial directory.
The lele_init_f function is in the console. c file under the common directory.
The display_banner function is in the board. c file under the arch/ARM/lib directory.
The dram_init function is in the smdk2410.c file under the directory of the Board/Samsung/smdk2410.
Initialization of various peripherals:
The flash_init function is in the cfi_flash.c file under the drivers/MTD directory (because config_flash_cfi_driver is defined in include/configs/smdk2410.h)
The nand_init function is defined in the NAND. c file under the divers/MTD/NAND directory.
The env_relocate function is defined in the env_common.c file in the common directory.
Stdio_init () defined in the stdio. c file under the common directory
Jumptable_init () defined in the exports. c file under the common directory
Lele_init_r () is defined in the console. c file under the common directory.
Interrupt_init () enable_interrupts () is defined in the interrupts. c file under the arch/ARM/lib directory.
The eth_initialize () function is defined in rows 209th to 298th Of The eth. c file under the net directory.
Main_loop () defined in the main. c file in the common directory
// ================================================ ==================================
Analysis and comprehension of the difference between the U-BOOT of tianyinxing and self-transplantation
First, let's list the biggest difference between the R & D personnel written by Tianyan company and our own porting (small transplantation:
After comparison, it is found that the biggest difference lies in the common/Main. c file, that is, the two-phase startup process is basically the same
Differences: (the number of lines is daily)
Abortboot () function (called in main_loop)
Ln239: printf ("Press space key to download mode! ");
Ln303: added the logo display program: embedsky_tq_logo () when detecting whether a key press is used ();
Main_loop () function
Ln 381: LCD initialization program
Ln481: Select Download or load mode for Branch: If (bootfrmnorflash ())
Run_command ("menu", 0 );
Else
{
Printf ("booting LINUX \ n ");
Run_command ("boot_zimage", 0 );
}
Parse the following:
In the previous sections, we didn't talk much about the LCD and logo display (because we didn't get the LCD transplant)
In the main_loop () function, ln481: Select Download or load mode for the branch.
First, run_command is the execution command function, which is defined in/common/Main. C at first glance.
Let's talk about the most important "menu" and "boot_zimage ".
1. If it is started from norflash, the download mode is used. Then, run the menu () function, which is defined in/common/cmd_menu.c.
Open the cmd_menu.c file and you will find that some serial port options are in the list. The download list we found when we turned on the 2440 power source is printed from the main_menu_usage () function, the selected items are executed through menu_shell () through the console. the execution process of each option is clearly listed, just like running a bare metal, perform the same on the fzb serial console.
2. When else is started from nandflash, It is configured and started in the loading mode.
In the lib_arm/boot_zimage.c file: The boot_zimage () function
The function execution content is roughly as follows:
1. Copy kernel Image
2. Setup Linux Parameters
3. Get Machine Type
4. Go-> call-Linux
Some Insights after comparison:
Although I also followed the transplantation of U-BOOT, can also establish their own board-level support package, can achieve the basic serial port console, Nand or nor flash, dm9000 network, jffs2 file system and other basic functions, however, there are still many deficiencies in the downloading and loading modes compared to the daily embedding mode.
Therefore, self-transplantation is just a way to feel it. After understanding it, we should add further transplantation on the basis of the embed. It doesn't feel necessary to do it all from start to end. I understand the method, the framework is familiar.
// ================================================ ==================================
A simple example of the porting process:
Because many of the porting operations are based on smdk2410, we must first have a certain understanding of the differences between 2410 and 2440. Furthermore, we have compiled a driver for modifying peripherals on bare metal, in this way, it will be more comfortable to transplant, and you will not be able to do anything. It feels very imaginary and you will not be able to learn anything.
Let U-BOOT support nandflash read and write
1. First, add the macro definition required by your peripherals to the macro definition header file.
The overall macro definition path is/include/configs/XX. h/(the last. h file is generally named after the Board)
Add macro definition, for example: # define config_nand_base 0
... And so on.
How can we know what macro definition to add? In general, look at the peripheral initialization function, and the U-BOOT two-phase start function to use which to define what...
2. Change the corresponding initialization functions, such as the board_nand_init function and the s3c2440_hwcontrol function.
Because the initialization function in the U-BOOT is basically based on 2410, And the NAND Configuration Parameter of 2440 is different from it, you need to change some places
3. Add the initialization function to the second stage.Board_init_rGenerally, the basic peripherals have been added to check whether you have defined a macro to compile this function.
Transplant some rule summary:
As a matter of fact, we can find that the uboot porting modification still follows a certain rule when porting multiple times. That is, first enable the macro definition support in the configuration header file, and add the initialization function that requires the support function in the code at the board level initialization (generally the second stage initialization process.
If the Board Version corresponding to the initialization function is incompatible or does not exist, you have to write it yourself.
// ================================================ ==================================
Finally, let's talk about the compilation of U-BOOT.
Speaking of compilation, it is recommended to go to "how to compile uboot from Ding Jie niu.
When it comes to the compilation execution process, we suggest you look at it.
Http://hi.baidu.com/serial_story/blog/item/871fc30311670783d53f7c74.html
《Detailed analysis of the execution process of the final compilation link of make uboot"
Finally, let's talk about the problem of failed compilation. If an internal program has an error, you can find it through the prompt.
If there are more than error one hundred errors or arm-Linux-LD problems, it should be caused by incompatibility of the compiler version. We recommend that you change to a new version or an earlier version and try again.
Well, here we can continue to transplant the system and write the driver. Recently, 503 of fatzi said they wanted to do a project on the Projector and camera, I am interested in image processing, and I think he is very creative.
It may have been done, go
Dizzy, just a few days off ~~