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) \
155 dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
156 mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o
157 fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o
158 fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
159 file2include-objs := file2include.o
161 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_TOOLS_LIBCRYPTO),)
162 # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
163 # the mxsimage support within tools/mxsimage.c .
164 HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
167 ifdef CONFIG_TOOLS_LIBCRYPTO
168 # This affects include/image.h, but including the board config file
169 # is tricky, so manually define this options here.
170 HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE
171 HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE_MAX_SIZE=0xffffffff
172 HOST_EXTRACFLAGS += -DCONFIG_FIT_CIPHER
175 # MXSImage needs LibSSL
176 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_TOOLS_LIBCRYPTO),)
177 HOSTCFLAGS_kwbimage.o += \
178 $(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "")
179 HOSTLDLIBS_mkimage += \
180 $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto")
182 # OS X deprecate openssl in favour of CommonCrypto, supress deprecation
183 # warnings on those systems
184 ifeq ($(HOSTOS),darwin)
185 HOSTCFLAGS_mxsimage.o += -Wno-deprecated-declarations
186 HOSTCFLAGS_image-sig.o += -Wno-deprecated-declarations
187 HOSTCFLAGS_rsa-sign.o += -Wno-deprecated-declarations
191 HOSTCFLAGS_fit_image.o += -DMKIMAGE_DTC=\"$(CONFIG_MKIMAGE_DTC_PATH)\"
193 HOSTLDLIBS_dumpimage := $(HOSTLDLIBS_mkimage)
194 HOSTLDLIBS_fit_info := $(HOSTLDLIBS_mkimage)
195 HOSTLDLIBS_fit_check_sign := $(HOSTLDLIBS_mkimage)
197 hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
198 hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
199 HOSTCFLAGS_mkexynosspl.o := -pedantic
201 HOSTCFLAGS_kwboot.o += -pthread
202 HOSTLDLIBS_kwboot += -pthread
203 HOSTLDLIBS_kwboot += \
204 $(shell pkg-config --libs tinfo 2> /dev/null || echo "-ltinfo")
206 ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o
207 hostprogs-$(CONFIG_X86) += ifdtool
209 ifwitool-objs := ifwitool.o
210 hostprogs-$(CONFIG_X86)$(CONFIG_SANDBOX) += ifwitool
212 hostprogs-$(CONFIG_MX23) += mxsboot
213 hostprogs-$(CONFIG_MX28) += mxsboot
214 HOSTCFLAGS_mxsboot.o := -pedantic
216 hostprogs-$(CONFIG_ARCH_SUNXI) += mksunxiboot
217 hostprogs-$(CONFIG_ARCH_SUNXI) += sunxi-spl-image-builder
218 sunxi-spl-image-builder-objs := sunxi-spl-image-builder.o lib/bch.o
220 hostprogs-$(CONFIG_NETCONSOLE) += ncb
221 hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1
223 ubsha1-objs := os_support.o ubsha1.o lib/sha1.o
225 HOSTCFLAGS_ubsha1.o := -pedantic
227 hostprogs-$(CONFIG_ARCH_KIRKWOOD) += kwboot
228 hostprogs-$(CONFIG_ARCH_MVEBU) += kwboot
229 hostprogs-y += proftool
230 hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
231 hostprogs-$(CONFIG_RISCV) += prelink-riscv
233 hostprogs-$(CONFIG_ARCH_OCTEON) += update_octeon_header
234 update_octeon_header-objs := update_octeon_header.o lib/crc32.o
236 hostprogs-y += fdtgrep
237 fdtgrep-objs += $(LIBFDT_OBJS) boot/fdt_region.o fdtgrep.o
239 ifneq ($(TOOLS_ONLY),y)
240 hostprogs-y += spl_size_limit
243 hostprogs-$(CONFIG_MIPS) += mips-relocs
245 hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler
246 HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
248 HOSTCFLAGS_mkeficapsule.o += \
249 $(shell pkg-config --cflags gnutls 2> /dev/null || echo "")
250 HOSTCFLAGS_mkeficapsule.o += \
251 $(shell pkg-config --cflags uuid 2> /dev/null || echo "")
252 HOSTLDLIBS_mkeficapsule += \
253 $(shell pkg-config --libs gnutls 2> /dev/null || echo "-lgnutls")
254 HOSTLDLIBS_mkeficapsule += \
255 $(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid")
256 hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule
258 # We build some files with extra pedantic flags to try to minimize things
259 # that won't build on some weird host compiler -- though there are lots of
260 # exceptions for files that aren't complaint.
261 HOSTCFLAGS_crc32.o := -pedantic
262 HOSTCFLAGS_crc8.o := -pedantic
263 HOSTCFLAGS_md5.o := -pedantic
264 HOSTCFLAGS_sha1.o := -pedantic
265 HOSTCFLAGS_sha256.o := -pedantic
266 HOSTCFLAGS_sha512.o := -pedantic -DCONFIG_SHA512 -DCONFIG_SHA384
268 quiet_cmd_wrap = WRAP $@
269 cmd_wrap = echo "\#include <../$(patsubst $(obj)/%,%,$@)>" >$@
271 $(obj)/boot/%.c $(obj)/common/%.c $(obj)/env/%.c $(obj)/lib/%.c:
274 clean-dirs := lib common
276 always := $(hostprogs-y)
278 # Generated LCD/video logo
279 LOGO_H = $(objtree)/include/bmp_logo.h
280 LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
281 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_H)
282 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_DATA_H)
283 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
284 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
288 LOGO_BMP= $(srctree)/$(src)/logos/denx.bmp
290 # Use board logo and fallback to vendor
291 ifneq ($(wildcard $(srctree)/$(src)/logos/$(BOARD).bmp),)
292 LOGO_BMP= $(srctree)/$(src)/logos/$(BOARD).bmp
294 ifneq ($(wildcard $(srctree)/$(src)/logos/$(VENDOR).bmp),)
295 LOGO_BMP= $(srctree)/$(src)/logos/$(VENDOR).bmp
302 # Use native tools and options
303 # Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
304 # Define _GNU_SOURCE to obtain the getline prototype from stdio.h
306 HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
307 $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
308 -I$(srctree)/scripts/dtc/libfdt \
311 -D__KERNEL_STRICT_NAMES \
316 $(LOGO_H): $(obj)/bmp_logo $(LOGO_BMP)
317 $(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
319 ifeq ($(CONFIG_DM_VIDEO),y)
320 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
321 $(obj)/bmp_logo --gen-bmp $(LOGO_BMP) > $@
323 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
324 $(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
328 # Let clean descend into subdirs
331 ifneq ($(CROSS_BUILD_TOOLS),)
332 override HOSTCC = $(CC)
333 override HOSTCFLAGS = $(CFLAGS)
335 quiet_cmd_crosstools_strip = STRIP $^
336 cmd_crosstools_strip = $(STRIP) $^; touch $@
337 $(obj)/.strip: $(call objectify,$(filter $(always),$(hostprogs-y)))
338 $(call cmd,crosstools_strip)
342 clean-files += .strip