嵌入式学习笔记100-uboot1.1.6初体验

时间:2022-06-14 08:11:00
  1. 到官网或其他网上下载u-boot-1.1.6.tar.bz2
  2. 解压包到相应目录:tar -jxvf u-boot-1.1.6.tar.bz2 -C ../xxxxxx , 我是解压到samba共享的目录上以便到时候用sourceinsight建立工程。
  3. 解压好后先 make distclean or make mrproper 确保源码干净
  4. setup project via sourceinsight
  5. uboot 流程分析:
    查看makefile,发现关键code如下:
Makefile:
# load ARCH, BOARD, and CPU configuration
include $(OBJTREE)/include/config.mk
export ARCH CPU BOARD VENDOR SOC

MKCONFIG := $(SRCTREE)/mkconfig
ifeq ($(ARCH),arm)
CROSS_COMPILE = arm-linux-
endif

smdk2410_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
unconfig:
@rm -f $(obj)include/config.h $(obj)include/config.mk \
$(obj)board/*/config.tmp $(obj)board/*/*/config.tmp

# load other configuration
include $(TOPDIR)/config.mk

以smdk2410_config为例:
当make smdk2410_config 时 会删除unconfig对应的文件,然后执行源码下的mkconfig smdk2410 arm arm920t smdk2410 NULL s3c24x0,查看源码下的mkconfig:

# Script to create header files and links to configure
# U-Boot for a specific board.
#
# Parameters: Target Architecture CPU Board [VENDOR] [SOC]



cd ./include
rm -f asm
ln -s asm-$2 asm


echo "ARCH = $2" > config.mk
echo "CPU = $3" >> config.mk
echo "BOARD = $4" >> config.mk

[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk

[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk



echo "/* Automatically generated - do not edit */" >>config.h
echo "#include <configs/$1.h>" >>config.h

根据Parameters 知道 Target =smdk2410 Architecture =arm CPU=arm920t Board=smdk2410 VENDOR=NULL SOC=s3c24x0 并在include 目录下新建config.mk将ARCH CPU BOARD 等写入,而makefile include/config.mk 后就将这几个export了。同时还是include下新建config.h 包含#include

config.mk:
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB = $(CROSS_COMPILE)RANLIB
ifdef ARCH
sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
endif
ifdef CPU
sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
endif
ifdef SOC
sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules
endif
ifdef VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
ifdef BOARD
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
endif
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds

LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)

在makefile设置好CROSS_COMPILE后剩下就由这个顶层的config.mk具体设置了。
板子具体的bin分布由u-boot.lds决定 在LDSCRIPT := (TOPDIR)/board/ (BOARDDIR)/u-boot.lds,查看smdk2410的u-boot.lds 如下:

SECTIONS
{
. = 0x00000000;

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

. = ALIGN(4);
.rodata : { *(.rodata) }

. = ALIGN(4);
.data : { *(.data) }

. = ALIGN(4);
.got : { *(.got) }

. = .;
__u_boot_cmd_start = .;
.u_boot_cmd : { *(.u_boot_cmd) }
__u_boot_cmd_end = .;

. = ALIGN(4);
__bss_start = .;
.bss : { *(.bss) }
_end = .;
}

唯一值得注意的是cpu/arm920t/start.o 要在最前面,uboot有两个启动阶段,第一阶段由汇编写的,最基本的初始化,就在这个start.S

6.综上所述,如果要新增一个板子的配置要:
a. 修改makefile的CROSS_COMPILE指定编译器
b. 在makefile里增加类似该配置
smdk2410_config : unconfig
@ (MKCONFIG) (@:_config=) arm arm920t smdk2410 NULL s3c24x0
c. 在board目录下新增板子的名称为目录
d. 在include/configs下新增板子的头文件,文件名是配置第一个参数名
e. make xxx_config 配置板子
f. make all 编译配置信息