本文主要是介绍基于 Beaglebone Black嵌入式linux系统u-boot编译 启动,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文地址:blog.csdn.net/zy812248258/article/details/39252733 作者写的很好,我保存一下。谢谢分享。
以官方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文件。
BeagleBone 的核心处理器是 AM3358,AM335x 有四个不同的启动阶段:
(1)ROM Code(处理器内部固化代码)
(2)SPL(Secondary Program Loader)
(3)U-BOOT
(4)Linux Kernel
为什么 AM335x 有多个启动阶段呢?直接从启动源加载 U-Boot 启动不是很方便?
一个全功能的U-Boot可能会超过400KB,因此不可能直接将它加载进内部RAM中直接运行,因此要分阶段。首先,第一步的 ROM Code (固化代码)不可能太复杂,ROM大小是一个限制,最重要的还是因为其所能获取的系统信息太少,所以处理器只能使用简单的方法去寻找能完成复杂功能的代码,而后将处理器初始化工作交给它来完成。其次,SPL (MLO)也不能很复杂,因为 ROM Code 只能将它加载到处理器内部 RAM 中运行,一般处理器的内部 RAM 都要小于128KB,其大小注定其不能完成很复杂的功能,所以 SPL 需要初始化 DDR 再加更复杂的代码加载到 DDR 中运行。到了在 DDR RAM 中执行的 Bootloader(U-Boot),其功能就比较完善了,此时就可以启动操作系统了。
第一阶段:ROM Code
ROM Code 是芯片上电复位之后第一块自动运行的代码。ROM Code 固化在芯片中不能被用户修改。 ROM Code 存储在片上地址 0x40000000-0x40040000 处。
ROM Code 主要功能如下:
(1)配置设备并初始化主要的外设
(2)建立堆栈
(3)配置开门狗定时器1(设置到三分钟)
(4)配置 PLL 和系统时钟
(5)为下一阶段启动做准备
(6)为下一阶段启动检查启动源(SPL)
(7)把下一启动阶段的 bootloader 代码(MLO)移动到内存中准备运行
ROM Code 针对不同的启动源有不同的启动过程,但最终还是为了把启动源的代码(MLO)搬运至内部 RAM 中运行,AM335X的内部RAM的大小只有128KB(从datasheet上看应该是64KB的Dedicated RAM和64KB的Shared RAM),而且由于各种各样的原因只剩下109KB可用。ROM Code 可以从以下设备中加载SPL:
(A)Memory devices non XIP (NAND/SDMMC)
从这类设备加载SPL时要有Image header(头信息),Image header的长度为8字节,包括加载地址(入口地址)和需要拷贝的SPL image的大小,二者各4字节。ROM Code会根据Image header中的信息将SPL image加载入内存中执行。此处SPL image指MLO文件。
(B)Peripheral devices (UART)
此种启动模式下,ROM Code会将SPL image加载入内部SRAM的0x402f0400地址处并执行,注意此时SPL image不包括头信息。此处SPL image指u-boot-spl.bin文件。
这里我们主要解析下针对 MMC/SD 卡设备,它的启动过程是怎么样的。
(1)初始化 MMC/SD 驱动
(2)检测是内存还是SD卡
(3)配置地址
(4)判断存储设备是 RAW 模式还是 FAT 模式
(5)如果是 RAW 模式就按照参考手册 Table 26-20 所定义的地址搬运代码至内部 RAM 中
(6)如果是 FAT 模式,就读取主引导记录并读取启动扇区查找 MLO 文件,并搬运到 RAM 中执行
第二阶段:SPL
第二阶段叫做 SPL,但有些时候也叫 MLO。SPL 是启动 U-Boot 前的一个阶段,并且必须从启动源(MMC、USB、SD、UART等)加载到内部 RAM 中。SPL 只有极少的功能,SPL 主要的职责就是初始化 DDR,时钟等最小系统,以读取 U-Boot 并加载到 DDR 中。
第三阶段:U-Boot
U-boot 主要的工作就是正确加载 Kernel。和 SPL 类似,U-boot 也是要加载下一个阶段的 image,但是 U-Boot 提供了更多外设的支持和更多的调试工具。所以,U-Boot 也要进行各个模块的配置,上述 SPL 配置的部分,除了 DDR 外,U-Boot 也会根据需求重新配置(这里重置主要是U-Boot 是一个开源工程,其要兼容某些特殊的芯片,从而需要做重载)。此外,U-Boot 也会对网口,SD卡等根据需求进行配置。 完成配置后,U-Boot 会从相应的存储器或者外设读取 Kernel,并传递参数给 Kernel,运行 Kernel。
U-Boot 允许用户通过串行终端在内核启动环境中做一些强大的基于命令的控制。用户可以控制很多启动参数和内核启动命令。另外 U-Boot 环境变量是可配置的,这些变量保存在存储媒介的 uEnv.txt 中。 更多内容可以查看 AM335x U-Boot 用户指南。
第四阶段:启动 Linux 内核
uImage 是与描述内核头信息交换过的内核镜像。这个头信息是一个 64kB的信息块,包含了目标架构、操作系统、内核尺寸、入口等信息。U-boot 启动 uImage的时候,头信息会在命令行输出。
在读出头文件之后,U-Boot 开始启动 Linux 内核。
其他
AM335x 能从不同的源启动:MMC/SD,NAND,NOR,UART,ETHERNET,USB,SPI和I2C。能从哪个源启动由启动阶段决定。比如,SPL/U-Boot 只能从能被 ROM Code 识别的源启动。 ROM 和 SPL bootloader在内部 RAM 中运行,U-boot 和内核在 DDR 中运行。 更多信息可以看《技术参考指南》的第二章。
BeagleBone 启动
BBB 板子上的 AM3335x 处理器上可以通过配置选择不同的接口启动,如数据手册 第二十六章所写。BBB 通过 S2 这个按键选择不同的启动顺序,默认情况下(S2 没有按下)启动过程如下:
(1)MMC1(板载 eMMC)
(2)MMC0(microSD)
(3)UART0
(4)USB0
如果按下 S2 按钮,启动过程如下:
(1)SPI0
(2)MMC0(microSD)
(3)UART0
(4)USB0
这篇关于基于 Beaglebone Black嵌入式linux系统u-boot编译 启动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!