u-boot 1、基础知识与移植使用

来源:互联网 发布:基础设施网络建设 编辑:程序博客网 时间:2024/06/06 00:19

u-boot是什么:是一种普遍用于嵌入式系统中的Bootloader。Bootloader是在操作系统运行之前执行的一小段程序,通过它,我们可以初始化硬件设备、建立内存空间的映射表,从而建立适当的软硬件环境,为最终调用操作系统内核做好准备。

从上面这段话,可以知道,u-boot的作用:启动系统内核。

u-boot的目录分类:1、平台(arch)、板级相关(board)
 2、通用的函数:(1)include:头文件和开发板配置文件(include/configs)
(2)common:对驱动程序进行进一步封装
(3)lib:通用的库函数(printf)
 3、驱动程序:drivers,fs,net,disk,nand_spl,post
 4、tools,example,doc

通常来说,我们对应的MCU,官网都会提供demo板的u-boot,那么我们要如何修改demo的uboot,从而得到我们板子相关的u-boot呢?以我现在使用的I.MX6的mx6q_sabresd为例,参考i.MX_6Solo6DualLite_BSP_Porting_Guide.pdf文档,主要有以下几个步骤(我使用的板子名为hd300):

1. Make a copy of the board directory:

    cp -R board/freescale/mx6q_sabresd board/freescale/mx6q_hd300

    (a)重命名目录下的mx6q_sabresd.c为mx6q_hd300.c:

         mv board/freescale/mx6q_hd300/mx6q_sabresd.c board/freescale/mx6q_hd300/mx6q_hd300.c

    (b)修改板级目录下的链接文件board/freescale/mx6_hd300/u-boot.lds:

         board/freescale/mx6q_sabresd/flash_header.o --> board/freescale/mx6q_hd300/flash_header.o
         board/freescale/mx6q_sabresd/libmx6q_sabresd.a --> board/freescale/mx6q_hd300/libmx6q_sabresd.a

2. Copy the existing mx6_<reference board name>.h board configuration file as mx6_<custom board name>.h:

    cp include/configs/mx6q_sabresd.h include/configs/mx6q_hd300.h

    该配置文件主要有两个作用:一是类似与kernel的make menuconfig;二是定义memory的起始地址和大小,并传给kernel。

     所以应当注意以下参数:

    CONFIG_LOADADDR: Normally your uImage will be loaded to this address for boot.

    CONFIG_NR_DRAM_BANKS: Number of ddr banks.

    PHYS_SDRAM_x, PHYS_SDRAM_x_SIZE: DDR bank x start address and size (where x denotes an index between 0 and CONFIG_NR_DRAM_BANKS-1,inclusive).

    CONFIG_NR_DRAM_BANKS, PHYS_SDRAM_x and PHYS_SDRAM_x_SIZE will be passed to kernel. If these configs are wrong, kernel might fail to boot.

3.修改uboot目录下的Makefile文件,增加:
mx6q_hd300_config   : unconfig
@$(MKCONFIG) $(@:_config=) arm arm_cortexa8 mx6q_hd300 freescale mx6

4.配置和编译:
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- mx6q_hd300_config
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-

至此,就可以得到跟官网demo板一模一样的u-boot.bin。当然,我们的目的是要得到我们板子,所以还需要针对我们的板子进行如下的修改:

5、如果使用的DDR3,需要修改board/freescale/mx6_hd300/flash_header.S,设置里面的DCD table以匹配我们板子的DDR时序

6、如果需要添加新的驱动代码,可以在board/freescale/mx6q_hd300/mx6q_hd300.c的board_init(这里还不能使用printf)和board_late_init

7、如果需要更加深入的添加新驱动,可以通过lib_arm/board.c的void start_armboot (void)函数,里面有个函数数组init_sequence[],里面定义了一堆初始化函数(board_init)。如果需要更改u-boot输出信息中的board名字,可以通过修改init_sequence[]数组里面check_board函数。


u-boot分析总结:http://blog.sina.com.cn/s/blog_54f82cc2010125xv.html


0 0
原创粉丝点击