1.bootloader引导
BootLoader 是在操作系统内核启动之前运行的一段小程序。通过这段程序,我们可以初始化硬件设备,从而将系统的软硬件环境带到一个合适的状态,以便为最终调用操作系统内核准备好正确的环境,最后从别处( Flash、以太网、 UART)载入内核映像到主存并跳到入口地址。
U-Boot 是 Das U-Boot 的简称,其含义是 Universal Boot Loader,是遵循 GPL 条款的开放源码项目。最早德国 DENX 软件工程中心的 Wolfgang Denk 基于 8xxROM 和 FADSROM的源码创建了 PPCBoot 工程项目,此后不断添加处理器的支持。
2.u-boot的下载地址
官网上下载u-boot,下载链接:http://ftp.denx.de/pub/u-boot/
2010.09下载地址:http://ftp.denx.de/pub/u-boot/u-boot-2010.09.tar.bz2
[klaus@localhost ~]$ mkdir u-boot
[klaus@localhost ~]$ ls
crosstool Desktop Documents Downloads fl2440 Music Pictures Public Templates u-boot Videos
[klaus@localhost ~]$ cd u-boot/
[klaus@localhost u-boot]$ wget http://ftp.denx.de/pub/u-boot/u-boot-2010.09.tar.bz2
--2018-03-16 13:58:36-- http://ftp.denx.de/pub/u-boot/u-boot-2010.09.tar.bz2
Resolving ftp.denx.de... 81.169.202.6
Connecting to ftp.denx.de|81.169.202.6|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8233711 (7.9M) [application/x-bzip2]
Saving to: “u-boot-2010.09.tar.bz2”
100%[===========================================================================================>] 8,233,711 33.9K/s in 3m 29s
2018-03-16 14:02:08 (38.4 KB/s) - “u-boot-2010.09.tar.bz2” saved [8233711/8233711]
[klaus@localhost u-boot]$ tar -xjf u-boot-2010.09.tar.bz2
[klaus@localhost u-boot]$ ls
u-boot-2010.09 u-boot-2010.09.tar.bz2
[klaus@localhost u-boot]$
3.打补丁
官网上下载的是没有修改的源码,要改成合适自己单片机使用的相关配置,由于u-boot比较复杂,也不太好修改,我这里直接用郭工给我们的补丁文件进行打补丁。
[klaus@localhost u-boot]$ patch -p0 < u-boot-2010.09-fl2440.patch
patching file u-boot-2010.09/arch/arm/cpu/arm920t/s3c24x0/speed.c
patching file u-boot-2010.09/arch/arm/cpu/arm920t/s3c24x0/timer.c
patching file u-boot-2010.09/arch/arm/cpu/arm920t/start.S
patching file u-boot-2010.09/arch/arm/cpu/arm920t/u-boot.lds
patching file u-boot-2010.09/arch/arm/include/asm/arch-s3c24x0/s3c24x0_cpu.h
patching file u-boot-2010.09/arch/arm/include/asm/arch-s3c24x0/s3c24x0.h
patching file u-boot-2010.09/board/lingyun/fl2440/config.mk
patching file u-boot-2010.09/board/lingyun/fl2440/fl2440.c
patching file u-boot-2010.09/board/lingyun/fl2440/flash.c
patching file u-boot-2010.09/board/lingyun/fl2440/lowlevel_init.S
patching file u-boot-2010.09/board/lingyun/fl2440/Makefile
patching file u-boot-2010.09/board/lingyun/fl2440/nand_read.c
patching file u-boot-2010.09/boards.cfg
patching file u-boot-2010.09/common/cmd_nand.c
patching file u-boot-2010.09/common/env_common.c
patching file u-boot-2010.09/common/serial.c
patching file u-boot-2010.09/drivers/mtd/nand/s3c2410_nand.c
patching file u-boot-2010.09/drivers/net/dm9000x.c
patching file u-boot-2010.09/include/configs/fl2440.h
patching file u-boot-2010.09/include/serial.h
patching file u-boot-2010.09/Makefile
[klaus@localhost u-boot]$ cd u-boot-2010.09
[klaus@localhost u-boot-2010.09]$ make fl2440_config
4.文件生成
1)u-boot-s3c2440.bin文件生成
u-boot.map -o u-boot
/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-objcopy -O srec u-boot u-boot.srec
/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
mv u-boot.bin u-boot-s3c2440.bin
[klaus@localhost u-boot-2010.09]$ ls
api boards.cfg COPYING doc fs MAINTAINERS mkconfig onenand_ipl rules.mk tools u-boot.map
arch common CREDITS drivers include MAKEALL nand_spl post snapshot.commit u-boot u-boot-s3c2440.bin
board config.mk disk examples lib Makefile net README System.map u-boot.lds u-boot.srec
[klaus@localhost u-boot-2010.09]$
2)将tools/mkimage拷贝成命令
[klaus@localhost u-boot-2010.09]$ ls tools/m
md5.o mingw_support.h mkimage.c mkimage.o
mingw_support.c mkimage mkimage.h mpc86x_clk.c
[klaus@localhost u-boot-2010.09]$ ls tools/mkimage
开发板上电操作显示文件--->mkimage
[klaus@localhost u-boot-2010.09]$ sudo cp tools/mkimage /usr/bin/
[sudo] password for klaus:
[klaus@localhost u-boot-2010.09]$
.bin文件生成后就可以参照上篇博客,将文件烧录进去,上篇博客的链接在这里。
关于补丁的制作与理解
1.生成打补丁文件
执行 patch -p0 < u-boot-2010.09-fl2440.patch命令后,生成的文件就是执行后的文件,我们可以使用diff命令查看两者之间的区别
[klaus@localhost u-boot]$ ls
u-boot-2010.09 u-boot-2010.09-fl2440.patch u-boot-2010.09.tar.bz2
[klaus@localhost u-boot]$ mv u-boot-2010.09 u-boot-2010.09-fl2440
[klaus@localhost u-boot]$ ls
u-boot-2010.09-fl2440 u-boot-2010.09-fl2440.patch u-boot-2010.09.tar.bz2
[klaus@localhost u-boot]$ tar -jxf u-boot-2010.09
u-boot-2010.09-fl2440/ u-boot-2010.09-fl2440.patch u-boot-2010.09.tar.bz2
[klaus@localhost u-boot]$ tar -jxf u-boot-2010.09.tar.bz2
[klaus@localhost u-boot]$ ls
u-boot-2010.09 u-boot-2010.09-fl2440 u-boot-2010.09-fl2440.patch u-boot-2010.09.tar.bz2
[klaus@localhost u-boot]$ diff -Nuar u-boot-2010.09 u-boot-2010.09-fl2440
2.反向打补丁
如果有补丁文件和打补丁过后的文件,我们可以恢复原码,当然了解一下就行。
[klaus@localhost u-boot]$ ls
u-boot-2010.09-fl2440 u-boot-2010.09-fl2440.patch
[klaus@localhost u-boot]$ cd u-boot-2010.09-fl2440
[klaus@localhost u-boot]$ patch -R -p1 < ../u-boot-2010.09-fl2440.patch