u-boot 的文件详解

发布时间 2024-01-09 22:19:33作者: zxddesk

1、目录分析(各个文件夹所包含的内容)

UBoot编译后文件进行说明及分析

arch 文件夹  与架构有关

board 文件夹 与具体板子有关的文件

configs 文件夹  为uboot的配置文件

配置方法:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-mx6ull_14x14_ddr512_emmc_ defconfig

.u-boot.xxx_cmd 文件 编译生成的一些命令文件

Makefile 文件  这个是顶层Makefile文件,支持嵌套调用单元Makefile文件

.config 文件 uboot 配置文件,使用命令“make xxx_defconfig”配置 uboot 以后就会自动生成

README 文件描述了 uboot 的详细信息

 

    1、因为uboot会使用到一些经过编译才会生成的文件,因此我们在分析uboot的时候,需要先编译一下uboot。

2、arch\arm\cpu\u-boot.lds就是整个UBOOT的连接脚本

3、board\freescale\mx6ullevk。重点。是使用的开发板

4、configs目录是uboot的默认配置文件目录。此目录下都是以_defconfig结尾的。这些配置文件对应不同的板子。

        mx6ull_alientek_alpha_ddr256_emmc_defconfig  默认配置文件命名

5、我们移植uboot的时候重点要关注。

        board\freescale

        · ·\configs,主要是_defconfig

 

6、当我们执行make xxx_defconfig以后就会生成.config文件,此文件保存了详细的uboot配置信息。

 

7、顶层README,非常重要,建议大家阅读,介绍uboot。

 

8、u-boot。这个就是编译出来带ELF信息的uboot可执行文件。

2、u-Boot 顶层 Makefile 分析

.vscode文件夹进行设置一个文件settings.json用来屏蔽相关不需要文件

{

2 "search.exclude": {

3 "**/node_modules": true,

4 "**/bower_components": true,

5 },

6 "files.exclude": {

7 "**/.git": true,

8 "**/.svn": true,

9 "**/.hg": true,

10 "**/CVS": true,

11 "**/.DS_Store": true,

12 }

13 }

 

编译输出设置:

设置 V=0 或者在命令行中不定义 V 的话,编译 uboot 的时候终端中显示的短命令

编译的时候使用“make -s”即可实现静默输出

 

make 的时候使用“O”来指定输出目录,比如“make O=out”就是设置目标文件输出到 out 目录中

 

make C=1”使能代码检查,检查那些需要重新编译的文件。“make C=2”用于检查所有的源码文件

 

测试源码中变量的内容:

 

uname - m”获取架构名称

name - s来获取主机 OS

 

 

编译处理过程

make distclean  删除

make mx6ull_14x14_ddr512_emmc_defconfig

规则:

%config: scripts_basic outputmakefile FORCE

$(Q)$(MAKE) $(build)=scripts/kconfig $@

 

Outputmakefile

因为分析 KBUILD_SRC 为空,所以 outputmakefile 无效

 

 

1、先目标为scripts_basic:

规则$(Q)$(MAKE) $(build)=scripts/basic展开:

Make  -f ./scripts/Makefile.build obj=scripts/basic

 

build定义在scripts\Kbuild.include:

build := -f $(srctree)/scripts/Makefile.build obj

build := -f ./scripts/Makefile.build obj

 

最终要执行的命令:

Make  -f ./scripts/Makefile.build obj=scripts/basic

 

2、后目标xxx_deconfig

$(Q)$(MAKE) $(build)=scripts/kconfig $@进行展开:

Make  -f ./scripts/Makefile.build obj=scripts/kconfig xxx_deconfig

 

 

最终要分析的命令:

Make  -f ./scripts/Makefile.build obj=scripts/basic

Make  -f ./scripts/Makefile.build obj=scripts/kconfig xxx_deconfig

 

 

第一条命令:

src= scripts/basic

 

kbuild-dir = ./scripts/kconfig

kbuild-file = ./scripts/kconfig/Makefile

 

__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \

 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \

 $(subdir-ym) $(always)

@:

 

__build: $(builtin-target)  $(lib-target) $(extra-y))  $(subdir-ym)  $(always)

@:

 

进一步缩减:

 __build: $(builtin-target)  $(lib-target) $(extra-y))  $(subdir-ym)  $(always)

@:

为:   __build: scripts/basic/fixdep

@:

scripts_basic 目标的作用就是编译出 scripts/basic/fixdep 这个软件。

 

 

第二条命令:

src= scripts/kconfig

kbuild-dir = ./scripts/kconfig

kbuild-file = ./scripts/kconfig/Makefile

include ./scripts/kconfig/Makefile

 

%_defconfig: $(obj)/conf

    $(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)

 

xxx_defconfig: scripts/kconfig/conf

    $(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)

  scripts/kconfig/conf --defconfig=arch/../configs/xxx_defconfig Kconfig

最终生成 uboot 根目录下的.config 文件。

 

make xxx_defconfig 执行流程

3、make过程

依赖目标:

PHONY := _all

_all:

_all: all

all: $(ALL-y) 

ALL-y += u-boot.srec u-boot.bin u-boot.sym System.map u-boot.cfg binary_size_check

 

ALL-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin  

.config 配置文件中就会有“CONFIG_ONENAND_U_BOOT=y”相当于

ALL-y += u-boot-onenand.bin

 

u-boot.bin: u-boot-dtb.bin FORCE

    $(call if_changed,copy)

 

u-boot-nodtb.bin: u-boot FORCE

    $(call if_changed,objcopy)

    $(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE))

    $(BOARD_SIZE_CHECK)

 

u-boot: $(u-boot-init) $(u-boot-main) u-boot.lds FORCE

    $(call if_changed,u-boot__)

ifeq ($(CONFIG_KALLSYMS),y)

    $(call cmd,smap)

    $(call cmd,u-boot__) common/system_map.o

endif

 

 

u-boot-init := $(head-y)

u-boot-main := $(libs-y)

head-y := arch/arm/cpu/$(CPU)/start.o 因此

u-boot-init= arch/arm/cpu/armv7/start.o

 

libs-y=保存uboot 各子目录的集合

libs-y+=lib/ -> lib/built-in.o

libs-y 保存大量的xxx/built-in.o

 

u-boot就是将大量的start.o与xxx/built-in.o链接在一起

总结:

make xxx_defconfig 用于配置 uboot ,这个命令最主要的目的就是生成 .config 文件。
make :用于编译 uboot ,这个命令的主要工作就是生成二进制的 u-boot.bin 文件和其他的一
些与 uboot 有关的文件,比如 u-boot.imx 等等。