歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

u-boot2010.03 Makefile分析

對於Makefile 由於源碼特別長,所以,我在這裡就一邊摘錄一邊分析

  1. # Include autoconf.mk before config.mk so that the config options are available
  2. # to all top level build files. We need the dummy all: target to prevent the
  3. # dependency target in autoconf.mk.dep from being the default.
  4. all:
  5. sinclude $(obj)include/autoconf.mk.dep
  6. sinclude $(obj)include/autoconf.mk
  7. # load ARCH, BOARD, and CPU configuration
  8. # 該文件為配置時生成的
  9. include $(obj)include/config.mk
  10. export ARCH CPU BOARD VENDOR SOC
  11. # set default to nothing for native builds
  12. ifeq ($(HOSTARCH),$(ARCH))
  13. CROSS_COMPILE ?= arm-linux-
  14. endif
  15. # load other configuration
  16. include $(TOPDIR)/config.mk

這段代碼中,上面的解釋已經很到位了.我這裡就不多說了,直接看一個相對比較重要的文件include $(TOPDIR)/config.mk
不知道怎麼分析好.就挑幾個重點講下.
1:編譯器的變量聲明
2:連接腳本
3:連接選項

1:編譯器的變量聲明

  1. #
  2. # Include the make variables (CC, etc...)
  3. #
  4. AS = $(CROSS_COMPILE)as
  5. LD = $(CROSS_COMPILE)ld
  6. CC = $(CROSS_COMPILE)gcc
  7. CPP = $(CC) -E
  8. AR = $(CROSS_COMPILE)ar
  9. NM = $(CROSS_COMPILE)nm
  10. LDR = $(CROSS_COMPILE)ldr
  11. STRIP = $(CROSS_COMPILE)strip
  12. OBJCOPY = $(CROSS_COMPILE)objcopy
  13. OBJDUMP = $(CROSS_COMPILE)objdump
  14. RANLIB = $(CROSS_COMPILE)RANLIB

這裡就知道為什麼交叉編譯器只需要指定前綴的原因了。

2:連接腳本

  1. ifndef LDSCRIPT
  2. #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
  3. ifeq ($(CONFIG_NAND_U_BOOT),y)
  4. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
  5. else
  6. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
  7. endif
  8. endif

LDSCRIPT會根據是否啟用nand_boot的選項,來選擇連接腳本,連接腳本可以指定代碼生成的先後位置,比如把nand相關的函數指定到最前面.
uboot就是通過該連接腳本來使start.S這段代碼放到整個程序的最前面,這樣才能保證arm能正常啟動

3:連接選項

  1. LDFLAGS += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS)
  2. ifneq ($(TEXT_BASE),)
  3. LDFLAGS += -Ttext $(TEXT_BASE)
  4. endif

LDFLAGS指明在連接的時候,指定連接地址,還有連接腳本的參數之類的.

剩下的就自己分析吧....

再回到Makefile,指定要編譯的對象了

  1. #########################################################################
  2. # U-Boot objects....order is important (i.e. start must be first)
  3. OBJS = cpu/$(CPU)/start.o
  4. ifeq ($(CPU),i386)
  5. OBJS += cpu/$(CPU)/start16.o
  6. OBJS += cpu/$(CPU)/resetvec.o
  7. endif
  8. ifeq ($(CPU),ppc4xx)
  9. OBJS += cpu/$(CPU)/resetvec.o
  10. endif
  11. ifeq ($(CPU),mpc85xx)
  12. OBJS += cpu/$(CPU)/resetvec.o
  13. endif
  14. OBJS := $(addprefix $(obj),$(OBJS))
  15. LIBS = lib_generic/libgeneric.a
  16. LIBS += lib_generic/lzma/liblzma.a
  17. LIBS += lib_generic/lzo/liblzo.a
  18. LIBS += $(shell if [ -f board/$(VENDOR)/common/Makefile ]; then echo \
  19. "board/$(VENDOR)/common/lib$(VENDOR).a"; fi)
  20. LIBS += cpu/$(CPU)/lib$(CPU).a
  21. ifdef SOC
  22. LIBS += cpu/$(CPU)/$(SOC)/lib$(SOC).a
  23. endif
  24. ifeq ($(CPU),ixp)
  25. LIBS += cpu/ixp/npe/libnpe.a
  26. endif
  27. LIBS += lib_$(ARCH)/lib$(ARCH).a
  28. LIBS += fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a \
  29. fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a fs/yaffs2/libyaffs2.a \
  30. fs/ubifs/libubifs.a
  31. LIBS += net/libnet.a
  32. LIBS += disk/libdisk.a
  33. LIBS += drivers/bios_emulator/libatibiosemu.a
  34. LIBS += drivers/block/libblock.a
  35. LIBS += drivers/dma/libdma.a
  36. LIBS += drivers/fpga/libfpga.a
  37. LIBS += drivers/gpio/libgpio.a
  38. LIBS += drivers/hwmon/libhwmon.a
  39. LIBS += drivers/i2c/libi2c.a
  40. LIBS += drivers/input/libinput.a
  41. LIBS += drivers/misc/libmisc.a
  42. LIBS += drivers/mmc/libmmc.a
  43. LIBS += drivers/mtd/libmtd.a
  44. LIBS += drivers/mtd/nand/libnand.a
  45. LIBS += drivers/mtd/onenand/libonenand.a
  46. LIBS += drivers/mtd/ubi/libubi.a
  47. LIBS += drivers/mtd/spi/libspi_flash.a
  48. LIBS += drivers/net/libnet.a
  49. LIBS += drivers/net/phy/libphy.a
  50. LIBS += drivers/pci/libpci.a
  51. LIBS += drivers/pcmcia/libpcmcia.a
  52. LIBS += drivers/power/libpower.a
  53. LIBS += drivers/spi/libspi.a
  54. ifeq ($(CPU),mpc83xx)
  55. LIBS += drivers/qe/qe.a
  56. endif
  57. ifeq ($(CPU),mpc85xx)
  58. LIBS += drivers/qe/qe.a
  59. LIBS += cpu/mpc8xxx/ddr/libddr.a
  60. LIBS += cpu/mpc8xxx/lib8xxx.a
  61. endif
  62. ifeq ($(CPU),mpc86xx)
  63. LIBS += cpu/mpc8xxx/ddr/libddr.a
  64. LIBS += cpu/mpc8xxx/lib8xxx.a
  65. endif
  66. LIBS += drivers/rtc/librtc.a
  67. LIBS += drivers/serial/libserial.a
  68. LIBS += drivers/twserial/libtws.a
  69. LIBS += drivers/usb/gadget/libusb_gadget.a
  70. LIBS += drivers/usb/host/libusb_host.a
  71. LIBS += drivers/usb/musb/libusb_musb.a
  72. LIBS += drivers/usb/phy/libusb_phy.a
  73. LIBS += drivers/video/libvideo.a
  74. LIBS += drivers/watchdog/libwatchdog.a
  75. LIBS += common/libcommon.a
  76. LIBS += libfdt/libfdt.a
  77. LIBS += api/libapi.a
  78. LIBS += post/libpost.a
  79. LIBS := $(addprefix $(obj),$(LIBS))
  80. .PHONY : $(LIBS) $(TIMESTAMP_FILE) $(VERSION_FILE)
  81. LIBBOARD = board/$(BOARDDIR)/lib$(BOARD).a
  82. LIBBOARD := $(addprefix $(obj),$(LIBBOARD))
  83. # Add GCC lib
  84. ifdef USE_PRIVATE_LIBGCC
  85. ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
  86. PLATFORM_LIBGCC = -L $(OBJTREE)/lib_$(ARCH) -lgcc
  87. else
  88. PLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC) -lgcc
  89. endif
  90. else
  91. PLATFORM_LIBGCC = -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc
  92. endif
  93. PLATFORM_LIBS += $(PLATFORM_LIBGCC)
  94. export PLATFORM_LIBS
  95. # Special flags for CPP when processing the linker script.
  96. # Pass the version down so we can handle backwards compatibility
  97. # on the fly.
  98. LDPPFLAGS += \
  99. -include $(TOPDIR)/include/u-boot/u-boot.lds.h \
  100. $(shell $(LD) --version | \
  101. sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
  102. ifeq ($(CONFIG_NAND_U_BOOT),y)
  103. NAND_SPL = nand_spl
  104. U_BOOT_NAND = $(obj)u-boot-nand.bin
  105. endif
  106. ifeq ($(CONFIG_ONENAND_U_BOOT),y)
  107. ONENAND_IPL = onenand_ipl
  108. U_BOOT_ONENAND = $(obj)u-boot-onenand.bin
  109. ONENAND_BIN ?= $(obj)onenand_ipl/onenand-ipl-2k.bin
  110. endif
  111. __OBJS := $(subst $(obj),,$(OBJS))
  112. __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))
  113. #########################################################################
  114. #########################################################################
Copyright © Linux教程網 All Rights Reserved