tools: kwbimage: Fix compilation without CONFIG_SYS_U_BOOT_OFFS
[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 common/image-fit.o
80 FIT_SIG_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := image-sig-host.o common/image-fit-sig.o
81 FIT_CIPHER_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := common/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                         common/fdt_region.o \
110                         common/bootm.o \
111                         lib/crc32.o \
112                         default_image.o \
113                         lib/fdtdec_common.o \
114                         lib/fdtdec.o \
115                         common/image.o \
116                         imagetool.o \
117                         imximage.o \
118                         imx8image.o \
119                         imx8mimage.o \
120                         kwbimage.o \
121                         lib/md5.o \
122                         lpc32xximage.o \
123                         mxsimage.o \
124                         omapimage.o \
125                         os_support.o \
126                         pblimage.o \
127                         pbl_crc32.o \
128                         vybridimage.o \
129                         stm32image.o \
130                         $(ROCKCHIP_OBS) \
131                         socfpgaimage.o \
132                         sunxi_egon.o \
133                         lib/crc16.o \
134                         lib/hash-checksum.o \
135                         lib/sha1.o \
136                         lib/sha256.o \
137                         lib/sha512.o \
138                         common/hash.o \
139                         ublimage.o \
140                         zynqimage.o \
141                         zynqmpimage.o \
142                         zynqmpbif.o \
143                         $(LIBCRYPTO_OBJS-y) \
144                         $(LIBFDT_OBJS) \
145                         gpimage.o \
146                         gpimage-common.o \
147                         mtk_image.o \
148                         $(ECDSA_OBJS-y) \
149                         $(RSA_OBJS-y) \
150                         $(AES_OBJS-y)
151
152 dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
153 mkimage-objs   := $(dumpimage-mkimage-objs) mkimage.o
154 fit_info-objs   := $(dumpimage-mkimage-objs) fit_info.o
155 fit_check_sign-objs   := $(dumpimage-mkimage-objs) fit_check_sign.o
156 file2include-objs := file2include.o
157
158 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_TOOLS_LIBCRYPTO),)
159 # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
160 # the mxsimage support within tools/mxsimage.c .
161 HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
162 endif
163
164 ifdef CONFIG_TOOLS_LIBCRYPTO
165 # This affects include/image.h, but including the board config file
166 # is tricky, so manually define this options here.
167 HOST_EXTRACFLAGS        += -DCONFIG_FIT_SIGNATURE
168 HOST_EXTRACFLAGS        += -DCONFIG_FIT_SIGNATURE_MAX_SIZE=0xffffffff
169 HOST_EXTRACFLAGS        += -DCONFIG_FIT_CIPHER
170 endif
171
172 ifneq ($(CONFIG_SYS_U_BOOT_OFFS),)
173 HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS)
174 endif
175
176 ifneq ($(CONFIG_ARMADA_38X),)
177 HOSTCFLAGS_kwbimage.o += -DCONFIG_KWB_SECURE
178 endif
179
180 # MXSImage needs LibSSL
181 ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_TOOLS_LIBCRYPTO),)
182 HOSTCFLAGS_kwbimage.o += \
183         $(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "")
184 HOSTLDLIBS_mkimage += \
185         $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto")
186
187 # OS X deprecate openssl in favour of CommonCrypto, supress deprecation
188 # warnings on those systems
189 ifeq ($(HOSTOS),darwin)
190 HOSTCFLAGS_mxsimage.o += -Wno-deprecated-declarations
191 HOSTCFLAGS_image-sig.o += -Wno-deprecated-declarations
192 HOSTCFLAGS_rsa-sign.o += -Wno-deprecated-declarations
193 endif
194 endif
195
196 HOSTCFLAGS_fit_image.o += -DMKIMAGE_DTC=\"$(CONFIG_MKIMAGE_DTC_PATH)\"
197
198 HOSTLDLIBS_dumpimage := $(HOSTLDLIBS_mkimage)
199 HOSTLDLIBS_fit_info := $(HOSTLDLIBS_mkimage)
200 HOSTLDLIBS_fit_check_sign := $(HOSTLDLIBS_mkimage)
201
202 hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
203 hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
204 HOSTCFLAGS_mkexynosspl.o := -pedantic
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) common/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 mkeficapsule-objs       := mkeficapsule.o $(LIBFDT_OBJS)
249 hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
250
251 # We build some files with extra pedantic flags to try to minimize things
252 # that won't build on some weird host compiler -- though there are lots of
253 # exceptions for files that aren't complaint.
254 HOSTCFLAGS_crc32.o := -pedantic
255 HOSTCFLAGS_crc8.o := -pedantic
256 HOSTCFLAGS_md5.o := -pedantic
257 HOSTCFLAGS_sha1.o := -pedantic
258 HOSTCFLAGS_sha256.o := -pedantic
259 HOSTCFLAGS_sha512.o := -pedantic -DCONFIG_SHA512 -DCONFIG_SHA384
260
261 quiet_cmd_wrap = WRAP    $@
262 cmd_wrap = echo "\#include <../$(patsubst $(obj)/%,%,$@)>" >$@
263
264 $(obj)/lib/%.c $(obj)/common/%.c $(obj)/env/%.c:
265         $(call cmd,wrap)
266
267 clean-dirs := lib common
268
269 always := $(hostprogs-y)
270
271 # Generated LCD/video logo
272 LOGO_H = $(objtree)/include/bmp_logo.h
273 LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
274 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_H)
275 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_DATA_H)
276 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
277 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
278
279 # Generic logo
280 ifeq ($(LOGO_BMP),)
281 LOGO_BMP= $(srctree)/$(src)/logos/denx.bmp
282
283 # Use board logo and fallback to vendor
284 ifneq ($(wildcard $(srctree)/$(src)/logos/$(BOARD).bmp),)
285 LOGO_BMP= $(srctree)/$(src)/logos/$(BOARD).bmp
286 else
287 ifneq ($(wildcard $(srctree)/$(src)/logos/$(VENDOR).bmp),)
288 LOGO_BMP= $(srctree)/$(src)/logos/$(VENDOR).bmp
289 endif
290 endif
291
292 endif # !LOGO_BMP
293
294 #
295 # Use native tools and options
296 # Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
297 # Define _GNU_SOURCE to obtain the getline prototype from stdio.h
298 #
299 HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
300                 $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
301                 -I$(srctree)/scripts/dtc/libfdt \
302                 -I$(srctree)/tools \
303                 -DUSE_HOSTCC \
304                 -D__KERNEL_STRICT_NAMES \
305                 -D_GNU_SOURCE \
306                 -std=gnu99
307
308 __build:        $(LOGO-y)
309
310 $(LOGO_H):      $(obj)/bmp_logo $(LOGO_BMP)
311         $(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
312
313 ifeq ($(CONFIG_DM_VIDEO),y)
314 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
315         $(obj)/bmp_logo --gen-bmp $(LOGO_BMP) > $@
316 else
317 $(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
318         $(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
319 #endif
320 endif
321
322 # Let clean descend into subdirs
323 subdir- += env
324
325 ifneq ($(CROSS_BUILD_TOOLS),)
326 override HOSTCC = $(CC)
327 override HOSTCFLAGS = $(CFLAGS)
328
329 quiet_cmd_crosstools_strip = STRIP   $^
330       cmd_crosstools_strip = $(STRIP) $^; touch $@
331 $(obj)/.strip: $(call objectify,$(filter $(always),$(hostprogs-y)))
332         $(call cmd,crosstools_strip)
333
334 always += .strip
335 endif
336 clean-files += .strip