Chinaunix首页 | 论坛 | 博客
  • 博客访问: 49370
  • 博文数量: 19
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 147
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-13 14:56
个人简介

待到山花烂漫时,依旧是那些经典在微笑 ~__~

文章分类
文章存档

2015年(17)

2014年(2)

我的朋友

分类: 嵌入式

2015-02-03 14:31:46

    ***********************目标***********************************
     1.分析uboot1.3.4如何引导内核
     2.uboot1.3.4和内核之间的参数传递
     3.uboot1.3.4的命令实现
     4.uboot1.3.4的环境变量
     ***********************目标***********************************

     ^^^^^^^^^^^^^^^^^^^^^^^^从头开始,fighting^^^^^^^^^^^^^^^^^^^^^^^^
        ***********************顶层Makefile*******************************

      
点击(此处)折叠或打开
  1. VERSION = 1
  2. PATCHLEVEL = 3
  3. SUBLEVEL = 4
  4. EXTRAVERSION =
  5. U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  6. VERSION_FILE = $(obj)include/version_autogenerated.h
        由代码可知uboot的版本为1.3.4。继续往下

点击(此处)折叠或打开

  1. #########################################################################
  2. #
  3. # U-boot build supports producing a object files to the separate external
  4. # directory. Two use cases are supported:
  5. #
  6. # 1) Add O= to the make command line
  7. # 'make O=/tmp/build all'
  8. #
  9. # 2) Set environement variable BUILD_DIR to point to the desired location
  10. # 'export BUILD_DIR=/tmp/build'
  11. # 'make'
  12. #
  13. # The second approach can also be used with a MAKEALL script
  14. # 'export BUILD_DIR=/tmp/build'
  15. # './MAKEALL'
  16. #
  17. # Command line 'O=' setting overrides BUILD_DIR environent variable.
  18. #
  19. # When none of the above methods is used the local build is performed and
  20. # the object files are placed in the source directory.
  21. #
         以上是关于输出目录的解释,为了保持目录的干净。
***********************顶层Makefile*******************************

################### 终端操作############################
######        现在编译并生成u-boot.bin,输出目录即是当前源码目录.使用以下命令:
######        1.make distclean
 ######      2.make _config
 ######      3.make (all)
################### 终端操作############################

    ***********************顶层Makefile*******************************
       
点击(此处)折叠或打开
  1. smdkv210single_config : unconfig
  2. @$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110
  3. @echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/smdkc110/config.mk
        执行三种操作
        unconfig是清除上一次的配置结果。操作结果如下:
        rm -rf  include/config.h include/config.mk board/*/config.tmp  include/autoconf.mk 

        @$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110 等效于 
        ./mkconfig   smdkv210single arm s5pc11x smdkc110 samsung s5pc110
        
        @echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/smdkc110/config.mk
    ***********************顶层Makefile*******************************

    ***********************顶层./mkconfig*******************************

        
点击(此处)折叠或打开
  1. # Script to create header files and links to configure
  2. # U-Boot for a specific board.
  3. #
  4. # Parameters: Target Architecture CPU Board [VENDOR] [SOC]
  5. #
  6. # (C) 2002-2006 DENX Software Engineering, Wolfgang Denk <wd@denx.de>
  7. #

    在mkconfig脚本中给出了mkconfig的用法:

        # Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]

       因此传递给mkconfig的参数的意义分别是:  ./mkconfig   smdkv210single arm s5pc11x smdkc110 samsung s5pc110

       smdkv210single :Target(目标板型号)

        arm:Architecture (目标板的CPU架构)

        s5pc11x:CPU (具体使用的CPU型号)

        smdkc110 :Board

        samsung:VENDOR(生产厂家名)

        s5pc110:SOC

       结果创建链接文件和在include下创建config.h("#include smdkv210single
.h>" >>config.h)和config.mk。
 ***********************顶层./mkconfig*******************************    

     ***********************顶层Makefile*******************************   
以上执行完uboot的配置过程,现在开始make。依据从顶层Makefile开始  
     点击(此处)折叠或打开
  1. ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk)) ############判断是否执行过make _config############

  2. # load ARCH, BOARD, and CPU configuration ############加载config.mk的配置信息,确定架构、目标板、cPU等配置############
  3. include $(obj)include/config.mk
  4. export    ARCH CPU BOARD VENDOR SOC   ############ ARCH CPU BOARD VENDOR SOC = arm s5pc11x smdkc110 samsung s5pc110 ############


  5. ifndef CROSS_COMPILE  ####决定编译工具链######
  6. ........
  7. ifeq ($(ARCH),arm)####指定工具链的位置######
  8. #CROSS_COMPILE = arm-linux-
  9. #CROSS_COMPILE = /usr/local/arm/4.4.1-eabi-cortex-a8/usr/bin/arm-linux-
  10. #CROSS_COMPILE = /usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-
  11. CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
  12. endif
  13. # load other configuration############加载其他配置############
    include $(TOPDIR)/config.mk
  14. ................
  15. else    # !config.mk ############未行过make _config,退出make过程############
  16. .....................
  17.  @echo "System not configured - see README" >&2
  18. endif
     加载完各个配置信息后,会生成各个库文件,然后开始真正的编译过程。

$(obj)u-boot.bin:       $(obj)u-boot

                $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@

arm-linux-objcopy   -O binary u-boot  u-boot.bin

     具体的编译过程,后续。。。。。。
    ***********************顶层Makefile
******************************* 
   
 ***********************include $(TOPDIR)/config.mk加载其他配置分析*******************************   
点击(此处)折叠或打开
  1. #
  2. # (C) Copyright 2000-2006
  3. # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. #
  5. # See file CREDITS for list of people who contributed to this
  6. # project.
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License as
  10. # published by the Free Software Foundation; either version 2 of
  11. # the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. # MA 02111-1307 USA
  22. #
  23. #########################################################################
  24. ifneq ($(OBJTREE),$(SRCTREE))
  25. ifeq ($(CURDIR),$(SRCTREE))
  26. dir :=
  27. else
  28. dir := $(subst $(SRCTREE)/,,$(CURDIR))
  29. endif
  30. obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
  31. src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
  32. $(shell mkdir -p $(obj))
  33. else
  34. obj :=
  35. src :=
  36. endif
  37. # clean the slate ...
  38. PLATFORM_RELFLAGS =
  39. PLATFORM_CPPFLAGS =
  40. PLATFORM_LDFLAGS =
  41. #
  42. # When cross-compiling on NetBSD, we have to define __PPC__ or else we
  43. # will pick up a va_list declaration that is incompatible with the
  44. # actual argument lists emitted by the compiler.
  45. #
  46. # [Tested on NetBSD/i386 1.5 + cross-powerpc-netbsd-1.3]
  47. ifeq ($(ARCH),ppc)
  48. ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
  49. PLATFORM_CPPFLAGS+= -D__PPC__
  50. endif
  51. ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
  52. PLATFORM_CPPFLAGS+= -D__PPC__
  53. endif
  54. endif
  55. ifeq ($(ARCH),arm)
  56. ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
  57. PLATFORM_CPPFLAGS+= -D__ARM__
  58. endif
  59. ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
  60. PLATFORM_CPPFLAGS+= -D__ARM__
  61. endif
  62. endif
  63. #########################################################################
  64. CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
  65. else if [ -x /bin/bash ]; then echo /bin/bash; \
  66. else echo sh; fi ; fi)
  67. ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
  68. HOSTCC = cc
  69. else
  70. HOSTCC = gcc
  71. endif
  72. HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
  73. HOSTSTRIP = strip
  74. #########################################################################
  75. #
  76. # Option checker (courtesy linux kernel) to ensure
  77. # only supported compiler options are used
  78. #
  79. cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
  80. > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
  81. #
  82. # Include the make variables (CC, etc...)
  83. #
  84. AS = $(CROSS_COMPILE)as
  85. LD = $(CROSS_COMPILE)ld
  86. CC = $(CROSS_COMPILE)gcc
  87. CPP = $(CC) -E
  88. AR = $(CROSS_COMPILE)ar
  89. NM = $(CROSS_COMPILE)nm
  90. LDR = $(CROSS_COMPILE)ldr
  91. STRIP = $(CROSS_COMPILE)strip
  92. OBJCOPY = $(CROSS_COMPILE)objcopy
  93. OBJDUMP = $(CROSS_COMPILE)objdump
  94. RANLIB = $(CROSS_COMPILE)RANLIB
  95. #########################################################################
  96. # Load generated board configuration
  97. sinclude $(OBJTREE)/include/autoconf.mk #####和目标板的宏定义相关#########
  98. ifdef ARCH
  99. sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
  100. endif
  101. ifdef CPU
  102. sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
  103. endif
  104. ifdef SOC
  105. sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules
  106. endif
  107. ifdef VENDOR
  108. BOARDDIR = $(VENDOR)/$(BOARD)
  109. else
  110. BOARDDIR = $(BOARD)
  111. endif
  112. ifdef BOARD
  113. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  114. endif
  115. #########################################################################
  116. ifneq (,$(findstring s,$(MAKEFLAGS)))
  117. ARFLAGS = cr
  118. else
  119. ARFLAGS = crv
  120. endif
  121. RELFLAGS= $(PLATFORM_RELFLAGS)
  122. DBGFLAGS= -g # -DDEBUG
  123. OPTFLAGS= -Os #-fomit-frame-pointer
  124. ifndef LDSCRIPT  #####在上层Makefile并没有全局定义LDSCRIPT####
  125. #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
  126. ifeq ($(CONFIG_NAND_U_BOOT),y)
  127. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
  128. else
  129. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
  130.  #####LDSCRIPT被定义为board/samsung/smdkc110/u-boot.lds####
  131. endif
  132. endif
  133. OBJCFLAGS += --gap-fill=0xff
  134. gccincdir := $(shell $(CC) -print-file-name=include)
  135. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  136. -D__KERNEL__
  137. ifneq ($(TEXT_BASE),)
  138. CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
  139. endif
  140. ifneq ($(OBJTREE),$(SRCTREE))
  141. CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
  142. endif
  143. CPPFLAGS += -I$(TOPDIR)/include
  144. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  145. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  146. ifdef BUILD_TAG
  147. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
  148. -DBUILD_TAG='"$(BUILD_TAG)"'
  149. else
  150. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  151. endif
  152. CFLAGS += $(call cc-option,-fno-stack-protector)
  153. # avoid trigraph warnings while parsing pci.h (produced by NIOS gcc-2.9)
  154. # this option have to be placed behind -Wall -- that's why it is here
  155. ifeq ($(ARCH),nios)
  156. ifeq ($(findstring 2.9,$(shell $(CC) --version)),2.9)
  157. CFLAGS := $(CPPFLAGS) -Wall -Wno-trigraphs
  158. endif
  159. endif
  160. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g
  161. # option to the assembler.
  162. AFLAGS_DEBUG :=
  163. # turn jbsr into jsr for m68k
  164. ifeq ($(ARCH),m68k)
  165. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  166. AFLAGS_DEBUG := -Wa,-gstabs,-S
  167. endif
  168. endif
  169. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  170. LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS)
  171. ifneq ($(TEXT_BASE),)
  172. LDFLAGS += -Ttext $(TEXT_BASE)
  173. endif
  174. # Location of a usable BFD library, where we define "usable" as
  175. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  176. # - When cross-compiling: the root of the cross-environment
  177. # - Linux/ppc (native): /usr
  178. # - NetBSD/ppc (native): you lose ... (must extract these from the
  179. # binutils build directory, plus the native and U-Boot include
  180. # files don't like each other)
  181. #
  182. # So far, this is used only by tools/gdb/Makefile.
  183. ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
  184. BFD_ROOT_DIR = /usr/local/tools
  185. else
  186. ifeq ($(HOSTARCH),$(ARCH))
  187. # native
  188. BFD_ROOT_DIR = /usr
  189. else
  190. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  191. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  192. BFD_ROOT_DIR = /opt/powerpc
  193. endif
  194. endif
  195. ifeq ($(PCI_CLOCK),PCI_66M)
  196. CFLAGS := $(CFLAGS) -DPCI_66M
  197. endif
  198. #########################################################################
  199. export CONFIG_SHELL HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \
  200. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP \
  201. MAKE
  202. export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
  203. #########################################################################
  204. ifndef REMOTE_BUILD
  205. %.s: %.S
  206. $(CPP) $(AFLAGS) -o $@ $<
  207. %.o: %.S
  208. $(CC) $(AFLAGS) -c -o $@ $<
  209. %.o: %.c
  210. $(CC) $(CFLAGS) -c -o $@ $<
  211. else
  212. $(obj)%.s: %.S
  213. $(CPP) $(AFLAGS) -o $@ $<
  214. $(obj)%.o: %.S
  215. $(CC) $(AFLAGS) -c -o $@ $<
  216. $(obj)%.o: %.c
  217. $(CC) $(CFLAGS) -c -o $@ $<
  218. endif
  219. #########################################################################
    从board/samsung/smdkc110/u-boot.lds可知

点击(此处)折叠或打开

  1. .text :
  2.     {
  3.      cpu/s5pc11x/start.o    (.text)
  4.      cpu/s5pc11x/s5pc110/cpu_init.o    (.text)
  5.      board/samsung/smdkc110/lowlevel_init.o    (.text)
  6.           cpu/s5pc11x/onenand_cp.o (.text)
  7.           cpu/s5pc11x/nand_cp.o (.text)
  8.           cpu/s5pc11x/movi.o (.text)
  9.           common/secure_boot.o (.text)
  10.      common/ace_sha1.o (.text)
  11.      cpu/s5pc11x/pmic.o (.text)
  12.      *(.text)
  13.     }
    生成的bin文件从cpu/s5pc11x/start.o开始执行。
  
    ***********************include $(TOPDIR)/config.mk加载其他配置分析*******************************    
   
***********************Makefile总结******************************* 
  顶层Makefile包含了各个子Makefile,并且用export定义了全局变量。当make时,Makefile顺序往下拓展执行,各个子Makefile被include进来,依据全局变量的定义,决定是否包含其他文件
   ***********************Makefile总结*******************************     
     
   
             

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