Chinaunix首页 | 论坛 | 博客
  • 博客访问: 682870
  • 博文数量: 516
  • 博客积分: 4119
  • 博客等级: 上校
  • 技术积分: 4288
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-30 17:29
文章分类

全部博文(516)

文章存档

2014年(4)

2013年(160)

2012年(352)

分类:

2012-11-01 10:50:27


点击(此处)折叠或打开

  1. 所有的注释都用 # 标示
  2. #第一步:配置 make smdk2410_config ,从这里执行,在Makefile里面找目标##:smdk2410_config。可以自己设置这么一个目标,如mini2440_config
  3. smdk2410_config : unconfig #unconfig前面定义的有。该目标smdk_2410依赖于unconfig目标。
  4. @$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
  5. #这条命令就是
  6. # MKCONFIG := $(SRCTREE)/mkconfig
  7. # OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
  8. # if函数计算OBJTREE的值,如果BUILD_DIR不为空,if函数的值就是BUILD_DIR,否则是CURDIR.
  9. # SRCTREE := $(CURDIR) CURDIR是个环境变量。代表当前文件的目录。
  10. # $(@:_config=) $@是目标smdk2410_config,这里将_config 替换为空。
  11. # 上面的命令可以替换如下
  12. # @$(CURDIR)/mkconfig smdk2410 arm arm920t smdk2410 NULL s3c24x0
  13. unconfig: #执行rm -f 命令,将以前的配置信息删除,
  14. #配置文件:include/config.h + config.mk
  15. # board/*/config.tmp board/*/*/config.tmp
  16. # include/autoconf.mk include/autoconf.mk.dep
  17. @rm -f $(obj)include/config.h $(obj)include/config.mk \
  18. $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \
  19. $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep
  20. # $(obj) and (src) are defined in config.mk but here in main Makefile
  21. # we also need them before config.mk is included which is the case for
  22. # some targets like unconfig, clean, clobber, distclean, etc.
  23. ifneq ($(OBJTREE),$(SRCTREE)) #如果 OBJTREE!=SRCTREE,这里人为的指定BUILD_DIR,OBJTREE=$(BUILD_DIR),CURDIR
  24. #是个环境变量,代表当前目录
  25. obj := $(OBJTREE)/ #这时obj 被赋值为OBJTREE
  26. src := $(SRCTREE)/ #src也被赋值为SRCTREE.
  27. else #这才是没有指定BUILD_TREE编译目录时,OBJTREE=CURDIR,与SRCTREE相等,
  28. obj := #obj为空
  29. src := #src为空
  30. endif
  31. export obj src #导出obj src
  32. OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
  33. SRCTREE := $(CURDIR)
  34. TOPDIR := $(SRCTREE)
  35. LNDIR := $(OBJTREE)
  36. export TOPDIR SRCTREE OBJTREE
  37. MKCONFIG := $(SRCTREE)/mkconfig
  38. export MKCONFIG
  39. 第二步:mkconfig文件的执行
  40. 这是一个shell脚本文件,主要功能是
  41. 1.确定开发板名称
  42. 2.创建到平台/开发板相关的头文件的连接
  43. 3.创建顶层Makefile包含的include/config.mk文件
  44. 4.创建开发板相关的头文件include/config.h
  45. mkconfig文件的内容:
  46. APPEND=no # Default: Create new config file
  47. BOARD_NAME="" # Name to print in make output
  48. [ "${BOARD_NAME}" ] || BOARD_NAME="$1" #BOARD_NAME如果不为空,就不用赋值,如果为空,赋值$1.
  49. #如果变量数目小于4或大于6,就直接退出。否则执行下面的
  50. [ $# -lt 4 ] && exit 1
  51. [ $# -gt 6 ] && exit 1
  52. #打印输出下面这么一句话
  53. echo "Configuring for ${BOARD_NAME} board..."
  54. #
  55. # Create link to architecture specific headers
  56. #
  57. cd ./include #切换到include目录下,删除asm文件,创建新的asm文件,连接指向asm-arm
  58. rm -f asm
  59. ln -s asm-$2 asm
  60. #删除asm-arm920t/arch 目录,为什么???
  61. rm -f asm-$2/arch
  62. #如果$6为0 或为空,这里$6=s3c24x0
  63. if [ -z "$6" -o "$6" = "NULL" ] ; then
  64. ln -s ${LNPREFIX}arch-$3 asm-$2/arch
  65. else
  66. ln -s ${LNPREFIX}arch-$6 asm-$2/arch #ln -s arch-s3c24x0 asm-arm920t/arch
  67. fi
  68. #
  69. # Create include file for Make
  70. #
  71. echo "ARCH = $2" > config.mk #将$2输出到并创建一个文件config.mk
  72. echo "CPU = $3" >> config.mk #只是添加到文件中
  73. echo "BOARD = $4" >> config.mk
  74. [ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk
  75. [ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
  76. #
  77. # Create board specific header file
  78. #
  79. if [ "$APPEND" = "yes" ] # Append to existing config file
  80. then
  81. echo >> config.h
  82. else
  83. > config.h # Create new config file
  84. fi
  85. echo "/* Automatically generated - do not edit */" >>config.h
  86. echo "#include " >>config.h #在config.h文件中包含conf#igs/$(board_name).h文件,该文件需要手动创建
  87. exit 0
  88. 创建开发板相关的头文件:include/configs/$(board_name).h
  89. 该文件存放的是开发板的配置信息,包括两类:
  90. 1.选项,前缀为CONFIG_,
  91. 2.参数,前缀为CFG_

  92. 在mini2440.h文件里添加如下配置:
  93. #define CONFIG_MINI2440 1
  94. #define CONFIG_S3C2440 1
  95. 第三步:make 命令的执行--uboot的编译连接过程
  96. 配置完后,执行make命令。
  97. make执行中要用到哪些信息:
  98. 1.include $(OBJTREE)/include/config.mk include目录下的config.mk文件,该文件包含ARCH,CPU,BOARD,VENDOR,SOC信息
  99. 2.include $(TOPDIR)/config.mk 顶层目录下的config.mk文件,该文件根据上面文件中的四个变量,确定了编译器,编译选项等。

  100. $(TOPDIR)/config.mk 的内容:
  101. BOARDDIR = $(BOARD) #确定了开发板名称,使用参数BOARD,这里是smdk2410,我们可以认为是mini2440
  102. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  103. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds #本开发的连接脚本,该脚本会向后期的start_armboot函数
  104. #传入一些参数,如__bss_start,_end,__u_boot_cmd_start,
  105. #__u_boot_cmd_end..供C函数调用
  106. LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS) #连接选项
  107. 在board/mini2440/config.mk文件中,定义了TEXT_BASE = 0x33f80000.
  108. 接着看Makefile:
  109. #################################################################
  110. # U-Boot objects....order is important (i.e. start must be first)
  111. OBJS = cpu/$(CPU)/start.o  #OBJS第一个成员必须是start.o
  112. OBJS := $(addprefix $(obj),$(OBJS)) #添加上前缀,使路径完整
  113. LIBS = lib_generic/libgeneric.a
  114. LIBS += lib_generic/lzma/liblzma.a
  115. LIBS += $(shell if [ -f board/$(VENDOR)/common/Makefile ]; then echo \ #看文件是否存在。
  116. "board/$(VENDOR)/common/lib$(VENDOR).a"; fi)
  117. LIBS += cpu/$(CPU)/lib$(CPU).a
  118. ifdef SOC
  119. LIBS += cpu/$(CPU)/$(SOC)/lib$(SOC).a
  120. endif
  121. LIBS += lib_$(ARCH)/lib$(ARCH).a
  122. LIBS += fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a \
  123. fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a fs/yaffs2/libyaffs2.a
  124. LIBS += net/libnet.a
  125. LIBS += disk/libdisk.a
  126. LIBS += drivers/bios_emulator/libatibiosemu.a
  127. LIBS += drivers/block/libblock.a
  128. LIBS += drivers/dma/libdma.a
  129. LIBS += drivers/hwmon/libhwmon.a
  130. LIBS += drivers/i2c/libi2c.a
  131. LIBS += drivers/input/libinput.a
  132. LIBS += drivers/misc/libmisc.a
  133. LIBS += drivers/mmc/libmmc.a
  134. LIBS += drivers/mtd/libmtd.a
  135. LIBS += drivers/mtd/nand/libnand.a
  136. LIBS += drivers/mtd/nand_legacy/libnand_legacy.a
  137. LIBS += drivers/mtd/onenand/libonenand.a
  138. LIBS += drivers/mtd/spi/libspi_flash.a
  139. LIBS += drivers/net/libnet.a
  140. LIBS += drivers/net/phy/libphy.a
  141. LIBS += drivers/net/sk98lin/libsk98lin.a
  142. LIBS += drivers/pci/libpci.a
  143. LIBS += drivers/pcmcia/libpcmcia.a
  144. LIBS += drivers/spi/libspi.a
  145. LIBS += drivers/rtc/librtc.a
  146. LIBS += drivers/serial/libserial.a
  147. LIBS += drivers/usb/libusb.a
  148. LIBS += drivers/video/libvideo.a
  149. LIBS += common/libcommon.a
  150. LIBS += libfdt/libfdt.a
  151. LIBS += api/libapi.a
  152. LIBS += post/libpost.a
  153. LIBS := $(addprefix $(obj),$(LIBS)) #也是给LIBS目标添加上完整的路径
  154. .PHONY : $(LIBS) $(VERSION_FILE)
  155. ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND)
  156. all: $(ALL)
  157. $(obj)u-boot.hex: $(obj)u-boot
  158. $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@
  159. $(obj)u-boot.srec: $(obj)u-boot
  160. $(OBJCOPY) -O srec $< $@
  161. $(obj)u-boot.bin: $(obj)u-boot
  162. $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
  163. $(obj)u-boot.ldr: $(obj)u-boot
  164. $(LDR) -T $(CONFIG_BFIN_CPU) -f -c $@ $< $(LDR_FLAGS)
  165. $(obj)u-boot.ldr.hex: $(obj)u-boot.ldr
  166. $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary
  167. $(obj)u-boot.ldr.srec: $(obj)u-boot.ldr
  168. $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ -I binary
  169. $(obj)u-boot.img: $(obj)u-boot.bin
  170. ./tools/mkimage -A $(ARCH) -T firmware -C none \
  171. -a $(TEXT_BASE) -e 0 \
  172. -n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \
  173. sed -e 's/"[ ]*$$/ for $(BOARD) board"/') \
  174. -d $< $@
  175. $(obj)u-boot.sha1: $(obj)u-boot.bin
  176. $(obj)tools/ubsha1 $(obj)u-boot.bin
  177. $(obj)u-boot.dis: $(obj)u-boot
  178. $(OBJDUMP) -d $< > $@
  179. $(obj)u-boot: depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT)
  180. UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \
  181. sed -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
  182. cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
  183. --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
  184. -Map u-boot.map -o u-boot
  185. $(OBJS): depend $(obj)include/autoconf.mk
  186. $(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))
  187. #if函数:
  188. #如果$1为真,计算第二个参数的值,
  189. #并将第二个参数的值作为if函数的值,如果$1为假。
  190. #计算第三个参数的值,如果第三个参数不存在,返回空。
  191. #notdir抽取$@的除路径外的文件名
  192. #上面这条命令,会进入cpu/arm目录下,对OBJS中每个成员进行make,依赖的Makefile是cpu/arm/下的
  193. #该目标OBJS的成员在前面已经添加完毕,这里对每个目标文件进行编译。
  194. #下面LIBS也是同理
  195. depend dep: $(VERSION_FILE)
  196. for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir _depend ; done
  197. #目标depend dep 依赖于VERSION_FILE
  198. #执行一个for循环,进入目录$dir,执行make命令,产生文件 _depend
  199. #depend文件具体是如何生成,起什么作用

  200. VERSION_FILE = $(obj)include/version_autogenerated.h
  201. $(LIBS): depend $(obj)include/autoconf.mk
  202. $(MAKE) -C $(dir $(subst $(obj),,$@))
  203. #dir抽取每一个文件名的路径部分,路径用空格隔开。
  204. #subst,将$@中的每一个$(obj)用空格替换掉。
  205. #切换到不同的路径下编译相应的库文件。
  206. $(LIBBOARD): depend $(LIBS) $(obj)include/autoconf.mk
  207. $(MAKE) -C $(dir $(subst $(obj),,$@))
  208. $(SUBDIRS): depend $(obj)include/autoconf.mk
  209. $(MAKE) -C $@ all
  210. $(LDSCRIPT): depend $(obj)include/autoconf.mk
  211. $(MAKE) -C $(dir $@) $(notdir $@)
  212. $(NAND_SPL): $(VERSION_FILE) $(obj)include/autoconf.mk
  213. $(MAKE) -C nand_spl/board/$(BOARDDIR) all
  214. $(U_BOOT_NAND): $(NAND_SPL) $(obj)u-boot.bin $(obj)include/autoconf.mk
  215. cat $(obj)nand_spl/u-boot-spl-16k.bin $(obj)u-boot.bin > $(obj)u-boot-nand.bin
  216. $(ONENAND_IPL): $(VERSION_FILE) $(obj)include/autoconf.mk
  217. $(MAKE) -C onenand_ipl/board/$(BOARDDIR) all
  218. $(U_BOOT_ONENAND): $(ONENAND_IPL) $(obj)u-boot.bin $(obj)include/autoconf.mk
  219. cat $(obj)onenand_ipl/onenand-ipl-2k.bin $(obj)u-boot.bin > $(obj)u-boot-onenand.bin
  220. cat $(obj)onenand_ipl/onenand-ipl-4k.bin $(obj)u-boot.bin > $(obj)u-boot-flexonenand.bin
  221. $(VERSION_FILE):
  222. @( printf '#define U_BOOT_VERSION "U-Boot %s%s"\n' "$(U_BOOT_VERSION)" \
  223. '$(shell $(CONFIG_SHELL) $(TOPDIR)/tools/setlocalversion $(TOPDIR))' \
  224. ) > $@.tmp
  225. @cmp -s $@ $@.tmp && rm -f $@.tmp || mv -f $@.tmp $@

阅读(632) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~