1 # SPDX-License-Identifier: GPL-2.0+
3 # (C) Copyright 2000-2006
4 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 # A note on target vs host configuration:
8 # Host tools can be used across multiple targets, or different configurations
9 # of the same target. Thus, host tools must be able to handle any combination
10 # of target configurations. To prevent having different variations of the same
11 # tool, the tool build options may not depend on target configuration.
13 # Some linux distributions package these utilities as u-boot-tools, and it
14 # would be unmaintainable to have a different tool variation for each
15 # arch or configuration.
17 # A couple of simple rules:
19 # 1) Do not use target CONFIG_* options to enable or disable features in host
20 # tools. Only use the configs from tools/Kconfig
21 # 2) It's okay to use target configs to disable building specific tools.
22 # That's as long as the features of those tools aren't modified.
25 # Enable all the config-independent tools
26 ifneq ($(HOST_TOOLS_ALL),)
27 CONFIG_ARCH_KIRKWOOD = y
31 CONFIG_XWAY_SWAP_BYTES = y
33 CONFIG_SHA1_CHECK_UB_IMG = y
37 subdir-$(HOST_TOOLS_ALL) += gdb
39 # Merge all the different vars for envcrc into one
40 ENVCRC-$(CONFIG_ENV_IS_EMBEDDED) = y
41 ENVCRC-$(CONFIG_ENV_IS_IN_EEPROM) = y
42 ENVCRC-$(CONFIG_ENV_IS_IN_FLASH) = y
43 ENVCRC-$(CONFIG_ENV_IS_IN_ONENAND) = y
44 ENVCRC-$(CONFIG_ENV_IS_IN_NAND) = y
45 ENVCRC-$(CONFIG_ENV_IS_IN_NVRAM) = y
46 ENVCRC-$(CONFIG_ENV_IS_IN_SPI_FLASH) = y
47 CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
49 hostprogs-$(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER) += atmel_pmecc_params
51 hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo
52 hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo
53 HOSTCFLAGS_bmp_logo.o := -pedantic
55 hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc
56 envcrc-objs := envcrc.o lib/crc32.o env/embedded.o lib/sha1.o
58 hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
59 HOSTCFLAGS_gen_eth_addr.o := -pedantic
61 hostprogs-$(CONFIG_CMD_NET) += gen_ethaddr_crc
62 gen_ethaddr_crc-objs := gen_ethaddr_crc.o lib/crc8.o
63 HOSTCFLAGS_gen_ethaddr_crc.o := -pedantic
65 hostprogs-$(CONFIG_CMD_LOADS) += img2srec
66 HOSTCFLAGS_img2srec.o := -pedantic
68 hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes
69 HOSTCFLAGS_xway-swap-bytes.o := -pedantic
71 hostprogs-y += mkenvimage
72 mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
74 hostprogs-y += dumpimage mkimage
75 hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign
77 hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
79 FIT_OBJS-y := fit_common.o fit_image.o image-host.o boot/image-fit.o
80 FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o boot/image-fit-sig.o
81 FIT_CIPHER_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := boot/image-cipher.o
83 # The following files are synced with upstream DTC.
84 # Use synced versions from scripts/dtc/libfdt/.
85 LIBFDT_OBJS := $(addprefix libfdt/, fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o \
86 fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o)
88 RSA_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix lib/rsa/, \
89 rsa-sign.o rsa-verify.o \
92 ECDSA_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix lib/ecdsa/, ecdsa-libcrypto.o)
94 AES_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix lib/aes/, \
95 aes-encrypt.o aes-decrypt.o)
97 # Cryptographic helpers and image types that depend on openssl/libcrypto
98 LIBCRYPTO_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := \
102 ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o
104 # common objs for dumpimage and mkimage
105 dumpimage-mkimage-objs := aisimage.o \
109 $(FIT_CIPHER_OBJS-y) \
114 lib/fdtdec_common.o \
136 lib/hash-checksum.o \
145 $(LIBCRYPTO_OBJS-y) \
154 dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
155 mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o
156 fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o
157 fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
158 file2include-objs := file2include.o
160 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_TOOLS_LIBCRYPTO),)
161 # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
162 # the mxsimage support within tools/mxsimage.c .
163 HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
166 ifdef CONFIG_TOOLS_LIBCRYPTO
167 # This affects include/image.h, but including the board config file
168 # is tricky, so manually define this options here.
169 HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE
170 HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE_MAX_SIZE=0xffffffff
171 HOST_EXTRACFLAGS += -DCONFIG_FIT_CIPHER
174 # MXSImage needs LibSSL
175 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_TOOLS_LIBCRYPTO),)
176 HOSTCFLAGS_kwbimage.o += \
177 $(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "")
178 HOSTLDLIBS_mkimage += \
179 $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto")
181 # OS X deprecate openssl in favour of CommonCrypto, supress deprecation
182 # warnings on those systems
183 ifeq ($(HOSTOS),darwin)
184 HOSTCFLAGS_mxsimage.o += -Wno-deprecated-declarations
185 HOSTCFLAGS_image-sig.o += -Wno-deprecated-declarations
186 HOSTCFLAGS_rsa-sign.o += -Wno-deprecated-declarations
190 HOSTCFLAGS_fit_image.o += -DMKIMAGE_DTC=\"$(CONFIG_MKIMAGE_DTC_PATH)\"
192 HOSTLDLIBS_dumpimage := $(HOSTLDLIBS_mkimage)
193 HOSTLDLIBS_fit_info := $(HOSTLDLIBS_mkimage)
194 HOSTLDLIBS_fit_check_sign := $(HOSTLDLIBS_mkimage)
196 hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
197 hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
198 HOSTCFLAGS_mkexynosspl.o := -pedantic
200 HOSTCFLAGS_kwboot.o += -pthread
201 HOSTLDLIBS_kwboot += -pthread
202 HOSTLDLIBS_kwboot += \
203 $(shell pkg-config --libs tinfo 2> /dev/null || echo "-ltinfo")
205 ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o
206 hostprogs-$(CONFIG_X86) += ifdtool
208 ifwitool-objs := ifwitool.o
209 hostprogs-$(CONFIG_X86)$(CONFIG_SANDBOX) += ifwitool
211 hostprogs-$(CONFIG_MX23) += mxsboot
212 hostprogs-$(CONFIG_MX28) += mxsboot
213 HOSTCFLAGS_mxsboot.o := -pedantic
215 hostprogs-$(CONFIG_ARCH_SUNXI) += mksunxiboot
216 hostprogs-$(CONFIG_ARCH_SUNXI) += sunxi-spl-image-builder
217 sunxi-spl-image-builder-objs := sunxi-spl-image-builder.o lib/bch.o
219 hostprogs-$(CONFIG_NETCONSOLE) += ncb
220 hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1
222 ubsha1-objs := os_support.o ubsha1.o lib/sha1.o
224 HOSTCFLAGS_ubsha1.o := -pedantic
226 hostprogs-$(CONFIG_ARCH_KIRKWOOD) += kwboot
227 hostprogs-$(CONFIG_ARCH_MVEBU) += kwboot
228 hostprogs-y += proftool
229 hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
230 hostprogs-$(CONFIG_RISCV) += prelink-riscv
232 hostprogs-$(CONFIG_ARCH_OCTEON) += update_octeon_header
233 update_octeon_header-objs := update_octeon_header.o lib/crc32.o
235 hostprogs-y += fdtgrep
236 fdtgrep-objs += $(LIBFDT_OBJS) boot/fdt_region.o fdtgrep.o
238 ifneq ($(TOOLS_ONLY),y)
239 hostprogs-y += spl_size_limit
242 hostprogs-$(CONFIG_MIPS) += mips-relocs
244 hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler
245 HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
247 HOSTCFLAGS_mkeficapsule.o += \
248 $(shell pkg-config --cflags gnutls 2> /dev/null || echo "")
249 HOSTCFLAGS_mkeficapsule.o += \
250 $(shell pkg-config --cflags uuid 2> /dev/null || echo "")
251 HOSTLDLIBS_mkeficapsule += \
252 $(shell pkg-config --libs gnutls 2> /dev/null || echo "-lgnutls")
253 HOSTLDLIBS_mkeficapsule += \
254 $(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid")
255 hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
257 # We build some files with extra pedantic flags to try to minimize things
258 # that won't build on some weird host compiler -- though there are lots of
259 # exceptions for files that aren't complaint.
260 HOSTCFLAGS_crc32.o := -pedantic
261 HOSTCFLAGS_crc8.o := -pedantic
262 HOSTCFLAGS_md5.o := -pedantic
263 HOSTCFLAGS_sha1.o := -pedantic
264 HOSTCFLAGS_sha256.o := -pedantic
265 HOSTCFLAGS_sha512.o := -pedantic -DCONFIG_SHA512 -DCONFIG_SHA384
267 quiet_cmd_wrap = WRAP $@
268 cmd_wrap = echo "\#include <../$(patsubst $(obj)/%,%,$@)>" >$@
270 $(obj)/boot/%.c $(obj)/common/%.c $(obj)/env/%.c $(obj)/lib/%.c:
273 clean-dirs := lib common
275 always := $(hostprogs-y)
277 # Generated LCD/video logo
278 LOGO_H = $(objtree)/include/bmp_logo.h
279 LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
280 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_H)
281 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_DATA_H)
282 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
283 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
287 LOGO_BMP= $(srctree)/$(src)/logos/denx.bmp
289 # Use board logo and fallback to vendor
290 ifneq ($(wildcard $(srctree)/$(src)/logos/$(BOARD).bmp),)
291 LOGO_BMP= $(srctree)/$(src)/logos/$(BOARD).bmp
293 ifneq ($(wildcard $(srctree)/$(src)/logos/$(VENDOR).bmp),)
294 LOGO_BMP= $(srctree)/$(src)/logos/$(VENDOR).bmp
301 # Use native tools and options
302 # Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
303 # Define _GNU_SOURCE to obtain the getline prototype from stdio.h
305 HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
306 $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
307 -I$(srctree)/scripts/dtc/libfdt \
310 -D__KERNEL_STRICT_NAMES \
315 $(LOGO_H): $(obj)/bmp_logo $(LOGO_BMP)
316 $(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
318 ifeq ($(CONFIG_DM_VIDEO),y)
319 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
320 $(obj)/bmp_logo --gen-bmp $(LOGO_BMP) > $@
322 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
323 $(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
327 # Let clean descend into subdirs
330 ifneq ($(CROSS_BUILD_TOOLS),)
331 override HOSTCC = $(CC)
332 override HOSTCFLAGS = $(CFLAGS)
334 quiet_cmd_crosstools_strip = STRIP $^
335 cmd_crosstools_strip = $(STRIP) $^; touch $@
336 $(obj)/.strip: $(call objectify,$(filter $(always),$(hostprogs-y)))
337 $(call cmd,crosstools_strip)
341 clean-files += .strip