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