首先是U-boot源码的来源,由于使用的是TI的BBB板子,所以TI自然也提供了自己定制的u-boot源码,该源码就在TI-SDK包中有,另外该安装包中的u-boot版本是2013.10版本,内核版本为3.12.10,除了源码包还自带工具链。
TI-SDK最新版下载链接:http://software-dl.ti.com/sitara_linux/esd/AM335xSDK/latest/index_FDS.html
当然,还有另外一个德国佬官方的u-boot源码,网站首页:http://www.denx.de/en/News/WebHome和git代码库:git://www.denx.de/git/u-boot.git。
以官方u-boot为例进行u-boot的编译,进入源码根目录可以看到内容如下,
zhouyu@zhouyu-virtual-machine:~$ cd u-boot/
zhouyu@zhouyu-virtual-machine:~/u-boot$ ls
api configs dts Kconfig Makefile snapshot.commit
arch CREDITS examples lib net spl
board disk fs Licenses post test
common doc include MAINTAINERS README tools
config.mk drivers Kbuild MAKEALL scripts
其中打开根目录下的Makefile文件,可以查看到本源码的版本,如下图:
step1:在进行任何操作之前,先清除源码树,
zhouyu@zhouyu-virtual-machine:~/u-boot$ make distclean
CLEAN scripts/basic
CLEAN scripts/kconfig
CLEAN include/config include/generated spl
CLEAN .config include/autoconf.mk include/autoconf.mk.dep include/config.h
zhouyu@zhouyu-virtual-machine:~/u-boot$
step2:编译之前的配置工作
zhouyu@zhouyu-virtual-machine:~/u-boot$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 O=am335x_beaglebone_black am335x_boneblack_defconfig
GEN /home/zhouyu/u-boot/am335x_beaglebone_black/Makefile
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
#
# configuration written to spl/.config
#
zhouyu@zhouyu-virtual-machine:~/u-boot$
make之后的第一个参数向Makefile指明了编译的目标体系结构,第二个参数向Makefile指明了使用哪个编译工具链,第四个参数告诉make程序,这个编译任务要分配4个线程来并行进行,以加快编译速度,通常这个数依据自己的处理器的核数来选择,一般选择2倍核数,第五个参数告诉Makefile编译时产生的中间文件以及最后的结果都存放在源码树根目录下的am335x_beaglebone_black文件夹中,这对于使用同一个源码树来编译多个不同配置的u-boot时是一个很好的选择。最后一个参数向Makefile指明了要使用哪个文件来进行具体的配置,最后所有的配置都将写进源码树根目录下面的.config文件中。
而至于具体后面应该跟一个什么样的配置参数,可以从下图中寻找答案
在源码树的configs文件夹中可以看到很多配置文件,我选择的是第一个红线框的配置文件。
step3:正式开始编译工作
zhouyu@zhouyu-virtual-machine:~/u-boot$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 O=am335x_beaglebone_black all
GEN /home/zhouyu/u-boot/am335x_beaglebone_black/Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
scripts/kconfig/conf --silentoldconfig Kconfig
CHK include/config.h
UPD include/config.h
GEN include/autoconf.mk
GEN include/autoconf.mk.dep
GEN spl/include/autoconf.mk
CHK include/config/uboot.release
CHK include/generated/timestamp_autogenerated.h
GEN /home/zhouyu/u-boot/am335x_beaglebone_black/Makefile
UPD include/generated/timestamp_autogenerated.h
UPD include/config/uboot.release
Using /home/zhouyu/u-boot as source for U-Boot
CHK include/generated/version_autogenerated.h
UPD include/generated/version_autogenerated.h
CC lib/asm-offsets.s
CC arch/arm/lib/asm-offsets.s
GEN include/generated/asm-offsets.h
GEN include/generated/generic-asm-offsets.h
LDS u-boot.lds
HOSTCC tools/gen_eth_addr
HOSTCC tools/img2srec
HOSTCC tools/aisimage.o
HOSTCC tools/atmelimage.o
WRAP tools/common/bootm.c
WRAP tools/common/image-fit.c
WRAP tools/common/image.c
HOSTCC tools/default_image.o
HOSTCC tools/dumpimage.o
HOSTCC tools/fit_common.o
HOSTCC tools/fit_image.o
HOSTCC tools/gpimage-common.o
HOSTCC tools/gpimage.o
HOSTCC tools/image-host.o
HOSTCC tools/imagetool.o
HOSTCC tools/imximage.o
HOSTCC tools/kwbimage.o
WRAP tools/lib/crc32.c
WRAP tools/lib/fdtdec.c
WRAP tools/lib/fdtdec_common.c
WRAP tools/lib/libfdt/fdt.c
WRAP tools/lib/libfdt/fdt_ro.c
WRAP tools/lib/libfdt/fdt_rw.c
WRAP tools/lib/libfdt/fdt_strerror.c
WRAP tools/lib/libfdt/fdt_wip.c
WRAP tools/lib/md5.c
WRAP tools/lib/sha1.c
WRAP tools/lib/sha256.c
HOSTCC tools/mkenvimage.o
HOSTCC tools/mkimage.o
HOSTCC tools/mxsimage.o
HOSTCC tools/omapimage.o
HOSTCC tools/os_support.o
HOSTCC tools/pbl_crc32.o
HOSTCC tools/pblimage.o
HOSTCC tools/ublimage.o
HOSTCC tools/proftool
HOSTCC tools/common/bootm.o
HOSTCC tools/common/image-fit.o
HOSTCC tools/common/image.o
HOSTCC tools/lib/crc32.o
HOSTCC tools/lib/fdtdec.o
HOSTCC tools/lib/fdtdec_common.o
HOSTCC tools/lib/libfdt/fdt.o
HOSTCC tools/lib/libfdt/fdt_ro.o
HOSTCC tools/lib/libfdt/fdt_rw.o
HOSTCC tools/lib/libfdt/fdt_strerror.o
HOSTCC tools/lib/libfdt/fdt_wip.o
HOSTCC tools/lib/md5.o
HOSTCC tools/lib/sha1.o
HOSTCC tools/lib/sha256.o
HOSTLD tools/mkenvimage
HOSTLD tools/dumpimage
HOSTLD tools/mkimage
LD arch/arm/cpu/built-in.o
CC arch/arm/cpu/armv7/cache_v7.o
CC arch/arm/cpu/armv7/am33xx/clock_am33xx.o
CC arch/arm/cpu/armv7/am33xx/clock.o
AS arch/arm/lib/vectors.o
AS arch/arm/lib/crt0.o
AS arch/arm/lib/relocate.o
CC arch/arm/lib/bootm-fdt.o
CC arch/arm/lib/bootm.o
CC arch/arm/cpu/armv7/am33xx/sys_info.o
CC arch/arm/cpu/armv7/cpu.o
CC arch/arm/cpu/armv7/am33xx/ddr.o
CC arch/arm/cpu/armv7/syslib.o
CC arch/arm/lib/sections.o
CC arch/arm/lib/interrupts.o
CC board/ti/am335x/board.o
CC arch/arm/cpu/armv7/am33xx/emif4.o
CC arch/arm/cpu/armv7/omap-common/reset.o
CC arch/arm/cpu/armv7/omap-common/timer.o
CC arch/arm/cpu/armv7/am33xx/board.o
CC arch/arm/lib/reset.o
LD board/ti/am335x/built-in.o
CC arch/arm/cpu/armv7/omap-common/utils.o
CC arch/arm/lib/cache.o
CC arch/arm/cpu/armv7/am33xx/mux.o
CC arch/arm/lib/cache-cp15.o
CC arch/arm/cpu/armv7/omap-common/omap-cache.o
LD arch/arm/cpu/armv7/am33xx/built-in.o
CC common/main.o
CC disk/part.o
AR arch/arm/lib/lib.a
CC arch/arm/cpu/armv7/omap-common/boot-common.o
CC arch/arm/lib/eabi_compat.o
CC common/command.o
LD arch/arm/lib/built-in.o
AS arch/arm/cpu/armv7/omap-common/lowlevel_init.o
CC arch/arm/cpu/armv7/omap-common/mem-common.o
LD drivers/block/built-in.o
CC disk/part_dos.o
CC drivers/bootcount/bootcount.o
LD arch/arm/cpu/armv7/omap-common/built-in.o
AS arch/arm/cpu/armv7/start.o
LD arch/arm/cpu/armv7/built-in.o
CC drivers/bootcount/bootcount_davinci.o
CC common/exports.o
LD drivers/dma/built-in.o
CC common/hash.o
CC disk/part_efi.o
LD drivers/bootcount/built-in.o
LD drivers/crypto/built-in.o
CC drivers/gpio/omap_gpio.o
CC drivers/dfu/dfu.o
CC common/cli_hush.o
LD drivers/gpio/built-in.o
CC drivers/i2c/i2c_core.o
CC drivers/i2c/omap24xx_i2c.o
CC drivers/dfu/dfu_mmc.o
LD disk/built-in.o
LD drivers/hwmon/built-in.o
LD drivers/memory/built-in.o
LD drivers/misc/built-in.o
CC drivers/pcmcia/tqm8xx_pcmcia.o
CC drivers/dfu/dfu_ram.o
LD drivers/i2c/built-in.o
CC drivers/rtc/date.o
CC common/cli_simple.o
LD drivers/pcmcia/built-in.o
CC common/cli.o
LD drivers/dfu/built-in.o
CC common/cli_readline.o
LD drivers/rtc/built-in.o
LD drivers/sound/built-in.o
LD drivers/tpm/built-in.o
LD drivers/twserial/built-in.o
LD drivers/video/built-in.o
CC drivers/watchdog/omap_wdt.o
CC common/s_record.o
CC common/xyzModem.o
CC common/cmd_disk.o
CC common/autoboot.o
LD drivers/watchdog/built-in.o
LD drivers/built-in.o
CC common/board_f.o
CC common/board_r.o
CC drivers/input/input.o
CC common/cmd_boot.o
CC common/cmd_bootm.o
CC common/bootm.o
LD drivers/input/built-in.o
LD drivers/mtd/built-in.o
CC drivers/mmc/mmc.o
CC common/bootm_os.o
CC drivers/mmc/omap_hsmmc.o
CC common/cmd_help.o
CC common/cmd_version.o
CC common/env_attr.o
CC common/env_callback.o
CC common/env_flags.o
CC common/env_mmc.o
CC common/cmd_source.o
CC drivers/mmc/mmc_write.o
CC common/cmd_bdinfo.o
CC common/cmd_console.o
LD drivers/mtd/onenand/built-in.o
CC common/cmd_echo.o
LD drivers/mmc/built-in.o
CC drivers/mtd/spi/sf.o
CC drivers/net/cpsw.o
CC common/cmd_eeprom.o
CC drivers/mtd/spi/sf_params.o
CC drivers/net/phy/phy.o
CC drivers/mtd/spi/sf_probe.o
CC common/cmd_exit.o
CC drivers/net/phy/smsc.o
LD drivers/net/built-in.o
LD drivers/pci/built-in.o
CC common/cmd_ext4.o
CC drivers/mtd/spi/sf_ops.o
LD drivers/power/built-in.o
LD drivers/power/battery/built-in.o
LD drivers/power/fuel_gauge/built-in.o
LD drivers/net/phy/built-in.o
LD drivers/power/mfd/built-in.o
CC common/cmd_ext2.o
CC drivers/serial/serial.o
CC drivers/power/pmic/pmic_tps65217.o
CC common/cmd_fat.o
LD drivers/mtd/spi/built-in.o
CC drivers/spi/spi.o
CC drivers/power/pmic/pmic_tps65910.o
CC common/cmd_fdt.o
CC drivers/serial/ns16550.o
CC drivers/spi/omap3_spi.o
LD drivers/power/pmic/built-in.o
LD drivers/usb/eth/built-in.o
CC common/fdt_support.o
CC drivers/serial/serial_ns16550.o
LD drivers/serial/built-in.o
CC drivers/usb/gadget/epautoconf.o
CC common/cmd_fs.o
LD drivers/spi/built-in.o
CC common/cmd_gpio.o
CC drivers/usb/gadget/config.o
CC common/cmd_i2c.o
CC common/cmd_itest.o
CC drivers/usb/gadget/usbstring.o
LD drivers/usb/host/built-in.o
CC common/cmd_load.o
CC drivers/usb/gadget/g_dnl.o
CC common/cmd_mem.o
LD drivers/usb/musb/built-in.o
LD drivers/usb/phy/built-in.o
CC drivers/usb/musb-new/musb_gadget.o
LD drivers/usb/ulpi/built-in.o
CC fs/fs.o
CC common/miiphyutil.o
CC fs/ext4/ext4fs.o
CC drivers/usb/gadget/f_dfu.o
CC fs/ext4/ext4_common.o
CC drivers/usb/gadget/ether.o
CC drivers/usb/musb-new/musb_gadget_ep0.o
CC common/cmd_mii.o
CC drivers/usb/musb-new/musb_core.o
CC common/cmd_mdio.o
CC fs/ext4/dev.o
CC common/cmd_misc.o
CC drivers/usb/gadget/rndis.o
LD fs/ext4/built-in.o
CC fs/fat/fat_write.o
CC drivers/usb/musb-new/musb_uboot.o
CC common/cmd_mmc.o
CC drivers/usb/musb-new/musb_host.o
LD drivers/usb/gadget/built-in.o
CC common/cmd_net.o
CC lib/lzo/lzo1x_decompress.o
CC common/cmd_part.o
CC common/cmd_pcmcia.o
LD lib/lzo/built-in.o
CC lib/zlib/zlib.o
CC common/cmd_sf.o
CC drivers/usb/musb-new/musb_dsps.o
LD drivers/usb/musb-new/built-in.o
CC common/cmd_spi.o
CC common/cmd_test.o
CC fs/fat/file.o
CC lib/crc7.o
CC common/cmd_usb.o
CC common/usb.o
LD fs/fat/built-in.o
LD fs/built-in.o
LD lib/zlib/built-in.o
CC lib/crc8.o
CC lib/libfdt/fdt.o
CC lib/crc16.o
CC lib/fdtdec_common.o
CC lib/libfdt/fdt_ro.o
CC common/usb_hub.o
CC lib/gunzip.o
CC common/usb_storage.o
CC lib/initcall.o
CC common/cmd_ximg.o
CC lib/lmb.o
CC lib/libfdt/fdt_rw.o
CC common/cmd_spl.o
CC lib/ldiv.o
CC lib/md5.o
CC net/arp.o
CC common/flash.o
CC lib/libfdt/fdt_strerror.o
CC lib/libfdt/fdt_sw.o
CC common/splash.o
CC net/bootp.o
CC lib/net_utils.o
CC common/cmd_dfu.o
CC lib/libfdt/fdt_wip.o
CC lib/qsort.o
CC net/eth.o
CC common/cmd_gpt.o
CC lib/sha1.o
CC lib/libfdt/fdt_empty_tree.o
CC lib/libfdt/fdt_addresses.o
LD lib/libfdt/built-in.o
CC lib/sha256.o
CC net/net.o
CC common/cmd_nvedit.o
CC lib/strmhz.o
CC lib/hashtable.o
CC common/env_common.o
CC net/nfs.o
CC net/ping.o
CC common/console.o
CC lib/errno.o
CC lib/display_options.o
CC net/tftp.o
CC lib/ctype.o
CC lib/crc32.o
CC lib/div64.o
CC common/dlmalloc.o
LD net/built-in.o
CC lib/hang.o
LD test/built-in.o
CC lib/linux_string.o
LD test/dm/built-in.o
CC lib/string.o
CC common/image.o
CC common/image-fdt.o
CC lib/time.o
AS spl/arch/arm/lib/vectors.o
AS spl/arch/arm/lib/crt0.o
CC spl/arch/arm/lib/spl.o
CC common/image-fit.o
CC spl/arch/arm/lib/sections.o
CC lib/uuid.o
CC spl/arch/arm/lib/interrupts.o
CC common/memsize.o
CC spl/arch/arm/lib/reset.o
CC lib/vsprintf.o
CC common/stdio.o
CC spl/arch/arm/lib/cache.o
CC spl/arch/arm/lib/cache-cp15.o
AR spl/arch/arm/lib/lib.a
CC spl/arch/arm/lib/eabi_compat.o
LD spl/arch/arm/lib/built-in.o
CC spl/arch/arm/cpu/armv7/cache_v7.o
CC spl/arch/arm/cpu/armv7/am33xx/clock_am33xx.o
LD common/built-in.o
CC spl/arch/arm/cpu/armv7/am33xx/clock.o
CC spl/arch/arm/cpu/armv7/cpu.o
CC spl/arch/arm/cpu/armv7/syslib.o
LD lib/built-in.o
AS spl/arch/arm/cpu/armv7/lowlevel_init.o
AS spl/arch/arm/cpu/armv7/start.o
CC spl/arch/arm/cpu/armv7/am33xx/sys_info.o
CC spl/arch/arm/cpu/armv7/omap-common/reset.o
CC spl/arch/arm/cpu/armv7/am33xx/ddr.o
CC examples/standalone/stubs.o
CC spl/arch/arm/cpu/armv7/omap-common/timer.o
CC spl/arch/arm/cpu/armv7/am33xx/emif4.o
CC spl/arch/arm/cpu/armv7/omap-common/utils.o
CC examples/standalone/hello_world.o
CC spl/board/ti/am335x/mux.o
CC spl/arch/arm/cpu/armv7/am33xx/board.o
CC spl/arch/arm/cpu/armv7/omap-common/omap-cache.o
CC spl/arch/arm/cpu/armv7/am33xx/mux.o
LD examples/standalone/libstubs.o
CC spl/board/ti/am335x/board.o
LD examples/standalone/hello_world
CC spl/arch/arm/cpu/armv7/omap-common/boot-common.o
LD spl/arch/arm/cpu/armv7/am33xx/built-in.o
AS spl/arch/arm/cpu/armv7/omap-common/lowlevel_init.o
CC spl/arch/arm/cpu/armv7/omap-common/mem-common.o
OBJCOPY examples/standalone/hello_world.srec
LD spl/board/ti/am335x/built-in.o
CC spl/common/spl/spl.o
OBJCOPY examples/standalone/hello_world.bin
LD spl/arch/arm/cpu/armv7/omap-common/built-in.o
CC spl/common/spl/spl_ymodem.o
LD spl/arch/arm/cpu/armv7/built-in.o
CC spl/common/spl/spl_net.o
CC spl/common/spl/spl_mmc.o
CC spl/common/spl/spl_fat.o
CC spl/disk/part.o
CC spl/disk/part_dos.o
CC spl/common/xyzModem.o
LD spl/common/spl/built-in.o
CC spl/drivers/i2c/i2c_core.o
CC spl/common/miiphyutil.o
CC spl/drivers/i2c/omap24xx_i2c.o
CC spl/disk/part_efi.o
CC spl/common/env_attr.o
CC spl/common/env_flags.o
CC spl/common/env_callback.o
LD spl/drivers/i2c/built-in.o
CC spl/drivers/gpio/omap_gpio.o
CC spl/common/env_nowhere.o
CC spl/common/cmd_nvedit.o
LD spl/disk/built-in.o
CC spl/drivers/mmc/mmc.o
LD spl/drivers/gpio/built-in.o
CC spl/drivers/mmc/omap_hsmmc.o
CC spl/common/env_common.o
CC spl/drivers/serial/serial.o
CC spl/drivers/serial/ns16550.o
CC spl/common/console.o
CC spl/drivers/serial/serial_ns16550.o
LD spl/drivers/mmc/built-in.o
CC spl/fs/fat/fat_write.o
CC spl/lib/crc16.o
LD spl/drivers/serial/built-in.o
CC spl/lib/net_utils.o
CC spl/lib/hashtable.o
LD spl/drivers/power/built-in.o
CC spl/common/dlmalloc.o
CC spl/lib/errno.o
CC spl/lib/display_options.o
CC spl/common/image.o
CC spl/lib/crc32.o
CC spl/common/image-fdt.o
CC spl/lib/ctype.o
CC spl/lib/div64.o
CC spl/lib/hang.o
CC spl/common/memsize.o
CC spl/common/stdio.o
CC spl/lib/linux_string.o
CC spl/lib/string.o
LD u-boot
LD spl/common/built-in.o
CC spl/drivers/power/pmic/pmic_tps65217.o
LD spl/fs/fat/built-in.o
LD spl/fs/built-in.o
CC spl/drivers/power/pmic/pmic_tps65910.o
CC spl/lib/time.o
LD spl/drivers/power/pmic/built-in.o
CC spl/net/arp.o
CC spl/net/bootp.o
CC spl/lib/uuid.o
CC spl/net/eth.o
CC spl/drivers/watchdog/omap_wdt.o
CC spl/lib/vsprintf.o
LD spl/drivers/watchdog/built-in.o
CC spl/drivers/usb/musb-new/musb_gadget.o
LD spl/arch/arm/cpu/built-in.o
CC spl/drivers/usb/musb-new/musb_gadget_ep0.o
CC spl/net/net.o
LD spl/lib/built-in.o
LDS spl/u-boot-spl.lds
CC spl/drivers/usb/musb-new/musb_core.o
CC spl/drivers/usb/musb-new/musb_uboot.o
CC spl/net/tftp.o
CC spl/drivers/usb/musb-new/musb_host.o
CC spl/drivers/usb/musb-new/musb_dsps.o
LD spl/net/built-in.o
OBJCOPY u-boot.bin
OBJCOPY u-boot.srec
LD spl/drivers/usb/musb-new/built-in.o
LD spl/u-boot-spl
OBJCOPY spl/u-boot-spl.bin
MKIMAGE MLO
MKIMAGE u-boot.img
编译工作至此完成。得到的结果如下图
图中所示文件和文件夹都在O=am335x_beaglebone_black所指定的文件夹中。
u-boot——ELF格式的可执行文件,由于里面含有调试程序所选的信息,所以该格式的可执行文件体积最大。
u-boot.bin——可以直接写入Flash的二进制可执行文件,直接被运行。
u-boot.srec——u-boot映像的S-Record格式
u-boot.map——这个文件包含了u-boot可执行文件的映像符号表
MLO——这个文件也是一个引导加载程序,用于加载u-boot.img到SDRAM。
u-boot-spl.bin——这个文件实际上就是纯粹的SPL程序,和上图的MLO文件相比,MLO=头部信息+u-boot-spl.bin。
具体使用那个文件根据自己的需要选择。
从SD卡启动时,应该把MLO、u-boot.img文件放到boot分区。
从串口启动时,应该传送u-boot-spl.bin、u-boot.img文件。