网站建设营销型网站概念,罗村网站建设公司,网站备案网站名称,模板网站建设珠海目录
1.架构相关 - /arch
2.开发板 - /board
3.配置文件 - /config
4.命令文件 - .u-boot.xxx_cmd
5.Makefile
6.输出文件 - u-boot.xxx
7.UBoot 配置文件 - .config
8.README uboot 的部分文件只会在编译时生成#xff0c;因此在分析源码目录前先编译#xff0c;编译…目录
1.架构相关 - /arch
2.开发板 - /board
3.配置文件 - /config
4.命令文件 - .u-boot.xxx_cmd
5.Makefile
6.输出文件 - u-boot.xxx
7.UBoot 配置文件 - .config
8.README uboot 的部分文件只会在编译时生成因此在分析源码目录前先编译编译后所有文件及目录如下 这些文件/文件夹的含义如下 主要关注以下文件夹中的内容 1.架构相关 - /arch /arch 文件夹中存放架构相关的文件 uboot 支持多种架构如 ARM、MIPS、x86 等I.MX6U 为 ARM 架构重点关注 /arm 文件夹中的内容 /mach-xxx 文件夹中的内容对应具体的 SoC 平台如 /mach-rockchip 对应瑞芯微的 SoC
/imx-common 对应 NXP 的 I.MX 平台
/cpu 文件夹对应具体的 ARM 架构如 ARMv7、ARMv8 等 I.MX6ULL 使用 ARM Cortex-A7 内核属于 ARMv7 架构
/cpu 文件夹中的 u-boot.lds 文件为 ARM SoC 所使用的链接脚本
后续分析 uboot 启动源码时需要重点关注 /cpu 文件夹中的内容 2.开发板 - /board /board 文件夹中的内容对应具体的平台/开发板 IMX 原属于飞思卡尔 Freescale因此后续添加正点原子的 I.MX6ULL 开发板时需要将相关文件放在该文件夹中 图中选中的 5 个文件夹对应 5 种类型的开发板
以 mx6ul 开头的为 I.MX6UL 开发板以 mx6ull 开头的为 I.MX6ULL 开发板
mx6ullevk 为 NXP 官方的 EVK 核心验证板正点原子的 ALPHA 开发板在此基础上进行开发后续进行 uboot 移植时需要参考该开发板 3.配置文件 - /config /config 文件夹存放 uboot 的配置文件 从头开始配置一个开发板过于复杂因此一般会在官方提供的配置文件基础上进行修改
SoC 厂商提供的配置文件一般命名为 xxx_defconfigxxx 表示开发板的名称
正点原子基于 NXP 官方配置文件修改得到的 APLHA 开发板的配置文件如下 图中这 6 个文件就是正点原子 I.MX6U-ALPHA 开发板对应的 uboot 默认配置文件其中 mx6ull_14x14_ddr512_emmc_defconfig 为 EMMC 核心板的配置文件 mx6ull_14x14_ddr256_nand_defconfig 为 NAND 核心板的配置文件
使用命令 make xxx_defconfig 即可配置 uboot比如
make mx6ull_14x14_ddr512_emmc_defconfig
该命令用于配置正点原子 I.MX6ULL EMMC 核心板的 uboot
注意编译 uboot 前一定要使用 defconfig 配置 uboot 4.命令文件 - .u-boot.xxx_cmd .u-boot.xxx_cmd 是一系列文件这些文件为编译生成的命令文件 比如文件 .u-boot.bin.cmd 的内容如下
cmd_u-boot.bin : cp u-boot-nodtb.bin u-boot.bin
.u-boot.bin.cmd 中定义了一个变量 cmd_u-boot.bin该变量的值为 cp u-boot-nodtb.bin u-boot.bin也就是拷贝一份 u-boot-nodtb.bin 文件并且重命名为 u-boot.bin这就是 u-boot.bin 的来源来自于文件 u-boot-nodtb.bin
.u-boot-nodtb.bin.cmd 文件用于生成 uboot.nodtb.bin该文件的内容如下
cmd_u-boot-nodtb.bin : arm-linux-gnueabihf-objcopy --gap-fill0xff - j .text -j .secure_text -j .rodata -j .hash -j .data -j .got - j .got.plt -j .u_boot_list -j .rel.dyn -O binary u-boot u-bootnodtb.bi
其使用 arm-linux-gnueabihf-objcopy将 ELF 格式的 u-boot 文件转换为二进制的 u-boot-nodtb.bin 文件
.u-boot.cmd 文件用于生成 u-boot.elf 文件该文件的内容如下
cmd_u-boot : arm-linux-gnueabihf-ld.bfd -pie --gc-sections - Bstatic -Ttext 0x87800000 -o u-boot -T u-boot.lds arch/arm/cpu/armv7/start.o --start-group arch/arm/cpu/built-in.o arch/arm/cpu/armv7/built-in.o arch/arm/imx-common/built-in.o arch/arm/lib/built-in.o board/freescale/common/built-in.o board/freescale/mx6ull_alientek_emmc/built-in.o cmd/built-in.o common/built-in.o disk/built-in.o drivers/built-in.o drivers/dma/built-in.o drivers/gpio/built-in.o drivers/i2c/builtin.o drivers/mmc/built-in.o drivers/mtd/built-in.o drivers/mtd/onenand/built-in.o drivers/mtd/spi/built-in.o drivers/net/built-in.o drivers/net/phy/built-in.o drivers/pci/builtin.o drivers/power/built-in.o drivers/power/battery/built-in.o drivers/power/fuel_gauge/built-in.o drivers/power/mfd/built-in.o drivers/power/pmic/built-in.o drivers/power/regulator/built-in.o drivers/serial/built-in.o drivers/spi/built-in.o drivers/usb/dwc3/built-in.o drivers/usb/emul/built-in.o drivers/usb/eth/built-in.o drivers/usb/gadget/built-in.o drivers/usb/gadget/udc/built-in.o drivers/usb/host/built-in.o drivers/usb/musb-new/built-in.o drivers/usb/musb/built-in.o drivers/usb/phy/built-in.o drivers/usb/ulpi/built-in.o fs/built-in.o lib/built-in.o net/built-in.o test/built-in.o test/dm/built-in.o -- end-group arch/arm/lib/eabi_compat.o -L /usr/local/arm/gcc-linaro4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linuxgnueabihf/4.9.4 -lgcc -Map u-boot.map
其通过 arm-linux-gnueabihf-ld.bfd 链接工具使用 ld.bfd 将各个 builtin.o 文件链接在一起形成 u-boot 文件
uboot 编译时会将同一个目录中所有的 .c 文件编译在一起并命名为 built-in.o相当于将众多 .c 文件对应的 .o 文件集合在一起这就是 u-boot 文件的来源
如果使用 NXP 提供的 MFGTools 工具向开发板烧写 uboot则烧写的是 u-boot.imx 文件而不是 u-boot.bin 文件u-boot.imx 是在 u-boot.bin 文件的头部添加了 IVT、DCD 等信息得到的文件该工作由文件 .u-boot.imx.cmd 完成该文件内容如下
cmd_u-boot.imx : ./tools/mkimage -n board/freescale/mx6ull_alientek_emmc/imximage.cfg.cfgtmp -T imximage - e 0x87800000 -d u-boot.bin u-boot.imx
其使用工具 tools/mkimage 完成该工作
IVT、DCD 等数据保存在文件 /board/freescale/mx6ullevk/imximage-ddr512.cfg.cfgtmp 中 (NAND 核心板为 imximage-ddr256.cfg.cfgtmp)
mkimage 工具读取文件 imximage-ddr512.cfg.cfgtmp 中的信息然后将其添加到文件 u-boot.bin 的头部最终生成 u-boot.imx
.u-boot.lds.cmd 文件用于生成 u-boot.lds 链接脚本 5.Makefile 顶层 Makefile 文件 Makefile 支持嵌套即顶层 Makefile 可以调用子目录中的 Makefile 文件
Makefile 嵌套在大项目中很常见一般大项目中源代码不会放到同一个目录中各个功能模块的源代码分开存放在各自的目录中每个功能模块目录中都有一个 Makefile该 Makefile 只处理本模块的编译链接工作这样所有的编译链接工作就不用全部放到一个 Makefile 中可以使 Makefile 更为简洁
uboot 源码根目录下的 Makefile 为顶层 Makefile其调用其它模块的 Makefile 文件比如 drivers/adc/Makefile 6.输出文件 - u-boot.xxx u-boot.xxx 为一系列文件包括 u-boot、u-boot.bin、u-boot.cfg、u-boot.imx、u-boot.lds、u-boot.map、u-boot.srec、u-boot.sym 和 u-boot-nodtb.bin 这些文件的含义如下 u-boot编译生成的 ELF 格式 uboot 镜像文件 u-boot.bin编译生成的二进制格式 uboot 可执行镜像文件 u-boot.cfguboot 的另一种配置文件 u-boot.imxu-boot.bin 添加头部信息后的文件NXP SoC 的专用文件 u-boot.lds链接脚本 u-boot.mapuboot 映射文件通过该文件可以查看某个函数被链接到了哪个地址 u-boot.srecS-Record 格式的镜像文件 u-boot.symuboot 符号文件 u-boot-nodtb.bin和 u-boot.bin 一样u-boot.bin 就是 u-boot-nodtb.bin 的副本 7.UBoot 配置文件 - .config 使用命令 make xxx_defconfig 配置 uboot 后会自动生成 .config 文件
#
# Automatically generated file; DO NOT EDIT.
# U-Boot 2016.03 Configuration
#
CONFIG_CREATE_ARCH_SYMLINKy
CONFIG_HAVE_GENERIC_BOARDy
CONFIG_SYS_GENERIC_BOARDy
# CONFIG_ARC is not set
CONFIG_ARMy
...
CONFIG_SYS_ARCHarm
CONFIG_SYS_CPUarmv7
CONFIG_SYS_SOCmx6
CONFIG_SYS_VENDORfreescale
CONFIG_SYS_BOARDmx6ullevk
CONFIG_SYS_CONFIG_NAMEmx6ullevk
...
#
# ARM architecture
#
CONFIG_HAS_VBARy
CONFIG_HAS_THUMB2y
CONFIG_CPU_V7y
...
.config 文件中配置项的名称均为 CONFIG_xxx这些配置项就是 Makefile 中的变量因此后面都跟有相应的值uboot 的顶层 Makefile 或子 Makefile 会调用这些变量值
.config 中许多变量的值为 y值为 y 的变量用于控制某项功能是否使能为 y 表示功能使能比如
CONFIG_CMD_BOOTMy
如果使能了 bootd 命令CONFIG_CMD_BOOTM 就为 y在 cmd/Makefile 中有如下代码
ifndef CONFIG_SPL_BUILD
# core command
obj-y boot.o
obj-$(CONFIG_CMD_BOOTM) bootm.o
obj-y help.o 6 obj-y version.o
其中obj-$(CONFIG_CMD_BOOTM) bootm.o 配合 CONFIG_CMD_BOOTMy 展开为
obj-y bootm.o
即给 obj-y 追加一个 bootm.oobj-y 包含所有待编译文件对应的 .o 文件这里表示需要编译文件 cmd/bootm.c相当于通过 CONFIG_CMD_BOOTDy 使能 bootm 命令进而编译 cmd/bootm.c 文件该文件实现命令 bootm在 uboot 和 Linux 内核中均采用这种方法使能某个功能并编译对应的源码文件 8.README README 文件描述 uboot 的详细信息包括 uboot 该如何编译、uboot 中各文件夹的含义、相应的命令等