[1],下载地址及简介
uboot下载地址:ftp://ftp.denx.de/pub/u-boot/ 版本号:2008年8月前按版本号命名,之后按日期命名。uboot支持引导多种操作系统,支持多种架构的cpu。
下载解压后目录:
文件属性 | 名称 | 功能 | 备注 |
d | api | 接口函数 | |
d | board | 板级支持,外围电路相关 | |
- | CHANGELOG | 变更记录 | |
- | CHANGELOG-before-U-Boot-1.1.5 | 变更记录 | |
d | common | 通用函数,进一步封装下一层驱动程序 | |
- | config.mk | 被Makefile调用,include $(TOPDIR)/config.mk | |
- | COPYING | 版权信息 | |
d | cpu | 平台相关,处理器架构 | |
- | CREDITS | 维护人联系方式 | |
d | disk | 磁盘分区 | |
d | doc | 文档,有很多说明 | |
d | drivers | 驱动程序,每种类型的设备驱动占用一个子目录 | |
d | examples | 示例程序 | |
d | fs | 文件系统,支持嵌入式开发板常见的文件系统 | |
d | include | 头文件和开发板配置文件,开发板配置文件都放在include/configs目录下 | |
d | lib_【arch】 | 平台相关的通用库文件如lib_arm | |
d | lib_generic | 通用库函数如printf等 | |
- | MAINTAINERS | 开发板和CPU的部分对应代码说明 | |
- | MAKEALL | 编译脚本 | |
- | mkconfig | 产生头文件等的编译脚本 | |
d | nand_spl | NAND存储器 | |
d | net | 网络,小型的协议栈 | |
d | onenand_ipl | onenand | |
d | post | 加电自检程序 | |
- | README | uboot介绍 | |
- | rules.mk | 被Makefile调用 | |
d | tools | 辅助程序,用于编译和检查uboot目标文件,如mkimage |
[2] uboot大概执行流程,包括两个阶段:
阶段1:
·硬件设备初始化;(屏蔽所有的中断、关闭处理器内部指令/数据Cache等)
·为加载第二阶段准备RAM空间;
·拷贝自身到RAM空间;
·设置好堆栈并将bss段清零;
·跳转到第2阶段的 C 入口点。
阶段2:
·初始化本阶段要使用到的硬件设备;
·检测系统内存映射(memory map);
·将内核映像和根文件系统映像从flash上读到 RAM 空间中;
·为内核设置启动参数;
·调用内核。
[3] 代码分析
<1>u-boot.lds文件指示程序的开始
1 oee@copener:/opt/bsp/uboot$ find -name "*.lds" 2 ./board/copener/u-boot.lds
1 OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 2 OUTPUT_ARCH(arm) 3 ENTRY(_start) 4 SECTIONS 5 { 6 . = 0x8fb00000; 7 _TTB_BASE = .; 8 9 . = 0x8fc00000; 10 . = ALIGN(4); 11 .text : 12 { 13 cpu/copener/start.o (.text) 14 *(.text) 15 } 16 .rodata : { *(.rodata) } 17 . = ALIGN(4); 18 .data : { *(.data) } 19 . = ALIGN(4); 20 .got : { *(.got) } 21 22 . = .; 23 __u_boot_cmd_start = .; 24 .u_boot_cmd : { *(.u_boot_cmd) } 25 __u_boot_cmd_end = .; 26 27 . = ALIGN(4); 28 __bss_start = .; 29 .bss : { *(.bss) } 30 _end = .; 31 }
cpu/copener/start.o (.text)指示了开始文件为cpu/copener/start.S,ENTRY(_start)指示了入口为_start
<2>cpu/copener/start.S
头文件:
include<config.h> //通过Makefile调用的mkconfig在include目录下生成了config.h,包含了目标板的头文件。即config.h最终是与目标板头文件挂勾。 ////////////////////////////////////////////////////////mkconfig//////////////////////////////////////////////////////////// # # Create board specific header file # if [ "$APPEND" = "yes" ] # Append to existing config file then echo >> config.h else > config.h # Create new config file fi echo "/* Automatically generated - do not edit */" >>config.h echo "#include <configs/$1.h>" >>config.h echo "#include <asm/config.h>" >>config.h
入口地址:
1 _start: 2 b start_code
start_code标号下执行的操作:
1 set the cpu to SVC32 mode 2 relocate U-Boot to RAM 3 Set up the stack 4 clear_bss 5 _InitCache 6 //if MMU/MPU enabled - disable 7 //Invalidate instruction cache 8 //Invalidate data cache 9 //Invalidate entire Unified main TLB 10 //init mmu and generate page table 11 // Enable caches 12 // Enable Program Flow Prediction 13 // Enable D-side prefetch 14 // Enable MMU
最后跳入c代码里面的start_armboot函数中
1 ldr pc, _start_armboot 2 3 _start_armboot: 4 .word start_armboot
<3>lib_arm/board.c
1 oee@copener:/opt/bsp/uboot$ findoee start_armboot 2 lib_arm/board.c:382:void start_armboot (void) 3 4 //注:findoee是我在在~/.bashrc文件中添加的命令: 5 alias findoee='grep -rnws'
board.c执行了以下操作
1 //gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t)); 2 //setup_realview_board_info();
3 //init_sequence 4 //display_flash_config (flash_init ()); 5 //env_relocate (); 6 //CONFIG_LCD 7 //CONFIG_FASTBOOT_RECOVERY 8 //CONFIG_UBOOT_CHARGER 9 //CONFIG_NS115_HDMI_STICK 10 //nand_init(); 11 //onenand_init(); 12 //CONFIG_HAS_DATAFLASH 13 //api_init (); 14 //arch_misc_init (); 15 //misc_init_r (); 16 //enable_interrupts (); 17 //board_late_init (); 18 //mmc_initialize (gd->bd); 19 //eth_initialize(gd->bd); 20 //usb_init(); 21 //console_init_r (); 22 //main_loop ();
init_sequence:
首先看函数指针数组,每个元素存放一个函数指针。
1 init_fnc_t *init_sequence[] = { 2 arch_cpu_init, /* basic arch cpu dependent setup */ 3 cpu_init, /**/ 4 board_init, /* basic board dependent setup */ 5 interrupt_init, /* set up exceptions */ 6 timer_init, /* initialize timer */ 7 env_init, /* initialize environment */ 8 init_baudrate, /* initialze baudrate settings */ 9 serial_init, /* serial communications setup */ 10 console_init_f, /* stage 1 init of console */ 11 display_banner, /* say that we are here */ 12 print_cpuinfo, /* display cpu info (and speed) */ 13 checkboard, /* display board info */ 14 init_func_i2c, 15 && !defined (CONFIG_ARCH_NS2816_YANGCHENG)) 16 dram_init, /* configure available RAM banks */ 17 display_dram_config, 18 arm_pci_init, 19 NULL, 20 };
通过指针循环调用初始化函数
1 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { 2 if ((*init_fnc_ptr)() != 0) { 3 hang (); 4 } 5 }
在board_init函数里面有个设置机器码的操作,gd->bd->bi_arch_number = MACH_TYPE_COPENER;这个会跟linux的启动有关。机器码头文件include/asm-arm/mach-types.h
[4]uboot与内核单向交互:uboot将参数放在某个约定地址,然后启动内核,内核启动后再从约定的地址获取参数
标记列表以ATAG_CORE开始,ATAG_NONE结束,标记的是结构体tag,由tag_header结构体和一个联合体组成。
#define ATAG_CORE 0x54410001
#define ATAG_NONE 0x00000000
tag结构体(include/asm/setup.h)
1 struct tag { 2 struct tag_header hdr; 3 union { 4 struct tag_core core; 5 struct tag_mem32 mem; 6 struct tag_videotext videotext; 7 struct tag_ramdisk ramdisk; 8 struct tag_initrd initrd; 9 struct tag_serialnr serialnr; 10 struct tag_revision revision; 11 struct tag_videolfb videolfb; 12 struct tag_cmdline cmdline; 13 14 /* 15 * Acorn specific 16 */ 17 struct tag_acorn acorn; 18 19 /* 20 * DC21285 specific 21 */ 22 struct tag_memclk memclk; 23 } u; 24 };
setup_start_tag函数设置ATAG_CORE标记(lib_arm/bootm.c)
1 static void setup_start_tag (bd_t *bd) 2 { 3 params = (struct tag *) bd->bi_boot_params; 4 params->hdr.tag = ATAG_CORE; 5 params->hdr.size = tag_size (tag_core); 6 7 params->u.core.flags = 0; 8 params->u.core.pagesize = 0; 9 params->u.core.rootdev = 0; 10 11 params = tag_next (params); 12 }
bootm.c文件还设置了下面几个标记
1 static void setup_start_tag (bd_t *bd); 2 static void setup_memory_tags (bd_t *bd); 3 static void setup_commandline_tag (bd_t *bd, char *commandline); 4 static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end); 5 static void setup_end_tag (bd_t *bd); 6 static void setup_videolfb_tag (gd_t *gd);
[4]配置,编译,连接
<1>编译一般都是执行三个命令:
1 #make distclean //清除上一次编译产生的文件 2 #make <board_name>_config //配置编译环境 3 #make //开始编译 4 //可能有时候还要在配置和编译前面加上条件
<2>生成的文件:
1 u-boot //ELF格式的可执行文件 2 u-boot.bin //二进制可执行文件,直接烧录进flash等设备 3 u-boot.srec //Motorola S-Record格式的可执行文件 4 5 //另外编译u-boot成功后还会在tools子目录下生成一些工具,如mkimage等,将它们复制到/usr/local/bin目录下,以后就可以直接使用它们来编译内核来生成u-boot格式的内核镜像文件uImage
<3>配置,从Makefiile开始,#make <board_name>_config就是Makefile里面的其中一个目标,以#make smdk2410_config配置命令为例
1 smdk2410_config : unconfig 2 @$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 samsung s3c24x0
简化后,实际执行如下(主要是调用了顶层的mkconfig来执行操作):
1 ./mkconfig smdk 2410 arm arm920t smdk2410 NULL s3c24x0
注:
1 @$(MKCONFIG) @是不输出此行操作的打印信息,$()是用于引用变量MKCONFIG,MKCONFIG定义在MKCONFIG := $(SRCTREE)/mkconfig 即顶层的mkconfig 3 $(@:_config=) $()是引用变量,即从命令行输入的参数smdk2410_config,@取消显示,@:取消指定的显示,后面_config=是说取消从命令行输入的参数后面中字符串_config=
<4>顶层mkconfig,主要是确定开发板名称,创建到平台/开发板相关的头文件链接,删除上一次配置创建新的配置文件config.mk,config.h,asm...
1 #!/bin/sh -e 2 3 # Script to create header files and links to configure 4 # U-Boot for a specific board. 5 # 6 # Parameters: Target Architecture CPU Board [VENDOR] [SOC] 7 # 8 # (C) 2002-2006 DENX Software Engineering, Wolfgang Denk <wd@denx.de> 9 # 10 11 APPEND=no # Default: Create new config file 12 BOARD_NAME="" # Name to print in make output 13 14 while [ $# -gt 0 ] ; do 15 case "$1" in 16 --) shift ; break ;; 17 -a) shift ; APPEND=yes ;; 18 -n) shift ; BOARD_NAME="${1%%_config}" ; shift ;; 19 *) break ;; 20 esac 21 done 22 23 [ "${BOARD_NAME}" ] || BOARD_NAME="$1" 24 25 [ $# -lt 4 ] && exit 1 26 [ $# -gt 6 ] && exit 1 27 28 echo "Configuring for ${BOARD_NAME} board..." 29 30 # 31 # Create link to architecture specific headers 32 # 33 if [ "$SRCTREE" != "$OBJTREE" ] ; then 34 mkdir -p ${OBJTREE}/include 35 mkdir -p ${OBJTREE}/include2 36 cd ${OBJTREE}/include2 37 rm -f asm 38 ln -s ${SRCTREE}/include/asm-$2 asm 39 LNPREFIX="../../include2/asm/" 40 cd ../include 41 rm -rf asm-$2 42 rm -f asm 43 mkdir asm-$2 44 ln -s asm-$2 asm 45 else 46 cd ./include 47 rm -f asm 48 ln -s asm-$2 asm 49 fi 50 51 rm -f asm-$2/arch 52 53 if [ -z "$6" -o "$6" = "NULL" ] ; then 54 ln -s ${LNPREFIX}arch-$3 asm-$2/arch 55 else 56 ln -s ${LNPREFIX}arch-$6 asm-$2/arch 57 fi 58 59 if [ "$2" = "arm" ] ; then 60 rm -f asm-$2/proc 61 ln -s ${LNPREFIX}proc-armv asm-$2/proc 62 fi 63 64 # 65 # Create include file for Make 66 # 67 echo "ARCH = $2" > config.mk 68 echo "CPU = $3" >> config.mk 69 echo "BOARD = $4" >> config.mk 70 71 [ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk 72 73 [ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk 74 75 # 76 # Create board specific header file 77 # 78 if [ "$APPEND" = "yes" ] # Append to existing config file 79 then 80 echo >> config.h 81 else 82 > config.h # Create new config file 83 fi 84 echo "/* Automatically generated - do not edit */" >>config.h 85 echo "#include <configs/$1.h>" >>config.h 86 echo "#include <asm/config.h>" >>config.h 87 88 exit 0
config.h主要添加了两个头文件:include/configs/<board_name>.h和include/asm/config.h
<5>include/configs/<board_name>.h,主要就uboot的配置文件,分两类宏:选项(option),前缀为CONFIG_,用于选择cpu,soc,开发板类型,设置系统时钟,选择驱动。另外一类是参数(setting),前缀为CFG_,用于设置malloc缓冲池大小,uboot的提示符,uboot下载文件时的默认加载地址,flash的起始地址。
<6>顶层Makefile
1 ###############################设置版本信息(都是变量赋值)############################################### 2 # = 是最基本的赋值语句 3 # := 是覆盖之前的值 4 # ?= 是如果没有被赋值过就赋予等号后面的值 5 # += 是添加等号后面的值 6 VERSION = 2009 7 PATCHLEVEL = 08 8 SUBLEVEL = 9 EXTRAVERSION = 10 ifneq "$(SUBLEVEL)" "" #$()表示变量引用,ifneq是判断语句,这里意思是判断变量SUBLEVEL是否为空 11 U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) 12 else 13 U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL)$(EXTRAVERSION) 14 endif 15 TIMESTAMP_FILE = $(obj)include/timestamp_autogenerated.h 16 VERSION_FILE = $(obj)include/version_autogenerated.h 17 18 ################################赋值主机硬件架构和系统版本之类的信息#################################### 19 # u-boot-armdev ARM Supplied Development Boards branch details 20 ARMLTD_BRANCH = 090727_armdev 21 ARMLTD_RELEASE = AEL-3.1_rc1 22 ARMLTDVC_FILE = $(obj)include/armltdvc_autogenerated.h 23 24 #shell表示调用shell命令,sed -e表示后面是一串命令脚本,s/str1/srt2 形式表示查找str1,并用str2替换 25 HOSTARCH := $(shell uname -m | \ 26 sed -e s/i.86/i386/ \ 27 -e s/sun4u/sparc64/ \ 28 -e s/arm.*/arm/ \ 29 -e s/sa110/arm/ \ 30 -e s/powerpc/ppc/ \ 31 -e s/ppc64/ppc/ \ 32 -e s/macppc/ppc/) 33 34 HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \ 35 sed -e 's/\(cygwin\).*/cygwin/') 36 #############################设置shell环境为bash,若有的话,否则设置为sh################################# 37 # Set shell to bash if possible, otherwise fall back to sh 38 SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ 39 else if [ -x /bin/bash ]; then echo /bin/bash; \ 40 else echo sh; fi; fi) 41 42 export HOSTARCH HOSTOS SHELL #export是设置环境变量语句,设置了上面所赋值的三个变量 43 44 # Deal with colliding definitions from tcsh etc. 45 VENDOR= 46 47 ######################################################################### 48 # Allow for silent builds 49 ifeq (,$(findstring s,$(MAKEFLAGS))) #$(findstring <str1>,<str2>)是一个查找字符串的函数 50 XECHO = echo 51 else 52 XECHO = : 53 endif 54 55 ##########################################设置编译目录################################################## 56 # 57 # U-boot build supports producing a object files to the separate external 58 # directory. Two use cases are supported: 59 # 60 # 1) Add O= to the make command line 61 # 'make O=/tmp/build all' 62 # 63 # 2) Set environement variable BUILD_DIR to point to the desired location 64 # 'export BUILD_DIR=/tmp/build' 65 # 'make' 66 # 67 # The second approach can also be used with a MAKEALL script 68 # 'export BUILD_DIR=/tmp/build' 69 # './MAKEALL' 70 # 71 # Command line 'O=' setting overrides BUILD_DIR environent variable. 72 # 73 # When none of the above methods is used the local build is performed and 74 # the object files are placed in the source directory. 75 # 76 77 ifdef O 78 ifeq ("$(origin O)", "command line") #origin是指示变量来源的函数,命令行参数指定编译目录时用 79 BUILD_DIR := $(O) 80 endif 81 endif 82 83 ifneq ($(BUILD_DIR),) 84 saved-output := $(BUILD_DIR) 85 86 # Attempt to create a output directory. 87 $(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}) 88 89 # Verify if it was successful. 90 BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd) 91 $(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist)) 92 endif # ifneq ($(BUILD_DIR),) 93 94 OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR)) 95 SRCTREE := $(CURDIR) 96 TOPDIR := $(SRCTREE) 97 LNDIR := $(OBJTREE) 98 export TOPDIR SRCTREE OBJTREE 99 100 MKCONFIG := $(SRCTREE)/mkconfig 101 export MKCONFIG 102 103 ifneq ($(OBJTREE),$(SRCTREE)) 104 REMOTE_BUILD := 1 105 export REMOTE_BUILD 106 endif 107 108 # $(obj) and (src) are defined in config.mk but here in main Makefile 109 # we also need them before config.mk is included which is the case for 110 # some targets like unconfig, clean, clobber, distclean, etc. 111 ifneq ($(OBJTREE),$(SRCTREE)) 112 obj := $(OBJTREE)/ 113 src := $(SRCTREE)/ 114 else 115 obj := 116 src := 117 endif 118 export obj src 119 120 # Make sure CDPATH settings don't interfere 121 unexport CDPATH 122 123 ######################################################################### 124 125 # The "tools" are needed early, so put this first 126 # Don't include stuff already done in $(LIBS) 127 SUBDIRS = tools \ 128 examples/standalone \ 129 examples/api 130 131 .PHONY : $(SUBDIRS) 132 133 ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk)) #wildcard是使config.mk里面的通配符有效 134 135 # Include autoconf.mk before config.mk so that the config options are available 136 # to all top level build files. We need the dummy all: target to prevent the 137 # dependency target in autoconf.mk.dep from being the default. 138 all: 139 sinclude $(obj)include/autoconf.mk.dep #sinclude跟-include用法差不多,兼容更多的make程序 140 sinclude $(obj)include/autoconf.mk 141 142 # load ARCH, BOARD, and CPU configuration 143 include $(obj)include/config.mk 144 export ARCH CPU BOARD VENDOR SOC 145 146 # set default to nothing for native builds 147 #ifeq ($(HOSTARCH),$(ARCH)) 148 #CROSS_COMPILE = arm-none-eabi- 149 CROSS_COMPILE = arm-none-linux-gnueabi- 150 #endif 151 152 # load other configuration 153 include $(TOPDIR)/config.mk 154 155 ###########################################要生成的目标文件############################################# 156 # U-Boot objects....order is important (i.e. start must be first) 157 158 OBJS = cpu/$(CPU)/start.o 159 ifeq ($(CPU),i386) 160 OBJS += cpu/$(CPU)/start16.o 161 OBJS += cpu/$(CPU)/resetvec.o 162 endif 163 ifeq ($(CPU),ppc4xx) 164 OBJS += cpu/$(CPU)/resetvec.o 165 endif 166 ifeq ($(CPU),mpc85xx) 167 OBJS += cpu/$(CPU)/resetvec.o 168 endif 169 170 OBJS := $(addprefix $(obj),$(OBJS)) 171 172 LIBS = lib_generic/libgeneric.a 173 LIBS += lib_generic/lzma/liblzma.a 174 LIBS += lib_generic/lzo/liblzo.a 175 LIBS += $(shell if [ -f board/$(VENDOR)/common/Makefile ]; then echo \ 176 "board/$(VENDOR)/common/lib$(VENDOR).a"; fi) 177 LIBS += cpu/$(CPU)/lib$(CPU).a 178 ifdef SOC 179 LIBS += cpu/$(CPU)/$(SOC)/lib$(SOC).a 180 endif 181 ifeq ($(CPU),ixp) 182 LIBS += cpu/ixp/npe/libnpe.a 183 endif 184 LIBS += lib_$(ARCH)/lib$(ARCH).a 185 LIBS += fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a \ 186 fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a fs/yaffs2/libyaffs2.a \ 187 fs/ubifs/libubifs.a fs/ext4/libext4fs.o 188 LIBS += net/libnet.a 189 LIBS += disk/libdisk.a 190 LIBS += drivers/bios_emulator/libatibiosemu.a 191 LIBS += drivers/block/libblock.a 192 LIBS += drivers/dma/libdma.a 193 LIBS += drivers/fpga/libfpga.a 194 LIBS += drivers/gpio/libgpio.a 195 LIBS += drivers/hwmon/libhwmon.a 196 LIBS += drivers/i2c/libi2c.a 197 LIBS += drivers/input/libinput.a 198 LIBS += drivers/misc/libmisc.a 199 LIBS += drivers/mmc/libmmc.a 200 LIBS += drivers/mtd/libmtd.a 201 LIBS += drivers/mtd/nand/libnand.a 202 LIBS += drivers/mtd/onenand/libonenand.a 203 LIBS += drivers/mtd/ubi/libubi.a 204 LIBS += drivers/mtd/spi/libspi_flash.a 205 LIBS += drivers/usb/eth/libusb_eth.o 206 LIBS += drivers/net/libnet.a 207 LIBS += drivers/net/phy/libphy.a 208 LIBS += drivers/net/sk98lin/libsk98lin.a 209 LIBS += drivers/pci/libpci.a 210 LIBS += drivers/pcmcia/libpcmcia.a 211 LIBS += drivers/power/libpower.a 212 LIBS += drivers/spi/libspi.a 213 LIBS += drivers/hdmi/libhdmi.a 214 ifeq ($(CPU),mpc83xx) 215 LIBS += drivers/qe/qe.a 216 endif 217 ifeq ($(CPU),mpc85xx) 218 LIBS += drivers/qe/qe.a 219 LIBS += cpu/mpc8xxx/ddr/libddr.a 220 LIBS += cpu/mpc8xxx/lib8xxx.a 221 TAG_SUBDIRS += cpu/mpc8xxx 222 endif 223 ifeq ($(CPU),mpc86xx) 224 LIBS += cpu/mpc8xxx/ddr/libddr.a 225 LIBS += cpu/mpc8xxx/lib8xxx.a 226 TAG_SUBDIRS += cpu/mpc8xxx 227 endif 228 LIBS += drivers/rtc/librtc.a 229 LIBS += drivers/serial/libserial.a 230 LIBS += drivers/twserial/libtws.a 231 LIBS += drivers/usb/gadget/libusb_gadget.a 232 LIBS += drivers/usb/host/libusb_host.a 233 LIBS += drivers/usb/musb/libusb_musb.a 234 LIBS += drivers/video/libvideo.a 235 LIBS += drivers/watchdog/libwatchdog.a 236 LIBS += common/libcommon.a 237 LIBS += libfdt/libfdt.a 238 LIBS += api/libapi.a 239 LIBS += post/libpost.a 240 241 LIBS := $(addprefix $(obj),$(LIBS)) 242 .PHONY : $(LIBS) $(TIMESTAMP_FILE) $(VERSION_FILE) 243 244 LIBBOARD = board/$(BOARDDIR)/lib$(BOARD).a 245 LIBBOARD := $(addprefix $(obj),$(LIBBOARD)) 246 247 # Add GCC lib 248 ifdef USE_PRIVATE_LIBGCC 249 ifeq ("$(USE_PRIVATE_LIBGCC)", "yes") 250 PLATFORM_LIBGCC = -L $(OBJTREE)/lib_$(ARCH) -lgcc 251 else 252 PLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC) -lgcc 253 endif 254 else 255 PLATFORM_LIBGCC = -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc 256 endif 257 PLATFORM_LIBS += $(PLATFORM_LIBGCC) 258 export PLATFORM_LIBS 259 260 # Special flags for CPP when processing the linker script. 261 # Pass the version down so we can handle backwards compatibility 262 # on the fly. 263 LDPPFLAGS += \ 264 -include $(TOPDIR)/include/u-boot/u-boot.lds.h \ 265 $(shell $(LD) --version | \ 266 sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p') 267 268 ifeq ($(CONFIG_NAND_U_BOOT),y) 269 NAND_SPL = nand_spl 270 U_BOOT_NAND = $(obj)u-boot-nand.bin 271 endif 272 273 ifeq ($(CONFIG_ONENAND_U_BOOT),y) 274 ONENAND_IPL = onenand_ipl 275 U_BOOT_ONENAND = $(obj)u-boot-onenand.bin 276 endif 277 278 __OBJS := $(subst $(obj),,$(OBJS)) 279 __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD)) 280 281 ######################################################################################################## 282 ################################大鱼出现了,就是我们make all要执行的地方################################ 283 284 # Always append ALL so that arch config.mk's can add custom ones 285 ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND) 286 287 all: $(ALL) 288 289 $(obj)u-boot.hex: $(obj)u-boot 290 $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ 291 292 $(obj)u-boot.srec: $(obj)u-boot 293 $(OBJCOPY) -O srec $< $@ 294 295 $(obj)u-boot.bin: $(obj)u-boot 296 $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ 297 298 $(obj)u-boot.ldr: $(obj)u-boot 299 $(obj)tools/envcrc --binary > $(obj)env-ldr.o 300 $(LDR) -T $(CONFIG_BFIN_CPU) -c $@ $< $(LDR_FLAGS) 301 302 $(obj)u-boot.ldr.hex: $(obj)u-boot.ldr 303 $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary 304 305 $(obj)u-boot.ldr.srec: $(obj)u-boot.ldr 306 $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ -I binary 307 308 $(obj)u-boot.img: $(obj)u-boot.bin 309 ./tools/mkimage -A $(ARCH) -T firmware -C none \ 310 -a $(TEXT_BASE) -e 0 \ 311 -n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \ 312 sed -e 's/"[ ]*$$/ for $(BOARD) board"/') \ 313 -d $< $@ 314 315 $(obj)u-boot.sha1: $(obj)u-boot.bin 316 $(obj)tools/ubsha1 $(obj)u-boot.bin 317 318 $(obj)u-boot.dis: $(obj)u-boot 319 $(OBJDUMP) -d $< > $@ 320 321 GEN_UBOOT = \ 322 UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \ 323 sed -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\ 324 cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \ 325 --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \ 326 -Map u-boot.map -o u-boot 327 $(obj)u-boot: depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds 328 $(GEN_UBOOT) 329 ifeq ($(CONFIG_KALLSYMS),y) 330 smap=`$(call SYSTEM_MAP,u-boot) | \ 331 awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \ 332 $(CC) $(CFLAGS) -DSYSTEM_MAP="\"$${smap}\"" \ 333 -c common/system_map.c -o $(obj)common/system_map.o 334 $(GEN_UBOOT) $(obj)common/system_map.o 335 endif 336 337 $(OBJS): depend 338 $(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@)) 339 340 $(LIBS): depend $(SUBDIRS) 341 $(MAKE) -C $(dir $(subst $(obj),,$@)) 342 343 $(LIBBOARD): depend $(LIBS) 344 $(MAKE) -C $(dir $(subst $(obj),,$@)) 345 346 $(SUBDIRS): depend 347 $(MAKE) -C $@ all 348 349 $(LDSCRIPT): depend 350 $(MAKE) -C $(dir $@) $(notdir $@) 351 352 $(obj)u-boot.lds: $(LDSCRIPT) 353 $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@ 354 355 $(NAND_SPL): $(TIMESTAMP_FILE) $(VERSION_FILE) $(obj)include/autoconf.mk 356 $(MAKE) -C nand_spl/board/$(BOARDDIR) all 357 358 $(U_BOOT_NAND): $(NAND_SPL) $(obj)u-boot.bin 359 cat $(obj)nand_spl/u-boot-spl-16k.bin $(obj)u-boot.bin > $(obj)u-boot-nand.bin 360 361 $(ONENAND_IPL): $(TIMESTAMP_FILE) $(VERSION_FILE) $(obj)include/autoconf.mk 362 $(MAKE) -C onenand_ipl/board/$(BOARDDIR) all 363 364 $(U_BOOT_ONENAND): $(ONENAND_IPL) $(obj)u-boot.bin 365 cat $(obj)onenand_ipl/onenand-ipl-2k.bin $(obj)u-boot.bin > $(obj)u-boot-onenand.bin 366 cat $(obj)onenand_ipl/onenand-ipl-4k.bin $(obj)u-boot.bin > $(obj)u-boot-flexonenand.bin 367 368 $(VERSION_FILE): 369 @( printf '#define U_BOOT_VERSION "U-Boot %s%s"\n' "$(U_BOOT_VERSION)" \ 370 '$(shell $(TOPDIR)/tools/setlocalversion $(TOPDIR))' ) > $@.tmp 371 @cmp -s $@ $@.tmp && rm -f $@.tmp || mv -f $@.tmp $@ 372 @echo -n "#define ARMLTD_BRANCH \"" > $(ARMLTDVC_FILE) 373 @echo "$(ARMLTD_BRANCH)\"" >> $(ARMLTDVC_FILE) 374 @echo -n "#define ARMLTD_RELEASE \"" >> $(ARMLTDVC_FILE) 375 @echo "$(ARMLTD_RELEASE)\"" >> $(ARMLTDVC_FILE) 376 @if [ -d .git ] ; then \ 377 echo -n "#define ARMLTD_COMMIT_REMOTE \"" >> $(ARMLTDVC_FILE) ; \ 378 text=`cat .git/refs/remotes/origin/$(ARMLTD_BRANCH)` ; \ 379 echo -n $$text >> $(ARMLTDVC_FILE) ; \ 380 echo "\"" >> $(ARMLTDVC_FILE) ; \ 381 echo -n "#define ARMLTD_COMMIT_LOCAL \"" >> $(ARMLTDVC_FILE) ; \ 382 text=`cat .git/refs/heads/$(ARMLTD_BRANCH)` ; \ 383 echo -n $$text >> $(ARMLTDVC_FILE) ; \ 384 echo "\"" >> $(ARMLTDVC_FILE) ; \ 385 text=`git status`; \ 386 echo "$$text" ; \ 387 echo -n "#define ARMLTD_SUPPLEMENTARY \" " >> $(ARMLTDVC_FILE) ; \ 388 echo $$text | grep "nothing to commit" >& /dev/null ; \ 389 if [ $$? -eq 0 ] ; then \ 390 echo "No uncommitted changes\"" >> $(ARMLTDVC_FILE) ; \ 391 else \ 392 echo "Uncommitted changes\"" >> $(ARMLTDVC_FILE) ; \ 393 fi; \ 394 else \ 395 echo "#define ARMLTD_COMMIT_REMOTE \"UNKNOWN\"" >> $(ARMLTDVC_FILE) ; \ 396 echo "#define ARMLTD_COMMIT_LOCAL \"UNKNOWN\"" >> $(ARMLTDVC_FILE) ; \ 397 echo "#define ARMLTD_SUPPLEMENTARY \"UNKNOWN\"" >> $(ARMLTDVC_FILE) ; \ 398 fi; \ 399 400 $(TIMESTAMP_FILE): 401 @date +'#define U_BOOT_DATE "%b %d %C%y"' > $@ 402 @date +'#define U_BOOT_TIME "%T"' >> $@ 403 404 gdbtools: 405 $(MAKE) -C tools/gdb all || exit 1 406 407 updater: 408 $(MAKE) -C tools/updater all || exit 1 409 410 env: 411 $(MAKE) -C tools/env all MTD_VERSION=${MTD_VERSION} || exit 1 412 413 depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) $(obj)include/autoconf.mk 414 for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir _depend ; done 415 416 TAG_SUBDIRS += include 417 TAG_SUBDIRS += lib_generic board/$(BOARDDIR) 418 TAG_SUBDIRS += cpu/$(CPU) 419 TAG_SUBDIRS += lib_$(ARCH) 420 TAG_SUBDIRS += fs/cramfs 421 TAG_SUBDIRS += fs/fat 422 TAG_SUBDIRS += fs/fdos 423 TAG_SUBDIRS += fs/jffs2 424 TAG_SUBDIRS += fs/yaffs2 425 TAG_SUBDIRS += net 426 TAG_SUBDIRS += disk 427 TAG_SUBDIRS += common 428 TAG_SUBDIRS += drivers/bios_emulator 429 TAG_SUBDIRS += drivers/block 430 TAG_SUBDIRS += drivers/gpio 431 TAG_SUBDIRS += drivers/hwmon 432 TAG_SUBDIRS += drivers/i2c 433 TAG_SUBDIRS += drivers/input 434 TAG_SUBDIRS += drivers/misc 435 TAG_SUBDIRS += drivers/mmc 436 TAG_SUBDIRS += drivers/mtd 437 TAG_SUBDIRS += drivers/mtd/nand 438 TAG_SUBDIRS += drivers/mtd/onenand 439 TAG_SUBDIRS += drivers/mtd/spi 440 TAG_SUBDIRS += drivers/net 441 TAG_SUBDIRS += drivers/net/sk98lin 442 TAG_SUBDIRS += drivers/pci 443 TAG_SUBDIRS += drivers/pcmcia 444 TAG_SUBDIRS += drivers/qe 445 TAG_SUBDIRS += drivers/rtc 446 TAG_SUBDIRS += drivers/serial 447 TAG_SUBDIRS += drivers/spi 448 TAG_SUBDIRS += drivers/usb 449 TAG_SUBDIRS += drivers/video 450 451 tags ctags: 452 ctags -w -o $(obj)ctags `find $(SUBDIRS) $(TAG_SUBDIRS) \ 453 -name '*.[ch]' -print` 454 455 etags: 456 etags -a -o $(obj)etags `find $(SUBDIRS) $(TAG_SUBDIRS) \ 457 -name '*.[ch]' -print` 458 cscope: 459 find $(SUBDIRS) $(TAG_SUBDIRS) -name '*.[ch]' -print \ 460 > cscope.files 461 cscope -b -q -k 462 463 SYSTEM_MAP = \ 464 $(NM) $1 | \ 465 grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \ 466 LC_ALL=C sort 467 $(obj)System.map: $(obj)u-boot 468 @$(call SYSTEM_MAP,$<) > $(obj)System.map 469 470 # 471 # Auto-generate the autoconf.mk file (which is included by all makefiles) 472 # 473 # This target actually generates 2 files; autoconf.mk and autoconf.mk.dep. 474 # the dep file is only include in this top level makefile to determine when 475 # to regenerate the autoconf.mk file. 476 # 477 # Note the kludge to prevent failing due to missing version file 478 # after a distclean 479 # 480 $(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h 481 @touch $(ARMLTDVC_FILE) 482 @$(XECHO) Generating $@ ; \ 483 set -e ; \ 484 : Generate the dependancies ; \ 485 $(CC) -x c -DDO_DEPS_ONLY -M $(HOSTCFLAGS) $(CPPFLAGS) \ 486 -MQ $(obj)include/autoconf.mk include/common.h > $@ 487 488 $(obj)include/autoconf.mk: $(obj)include/config.h 489 @touch $(ARMLTDVC_FILE) 490 @$(XECHO) Generating $@ ; \ 491 set -e ; \ 492 : Extract the config macros ; \ 493 $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \ 494 sed -n -f tools/scripts/define2mk.sed > $@.tmp && \ 495 mv $@.tmp $@ 496 497 ######################################################################### 498 else # !config.mk 499 all $(obj)u-boot.hex $(obj)u-boot.srec $(obj)u-boot.bin \ 500 $(obj)u-boot.img $(obj)u-boot.dis $(obj)u-boot \ 501 $(SUBDIRS) $(TIMESTAMP_FILE) $(VERSION_FILE) gdbtools updater env depend \ 502 dep tags ctags etags cscope $(obj)System.map: 503 @echo "System not configured - see README" >&2 504 @ exit 1 505 endif # config.mk 506 507 .PHONY : CHANGELOG 508 CHANGELOG: 509 git log --no-merges U-Boot-1_1_5.. | \ 510 unexpand -a | sed -e 's/\s\s*$$//' > $@ 511 512 include/license.h: tools/bin2header COPYING 513 cat COPYING | gzip -9 -c | ./tools/bin2header license_gzip > include/license.h 514 ###################################编译前执行的配置##################################################### 515 516 unconfig: 517 @rm -f $(obj)include/config.h $(obj)include/config.mk \ 518 $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \ 519 $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep 520 521 #======================================================================== 522 # ARM supplied RealView boards 523 # - detected using HBI 524 525 # 编译前的配置,make <board_name>_config就是执行这条语句,会调用顶层的mkconfig文件 526 copener_config: unconfig 527 @$(MKCONFIG) $(@:_config=) arm cpu board vendor 528 529 ######################################################################################################## 530 #################################删除上次配置和编译的文件############################################### 531 532 clean: 533 @rm -f $(obj)examples/standalone/82559_eeprom \ 534 $(obj)examples/standalone/eepro100_eeprom \ 535 $(obj)examples/standalone/hello_world \ 536 $(obj)examples/standalone/interrupt \ 537 $(obj)examples/standalone/mem_to_mem_idma2intr \ 538 $(obj)examples/standalone/sched \ 539 $(obj)examples/standalone/smc91111_eeprom \ 540 $(obj)examples/standalone/test_burst \ 541 $(obj)examples/standalone/timer 542 @rm -f $(obj)examples/api/demo{,.bin} 543 @rm -f $(obj)tools/bmp_logo $(obj)tools/easylogo/easylogo \ 544 $(obj)tools/env/{fw_printenv,fw_setenv} \ 545 $(obj)tools/envcrc \ 546 $(obj)tools/gdb/{astest,gdbcont,gdbsend} \ 547 $(obj)tools/gen_eth_addr $(obj)tools/img2srec \ 548 $(obj)tools/mkimage $(obj)tools/mpc86x_clk \ 549 $(obj)tools/ncb $(obj)tools/ubsha1 550 @rm -f $(obj)board/cray/L1/{bootscript.c,bootscript.image} \ 551 $(obj)board/netstar/{eeprom,crcek,crcit,*.srec,*.bin} \ 552 $(obj)board/trab/trab_fkt $(obj)board/voiceblue/eeprom \ 553 $(obj)board/armltd/integrator/u-boot.lds \ 554 $(obj)include/armltdvc_autogenerated.h \ 555 $(obj)lib_blackfin/u-boot.lds \ 556 $(obj)u-boot.lds \ 557 $(obj)cpu/blackfin/bootrom-asm-offsets.[chs] 558 @rm -f $(obj)include/bmp_logo.h 559 @rm -f $(obj)nand_spl/{u-boot.lds,u-boot-spl,u-boot-spl.map,System.map} 560 @rm -f $(obj)onenand_ipl/onenand-{ipl,ipl.bin,ipl-2k.bin,ipl-4k.bin,ipl.map} 561 @rm -f $(obj)onenand_ipl/u-boot.lds 562 @rm -f $(TIMESTAMP_FILE) $(VERSION_FILE) 563 @find $(OBJTREE) -type f \ 564 \( -name 'core' -o -name '*.bak' -o -name '*~' \ 565 -o -name '*.o' -o -name '*.a' -o -name '*.exe' \) -print \ 566 | xargs rm -f 567 568 clobber: clean 569 @find $(OBJTREE) -type f \( -name .depend \ 570 -o -name '*.srec' -o -name '*.bin' -o -name u-boot.img \) \ 571 -print0 \ 572 | xargs -0 rm -f 573 @rm -f $(OBJS) $(obj)*.bak $(obj)ctags $(obj)etags $(obj)TAGS \ 574 $(obj)cscope.* $(obj)*.*~ 575 @rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL) 576 @rm -f $(obj)tools/{env/crc32.c,inca-swap-bytes} 577 @rm -f $(obj)cpu/mpc824x/bedbug_603e.c 578 @rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm 579 @[ ! -d $(obj)nand_spl ] || find $(obj)nand_spl -name "*" -type l -print | xargs rm -f 580 @[ ! -d $(obj)onenand_ipl ] || find $(obj)onenand_ipl -name "*" -type l -print | xargs rm -f 581 582 ifeq ($(OBJTREE),$(SRCTREE)) 583 mrproper \ 584 distclean: clobber unconfig 585 else 586 mrproper \ 587 distclean: clobber unconfig 588 rm -rf $(obj)* 589 endif 590 591 backup: 592 F=`basename $(TOPDIR)` ; cd .. ; \ 593 gtar --force-local -zcvf `date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F 594 595 #########################################################################