One 、uboot Introduction to the startup process

     With most BootLoader equally ,uboot The startup process is divided into BL1 and BL2 Two phases .BL1 The stage is usually the device initialization code such as the configuration of the development board , Need to depend on SoC Architecture , It's usually implemented in assembly language ;BL2 Stage is mainly for external devices such as network card 、Flash And so on uboot Self implementation of command set, etc , Usually use C Language to achieve .

1、BL1 Stage

    uboot Of BL1 Phase code is usually placed in start.s In file , Using assembly language , The main code functions are as follows :

    (1)  Appoint uboot Entrance . In the link script uboot.lds It is specified in uboot The entrance of is start.S Medium _start.

 (2) Set the exception vector (exception vector)

        (3) close IRQ、FIQ, Set up SVC Pattern

        (4) close L1 cache、 Set up L2 cache、 close MMU

        (5) according to OM The pin determines the starting mode

        (6) stay SoC Inside SRAM Set stack in

 (7)lowlevel_init( It mainly initializes the system clock 、SDRAM initialization 、 Serial port initialization, etc )

    (8) Set the power supply latch of the development board

    (9) Set up SDRAM The stack in

    (10) take uboot from SD Copy the card to SDRAM in

    (11) Set and turn on MMU

(12) Through to SDRAM Overall use planning , stay SDRAM Set the stack in the right place in the

 (13) eliminate bss paragraph , Jump to start_armboot perform ,BL1 The stage is finished

2、BL2 Stage

    start_armboot Function in lib_arm/board.c in , yes C The function at the beginning of the language , It's also BL2 In the phase code C Linguistic The main function , At the same time, it's the whole u-boot(armboot) The main function of ,BL2 The main functions of this stage are as follows :

        (1) planning uboot Memory usage

    (2) Traverse the array of calling function pointers init_sequence Initialization functions in

 (3) initialization uboot The heap manager for mem_malloc_init

 (4) initialization SMDKV210 Development board SD/MMC controller mmc_initialize

 (5) Relocation of environment variables env_relocate

 (6)、 Assign the network card address in the environment variable to the development board variable of the global variable

 (7)、 Development board hardware device initialization devices_init

 (8)、 Jump table jumptable_init

 (9)、 Console initialization console_init_r

 (10)、 Network card chip initialization eth_initialize

 (11)、uboot Enter the main loop main_loop

Two 、uboot Program entry analysis

1、link.lds Link script file analysis

u-boot.lds File is uboot Project link script file , be located board\samsung\smdkc110 Under the table of contents , It's very important for the link phase in the later stage of project compilation , To determine the uboot Assembly of programs .

u-boot.lds Link to ENTRY(_start) It specifies uboot The entry address of the program is _start.

2、 location uboot Program entry address

stay SourceInsight establish uboot engineering , Use the index function to find _start, Find Samsung in search results smdkv210 Development board related code , Final lock cpu\s5pc11x\start.S file , Go to... In the file _start identifier .

3、 ... and 、start.S File analysis

1、 Header file analysis

start.S There are four header files :

#include <config.h>

    config.h The header file is created by mkconfig The header file created by the script , The content of the header file contains the header file of the development board :#include <configs/smdkv210single.h>

#include <version.h>

    version.h The content of the header file contains the automatically generated version header file , The content of the header file is :#include "version_autogenerated.h",version_autogenerated.h The header file defines the version macro , A macro is defined as :#define U_BOOT_VERSION "U-Boot 1.3.4". The value of the version macro is Makefile Version information defined in .

#include <asm/proc/domain.h>

    domain.h The header file defines CONFIG_ENABLE_MMU Macro is valid , For linked files , The file actually pointed to is include/asm-arm/proc-armv/domain.h.

#include <regs.h>

regs.h The header file is the link file , Point to s5pc110.h The header file ,s5pc110.h Inside the file, macro is used to define SoC A lot of information about internal registers .

2、 Bit occupancy of header check information

#if defined(CONFIG_EVT1) && !defined(CONFIG_FUSED)

.word 0x2000

.word 0x0

.word 0x0

.word 0x0

#endif

Definition uboot At the beginning of the program 16 Byte check header information fills the space , The value in the header check information block needs to be written later .

3、 The construction of abnormal vector table

.globl _start

_start:

b reset

ldrpc, _undefined_instruction

ldrpc, _software_interrupt

ldrpc, _prefetch_abort

ldrpc, _data_abort

ldrpc, _not_used

ldrpc, _irq

ldrpc, _fiq

    uboot The entry point of the program actually defines the exception vector table , The exception vector table consists of SoC Hardware implementation , therefore uboot When power on and reset, you need to jump to reset perform .

4、 Reset reset analysis

SoC The first code to run after power on reset is reset. It mainly includes the following parts :

A、 close IRQ、FIQ, And set the processor mode to SVC Pattern

B、CPU Initialization of key registers cpu_init_crit:

     close L2 cache

     initialization L2 cache

     Turn on L2 cache

     close L1 cache

     close MMU

     Read OM Boot pin information

     Make sure to boot the device from SD Card activation

     Set up SRAM The stack in is called lowlevel_init To prepare for (lowlevel_init There are nested calls inside )

     call lowlevel_init( It mainly initializes the system clock 、SDRAM initialization 、 Serial port initialization, etc )

     Set the power supply latch of the development board

     Set up SDRAM The stack in

     Determine whether the current code is running in SDRAM in , If the current code is running in SDRAM in , Skip code relocation .

     Judge the startup mode , choice SD Card boot device , Jump to mmcsd_boot

    SD Preparation for card start up , from SD Card copy uboot To SDRAM:movi_bl2_copy

 

C、 Set up MMU, Turn on MMU

D、 Through to SDRAM Overall use planning , stay SDRAM Set the stack in the right place in the

E、 eliminate bss paragraph , Jump to start_armboot perform ,BL1 The stage is finished

5、lowlevel_init analysis

lowlevel_init be located \board\samsung\smdkc110\lowlevel_init.S in , The main functions are as follows :

    A、 Check the reset state , Judge how to start

Select the reset start mode according to the reset status , In the low power consumption state, reset startup can skip the following steps .

    B、IO back

    C、 Turn off the watchdog

    D、 external SRAM Of GPIO initialization 、 external SROM initialization

    E、 Development board power supply latch settings

    F、 Determine whether the current code is running in SDRAM, If the current code is running in SDRAM, Indicates that the current reset from low power consumption state , You can skip system clock initialization 、 Serial initialization 、SDRAM Initialization etc.

    G、 Initialize the system clock :system_clock_init

    H、 initialization SDRAM Memory :mem_ctrl_asm_init

    I、 Initialize serial port , Print out ’O’:uart_asm_init

    J、 initialization trustzone:tzpc_init

    K、 initialization nand or onenand

    L、 Check the reset state

    M、 close ABB

    N、 The serial port prints out ‘K’

explain :”OK” It's the debug information printed out , If it prints out ’O’ It indicates that the serial port is initialized uart_asm_init All the code before is correct . If it prints out ”OK” It indicates that it is initialized at the board level of the development board lowlevel_init All the code before is working properly .

system_clock_init、uart_asm_init、tzpc_init、nand_asm_init All in lowlevel_init.S In the file ,mem_ctrl_asm_init be located cpu\s5pc11x\s5pc110\cpu_init.S In file .

Four 、board.c File analysis

uboot The execution of the BL1 After the stage, jump far to start_armboot Function execution BL2,start_armboot Function in lib_arm\board.c in .

1、 Description of important variables

typedef int (init_fnc_t) (void); Function type

init_fnc_t **init_fnc_ptr;// Secondary function pointer

#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r8")

DECLARE_GLOBAL_DATA_PTR Defines a register stored in r8 The point in the book is gd_t Pointer to type global variable gd.

Definition of global variable structure :

typedefstructglobal_data {

bd_t*bd;//boardinfo Structure information , Store information about the development board

unsigned longflags;// Sign a

unsigned longbaudrate;// Baud communication rate

unsigned longhave_console;// Console /* serial_init() was called */

unsigned longreloc_off;// Relocation offset /* Relocation Offset */

unsigned longenv_addr;// The address of the environment variable structure /* Address  of Environment struct */

unsigned longenv_valid;// Environment variables use flags /* Checksum of Environment valid? */

unsigned longfb_base;//fb Base address /* base address of frame buffer */

#ifdef CONFIG_VFD

unsigned charvfd_type;///* display type */

#endif

void**jt;// Jump table /* jump table */

} gd_t;

Development board information structure variable definition :

typedef struct bd_info {

    intbi_baudrate;// Baud rate of hardware serial port /* serial console baudrate */

    unsigned longbi_ip_addr;// Development board IP Address /* IP Address */

    unsigned charbi_enetaddr[6];// Development board network card address /* Ethernet adress */

    struct environment_s       *bi_env;// Environment variable pointer

    ulong        bi_arch_number;// Machine code /* unique id for this board */

    ulong        bi_boot_params;//uboot Launch parameters /* where this board expects params */

    struct/* RAM configuration */

    {

ulong start;

ulong size;

    }bi_dram[CONFIG_NR_DRAM_BANKS];// Memory module information

#ifdef CONFIG_HAS_ETH1

    /* second onboard ethernet port */

    unsigned char   bi_enet1addr[6];// The address of the second NIC

#endif

} bd_t;

 

2、uboot Memory planning for

wKioL1drRfTyRHOGAADgnjy9DiE579.jpg

    SDRAM_BASE By MMU Map on 0xC0000000,CFG_UBOOT_BASE yes 0xC3E00000

     stay BL1 Segment runtime ,uboot The image is copied to CFG_UBOOT_BASE At the beginning of the address .

  gd The address of :

gd_base = CFG_UBOOT_BASE + CFG_UBOOT_SIZE - CFG_MALLOC_LEN - CFG_STACK_SIZE - sizeof(gd_t);

  bd The address of :

gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));

3、start_armboot Function analysis

    start_armboot The main functions of the function are as follows :

(1)、 Traverse the array of calling function pointers init_sequence Initialization functions in

Iterate through the array of calling function pointers in turn init_sequence The function in , If there is a function execution error , execute hang function , Print out ”### ERROR ### Please RESET the board ###”, Into the dead cycle .

(2)、 initialization uboot The heap manager for mem_malloc_init

(3)、 initialization SMDKV210 Of SD/MMC controller mmc_initialize

(4)、 Relocation of environment variables env_relocate

(5)、 Assign the network card address in the environment variable to the development board variable of the global variable

(6)、 Development board hardware device initialization devices_init

(7)、 Jump table jumptable_init

(8)、 Console initialization console_init_r

(9)、 Network card chip initialization eth_initialize

(10)、uboot Enter the main loop main_loop

void start_armboot (void)
   {
   // Global data variable pointer gd Occupy r8.
   DECLARE_GLOBAL_DATA_PTR;       
   /* Give global data variables gd Arrange space */
   gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
   memset ((void*)gd, 0, sizeof (gd_t));
   /* Give board data variables gd->bd Arrange space */
   gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
   memset (gd->bd, 0, sizeof (bd_t));
   monitor_flash_len = _bss_start - _armboot_start;//u-boot length .       
   /* Sequential execution init_sequence Initialization functions in arrays */
   for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
       if ((*init_fnc_ptr)() != 0) {
           hang ();
                 }
          }
    /* Initialize heap space */
    mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);
    /* Relocate environment variables , */
     env_relocate ();
    /* Get... From the environment variable IP Address */
    gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
    /* Ethernet interface MAC Address */
    devices_init ();      /*  Device initialization */
    jumptable_init ();  // Jump table initialization
    console_init_r ();    /* Fully initialize the console device */
    enable_interrupts (); /* Enable interrupt processing */
     /* Initialization through environment variables */
     if ((s = getenv ("loadaddr")) != NULL) {
        load_addr = simple_strtoul (s, NULL, 16);
     }
     /* main_loop() The cycle goes on */
     for (;;) {
         main_loop ();      /* The main loop function handles the execution of user commands -- common/main.c */
          }
   }

4、 Function pointer array init_sequence

Function pointer array init_sequence:

init_fnc_t *init_sequence[] = {

cpu_init,//CPU Initialization of the architecture , It's empty cpu\s5pc11x\cpu.c

board_init,// Development board initialization board\samsung\smdkc110\smdkc110.c

interrupt_init,// Timer timer4 initialization cpu\s5pc11x\interrupts.c

env_init,// Environment variable initialization common\env_movi.c

init_baudrate,// Baud rate setting lib_arm\board.c

serial_init,// The time delay function C, The serial port is not initialized again cpu\s5pc11x\serial.c

console_init_f,// The first stage of console initialization , The console is not initialized common\console.c

display_banner,// Send by serial port uboot Version information lib_arm\board.c

#if defined(CONFIG_DISPLAY_CPUINFO)

print_cpuinfo,// Serial port printing system clock information cpu\s5pc11x\s5pc110\speed.c

#endif

#if defined(CONFIG_DISPLAY_BOARDINFO)

checkboard,// Print development board letters Board:SMDKV210

//board\samsung\smdkc110\smdkc110.c

#endif

#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)

init_func_i2c,//SMDKV210 Undefined I2C, Function is empty lib_arm\board.c

#endif

dram_init,// initialization gd->bd->bi_dram, Development board SDRAM Configuration information

board\samsung\smdkc110\smdkc110.c 

   display_dram_config,// The serial port prints out DRAM The size of information ,DRAM:xxxMB

lib_arm\board.c

NULL,

};

board_init function :

dm9000_pre_init();// Network card initialization ,GPIO And port settings

gd->bd->bi_arch_number = MACH_TYPE;// The machine code of the development board ,uboot The machine code and linux The machine codes must be adapted to each other

gd->bd->bi_boot_params = (PHYS_SDRAM_1+0x100);//uboot The parameter address to the kernel

display_banner function :

Print uboot Version information :uboot-1.3.4

print_cpuinfo function :

Print CPU The clock information of the clock system

checkboard function :

Print out the development board information Board:   SMDKV210

display_dram_config function :

Print out DRAM The size of information ,DRAM:xxxMB

The printed information can be used as debugging , Iterate through the array of calling function pointers in turn init_sequence The function in , If there is a function execution error , execute hang function , Print out ”### ERROR ### Please RESET the board ###”, Into the dead cycle .