u-boot.mk 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #############################################################
  2. #
  3. # U-Boot
  4. #
  5. #############################################################
  6. U_BOOT_VERSION:=$(call qstrip,$(BR2_TARGET_UBOOT_VERSION))
  7. U_BOOT_BOARD_NAME:=$(call qstrip,$(BR2_TARGET_UBOOT_BOARDNAME))
  8. # U-Boot may not be selected in the configuration, but mkimage might
  9. # be needed to build/prepare a kernel image. In this case, we just
  10. # pick some random stable U-Boot version that will be used just to
  11. # build mkimage.
  12. ifeq ($(U_BOOT_VERSION),)
  13. U_BOOT_VERSION=2010.03
  14. endif
  15. ifeq ($(U_BOOT_VERSION),custom)
  16. # Handle custom U-Boot tarballs as specified by the configuration
  17. U_BOOT_TARBALL=$(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION))
  18. U_BOOT_SITE:=$(dir $(U_BOOT_TARBALL))
  19. U_BOOT_SOURCE:=$(notdir $(U_BOOT_TARBALL))
  20. else
  21. # Handle stable official U-Boot versions
  22. U_BOOT_SITE:=ftp://ftp.denx.de/pub/u-boot
  23. U_BOOT_SOURCE:=u-boot-$(U_BOOT_VERSION).tar.bz2
  24. endif
  25. U_BOOT_DIR:=$(BUILD_DIR)/u-boot-$(U_BOOT_VERSION)
  26. U_BOOT_CAT:=$(BZCAT)
  27. ifeq ($(BR2_TARGET_UBOOT_FORMAT_KWB),y)
  28. U_BOOT_BIN:=u-boot.kwb
  29. U_BOOT_MAKE_OPT:=$(U_BOOT_BIN)
  30. else
  31. U_BOOT_BIN:=u-boot.bin
  32. endif
  33. MKIMAGE:=$(HOST_DIR)/usr/bin/mkimage
  34. U_BOOT_TARGETS:=$(BINARIES_DIR)/$(U_BOOT_BIN) $(MKIMAGE)
  35. U_BOOT_ARCH=$(KERNEL_ARCH)
  36. # u-boot in the past used arch=ppc for powerpc
  37. ifneq ($(findstring x200,x$(U_BOOT_VERSION))$(findstring x2010.03,x$(U_BOOT_VERSION)),)
  38. U_BOOT_ARCH=$(KERNEL_ARCH:powerpc=ppc)
  39. endif
  40. U_BOOT_INC_CONF_FILE:=$(U_BOOT_DIR)/include/config.h
  41. ifeq ($(BR2_TARGET_UBOOT_TOOL_MKIMAGE),y)
  42. U_BOOT_TARGETS+=$(TARGET_DIR)/usr/bin/mkimage
  43. endif
  44. ifeq ($(BR2_TARGET_UBOOT_TOOL_ENV),y)
  45. U_BOOT_TARGETS+=$(TARGET_DIR)/usr/sbin/fw_printenv
  46. endif
  47. U_BOOT_CONFIGURE_OPTS += CONFIG_NOSOFTFLOAT=1
  48. # Define a helper function
  49. define insert_define
  50. @echo "#ifdef $(strip $(1))" >> $(U_BOOT_INC_CONF_FILE)
  51. @echo "#undef $(strip $(1))" >> $(U_BOOT_INC_CONF_FILE)
  52. @echo "#endif" >> $(U_BOOT_INC_CONF_FILE)
  53. @echo '#define $(strip $(1)) $(call qstrip,$(2))' >> $(U_BOOT_INC_CONF_FILE)
  54. endef
  55. $(DL_DIR)/$(U_BOOT_SOURCE):
  56. $(call DOWNLOAD,$(U_BOOT_SITE),$(U_BOOT_SOURCE))
  57. $(U_BOOT_DIR)/.unpacked: $(DL_DIR)/$(U_BOOT_SOURCE)
  58. mkdir -p $(@D)
  59. $(INFLATE$(suffix $(U_BOOT_SOURCE))) $(DL_DIR)/$(U_BOOT_SOURCE) \
  60. | tar $(TAR_STRIP_COMPONENTS)=1 -C $(@D) $(TAR_OPTIONS) -
  61. touch $@
  62. $(U_BOOT_DIR)/.patched: $(U_BOOT_DIR)/.unpacked
  63. toolchain/patch-kernel.sh $(U_BOOT_DIR) boot/u-boot \
  64. u-boot-$(U_BOOT_VERSION)-\*.patch \
  65. u-boot-$(U_BOOT_VERSION)-\*.patch.$(ARCH)
  66. ifneq ($(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_PATCH_DIR)),)
  67. toolchain/patch-kernel.sh $(U_BOOT_DIR) $(BR2_TARGET_UBOOT_CUSTOM_PATCH_DIR) u-boot-$(U_BOOT_VERSION)-\*.patch
  68. endif
  69. touch $@
  70. $(U_BOOT_DIR)/.configured: $(U_BOOT_DIR)/.patched
  71. ifeq ($(U_BOOT_BOARD_NAME),)
  72. $(error NO U-Boot board name set. Check your BR2_TARGET_UBOOT_BOARDNAME setting)
  73. endif
  74. $(TARGET_CONFIGURE_OPTS) \
  75. $(U_BOOT_CONFIGURE_OPTS) \
  76. $(MAKE) -C $(U_BOOT_DIR) \
  77. CROSS_COMPILE="$(TARGET_CROSS)" ARCH=$(U_BOOT_ARCH) \
  78. $(U_BOOT_BOARD_NAME)_config
  79. touch $@
  80. $(U_BOOT_DIR)/.header_modified: $(U_BOOT_DIR)/.configured
  81. # Modify configuration header in $(U_BOOT_INC_CONF_FILE)
  82. ifdef BR2_TARGET_UBOOT_NETWORK
  83. @echo >> $(U_BOOT_INC_CONF_FILE)
  84. @echo "/* Add a wrapper around the values Buildroot sets. */" >> $(U_BOOT_INC_CONF_FILE)
  85. @echo "#ifndef __BR2_ADDED_CONFIG_H" >> $(U_BOOT_INC_CONF_FILE)
  86. @echo "#define __BR2_ADDED_CONFIG_H" >> $(U_BOOT_INC_CONF_FILE)
  87. $(call insert_define, DATE, $(DATE))
  88. $(call insert_define, CONFIG_LOAD_SCRIPTS, 1)
  89. ifneq ($(strip $(BR2_TARGET_UBOOT_IPADDR)),"")
  90. $(call insert_define, CONFIG_IPADDR, $(BR2_TARGET_UBOOT_IPADDR))
  91. endif
  92. ifneq ($(strip $(BR2_TARGET_UBOOT_GATEWAY)),"")
  93. $(call insert_define, CONFIG_GATEWAYIP, $(BR2_TARGET_UBOOT_GATEWAY))
  94. endif
  95. ifneq ($(strip $(BR2_TARGET_UBOOT_NETMASK)),"")
  96. $(call insert_define, CONFIG_NETMASK, $(BR2_TARGET_UBOOT_NETMASK))
  97. endif
  98. ifneq ($(strip $(BR2_TARGET_UBOOT_SERVERIP)),"")
  99. $(call insert_define, CONFIG_SERVERIP, $(BR2_TARGET_UBOOT_SERVERIP))
  100. endif
  101. ifneq ($(strip $(BR2_TARGET_UBOOT_ETHADDR)),"")
  102. $(call insert_define, CONFIG_ETHADDR, $(BR2_TARGET_UBOOT_ETHADDR))
  103. endif
  104. ifneq ($(strip $(BR2_TARGET_UBOOT_ETH1ADDR)),"")
  105. $(call insert_define, CONFIG_ETH1ADDR, $(BR2_TARGET_UBOOT_ETH1ADDR))
  106. endif
  107. @echo "#endif /* __BR2_ADDED_CONFIG_H */" >> $(U_BOOT_INC_CONF_FILE)
  108. endif # BR2_TARGET_UBOOT_NETWORK
  109. touch $@
  110. # Build U-Boot itself
  111. $(U_BOOT_DIR)/$(U_BOOT_BIN): $(U_BOOT_DIR)/.header_modified
  112. $(TARGET_CONFIGURE_OPTS) \
  113. CFLAGS="$(TARGET_CFLAGS)" \
  114. LDFLAGS="$(TARGET_LDFLAGS)" \
  115. $(U_BOOT_CONFIGURE_OPTS) \
  116. $(MAKE) CROSS_COMPILE="$(TARGET_CROSS)" ARCH=$(U_BOOT_ARCH) \
  117. $(U_BOOT_MAKE_OPT) -C $(U_BOOT_DIR)
  118. # Copy the result to the images/ directory
  119. $(BINARIES_DIR)/$(U_BOOT_BIN): $(U_BOOT_DIR)/$(U_BOOT_BIN)
  120. rm -f $(BINARIES_DIR)/$(U_BOOT_BIN)
  121. cp -dpf $(U_BOOT_DIR)/$(U_BOOT_BIN) $(BINARIES_DIR)/
  122. # Build just mkimage for the host. It might have already been built by
  123. # the U-Boot build procedure, but mkimage may also be needed even if
  124. # U-Boot isn't selected in the configuration, to generate a kernel
  125. # uImage.
  126. $(MKIMAGE): $(U_BOOT_DIR)/.patched
  127. mkdir -p $(@D)
  128. $(MAKE) -C $(U_BOOT_DIR) tools
  129. cp -dpf $(U_BOOT_DIR)/tools/mkimage $(@D)
  130. # Build manually mkimage for the target
  131. $(TARGET_DIR)/usr/bin/mkimage: $(U_BOOT_DIR)/.configured
  132. mkdir -p $(@D)
  133. $(TARGET_CC) -I$(U_BOOT_DIR)/include -I$(U_BOOT_DIR)/tools \
  134. -DUSE_HOSTCC -o $@ \
  135. $(U_BOOT_DIR)/common/image.c \
  136. $(wildcard $(addprefix $(U_BOOT_DIR)/tools/,default_image.c \
  137. fit_image.c imximage.c kwbimage.c mkimage.c)) \
  138. $(addprefix $(U_BOOT_DIR)/lib*/,crc32.c md5.c sha1.c) \
  139. $(U_BOOT_DIR)/tools/os_support.c \
  140. $(wildcard $(U_BOOT_DIR)/libfdt/fdt*.c $(U_BOOT_DIR)/lib/libfdt/fdt*.c)
  141. $(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $@
  142. # Build manually fw_printenv for the target
  143. $(TARGET_DIR)/usr/sbin/fw_printenv: $(U_BOOT_DIR)/.configured
  144. mkdir -p $(@D)
  145. $(TARGET_CC) -I$(U_BOOT_DIR)/include -I$(LINUX_HEADERS_DIR)/include \
  146. -DUSE_HOSTCC -o $@ \
  147. $(U_BOOT_DIR)/tools/env/*.c $(U_BOOT_DIR)/lib*/crc32.c
  148. $(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $@
  149. ln -sf fw_printenv $(TARGET_DIR)/usr/sbin/fw_setenv
  150. u-boot: $(U_BOOT_TARGETS)
  151. u-boot-clean:
  152. -$(MAKE) -C $(U_BOOT_DIR) clean
  153. rm -f $(MKIMAGE)
  154. u-boot-dirclean:
  155. rm -rf $(U_BOOT_DIR)
  156. u-boot-source: $(DL_DIR)/$(U_BOOT_SOURCE)
  157. u-boot-unpacked: $(U_BOOT_DIR)/.patched
  158. u-boot-configured: $(U_BOOT_DIR)/.header_modified
  159. #############################################################
  160. #
  161. # Toplevel Makefile options
  162. #
  163. #############################################################
  164. ifeq ($(BR2_TARGET_UBOOT),y)
  165. TARGETS+=u-boot
  166. # we NEED a board name unless we're at make source
  167. ifeq ($(filter source,$(MAKECMDGOALS)),)
  168. ifeq ($(U_BOOT_BOARD_NAME),)
  169. $(error NO U-Boot board name set. Check your BR2_TARGET_UBOOT_BOARDNAME setting)
  170. endif
  171. endif
  172. endif