tools: moved code common to all image tools to a separated module.
[platform/kernel/u-boot.git] / tools / Makefile
1 #
2 # (C) Copyright 2000-2006
3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 #
5 # SPDX-License-Identifier:      GPL-2.0+
6 #
7
8 TOOLSUBDIRS = kernel-doc
9
10 #
11 # Include this after HOSTOS HOSTARCH check
12 # so that we can act intelligently.
13 #
14 include $(TOPDIR)/config.mk
15
16 #
17 # toolchains targeting win32 generate .exe files
18 #
19 ifneq (,$(findstring WIN32 ,$(shell $(HOSTCC) -E -dM -xc /dev/null)))
20 SFX = .exe
21 else
22 SFX =
23 endif
24
25 # Enable all the config-independent tools
26 ifneq ($(HOST_TOOLS_ALL),)
27 CONFIG_LCD_LOGO = y
28 CONFIG_CMD_LOADS = y
29 CONFIG_CMD_NET = y
30 CONFIG_XWAY_SWAP_BYTES = y
31 CONFIG_NETCONSOLE = y
32 CONFIG_SHA1_CHECK_UB_IMG = y
33 endif
34
35 # Merge all the different vars for envcrc into one
36 ENVCRC-$(CONFIG_ENV_IS_EMBEDDED) = y
37 ENVCRC-$(CONFIG_ENV_IS_IN_DATAFLASH) = y
38 ENVCRC-$(CONFIG_ENV_IS_IN_EEPROM) = y
39 ENVCRC-$(CONFIG_ENV_IS_IN_FLASH) = y
40 ENVCRC-$(CONFIG_ENV_IS_IN_ONENAND) = y
41 ENVCRC-$(CONFIG_ENV_IS_IN_NAND) = y
42 ENVCRC-$(CONFIG_ENV_IS_IN_NVRAM) = y
43 ENVCRC-$(CONFIG_ENV_IS_IN_SPI_FLASH) = y
44 CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
45
46 # Generated executable files
47 BIN_FILES-$(CONFIG_LCD_LOGO) += bmp_logo$(SFX)
48 BIN_FILES-$(CONFIG_VIDEO_LOGO) += bmp_logo$(SFX)
49 BIN_FILES-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX)
50 BIN_FILES-$(CONFIG_CMD_NET) += gen_eth_addr$(SFX)
51 BIN_FILES-$(CONFIG_CMD_LOADS) += img2srec$(SFX)
52 BIN_FILES-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX)
53 BIN_FILES-y += mkenvimage$(SFX)
54 BIN_FILES-y += mkimage$(SFX)
55 BIN_FILES-$(CONFIG_EXYNOS5250) += mk$(BOARD)spl$(SFX)
56 BIN_FILES-$(CONFIG_MX23) += mxsboot$(SFX)
57 BIN_FILES-$(CONFIG_MX28) += mxsboot$(SFX)
58 BIN_FILES-$(CONFIG_NETCONSOLE) += ncb$(SFX)
59 BIN_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
60 BIN_FILES-$(CONFIG_KIRKWOOD) += kwboot$(SFX)
61 BIN_FILES-y += proftool(SFX)
62
63 # Source files which exist outside the tools directory
64 EXT_OBJ_FILES-$(CONFIG_BUILD_ENVCRC) += common/env_embedded.o
65 EXT_OBJ_FILES-y += common/image.o
66 EXT_OBJ_FILES-$(CONFIG_FIT) += common/image-fit.o
67 EXT_OBJ_FILES-y += common/image-sig.o
68 EXT_OBJ_FILES-y += lib/crc32.o
69 EXT_OBJ_FILES-y += lib/md5.o
70 EXT_OBJ_FILES-y += lib/sha1.o
71
72 # Source files located in the tools directory
73 NOPED_OBJ_FILES-y += aisimage.o
74 NOPED_OBJ_FILES-y += default_image.o
75 NOPED_OBJ_FILES-y += fit_image.o
76 NOPED_OBJ_FILES-y += image-host.o
77 NOPED_OBJ_FILES-y += imximage.o
78 NOPED_OBJ_FILES-y += kwbimage.o
79 NOPED_OBJ_FILES-y += imagetool.o
80 NOPED_OBJ_FILES-y += mkenvimage.o
81 NOPED_OBJ_FILES-y += mkimage.o
82 NOPED_OBJ_FILES-y += mxsimage.o
83 NOPED_OBJ_FILES-y += omapimage.o
84 NOPED_OBJ_FILES-y += os_support.o
85 NOPED_OBJ_FILES-y += pblimage.o
86 NOPED_OBJ_FILES-y += proftool.o
87 NOPED_OBJ_FILES-y += ublimage.o
88 OBJ_FILES-$(CONFIG_BUILD_ENVCRC) += envcrc.o
89 OBJ_FILES-$(CONFIG_CMD_LOADS) += img2srec.o
90 OBJ_FILES-$(CONFIG_CMD_NET) += gen_eth_addr.o
91 OBJ_FILES-$(CONFIG_EXYNOS5250) += mkexynosspl.o
92 OBJ_FILES-$(CONFIG_KIRKWOOD) += kwboot.o
93 OBJ_FILES-$(CONFIG_LCD_LOGO) += bmp_logo.o
94 OBJ_FILES-$(CONFIG_MX23) += mxsboot.o
95 OBJ_FILES-$(CONFIG_MX28) += mxsboot.o
96 OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
97 OBJ_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1.o
98 OBJ_FILES-$(CONFIG_SMDK5250) += mkexynosspl.o
99 OBJ_FILES-$(CONFIG_VIDEO_LOGO) += bmp_logo.o
100 OBJ_FILES-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes.o
101
102 # Don't build by default
103 #ifeq ($(ARCH),ppc)
104 #BIN_FILES-y += mpc86x_clk$(SFX)
105 #OBJ_FILES-y += mpc86x_clk.o
106 #endif
107
108 # Flattened device tree objects
109 LIBFDT_OBJ_FILES-y += fdt.o
110 LIBFDT_OBJ_FILES-y += fdt_ro.o
111 LIBFDT_OBJ_FILES-y += fdt_rw.o
112 LIBFDT_OBJ_FILES-y += fdt_strerror.o
113 LIBFDT_OBJ_FILES-y += fdt_wip.o
114
115 # RSA objects
116 RSA_OBJ_FILES-$(CONFIG_FIT_SIGNATURE) += rsa-sign.o
117
118 # Generated LCD/video logo
119 LOGO_H = $(OBJTREE)/include/bmp_logo.h
120 LOGO_DATA_H = $(OBJTREE)/include/bmp_logo_data.h
121 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_H)
122 LOGO-$(CONFIG_LCD_LOGO) += $(LOGO_DATA_H)
123 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
124 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
125
126 # Generic logo
127 ifeq ($(LOGO_BMP),)
128 LOGO_BMP= logos/denx.bmp
129
130 # Use board logo and fallback to vendor
131 ifneq ($(wildcard logos/$(BOARD).bmp),)
132 LOGO_BMP= logos/$(BOARD).bmp
133 else
134 ifneq ($(wildcard logos/$(VENDOR).bmp),)
135 LOGO_BMP= logos/$(VENDOR).bmp
136 endif
137 endif
138
139 endif # !LOGO_BMP
140
141 # now $(obj) is defined
142 HOSTSRCS += $(addprefix $(SRCTREE)/,$(EXT_OBJ_FILES-y:.o=.c))
143 HOSTSRCS += $(addprefix $(SRCTREE)/tools/,$(OBJ_FILES-y:.o=.c))
144 HOSTSRCS += $(addprefix $(SRCTREE)/lib/libfdt/,$(LIBFDT_OBJ_FILES-y:.o=.c))
145 HOSTSRCS += $(addprefix $(SRCTREE)/lib/rsa/,$(RSA_OBJ_FILES-y:.o=.c))
146 BINS    := $(addprefix $(obj),$(sort $(BIN_FILES-y)))
147 LIBFDT_OBJS     := $(addprefix $(obj),$(LIBFDT_OBJ_FILES-y))
148 RSA_OBJS        := $(addprefix $(obj),$(RSA_OBJ_FILES-y))
149
150 # We cannot check CONFIG_FIT_SIGNATURE here since it is not set on the host
151 FIT_SIG_OBJ_FILES       := image-sig.o
152 FIT_SIG_OBJS            := $(addprefix $(obj),$(FIT_SIG_OBJ_FILES))
153
154 HOSTOBJS := $(addprefix $(obj),$(OBJ_FILES-y))
155 NOPEDOBJS := $(addprefix $(obj),$(NOPED_OBJ_FILES-y))
156
157 #
158 # Use native tools and options
159 # Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
160 # Define _GNU_SOURCE to obtain the getline prototype from stdio.h
161 #
162 HOSTCPPFLAGS =  -include $(SRCTREE)/include/libfdt_env.h \
163                 -idirafter $(SRCTREE)/include \
164                 -idirafter $(SRCTREE)/arch/$(ARCH)/include \
165                 -idirafter $(OBJTREE)/include \
166                 -I $(SRCTREE)/lib/libfdt \
167                 -I $(SRCTREE)/tools \
168                 -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \
169                 -DUSE_HOSTCC \
170                 -D__KERNEL_STRICT_NAMES \
171                 -D_GNU_SOURCE
172
173
174 all:    $(obj).depend $(BINS) $(LOGO-y) subdirs
175
176 $(obj)bin2header$(SFX): $(obj)bin2header.o
177         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
178         $(HOSTSTRIP) $@
179
180 $(obj)bmp_logo$(SFX):   $(obj)bmp_logo.o
181         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
182         $(HOSTSTRIP) $@
183
184 $(obj)proftool(SFX):    $(obj)proftool.o
185         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
186         $(HOSTSTRIP) $@
187
188 $(obj)envcrc$(SFX):     $(obj)crc32.o $(obj)env_embedded.o $(obj)envcrc.o $(obj)sha1.o
189         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
190
191 $(obj)gen_eth_addr$(SFX):       $(obj)gen_eth_addr.o
192         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
193         $(HOSTSTRIP) $@
194
195 $(obj)img2srec$(SFX):   $(obj)img2srec.o
196         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
197         $(HOSTSTRIP) $@
198
199 $(obj)xway-swap-bytes$(SFX):    $(obj)xway-swap-bytes.o
200         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
201         $(HOSTSTRIP) $@
202
203 $(obj)mkenvimage$(SFX): $(obj)crc32.o $(obj)mkenvimage.o \
204         $(obj)os_support.o
205         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
206         $(HOSTSTRIP) $@
207
208 $(obj)mkimage$(SFX):    $(obj)aisimage.o \
209                         $(FIT_SIG_OBJS) \
210                         $(obj)crc32.o \
211                         $(obj)default_image.o \
212                         $(obj)fit_image.o \
213                         $(obj)image-fit.o \
214                         $(obj)image-host.o \
215                         $(obj)image.o \
216                         $(obj)imagetool.o \
217                         $(obj)imximage.o \
218                         $(obj)kwbimage.o \
219                         $(obj)md5.o \
220                         $(obj)mkimage.o \
221                         $(obj)mxsimage.o \
222                         $(obj)omapimage.o \
223                         $(obj)os_support.o \
224                         $(obj)pblimage.o \
225                         $(obj)sha1.o \
226                         $(obj)ublimage.o \
227                         $(LIBFDT_OBJS) \
228                         $(RSA_OBJS)
229         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^ $(HOSTLIBS)
230         $(HOSTSTRIP) $@
231
232 $(obj)mk$(BOARD)spl$(SFX):      $(obj)mkexynosspl.o
233         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
234         $(HOSTSTRIP) $@
235
236 $(obj)mpc86x_clk$(SFX): $(obj)mpc86x_clk.o
237         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
238         $(HOSTSTRIP) $@
239
240 $(obj)mxsboot$(SFX):    $(obj)mxsboot.o
241         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
242         $(HOSTSTRIP) $@
243
244 $(obj)ncb$(SFX):        $(obj)ncb.o
245         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
246         $(HOSTSTRIP) $@
247
248 $(obj)ubsha1$(SFX):     $(obj)os_support.o $(obj)sha1.o $(obj)ubsha1.o
249         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
250
251 $(obj)kwboot$(SFX): $(obj)kwboot.o
252         $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
253         $(HOSTSTRIP) $@
254
255 # Some of the tool objects need to be accessed from outside the tools directory
256 $(obj)%.o: $(SRCTREE)/common/%.c
257         $(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
258
259 $(obj)%.o: $(SRCTREE)/lib/%.c
260         $(HOSTCC) -g $(HOSTCFLAGS) -c -o $@ $<
261
262 $(obj)%.o: $(SRCTREE)/lib/libfdt/%.c
263         $(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
264
265 $(obj)%.o: $(SRCTREE)/lib/rsa/%.c
266         $(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
267
268 subdirs:
269 ifeq ($(TOOLSUBDIRS),)
270         @:
271 else
272         @for dir in $(TOOLSUBDIRS) ; do \
273             $(MAKE) \
274                 HOSTOS=$(HOSTOS) \
275                 HOSTARCH=$(HOSTARCH) \
276                 -C $$dir || exit 1 ; \
277         done
278 endif
279
280 $(LOGO_H):      $(obj)bmp_logo $(LOGO_BMP)
281         $(obj)./bmp_logo --gen-info $(LOGO_BMP) > $@
282
283 $(LOGO_DATA_H): $(obj)bmp_logo $(LOGO_BMP)
284         $(obj)./bmp_logo --gen-data $(LOGO_BMP) > $@
285
286 #########################################################################
287
288 # defines $(obj).depend target
289 include $(SRCTREE)/rules.mk
290
291 sinclude $(obj).depend
292
293 #########################################################################