注:本文以下所有操作基于系统Ubuntu 12.04

什么是U-Boot

U-Boot是(Universal Boot Loader)的缩写,uboot是一个开源的、跨平台的引导装载程序,提供了数百中可支持的嵌入式开发板和多个CPU,包括PowerPC,ARM,MIPS,XScale,ColdFire,Nios,MicroBlaze,和x86。

而cubieboard的u-boot则是全志(allwinner) SoCs 所提供的一个bootloader程序,它提供了将板载引导加载linux内核并启动您的操作系统。

cubieboard的u-boot源代码地址:https://github.com/linux-sunxi/u-boot-sunxi

编译U-Boot

安装工具软件及交叉编译环境

apt-get install build-essential u-boot-tools qemu-user-static debootstrap emdebian-archive-keyring git libusb-1.0-0-dev pkg-config

PC交差编译ARM系统

apt-get install gcc-arm-linux-gnueabihf

下载U-Boot源代码

git clone -b sunxi https://github.com/linux-sunxi/u-boot-sunxi.git

克隆代码库并切换到sunxi分支

查看支持的boardtype

grep sunxi boards.cfg | awk '{print $7}'

编译

配置cubieboard

make CROSS_COMPILE=arm-linux-gnueabihf- Cubieboard_config

开始编译

make CROSS_COMPILE=arm-linux-gnueabihf-

或者直接执行

make Cubieboard CROSS_COMPILE=arm-linux-gnueabihf-

终端将会输出如下信息

GEN include/autoconf.mk.dep
GEN include/autoconf.mk
...
OBJCOPY spl/u-boot-spl.bin
MKSUNXI spl/sunxi-spl.bin
OBJCOPY u-boot.bin
MKIMAGE u-boot.img
CAT u-boot-sunxi-with-spl.bin
OBJCOPY u-boot.srec

看到上面的信息则表示编译完成

写入TF卡
编译完成后将会在当前目录生成u-boot-sunxi-with-spl.bin,使用dd命令写入到TF卡中。

清楚旧的分区表

dd if=/dev/zero of=/dev/mmcb1k0 bs=1M count=5

写入u-boot-sunxi-with-spl.bin文件(spl/sunxi-spl.bin + u-boot.bin 这两个文件合一起的)

dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

此刻将TF插入Cubieboard加电启动,通过TTL串口会输出如下信息

U-Boot SPL 2014.04-10734-gfec9bf7 (Aug 07 2016 - 17:46:58)

Board: Cubieboard

DRAM: 1024 MiB

CPU: 1008000000Hz, AXI/AHB/APB: 3/2/2

spl: not an uImage at 1600

 

 

U-Boot 2014.04-10734-gfec9bf7 (Aug 07 2016 - 17:46:58) Allwinner Technology

 

CPU:   Allwinner A10 (SUN4I)

Board: Cubieboard

I2C:   ready

DRAM:  1 GiB

MMC:   SUNXI SD/MMC: 0

*** Warning - bad CRC, using default environment

 

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any key to stop autoboot:  0

** No partition table - mmc 0 **

** No partition table - mmc 0 **

** No partition table - mmc 0 **

** No partition table - mmc 0 **

** No partition table - mmc 0 **

** No partition table - mmc 0 **

** No partition table - mmc 0 **

** No partition table - mmc 0 **

** No partition table - mmc 0 **

sun4i#

至此说明U-Boot编译写卡成功。

下一步骤需要引导启动我们的操作系统

参考:

start size usage
0 8KB Unused, available for partition table etc.
8 24KB Initial SPL loader
32 512KB U-Boot
544 128KB environment
672 352KB reserved
1024 Free for partitions