Licenses: Clarify exceptions for standalone apps
[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 and image types that depend on openssl/libcrypto
98 LIBCRYPTO_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := \
99                         lib/fdt-libcrypto.o \
100                         sunxi_toc0.o
101
102 ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o
103
104 # common objs for dumpimage and mkimage
105 dumpimage-mkimage-objs := aisimage.o \
106                         atmelimage.o \
107                         $(FIT_OBJS-y) \
108                         $(FIT_SIG_OBJS-y) \
109                         $(FIT_CIPHER_OBJS-y) \
110                         boot/fdt_region.o \
111                         boot/bootm.o \
112                         lib/crc32.o \
113                         default_image.o \
114                         lib/fdtdec_common.o \
115                         lib/fdtdec.o \
116                         boot/image.o \
117                         boot/image-host.o \
118                         imagetool.o \
119                         imximage.o \
120                         imx8image.o \
121                         imx8mimage.o \
122                         kwbimage.o \
123                         lib/md5.o \
124                         lpc32xximage.o \
125                         mxsimage.o \
126                         omapimage.o \
127                         os_support.o \
128                         pblimage.o \
129                         pbl_crc32.o \
130                         vybridimage.o \
131                         stm32image.o \
132                         $(ROCKCHIP_OBS) \
133                         socfpgaimage.o \
134                         sunxi_egon.o \
135                         lib/crc16-ccitt.o \
136                         lib/hash-checksum.o \
137                         lib/sha1.o \
138                         lib/sha256.o \
139                         lib/sha512.o \
140                         common/hash.o \
141                         ublimage.o \
142                         zynqimage.o \
143                         zynqmpimage.o \
144                         zynqmpbif.o \
145                         $(LIBCRYPTO_OBJS-y) \
146                         $(LIBFDT_OBJS) \
147                         gpimage.o \
148                         gpimage-common.o \
149                         mtk_image.o \
150                         mtk_nand_headers.o \
151                         $(ECDSA_OBJS-y) \
152                         $(RSA_OBJS-y) \
153                         $(AES_OBJS-y)
154
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
160
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
165 endif
166
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
173 endif
174
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")
181
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
188 endif
189 endif
190
191 HOSTCFLAGS_fit_image.o += -DMKIMAGE_DTC=\"$(CONFIG_MKIMAGE_DTC_PATH)\"
192
193 HOSTLDLIBS_dumpimage := $(HOSTLDLIBS_mkimage)
194 HOSTLDLIBS_fit_info := $(HOSTLDLIBS_mkimage)
195 HOSTLDLIBS_fit_check_sign := $(HOSTLDLIBS_mkimage)
196
197 hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
198 hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
199 HOSTCFLAGS_mkexynosspl.o := -pedantic
200
201 HOSTCFLAGS_kwboot.o += -pthread
202 HOSTLDLIBS_kwboot += -pthread
203 HOSTLDLIBS_kwboot += \
204         $(shell pkg-config --libs tinfo 2> /dev/null || echo "-ltinfo")
205
206 ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o
207 hostprogs-$(CONFIG_X86) += ifdtool
208
209 ifwitool-objs := ifwitool.o
210 hostprogs-$(CONFIG_X86)$(CONFIG_SANDBOX) += ifwitool
211
212 hostprogs-$(CONFIG_MX23) += mxsboot
213 hostprogs-$(CONFIG_MX28) += mxsboot
214 HOSTCFLAGS_mxsboot.o := -pedantic
215
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
219
220 hostprogs-$(CONFIG_NETCONSOLE) += ncb
221 hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1
222
223 ubsha1-objs := os_support.o ubsha1.o lib/sha1.o
224
225 HOSTCFLAGS_ubsha1.o := -pedantic
226
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
232
233 hostprogs-$(CONFIG_ARCH_OCTEON) += update_octeon_header
234 update_octeon_header-objs := update_octeon_header.o lib/crc32.o
235
236 hostprogs-y += fdtgrep
237 fdtgrep-objs += $(LIBFDT_OBJS) boot/fdt_region.o fdtgrep.o
238
239 ifneq ($(TOOLS_ONLY),y)
240 hostprogs-y += spl_size_limit
241 endif
242
243 hostprogs-$(CONFIG_MIPS) += mips-relocs
244
245 hostprogs-$(CONFIG_ASN1_COMPILER)       += asn1_compiler
246 HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
247
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
257
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
267
268 quiet_cmd_wrap = WRAP    $@
269 cmd_wrap = echo "\#include <../$(patsubst $(obj)/%,%,$@)>" >$@
270
271 $(obj)/boot/%.c $(obj)/common/%.c $(obj)/env/%.c $(obj)/lib/%.c:
272         $(call cmd,wrap)
273
274 clean-dirs := lib common
275
276 always := $(hostprogs-y)
277
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)
285
286 # Generic logo
287 ifeq ($(LOGO_BMP),)
288 LOGO_BMP= $(srctree)/$(src)/logos/denx.bmp
289
290 # Use board logo and fallback to vendor
291 ifneq ($(wildcard $(srctree)/$(src)/logos/$(BOARD).bmp),)
292 LOGO_BMP= $(srctree)/$(src)/logos/$(BOARD).bmp
293 else
294 ifneq ($(wildcard $(srctree)/$(src)/logos/$(VENDOR).bmp),)
295 LOGO_BMP= $(srctree)/$(src)/logos/$(VENDOR).bmp
296 endif
297 endif
298
299 endif # !LOGO_BMP
300
301 #
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
305 #
306 HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
307                 $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
308                 -I$(srctree)/scripts/dtc/libfdt \
309                 -I$(srctree)/tools \
310                 -DUSE_HOSTCC \
311                 -D__KERNEL_STRICT_NAMES \
312                 -D_GNU_SOURCE
313
314 __build:        $(LOGO-y)
315
316 $(LOGO_H):      $(obj)/bmp_logo $(LOGO_BMP)
317         $(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
318
319 ifeq ($(CONFIG_DM_VIDEO),y)
320 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
321         $(obj)/bmp_logo --gen-bmp $(LOGO_BMP) > $@
322 else
323 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
324         $(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
325 #endif
326 endif
327
328 # Let clean descend into subdirs
329 subdir- += env
330
331 ifneq ($(CROSS_BUILD_TOOLS),)
332 override HOSTCC = $(CC)
333 override HOSTCFLAGS = $(CFLAGS)
334
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)
339
340 always += .strip
341 endif
342 clean-files += .strip