MIPS architecture U-boot Startup Process

Source: Internet
Author: User
Process Analysis
**************************************** ****************
1. After the system is powered on
Entry (_ start) program entry point is _ start board/mingddie/u-boot.lds

2. _ start: CPU/MIPS/start. s

3. La T9, board_init_f assign the board_init_f address of the function to T9
The instruction in which J T9 redirects to the address point saved in the T9 register
Jump to Ram and execute C code
Some information is printed here.

3.1 board_init_f () lib_mips/board. c
Initialize external memory
Relocate_code () is returned to CPU/MIPS/start. s to continue execution.

4. La T9, board_init_r CPU/MIPS/start. s
J T9 assign the board_init_r address of the function to T9
Jump to the instruction pointed to by the address saved in the T9 register
Jump to Ram and execute C code
Some information will be printed here

4.1 board_init_r () function lib_mips/board. c

4.2 main_loop () Common/Main. c
S = getenv ("bootcmd") to get the start command line in the environment variable, for example, bootcmd = bootm 0xbf020000
Run_command (S, 0); // execute this command line, that is, bootm

4.3 do_bootm () Common/pai_bootm.c
// Printf ("# booting image at % 08lx.../N", ADDR); // for Example

5. bootm starts the kernel.
5.1 do_bootm_linux () lib_mips/mis_linux.c

Function Parsing
**************************************** ***********
1. board_init_f ()

1.1
Void board_init_f (ulong bootflag)
{

For (init_fnc_ptr = init_sequence; * init_fnc_ptr; ++ init_fnc_ptr ){
If (* init_fnc_ptr )()! = 0 ){
Hang ();
}
}
// Call the init_sequence function queue to initialize the Board. For details, refer to the following section.

Initialize external memory, initialize the stack and use cache as the stack.

Relocate_code (addr_sp, ID, ADDR); // return to CPU/MIPS/start. s

/* Notreached-relocate_code () does not return */
}

1.2
Typedef int (init_fnc_t) (void );

Init_fnc_t * init_sequence [] = {

Clx_board_init, // initialize gpio, CPU speed, PLL, SDRAM, etc.
Timer_init, // clock Initialization
Env_init, // initialize environment face changing
Incaip_set_cpuclk, // set the CPU clock according to the Environment Variable
Init_baudrate, // initialize the serial port baud rate
Serial_init,/* serial communications setup */
Lele_init_f, // serial port initialization, which will be displayed later
Display_banner, // output some display information on the screen
Checkboard,
Init_func_ram,
Null,
};

2. board_init_r ()
(1) call a series of initialization functions.
(2) initialize the flash device.
(3) initialize the system memory allocation function.
(4) If the target system has a NAND device, initialize the NAND device.
(5) If the target system has a display device, initialize the device.
(6) initialize related network devices, and fill in IP addresses and MAC addresses.
(7) enter the command loop (that is, the operating cycle of the entire boot), accept the commands input by the user from the serial port, and then perform the corresponding work
Void board_init_r (gd_t * ID, ulong dest_addr)
{

/* Configure available Flash banks * // configure available flash units
Size = flash_init (); // initialize flash
Display_flash_config (size); // display the flash size

/* Initialize malloc () area */
Mem_malloc_init ();
Malloc_bin_reloc ();

Puts ("NAND :");
Nand_init ();/* Go init the NAND * // NAND Initialization

/* Relocate environment function pointers etc .*/
Env_relocate (); // initialize the environment variable

/* Board MAC address */
S = getenv ("ethaddr"); // Ethernet MAC address
For (I = 0; I <6; ++ I ){
BD-> bi_enetaddr [I] = s? Simple_strtoul (S, & E, 16): 0;
If (s)
S = (* E )? E + 1: E;
}

/* IP Address */
BD-> bi_ip_addr = getenv_ipaddr ("ipaddr ");

Pci_init (); // PCI Initialization Configuration

/** Leave this here (after malloc (), Environment and PCI are working )**/
/* Initialize devices */
Devices_init ();

Jumptable_init ();

/* Initialize the console (after the relocation and devices init )*/
Lele_init_r (); // serial port Initialization

/* Miscellaneous platform dependent initialisations */
Misc_init_r ();

Puts ("Net :");
Eth_initialize (Gd-> BD );

/* Main_loop () can return to retry autoboot, if so just run it again .*/
For (;;){
Main_loop (); // execute cyclically, attempt to start automatically, and accept the commands entered by the user from the serial port,
Then perform relevant work, set the delay time, and determine whether the target board enters the download mode or the start loading mode.
}

/* Notreached-No Way Out of command loop handle T booting */
}

 
3. main_loop ()

Void main_loop (void)
{

S = getenv ("bootdelay"); // get the bootdelay kernel waiting delay from the Environment Variable
Bootdelay = s? (INT) simple_strtol (S, null, 10): config_bootdelay;

Debug ("### main_loop entered: bootdelay = % d/n", bootdelay );

S = getenv ("bootcmd"); // get the bootcmd startup command line from the Environment Variable
For example, bootcmd = TFTP; bootm or bootcmd = bootm 0xbf020000
Char * S1 = getenv ("bootargs"); // get the bootargs startup parameter from the Environment Variable

Debug ("### main_loop: bootcmd =/" % S/"/N", s? S: "<undefined> ");

Run_command (S, 0); // execute the startup command

// Manually enter the command

For (;;){

Len = Readline (cmd_prompt); // read the input command to cmd_prompt.

Rc = run_command (lastcommand, flag); // execute this command


}
# Endif/* cmd_hush_parser */
}

4. do_bootm ()

Int do_bootm (pai_tbl_t * cmdtp, int flag, int argc, char * argv [])
This function looks quite long. In fact, it is nothing more than extracting the kernel and then calling do_bootm_linux to guide the kernel

5. do_bootm_linux () lib_mips/mis_linux.c

Print the information starting kernel...

Void do_bootm_linux (pai_tbl_t * cmdtp, int flag, int argc, char * argv [],
Ulong ADDR, ulong * len_ptr, int verify)
{

Char * CommandLine = getenv ("bootargs ");

Thekernel =
(Void (*) (INT, char **, char **, int *) ntohl (HDR-> ih_ep );

// HDR is the pointer to the image header. HDR-> ih_ep is the-E Option parameter when we create an image using mkimage: the kernel entry address.

Linux_params_init (uncached_sdram (Gd-> BD-> bi_boot_params), CommandLine );

/* We assume that the kernel is in place */
Printf ("/nstarting kernel.../n ");

Thekernel (linux_argc, linux_argv, linux_env, 0); // start the kernel

}

U-boot transmits startup parameters to the kernel and is controlled by a series of Macros in include/configs/. h. The address passed by the startup parameters is initialized in board_init.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.