1# SPDX-License-Identifier: GPL-2.0+
2#
3# (C) Copyright 2000-2006
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5
6# Enable all the config-independent tools
7ifneq ($(HOST_TOOLS_ALL),)
8CONFIG_ARCH_KIRKWOOD = y
9CONFIG_LCD_LOGO = y
10CONFIG_CMD_LOADS = y
11CONFIG_CMD_NET = y
12CONFIG_XWAY_SWAP_BYTES = y
13CONFIG_NETCONSOLE = y
14CONFIG_SHA1_CHECK_UB_IMG = y
15CONFIG_ARCH_SUNXI = y
16endif
17
18subdir-$(HOST_TOOLS_ALL) += gdb
19
20# Merge all the different vars for envcrc into one
21ENVCRC-$(CONFIG_ENV_IS_EMBEDDED) = y
22ENVCRC-$(CONFIG_ENV_IS_IN_EEPROM) = y
23ENVCRC-$(CONFIG_ENV_IS_IN_FLASH) = y
24ENVCRC-$(CONFIG_ENV_IS_IN_ONENAND) = y
25ENVCRC-$(CONFIG_ENV_IS_IN_NAND) = y
26ENVCRC-$(CONFIG_ENV_IS_IN_NVRAM) = y
27ENVCRC-$(CONFIG_ENV_IS_IN_SPI_FLASH) = y
28CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
29
30hostprogs-$(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER) += atmel_pmecc_params
31
32hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo
33hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo
34HOSTCFLAGS_bmp_logo.o := -pedantic
35
36hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc
37envcrc-objs := envcrc.o lib/crc32.o env/embedded.o lib/sha1.o
38
39hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
40HOSTCFLAGS_gen_eth_addr.o := -pedantic
41
42hostprogs-$(CONFIG_CMD_NET) += gen_ethaddr_crc
43gen_ethaddr_crc-objs := gen_ethaddr_crc.o lib/crc8.o
44HOSTCFLAGS_gen_ethaddr_crc.o := -pedantic
45
46hostprogs-$(CONFIG_CMD_LOADS) += img2srec
47HOSTCFLAGS_img2srec.o := -pedantic
48
49hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes
50HOSTCFLAGS_xway-swap-bytes.o := -pedantic
51
52hostprogs-y += mkenvimage
53mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
54
55hostprogs-y += dumpimage mkimage
56hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info fit_check_sign
57
58hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
59
60FIT_OBJS-$(CONFIG_FIT) := fit_common.o fit_image.o image-host.o common/image-fit.o
61FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o common/image-fit-sig.o
62FIT_CIPHER_OBJS-$(CONFIG_FIT_CIPHER) := common/image-cipher.o
63
64# The following files are synced with upstream DTC.
65# Use synced versions from scripts/dtc/libfdt/.
66LIBFDT_OBJS := $(addprefix libfdt/, fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o \
67		fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o)
68
69RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
70					rsa-sign.o rsa-verify.o rsa-checksum.o \
71					rsa-mod-exp.o)
72
73AES_OBJS-$(CONFIG_FIT_CIPHER) := $(addprefix lib/aes/, \
74					aes-encrypt.o aes-decrypt.o)
75
76ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o
77
78# common objs for dumpimage and mkimage
79dumpimage-mkimage-objs := aisimage.o \
80			atmelimage.o \
81			$(FIT_OBJS-y) \
82			$(FIT_SIG_OBJS-y) \
83			$(FIT_CIPHER_OBJS-y) \
84			common/fdt_region.o \
85			common/bootm.o \
86			lib/crc32.o \
87			default_image.o \
88			lib/fdtdec_common.o \
89			lib/fdtdec.o \
90			common/image.o \
91			imagetool.o \
92			imximage.o \
93			imx8image.o \
94			imx8mimage.o \
95			kwbimage.o \
96			lib/md5.o \
97			lpc32xximage.o \
98			mxsimage.o \
99			omapimage.o \
100			os_support.o \
101			pblimage.o \
102			pbl_crc32.o \
103			vybridimage.o \
104			stm32image.o \
105			$(ROCKCHIP_OBS) \
106			socfpgaimage.o \
107			sunxi_egon.o \
108			lib/crc16.o \
109			lib/sha1.o \
110			lib/sha256.o \
111			lib/sha512.o \
112			common/hash.o \
113			ublimage.o \
114			zynqimage.o \
115			zynqmpimage.o \
116			zynqmpbif.o \
117			$(LIBFDT_OBJS) \
118			gpimage.o \
119			gpimage-common.o \
120			mtk_image.o \
121			$(RSA_OBJS-y) \
122			$(AES_OBJS-y)
123
124dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
125mkimage-objs   := $(dumpimage-mkimage-objs) mkimage.o
126fit_info-objs   := $(dumpimage-mkimage-objs) fit_info.o
127fit_check_sign-objs   := $(dumpimage-mkimage-objs) fit_check_sign.o
128file2include-objs := file2include.o
129
130ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_FIT_SIGNATURE),)
131# Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
132# the mxsimage support within tools/mxsimage.c .
133HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
134endif
135
136ifdef CONFIG_FIT_SIGNATURE
137# This affects include/image.h, but including the board config file
138# is tricky, so manually define this options here.
139HOST_EXTRACFLAGS	+= -DCONFIG_FIT_SIGNATURE
140HOST_EXTRACFLAGS	+= -DCONFIG_FIT_SIGNATURE_MAX_SIZE=$(CONFIG_FIT_SIGNATURE_MAX_SIZE)
141endif
142
143ifdef CONFIG_FIT_CIPHER
144# This affects include/image.h, but including the board config file
145# is tricky, so manually define this options here.
146HOST_EXTRACFLAGS	+= -DCONFIG_FIT_CIPHER
147endif
148
149ifdef CONFIG_SYS_U_BOOT_OFFS
150HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS)
151endif
152
153ifneq ($(CONFIG_ARMADA_38X),)
154HOSTCFLAGS_kwbimage.o += -DCONFIG_KWB_SECURE
155endif
156
157# MXSImage needs LibSSL
158ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_FIT_SIGNATURE)$(CONFIG_FIT_CIPHER),)
159HOSTCFLAGS_kwbimage.o += \
160	$(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "")
161HOSTLDLIBS_mkimage += \
162	$(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto")
163
164# OS X deprecate openssl in favour of CommonCrypto, supress deprecation
165# warnings on those systems
166ifeq ($(HOSTOS),darwin)
167HOSTCFLAGS_mxsimage.o += -Wno-deprecated-declarations
168HOSTCFLAGS_image-sig.o += -Wno-deprecated-declarations
169HOSTCFLAGS_rsa-sign.o += -Wno-deprecated-declarations
170endif
171endif
172
173HOSTCFLAGS_fit_image.o += -DMKIMAGE_DTC=\"$(CONFIG_MKIMAGE_DTC_PATH)\"
174
175HOSTLDLIBS_dumpimage := $(HOSTLDLIBS_mkimage)
176HOSTLDLIBS_fit_info := $(HOSTLDLIBS_mkimage)
177HOSTLDLIBS_fit_check_sign := $(HOSTLDLIBS_mkimage)
178
179hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
180hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
181HOSTCFLAGS_mkexynosspl.o := -pedantic
182
183ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o
184hostprogs-$(CONFIG_X86) += ifdtool
185
186ifwitool-objs := ifwitool.o
187hostprogs-$(CONFIG_X86)$(CONFIG_SANDBOX) += ifwitool
188
189hostprogs-$(CONFIG_MX23) += mxsboot
190hostprogs-$(CONFIG_MX28) += mxsboot
191HOSTCFLAGS_mxsboot.o := -pedantic
192
193hostprogs-$(CONFIG_ARCH_SUNXI) += mksunxiboot
194hostprogs-$(CONFIG_ARCH_SUNXI) += sunxi-spl-image-builder
195sunxi-spl-image-builder-objs := sunxi-spl-image-builder.o lib/bch.o
196
197hostprogs-$(CONFIG_NETCONSOLE) += ncb
198hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1
199
200ubsha1-objs := os_support.o ubsha1.o lib/sha1.o
201
202HOSTCFLAGS_ubsha1.o := -pedantic
203
204hostprogs-$(CONFIG_ARCH_KIRKWOOD) += kwboot
205hostprogs-$(CONFIG_ARCH_MVEBU) += kwboot
206hostprogs-y += proftool
207hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
208hostprogs-$(CONFIG_RISCV) += prelink-riscv
209
210hostprogs-$(CONFIG_ARCH_OCTEON) += update_octeon_header
211update_octeon_header-objs := update_octeon_header.o lib/crc32.o
212
213hostprogs-y += fdtgrep
214fdtgrep-objs += $(LIBFDT_OBJS) common/fdt_region.o fdtgrep.o
215
216ifneq ($(TOOLS_ONLY),y)
217hostprogs-y += spl_size_limit
218endif
219
220hostprogs-$(CONFIG_MIPS) += mips-relocs
221
222hostprogs-$(CONFIG_ASN1_COMPILER)	+= asn1_compiler
223HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
224
225mkeficapsule-objs	:= mkeficapsule.o $(LIBFDT_OBJS)
226hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
227
228# We build some files with extra pedantic flags to try to minimize things
229# that won't build on some weird host compiler -- though there are lots of
230# exceptions for files that aren't complaint.
231HOSTCFLAGS_crc32.o := -pedantic
232HOSTCFLAGS_crc8.o := -pedantic
233HOSTCFLAGS_md5.o := -pedantic
234HOSTCFLAGS_sha1.o := -pedantic
235HOSTCFLAGS_sha256.o := -pedantic
236HOSTCFLAGS_sha512.o := -pedantic -DCONFIG_SHA512 -DCONFIG_SHA384
237
238quiet_cmd_wrap = WRAP    $@
239cmd_wrap = echo "\#include <../$(patsubst $(obj)/%,%,$@)>" >$@
240
241$(obj)/lib/%.c $(obj)/common/%.c $(obj)/env/%.c:
242	$(call cmd,wrap)
243
244clean-dirs := lib common
245
246always := $(hostprogs-y)
247
248# Generated LCD/video logo
249LOGO_H = $(objtree)/include/bmp_logo.h
250LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
251LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_H)
252LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_DATA_H)
253LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
254LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
255
256# Generic logo
257ifeq ($(LOGO_BMP),)
258LOGO_BMP= $(srctree)/$(src)/logos/denx.bmp
259
260# Use board logo and fallback to vendor
261ifneq ($(wildcard $(srctree)/$(src)/logos/$(BOARD).bmp),)
262LOGO_BMP= $(srctree)/$(src)/logos/$(BOARD).bmp
263else
264ifneq ($(wildcard $(srctree)/$(src)/logos/$(VENDOR).bmp),)
265LOGO_BMP= $(srctree)/$(src)/logos/$(VENDOR).bmp
266endif
267endif
268
269endif # !LOGO_BMP
270
271#
272# Use native tools and options
273# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
274# Define _GNU_SOURCE to obtain the getline prototype from stdio.h
275#
276HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
277		$(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
278		-I$(srctree)/scripts/dtc/libfdt \
279		-I$(srctree)/tools \
280		-DUSE_HOSTCC \
281		-D__KERNEL_STRICT_NAMES \
282		-D_GNU_SOURCE \
283		-std=gnu99
284
285__build:	$(LOGO-y)
286
287$(LOGO_H):	$(obj)/bmp_logo $(LOGO_BMP)
288	$(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
289
290ifeq ($(CONFIG_DM_VIDEO),y)
291$(LOGO_DATA_H):	$(obj)/bmp_logo $(LOGO_BMP)
292	$(obj)/bmp_logo --gen-bmp $(LOGO_BMP) > $@
293else
294$(LOGO_DATA_H):	$(obj)/bmp_logo $(LOGO_BMP)
295	$(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
296#endif
297endif
298
299# Let clean descend into subdirs
300subdir- += env
301
302ifneq ($(CROSS_BUILD_TOOLS),)
303override HOSTCC = $(CC)
304override HOSTCFLAGS = $(CFLAGS)
305
306quiet_cmd_crosstools_strip = STRIP   $^
307      cmd_crosstools_strip = $(STRIP) $^; touch $@
308$(obj)/.strip: $(call objectify,$(filter $(always),$(hostprogs-y)))
309	$(call cmd,crosstools_strip)
310
311always += .strip
312endif
313clean-files += .strip
314