btrfs-progs: fix build with musl
[buildroot-gz.git] / boot / uboot / uboot.mk
blob1e22eaa8eab1ff67cf5ad3502fff00c629cee716
1 ################################################################################
3 # uboot
5 ################################################################################
7 UBOOT_VERSION = $(call qstrip,$(BR2_TARGET_UBOOT_VERSION))
8 UBOOT_BOARD_NAME = $(call qstrip,$(BR2_TARGET_UBOOT_BOARDNAME))
10 UBOOT_LICENSE = GPLv2+
11 UBOOT_LICENSE_FILES = Licenses/gpl-2.0.txt
13 UBOOT_INSTALL_IMAGES = YES
15 ifeq ($(UBOOT_VERSION),custom)
16 # Handle custom U-Boot tarballs as specified by the configuration
17 UBOOT_TARBALL = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION))
18 UBOOT_SITE = $(patsubst %/,%,$(dir $(UBOOT_TARBALL)))
19 UBOOT_SOURCE = $(notdir $(UBOOT_TARBALL))
20 BR_NO_CHECK_HASH_FOR += $(UBOOT_SOURCE)
21 else ifeq ($(BR2_TARGET_UBOOT_CUSTOM_GIT),y)
22 UBOOT_SITE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_REPO_URL))
23 UBOOT_SITE_METHOD = git
24 else ifeq ($(BR2_TARGET_UBOOT_CUSTOM_HG),y)
25 UBOOT_SITE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_REPO_URL))
26 UBOOT_SITE_METHOD = hg
27 else ifeq ($(BR2_TARGET_UBOOT_CUSTOM_SVN),y)
28 UBOOT_SITE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_REPO_URL))
29 UBOOT_SITE_METHOD = svn
30 else
31 # Handle stable official U-Boot versions
32 UBOOT_SITE = ftp://ftp.denx.de/pub/u-boot
33 UBOOT_SOURCE = u-boot-$(UBOOT_VERSION).tar.bz2
34 ifeq ($(BR2_TARGET_UBOOT_CUSTOM_VERSION),y)
35 BR_NO_CHECK_HASH_FOR += $(UBOOT_SOURCE)
36 endif
37 endif
39 ifeq ($(BR2_TARGET_UBOOT_FORMAT_BIN),y)
40 UBOOT_BINS += u-boot.bin
41 endif
43 ifeq ($(BR2_TARGET_UBOOT_FORMAT_ELF),y)
44 UBOOT_BINS += u-boot
45 # To make elf usable for debuging on ARC use special target
46 ifeq ($(BR2_arc),y)
47 UBOOT_MAKE_TARGET += mdbtrick
48 endif
49 endif
51 # Call 'make all' unconditionally
52 UBOOT_MAKE_TARGET += all
54 ifeq ($(BR2_TARGET_UBOOT_FORMAT_KWB),y)
55 UBOOT_BINS += u-boot.kwb
56 UBOOT_MAKE_TARGET += u-boot.kwb
57 endif
59 ifeq ($(BR2_TARGET_UBOOT_FORMAT_AIS),y)
60 UBOOT_BINS += u-boot.ais
61 UBOOT_MAKE_TARGET += u-boot.ais
62 endif
64 ifeq ($(BR2_TARGET_UBOOT_FORMAT_LDR),y)
65 UBOOT_BINS += u-boot.ldr
66 endif
68 ifeq ($(BR2_TARGET_UBOOT_FORMAT_NAND_BIN),y)
69 UBOOT_BINS += u-boot-nand.bin
70 endif
72 ifeq ($(BR2_TARGET_UBOOT_FORMAT_DTB_IMG),y)
73 UBOOT_BINS += u-boot-dtb.img
74 UBOOT_MAKE_TARGET += u-boot-dtb.img
75 endif
77 ifeq ($(BR2_TARGET_UBOOT_FORMAT_DTB_BIN),y)
78 UBOOT_BINS += u-boot-dtb.bin
79 UBOOT_MAKE_TARGET += u-boot-dtb.bin
80 endif
82 ifeq ($(BR2_TARGET_UBOOT_FORMAT_IMG),y)
83 UBOOT_BINS += u-boot.img
84 UBOOT_MAKE_TARGET += u-boot.img
85 endif
87 ifeq ($(BR2_TARGET_UBOOT_FORMAT_IMX),y)
88 UBOOT_BINS += u-boot.imx
89 UBOOT_MAKE_TARGET += u-boot.imx
90 endif
92 ifeq ($(BR2_TARGET_UBOOT_FORMAT_SB),y)
93 UBOOT_BINS += u-boot.sb
94 UBOOT_MAKE_TARGET += u-boot.sb
95 # mxsimage needs OpenSSL
96 UBOOT_DEPENDENCIES += host-elftosb host-openssl
97 endif
99 ifeq ($(BR2_TARGET_UBOOT_FORMAT_SD),y)
100 # BootStream (.sb) is generated by U-Boot, we convert it to SD format
101 UBOOT_BINS += u-boot.sd
102 UBOOT_MAKE_TARGET += u-boot.sb
103 UBOOT_DEPENDENCIES += host-elftosb host-openssl
104 endif
106 ifeq ($(BR2_TARGET_UBOOT_FORMAT_NAND),y)
107 UBOOT_BINS += u-boot.nand
108 UBOOT_MAKE_TARGET += u-boot.sb
109 UBOOT_DEPENDENCIES += host-elftosb host-openssl
110 endif
112 ifeq ($(BR2_TARGET_UBOOT_FORMAT_CUSTOM),y)
113 UBOOT_BINS += $(call qstrip,$(BR2_TARGET_UBOOT_FORMAT_CUSTOM_NAME))
114 endif
116 ifeq ($(BR2_TARGET_UBOOT_OMAP_IFT),y)
117 UBOOT_BINS += u-boot.bin
118 UBOOT_BIN_IFT = u-boot.bin.ift
119 endif
121 # The kernel calls AArch64 'arm64', but U-Boot calls it just 'arm', so
122 # we have to special case it. Similar for i386/x86_64 -> x86
123 ifeq ($(KERNEL_ARCH),arm64)
124 UBOOT_ARCH = arm
125 else ifneq ($(filter $(KERNEL_ARCH),i386 x86_64),)
126 UBOOT_ARCH = x86
127 else
128 UBOOT_ARCH = $(KERNEL_ARCH)
129 endif
131 UBOOT_MAKE_OPTS += \
132 CROSS_COMPILE="$(TARGET_CROSS)" \
133 ARCH=$(UBOOT_ARCH) \
134 HOSTCC="$(HOSTCC) $(HOST_CFLAGS)" \
135 HOSTLDFLAGS="$(HOST_LDFLAGS)"
137 ifeq ($(BR2_TARGET_UBOOT_NEEDS_DTC),y)
138 UBOOT_DEPENDENCIES += host-dtc
139 endif
141 ifeq ($(BR2_TARGET_UBOOT_NEEDS_OPENSSL),y)
142 UBOOT_DEPENDENCIES += host-openssl
143 endif
145 # prior to u-boot 2013.10 the license info was in COPYING. Copy it so
146 # legal-info finds it
147 define UBOOT_COPY_OLD_LICENSE_FILE
148 if [ -f $(@D)/COPYING ]; then \
149 $(INSTALL) -m 0644 -D $(@D)/COPYING $(@D)/Licenses/gpl-2.0.txt; \
151 endef
153 UBOOT_POST_EXTRACT_HOOKS += UBOOT_COPY_OLD_LICENSE_FILE
154 UBOOT_POST_RSYNC_HOOKS += UBOOT_COPY_OLD_LICENSE_FILE
156 # Analogous code exists in linux/linux.mk. Basically, the generic
157 # package infrastructure handles downloading and applying remote
158 # patches. Local patches are handled depending on whether they are
159 # directories or files.
160 UBOOT_PATCHES = $(call qstrip,$(BR2_TARGET_UBOOT_PATCH))
161 UBOOT_PATCH = $(filter ftp://% http://% https://%,$(UBOOT_PATCHES))
163 define UBOOT_APPLY_LOCAL_PATCHES
164 for p in $(filter-out ftp://% http://% https://%,$(UBOOT_PATCHES)) ; do \
165 if test -d $$p ; then \
166 $(APPLY_PATCHES) $(@D) $$p \*.patch || exit 1 ; \
167 else \
168 $(APPLY_PATCHES) $(@D) `dirname $$p` `basename $$p` || exit 1; \
169 fi \
170 done
171 endef
172 UBOOT_POST_PATCH_HOOKS += UBOOT_APPLY_LOCAL_PATCHES
174 ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY),y)
175 define UBOOT_CONFIGURE_CMDS
176 $(TARGET_CONFIGURE_OPTS) \
177 $(MAKE) -C $(@D) $(UBOOT_MAKE_OPTS) \
178 $(UBOOT_BOARD_NAME)_config
179 endef
180 else ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG),y)
181 ifeq ($(BR2_TARGET_UBOOT_USE_DEFCONFIG),y)
182 UBOOT_KCONFIG_DEFCONFIG = $(call qstrip,$(BR2_TARGET_UBOOT_BOARD_DEFCONFIG))_defconfig
183 else ifeq ($(BR2_TARGET_UBOOT_USE_CUSTOM_CONFIG),y)
184 UBOOT_KCONFIG_FILE = $(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE))
185 endif # BR2_TARGET_UBOOT_USE_DEFCONFIG
187 UBOOT_KCONFIG_EDITORS = menuconfig xconfig gconfig nconfig
188 UBOOT_KCONFIG_OPTS = $(UBOOT_MAKE_OPTS)
189 define UBOOT_HELP_CMDS
190 @echo ' uboot-menuconfig - Run U-Boot menuconfig'
191 @echo ' uboot-savedefconfig - Run U-Boot savedefconfig'
192 @echo ' uboot-update-defconfig - Save the U-Boot configuration to the path specified'
193 @echo ' by BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE'
194 endef
195 endif # BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY
197 define UBOOT_BUILD_CMDS
198 $(TARGET_CONFIGURE_OPTS) \
199 $(MAKE) -C $(@D) $(UBOOT_MAKE_OPTS) \
200 $(UBOOT_MAKE_TARGET)
201 $(if $(BR2_TARGET_UBOOT_FORMAT_SD),
202 $(@D)/tools/mxsboot sd $(@D)/u-boot.sb $(@D)/u-boot.sd)
203 $(if $(BR2_TARGET_UBOOT_FORMAT_NAND),
204 $(@D)/tools/mxsboot \
205 -w $(BR2_TARGET_UBOOT_FORMAT_NAND_PAGE_SIZE) \
206 -o $(BR2_TARGET_UBOOT_FORMAT_NAND_OOB_SIZE) \
207 -e $(BR2_TARGET_UBOOT_FORMAT_NAND_ERASE_SIZE) \
208 nand $(@D)/u-boot.sb $(@D)/u-boot.nand)
209 endef
211 define UBOOT_BUILD_OMAP_IFT
212 $(HOST_DIR)/usr/bin/gpsign -f $(@D)/u-boot.bin \
213 -c $(call qstrip,$(BR2_TARGET_UBOOT_OMAP_IFT_CONFIG))
214 endef
216 define UBOOT_INSTALL_IMAGES_CMDS
217 $(foreach f,$(UBOOT_BINS), \
218 cp -dpf $(@D)/$(f) $(BINARIES_DIR)/
220 $(if $(BR2_TARGET_UBOOT_FORMAT_NAND),
221 cp -dpf $(@D)/u-boot.sb $(BINARIES_DIR))
222 $(if $(BR2_TARGET_UBOOT_SPL),
223 $(foreach f,$(call qstrip,$(BR2_TARGET_UBOOT_SPL_NAME)), \
224 cp -dpf $(@D)/$(f) $(BINARIES_DIR)/
227 $(if $(BR2_TARGET_UBOOT_ENVIMAGE),
228 cat $(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SOURCE)) | \
229 $(HOST_DIR)/usr/bin/mkenvimage -s $(BR2_TARGET_UBOOT_ENVIMAGE_SIZE) \
230 $(if $(BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT),-r) \
231 $(if $(filter BIG,$(BR2_ENDIAN)),-b) \
232 -o $(BINARIES_DIR)/uboot-env.bin -)
233 endef
235 define UBOOT_INSTALL_OMAP_IFT_IMAGE
236 cp -dpf $(@D)/$(UBOOT_BIN_IFT) $(BINARIES_DIR)/
237 endef
239 ifeq ($(BR2_TARGET_UBOOT_OMAP_IFT),y)
240 ifeq ($(BR_BUILDING),y)
241 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_OMAP_IFT_CONFIG)),)
242 $(error No gpsign config file. Check your BR2_TARGET_UBOOT_OMAP_IFT_CONFIG setting)
243 endif
244 ifeq ($(wildcard $(call qstrip,$(BR2_TARGET_UBOOT_OMAP_IFT_CONFIG))),)
245 $(error gpsign config file $(BR2_TARGET_UBOOT_OMAP_IFT_CONFIG) not found. Check your BR2_TARGET_UBOOT_OMAP_IFT_CONFIG setting)
246 endif
247 endif
248 UBOOT_DEPENDENCIES += host-omap-u-boot-utils
249 UBOOT_POST_BUILD_HOOKS += UBOOT_BUILD_OMAP_IFT
250 UBOOT_POST_INSTALL_IMAGES_HOOKS += UBOOT_INSTALL_OMAP_IFT_IMAGE
251 endif
253 ifeq ($(BR2_TARGET_UBOOT_ZYNQ_IMAGE),y)
254 define UBOOT_GENERATE_ZYNQ_IMAGE
255 $(HOST_DIR)/usr/bin/python2 \
256 $(HOST_DIR)/usr/bin/zynq-boot-bin.py \
257 -u $(@D)/$(firstword $(call qstrip,$(BR2_TARGET_UBOOT_SPL_NAME))) \
258 -o $(BINARIES_DIR)/BOOT.BIN
259 endef
260 UBOOT_DEPENDENCIES += host-zynq-boot-bin
261 UBOOT_POST_INSTALL_IMAGES_HOOKS += UBOOT_GENERATE_ZYNQ_IMAGE
262 endif
264 ifeq ($(BR2_TARGET_UBOOT_ALTERA_SOCFPGA_IMAGE_CRC),y)
265 ifeq ($(BR2_TARGET_UBOOT_SPL),y)
266 UBOOT_CRC_ALTERA_SOCFPGA_INPUT_IMAGES = $(call qstrip,$(BR2_TARGET_UBOOT_SPL_NAME))
267 UBOOT_CRC_ALTERA_SOCFPGA_HEADER_VERSION = 0
268 else
269 UBOOT_CRC_ALTERA_SOCFPGA_INPUT_IMAGES = u-boot-dtb.bin
270 UBOOT_CRC_ALTERA_SOCFPGA_HEADER_VERSION = 1
271 endif
272 define UBOOT_CRC_ALTERA_SOCFPGA_IMAGE
273 $(foreach f,$(UBOOT_CRC_ALTERA_SOCFPGA_INPUT_IMAGES), \
274 $(HOST_DIR)/usr/bin/mkpimage \
275 -v $(UBOOT_CRC_ALTERA_SOCFPGA_HEADER_VERSION) \
276 -o $(BINARIES_DIR)/$(notdir $(call qstrip,$(f))).crc \
277 $(@D)/$(call qstrip,$(f))
279 endef
280 UBOOT_DEPENDENCIES += host-mkpimage
281 UBOOT_POST_INSTALL_IMAGES_HOOKS += UBOOT_CRC_ALTERA_SOCFPGA_IMAGE
282 endif
284 ifeq ($(BR2_TARGET_UBOOT_ENVIMAGE),y)
285 ifeq ($(BR_BUILDING),y)
286 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SOURCE)),)
287 $(error Please define a source file for Uboot environment (BR2_TARGET_UBOOT_ENVIMAGE_SOURCE setting))
288 endif
289 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SIZE)),)
290 $(error Please provide Uboot environment size (BR2_TARGET_UBOOT_ENVIMAGE_SIZE setting))
291 endif
292 endif
293 UBOOT_DEPENDENCIES += host-uboot-tools
294 endif
296 ifeq ($(BR2_TARGET_UBOOT)$(BR_BUILDING),yy)
299 # Check U-Boot board name (for legacy) or the defconfig/custom config
300 # file options (for kconfig)
302 ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY),y)
303 ifeq ($(UBOOT_BOARD_NAME),)
304 $(error No U-Boot board name set. Check your BR2_TARGET_UBOOT_BOARDNAME setting)
305 endif # UBOOT_BOARD_NAME
306 else ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG),y)
307 ifeq ($(BR2_TARGET_UBOOT_USE_DEFCONFIG),y)
308 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_BOARD_DEFCONFIG)),)
309 $(error No board defconfig name specified, check your BR2_TARGET_UBOOT_DEFCONFIG setting)
310 endif # qstrip BR2_TARGET_UBOOT_BOARD_DEFCONFIG
311 endif # BR2_TARGET_UBOOT_USE_DEFCONFIG
312 ifeq ($(BR2_TARGET_UBOOT_USE_CUSTOM_CONFIG),y)
313 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE)),)
314 $(error No board configuration file specified, check your BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE setting)
315 endif # qstrip BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE
316 endif # BR2_TARGET_UBOOT_USE_CUSTOM_CONFIG
317 endif # BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY
320 # Check custom version option
322 ifeq ($(BR2_TARGET_UBOOT_CUSTOM_VERSION),y)
323 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE)),)
324 $(error No custom U-Boot version specified. Check your BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE setting)
325 endif # qstrip BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE
326 endif # BR2_TARGET_UBOOT_CUSTOM_VERSION
329 # Check custom tarball option
331 ifeq ($(BR2_TARGET_UBOOT_CUSTOM_TARBALL),y)
332 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION)),)
333 $(error No custom U-Boot tarball specified. Check your BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION setting)
334 endif # qstrip BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION
335 endif # BR2_TARGET_UBOOT_CUSTOM_TARBALL
338 # Check Git/Mercurial repo options
340 ifeq ($(BR2_TARGET_UBOOT_CUSTOM_GIT)$(BR2_TARGET_UBOOT_CUSTOM_HG),y)
341 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_REPO_URL)),)
342 $(error No custom U-Boot repository URL specified. Check your BR2_TARGET_UBOOT_CUSTOM_REPO_URL setting)
343 endif # qstrip BR2_TARGET_UBOOT_CUSTOM_CUSTOM_REPO_URL
344 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_CUSTOM_REPO_VERSION)),)
345 $(error No custom U-Boot repository URL specified. Check your BR2_TARGET_UBOOT_CUSTOM_REPO_VERSION setting)
346 endif # qstrip BR2_TARGET_UBOOT_CUSTOM_CUSTOM_REPO_VERSION
347 endif # BR2_TARGET_UBOOT_CUSTOM_GIT || BR2_TARGET_UBOOT_CUSTOM_HG
349 endif # BR2_TARGET_UBOOT && BR_BUILDING
351 ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY),y)
352 $(eval $(generic-package))
353 else ifeq ($(BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG),y)
354 $(eval $(kconfig-package))
355 endif # BR2_TARGET_UBOOT_BUILD_SYSTEM_LEGACY