u-boot启动过程 u-boot (3)

来源:互联网 发布:购买软件付款方式 编辑:程序博客网 时间:2024/05/30 05:11

1.u-boot启动模式简介

uboot包含启动模式和下载模式。

启动模式(boot loading)这种模式也称之为“自主”,整个过程是没有用户的参与的

下载模式(downloadig)这种模式下。目标机上的bootloader通过串口或者是网络来从主机上下载文件,然后控制启动流程

 

2.u-boot启动分析

由于一个可执行的image文件必须有一个入口点,这个入口点通常是放在flash的0x0处,因此必须通知编译器使其知道这个

工作是通过/board/smdk2410/uboot.lds来实现的

ENTRY(_start)
SECTIONS
{
        . = 0x00000000;

        . = ALIGN(4);
        .text      :
        {
          cpu/arm920t/start.o   (.text)
          *(.text)
        }

       *****

u-boot在代码区的位置在board/smdk2410/config.mk

# Linux-Kernel is expected to be at 3000'8000, entry 3000'8000
# optionally with a ramdisk at 3080'0000
TEXT_BASE = 0x33F80000

 

###################################

下面开始分析start.S文件

###################################

/*

 * 当发生异常时,执行/cpu/arm920t/interrupts.c中的中断处理函数

 */

.globl _start
_start: b       reset
        ldr     pc, _undefined_instruction
        ldr     pc, _software_interrupt
        ldr     pc, _prefetch_abort
        ldr     pc, _data_abort
        ldr     pc, _not_used
        ldr     pc, _irq
        ldr     pc, _fiq
/*
 * the actual reset code,实际开始运行点,设置为特权模式SVC
 */

/* turn off the watchdog,设置cpu频率*/

/* 与内存管理相关寄存器的设置 */

 /* relocate U-Boot to RAM           */

 /* Set up the stack  */

/* clear bss */

ldr     pc, _start_armboot跳转到start_armboot(lib_arm/board.c)的c代码开始执行

 

###########################

board.c

############################

board.c文件中主函数是start_armboot函数,该函数同时也是整个uboot的主函数。

        for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
                if ((*init_fnc_ptr)() != 0) {
                        hang ();
                }
        }

调用init_sequence中函数

/* configure available FLASH banks */

configure LCD

configure network

            *

 

最后调用函数main_loop来实现接受串口中传来的命令,调用相应函数(main_loop在common/main.c中定义)       *

/* main_loop() can return to retry autoboot, if so just run it again. */
        for (;;) {
                main_loop ();
        }

 

#############################

main.c

##############################

在main.c中接受串口的命令来执行

 for (;;)

      // get command and execute the command

 

 

原创粉丝点击