新闻中心

EEPW首页>嵌入式系统>设计应用> GNU ARM汇编--(十七)u-boot的makefile和mkconfig解读

GNU ARM汇编--(十七)u-boot的makefile和mkconfig解读

作者: 时间:2016-11-26 来源:网络 收藏
[cpp]view plaincopy
  1. VERSION=2012
  2. PATCHLEVEL=07
  3. SUBLEVEL=
  4. EXTRAVERSION=
  5. ifneq"$(SUBLEVEL)"""
  6. U_BOOT_VERSION=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  7. else
  8. U_BOOT_VERSION=$(VERSION).$(PATCHLEVEL)$(EXTRAVERSION)
  9. endif
  10. ################################
  11. #定义U_BOOT_VERSION为2012.07
  12. #####################################
  13. TIMESTAMP_FILE=$(obj)include/generated/timestamp_autogenerated.h
  14. VERSION_FILE=$(obj)include/generated/version_autogenerated.h
  15. ###############################
  16. #因为obj为空,所以定义TIMESTAMP_FILE为include/generated/timestamp_autogenerated.h
  17. #定义VERSION_FILE为include/generated/version_autogenerated.h
  18. #****************
  19. HOSTARCH:=$(shelluname-m|
  20. sed-es/i.86/x86/
  21. -es/sun4u/sparc64/
  22. -es/arm.*/arm/
  23. -es/sa110/arm/
  24. -es/ppc64/powerpc/
  25. -es/ppc/powerpc/
  26. -es/macppc/powerpc/
  27. -es/sh.*/sh/)
  28. HOSTOS:=$(shelluname-s|tr[:upper:][:lower:]|
  29. sed-es/ .*/cygwin/)
  30. #Setshelltobashifpossible,otherwisefallbacktosh
  31. SHELL:=$(shellif[-x"$$BASH"];thenecho$$BASH;
  32. elseif[-x/bin/bash];thenecho/bin/bash;
  33. elseechosh;fi;fi)
  34. exportHOSTARCHHOSTOSSHELL
  35. #########################
  36. #HOSTARCH为i686,HOSTOS为linux,SHELL为/bin/sh
  37. #############################
  38. #Dealwithcollidingdefinitionsfromtcshetc.
  39. VENDOR=
  40. #########################################################################
  41. #Allowforsilentbuilds
  42. ifeq(,$(findstrings,$(MAKEFLAGS)))
  43. XECHO=echo
  44. else
  45. XECHO=:
  46. endif
  47. ###########################
  48. #因为MAKEFLAGS变量的字符串为空,找不到s,所以ifeq为真,XECHO=echo
  49. ###########################
  50. #########################################################################
  51. #
  52. #U-bootbuildsupportsproducingaobjectfilestotheseparateexternal
  53. #directory.Twousecasesaresupported:
  54. #
  55. #1)AddO=tothemakecommandline
  56. #makeO=/tmp/buildall
  57. #
  58. #2)SetenvironementvariableBUILD_DIRtopointtothedesiredlocation
  59. #exportBUILD_DIR=/tmp/build
  60. #make
  61. #
  62. #ThesecondapproachcanalsobeusedwithaMAKEALLscript
  63. #exportBUILD_DIR=/tmp/build
  64. #./MAKEALL
  65. #
  66. #CommandlineO=settingoverridesBUILD_DIRenvironentvariable.
  67. #
  68. #Whennoneoftheabovemethodsisusedthelocalbuildisperformedand
  69. #theobjectfilesareplacedinthesourcedirectory.
  70. #
  71. ifdefO
  72. ifeq("$(originO)","commandline")
  73. BUILD_DIR:=$(O)
  74. endif
  75. endif
  76. #################################
  77. #如果没有在make命令行中定义O=/tmp之类的,那么BUILD_DIR就为/tmp,否则为空。
  78. #当使用makeO=/tmp时,表明#ifdefO有定义,而$(originO)返回的就是"commandline"
  79. #################################
  80. ifneq($(BUILD_DIR),)
  81. saved-output:=$(BUILD_DIR)
  82. #Attempttocreateaoutputdirectory.
  83. $(shell[-d${BUILD_DIR}]||mkdir-p${BUILD_DIR})
  84. #Verifyifitwassuccessful.
  85. BUILD_DIR:=$(shellcd$(BUILD_DIR)&&/bin/pwd)
  86. $(if$(BUILD_DIR),,$(erroroutputdirectory"$(saved-output)"doesnotexist))
  87. endif#ifneq($(BUILD_DIR),)
  88. #################################
  89. #如果BUILD_DIR不为空,那么这几句就执行:
  90. #首先,saved-output变量也是BUILD_DIR的值
  91. #如果BUILD_DIR不存在,那么就创建BUILD_DIR目录
  92. #检测BUILD_DIR目录是否成功建好了,如果有问题就输出错误信息
  93. #################################
  94. OBJTREE:=$(if$(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
  95. SPLTREE:=$(OBJTREE)/spl
  96. SRCTREE:=$(CURDIR)
  97. TOPDIR:=$(SRCTREE)
  98. LNDIR:=$(OBJTREE)
  99. exportTOPDIRSRCTREEOBJTREESPLTREE
  100. ###########################################
  101. #如果BUILD_DIR有值,那么OBJTREE就是BUILD_DIR的值,如果BUILD_DIR为空,那么OBJTREE就是CURDIR的值,$(CURDIR)时GNUMake内嵌的变量,是当前目录。
  102. #我们在make时候不加O=/tmp之类的参数,所以OBJTREE就是当前工作目录,SPLTREE是当前工作目录下的spl目录,SRCTREE时当前工作目录,TOPDIR也是当前目录,LNDIR也是当前目录。
  103. ##########################################
  104. MKCONFIG:=$(SRCTREE)/mkconfig
  105. exportMKCONFIG
  106. #############################################
  107. #MKCONFIG定义为当前工作目录下的mkconfig脚本,并export
  108. #############################################
  109. ifneq($(OBJTREE),$(SRCTREE))
  110. REMOTE_BUILD:=1
  111. exportREMOTE_BUILD
  112. endif
  113. ####################################################################
  114. #在我们的执行中,OBJTREE和SRCTREE是相等的,所以不管了
  115. ###################################################################
  116. #$(obj)and(src)aredefinedinconfig.mkbuthereinmainMakefile
  117. #wealsoneedthembeforeconfig.mkisincludedwhichisthecasefor
  118. #sometargetslikeunconfig,clean,clobber,distclean,etc.
  119. ifneq($(OBJTREE),$(SRCTREE))
  120. obj:=$(OBJTREE)/
  121. src:=$(SRCTREE)/
  122. else
  123. obj:=
  124. src:=
  125. endif
  126. exportobjsrc
  127. #######################################
  128. #可以先看下上面的注释因为两个路径相同,所以执行else
  129. #########################################
  130. #MakesureCDPATHsettingsdontinterfere
  131. unexportCDPATH
  132. #########################################################################
  133. #The"tools"areneededearly,soputthisfirst
  134. #Dontincludestuffalreadydonein$(LIBS)
  135. #The"examples"conditionallydependonU-Boot(say,whenUSE_PRIVATE_LIBGCC
  136. #is"yes"),socompileexamplesafterU-Bootiscompiled.
  137. SUBDIR_TOOLS=tools
  138. SUBDIR_EXAMPLES=examples/standaloneexamples/api
  139. SUBDIRS=$(SUBDIR_TOOLS)
  140. ###############################################
  141. #定义SUBDIR_TOOLSSUBDIR_EXAMPLES和SUBDIRS
  142. ###############################################
  143. .PHONY:$(SUBDIRS)$(VERSION_FILE)$(TIMESTAMP_FILE)
  144. ########################
  145. #定义几个伪目标
  146. ########################
  147. ifeq($(obj)include/config.mk,$(wildcard$(obj)include/config.mk))
  148. #Includeautoconf.mkbeforeconfig.mksothattheconfigoptionsareavailable
  149. #toalltoplevelbuildfiles.Weneedthedummyall:targettopreventthe
  150. #dependencytargetinautoconf.mk.depfrombeingthedefault.
  151. all:
  152. sinclude$(obj)include/autoconf.mk.dep
  153. sinclude$(obj)include/autoconf.mk
  154. ###################################################################################
  155. #包含auoconf.mk和autoconf.mk.dep文件
  156. ###################################################################################
  157. ifndefCONFIG_SANDBOX
  158. SUBDIRS+=$(SUBDIR_EXAMPLES)
  159. endif
  160. ###################################
  161. #追加SUBDIRS为"toolsexamples/standaloneexamples/api"
  162. ###################################
  163. #loadARCH,BOARD,andCPUconfiguration
  164. include$(obj)include/config.mk
  165. exportARCHCPUBOARDVENDORSOC
  166. #######################################
  167. #包含include/config.mk文件,这个文件是在makexxx_config过程中产生的
  168. #######################################
  169. #setdefaulttonothingfornativebuilds
  170. ifeq($(HOSTARCH),$(ARCH))
  171. CROSS_COMPILE?=
  172. endif
  173. #######################################
  174. #看看注释就知道了,但是很显示我们的HOSTARCH是x86的,目标时arm的
  175. ########################################
  176. #loadotherconfiguration
  177. include$(TOPDIR)/config.mk
  178. #######################################
  179. #包含uboot顶层目录的config.mk文件
  180. #######################################
  181. #IfboardcodeexplicitlyspecifiedLDSCRIPTorCONFIG_SYS_LDSCRIPT,use
  182. #that(orfailifabsent).Otherwise,searchforalinkerscriptina
  183. #standardlocation.
  184. LDSCRIPT_MAKEFILE_DIR=$(dir$(LDSCRIPT))
  185. ##############################################################################
  186. #用等号赋值的变量是递归方式扩展的变量。变量定义时,变量值中对其他变量的引用不会被替换展开;
  187. #而是变量在引用它的地方替换展开的同时,它所引用的其它变量才会被一同替换展开。
  188. #其优点是:
  189. #这种类型变量在定义时,可以引用其它的之前没有定义的变量(可能在后续部分定义,或者是通过make的命令行选项传递的变量)。
  190. #LDSCRIPT变量就是后面才定义的
  191. ##############################################################################
  192. ifndefLDSCRIPT
  193. #LDSCRIPT:=$(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
  194. ifdefCONFIG_SYS_LDSCRIPT
  195. #needtostripoffdoublequotes
  196. LDSCRIPT:=$(subst",,$(CONFIG_SYS_LDSCRIPT))
  197. endif
  198. endif
  199. #######################################################################################
  200. #如果定义了CONFIG_SYS_LDSCRIPT,将CONFIG_SYS_LDSCRIPT代表的字符串去掉双引号后赋值给LDSCRIPT变量
  201. #这里我们并没有定义CONFIG_SYS_LDSCRIPT
  202. #######################################################################################
  203. #Ifthereisnospecifiedlinkscript,welookinanumberofplacesforit
  204. ifndefLDSCRIPT
  205. ifeq($(CONFIG_NAND_U_BOOT),y)
  206. LDSCRIPT:=$(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
  207. ifeq($(wildcard$(LDSCRIPT)),)
  208. LDSCRIPT:=$(TOPDIR)/$(CPUDIR)/u-boot-nand.lds
  209. endif
  210. endif
  211. ifeq($(wildcard$(LDSCRIPT)),)
  212. LDSCRIPT:=$(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
  213. endif
  214. ifeq($(wildcard$(LDSCRIPT)),)
  215. LDSCRIPT:=$(TOPDIR)/$(CPUDIR)/u-boot.lds
  216. endif
  217. ifeq($(wildcard$(LDSCRIPT)),)
  218. LDSCRIPT:=$(TOPDIR)/arch/$(ARCH)/cpu/u-boot.lds
  219. #WedontexpectaMakefilehere
  220. LDSCRIPT_MAKEFILE_DIR=
  221. endif
  222. ifeq($(wildcard$(LDSCRIPT)),)
  223. $(errorcouldnotfindlinkerscript)
  224. endif
  225. endif
  226. ##########################################################################################
  227. #注释写的很明确,如果没有用CONFIG_SYS_LDSCRIPT指定LDSCRIPT,那么就在几个地方搜
  228. #第一个地方:如果CONFIG_NAND_U_BOOT是y,就用u-boot-nand.lds但是这里没有这个定义
  229. #第一个地方没找到,就找第二个地方:u-boot-2012.07/board/samsung/smdk2410这个目录没有u-boot.lds文件
  230. #第二个地方没找到,就找第三个地方:其中CPUDIR是在顶层的config.mk中定义的,在arch/arm/cpu/arm920t中找这个目录也没有
  231. #第三个地方没找到,就找第四个地方:arch/arm/cpu/u-boot.lds,这里就找到了!!!!
  232. ##########################################################################################
  233. #########################################################################
  234. #U-Bootobjects....orderisimportant(i.e.startmustbefirst)
  235. OBJS=$(CPUDIR)/start.o
  236. ifeq($(CPU),x86)
  237. OBJS+=$(CPUDIR)/start16.o
  238. OBJS+=$(CPUDIR)/resetvec.o
  239. endif
  240. ifeq($(CPU),ppc4xx)
  241. OBJS+=$(CPUDIR)/resetvec.o
  242. endif
  243. ifeq($(CPU),mpc85xx)
  244. OBJS+=$(CPUDIR)/resetvec.o
  245. endif
  246. OBJS:=$(addprefix$(obj),$(OBJS))
  247. #####################################
  248. #为OBJS增加前缀,其中obj在顶层目录的config.mk中定义,这里根据实际情况OBJS就是arch/arm/cpu/arm920t/start.o
  249. #####################################
  250. LIBS=lib/libgeneric.o
  251. LIBS+=lib/lzma/liblzma.o
  252. LIBS+=lib/lzo/liblzo.o
  253. LIBS+=lib/zlib/libz.o
  254. ifeq($(CONFIG_TIZEN),y)
  255. LIBS+=lib/tizen/libtizen.o
  256. endif
  257. LIBS+=$(shellif[-fboard/$(VENDOR)/common/Makefile];thenecho
  258. "board/$(VENDOR)/common/lib$(VENDOR).o";fi)
  259. LIBS+=$(CPUDIR)/lib$(CPU).o
  260. ifdefSOC
  261. LIBS+=$(CPUDIR)/$(SOC)/lib$(SOC).o
  262. endif
  263. ifeq($(CPU),ixp)
  264. LIBS+=arch/arm/cpu/ixp/npe/libnpe.o
  265. endif
  266. ifeq($(CONFIG_OF_EMBED),y)
  267. LIBS+=dts/libdts.o
  268. endif
  269. LIBS+=arch/$(ARCH)/lib/lib$(ARCH).o
  270. LIBS+=fs/cramfs/libcramfs.ofs/fat/libfat.ofs/fdos/libfdos.ofs/jffs2/libjffs2.o
  271. fs/reiserfs/libreiserfs.ofs/ext2/libext2fs.ofs/yaffs2/libyaffs2.o
  272. fs/ubifs/libubifs.o
  273. LIBS+=net/libnet.o
  274. LIBS+=disk/libdisk.o
  275. LIBS+=drivers/bios_emulator/libatibiosemu.o
  276. LIBS+=drivers/block/libblock.o
  277. LIBS+=drivers/dma/libdma.o
  278. LIBS+=drivers/fpga/libfpga.o
  279. LIBS+=drivers/gpio/libgpio.o
  280. LIBS+=drivers/hwmon/libhwmon.o
  281. LIBS+=drivers/i2c/libi2c.o
  282. LIBS+=drivers/input/libinput.o
  283. LIBS+=drivers/misc/libmisc.o
  284. LIBS+=drivers/mmc/libmmc.o
  285. LIBS+=drivers/mtd/libmtd.o
  286. LIBS+=drivers/mtd/nand/libnand.o
  287. LIBS+=drivers/mtd/onenand/libonenand.o
  288. LIBS+=drivers/mtd/ubi/libubi.o
  289. LIBS+=drivers/mtd/spi/libspi_flash.o
  290. LIBS+=drivers/net/libnet.o
  291. LIBS+=drivers/net/phy/libphy.o
  292. LIBS+=drivers/pci/libpci.o
  293. LIBS+=drivers/pcmcia/libpcmcia.o
  294. LIBS+=drivers/power/libpower.o
  295. LIBS+=drivers/spi/libspi.o
  296. ifeq($(CPU),mpc83xx)
  297. LIBS+=drivers/qe/libqe.o
  298. LIBS+=arch/powerpc/cpu/mpc8xxx/ddr/libddr.o
  299. LIBS+=arch/powerpc/cpu/mpc8xxx/lib8xxx.o
  300. endif
  301. ifeq($(CPU),mpc85xx)
  302. LIBS+=drivers/qe/libqe.o
  303. LIBS+=drivers/net/fm/libfm.o
  304. LIBS+=arch/powerpc/cpu/mpc8xxx/ddr/libddr.o
  305. LIBS+=arch/powerpc/cpu/mpc8xxx/lib8xxx.o
  306. endif
  307. ifeq($(CPU),mpc86xx)
  308. LIBS+=arch/powerpc/cpu/mpc8xxx/ddr/libddr.o
  309. LIBS+=arch/powerpc/cpu/mpc8xxx/lib8xxx.o
  310. endif
  311. LIBS+=drivers/rtc/librtc.o
  312. LIBS+=drivers/serial/libserial.o
  313. ifeq($(CONFIG_GENERIC_LPC_TPM),y)
  314. LIBS+=drivers/tpm/libtpm.o
  315. endif
  316. LIBS+=drivers/twserial/libtws.o
  317. LIBS+=drivers/usb/eth/libusb_eth.o
  318. LIBS+=drivers/usb/gadget/libusb_gadget.o
  319. LIBS+=drivers/usb/host/libusb_host.o
  320. LIBS+=drivers/usb/musb/libusb_musb.o
  321. LIBS+=drivers/usb/phy/libusb_phy.o
  322. LIBS+=drivers/usb/ulpi/libusb_ulpi.o
  323. LIBS+=drivers/video/libvideo.o
  324. LIBS+=drivers/watchdog/libwatchdog.o
  325. LIBS+=common/libcommon.o
  326. LIBS+=lib/libfdt/libfdt.o
  327. LIBS+=api/libapi.o
  328. LIBS+=post/libpost.o
  329. ifneq($(CONFIG_AM33XX)$(CONFIG_OMAP34XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX),)
  330. LIBS+=$(CPUDIR)/omap-common/libomap-common.o
  331. endif
  332. ifeq($(SOC),mx5)
  333. LIBS+=$(CPUDIR)/imx-common/libimx-common.o
  334. endif
  335. ifeq($(SOC),mx6)
  336. LIBS+=$(CPUDIR)/imx-common/libimx-common.o
  337. endif
  338. ifeq($(SOC),s5pc1xx)
  339. LIBS+=$(CPUDIR)/s5p-common/libs5p-common.o
  340. endif
  341. ifeq($(SOC),exynos)
  342. LIBS+=$(CPUDIR)/s5p-common/libs5p-common.o
  343. endif


评论


技术专区

关闭