xref: /OK3568_Linux_fs/u-boot/scripts/Makefile.lib (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#
2*4882a593Smuzhiyun# SPDX-License-Identifier:	GPL-2.0
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# Backward compatibility
5*4882a593Smuzhiyunasflags-y  += $(EXTRA_AFLAGS)
6*4882a593Smuzhiyunccflags-y  += $(EXTRA_CFLAGS)
7*4882a593Smuzhiyuncppflags-y += $(EXTRA_CPPFLAGS)
8*4882a593Smuzhiyunldflags-y  += $(EXTRA_LDFLAGS)
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun#
11*4882a593Smuzhiyun# flags that take effect in sub directories
12*4882a593Smuzhiyunexport KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y)
13*4882a593Smuzhiyunexport KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun# Figure out what we need to build from the various variables
16*4882a593Smuzhiyun# ===========================================================================
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun# When an object is listed to be built compiled-in and modular,
19*4882a593Smuzhiyun# only build the compiled-in version
20*4882a593Smuzhiyun
21*4882a593Smuzhiyunobj-m := $(filter-out $(obj-y),$(obj-m))
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun# Libraries are always collected in one lib file.
24*4882a593Smuzhiyun# Filter out objects already built-in
25*4882a593Smuzhiyun
26*4882a593Smuzhiyunlib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun# Handle objects in subdirs
30*4882a593Smuzhiyun# ---------------------------------------------------------------------------
31*4882a593Smuzhiyun# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
32*4882a593Smuzhiyun#   and add the directory to the list of dirs to descend into: $(subdir-y)
33*4882a593Smuzhiyun# o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
34*4882a593Smuzhiyun#   and add the directory to the list of dirs to descend into: $(subdir-m)
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun# Determine modorder.
37*4882a593Smuzhiyun# Unfortunately, we don't have information about ordering between -y
38*4882a593Smuzhiyun# and -m subdirs.  Just put -y's first.
39*4882a593Smuzhiyunmodorder	:= $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
42*4882a593Smuzhiyunsubdir-y	+= $(__subdir-y)
43*4882a593Smuzhiyun__subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
44*4882a593Smuzhiyunsubdir-m	+= $(__subdir-m)
45*4882a593Smuzhiyunobj-y		:= $(patsubst %/, %/built-in.o, $(obj-y))
46*4882a593Smuzhiyunobj-m		:= $(filter-out %/, $(obj-m))
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun# Subdirectories we need to descend into
49*4882a593Smuzhiyun
50*4882a593Smuzhiyunsubdir-ym	:= $(sort $(subdir-y) $(subdir-m))
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun# if $(foo-objs) exists, foo.o is a composite object
53*4882a593Smuzhiyunmulti-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
54*4882a593Smuzhiyunmulti-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
55*4882a593Smuzhiyunmulti-used   := $(multi-used-y) $(multi-used-m)
56*4882a593Smuzhiyunsingle-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun# Build list of the parts of our composite objects, our composite
59*4882a593Smuzhiyun# objects depend on those (obviously)
60*4882a593Smuzhiyunmulti-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
61*4882a593Smuzhiyunmulti-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
62*4882a593Smuzhiyunmulti-objs   := $(multi-objs-y) $(multi-objs-m)
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
65*4882a593Smuzhiyun# tell kbuild to descend
66*4882a593Smuzhiyunsubdir-obj-y := $(filter %/built-in.o, $(obj-y))
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun# $(obj-dirs) is a list of directories that contain object files
69*4882a593Smuzhiyunobj-dirs := $(dir $(multi-objs) $(obj-y))
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun# Replace multi-part objects by their individual parts, look at local dir only
72*4882a593Smuzhiyunreal-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y)
73*4882a593Smuzhiyunreal-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun# Add subdir path
76*4882a593Smuzhiyun
77*4882a593Smuzhiyunextra-y		:= $(addprefix $(obj)/,$(extra-y))
78*4882a593Smuzhiyunalways		:= $(addprefix $(obj)/,$(always))
79*4882a593Smuzhiyuntargets		:= $(addprefix $(obj)/,$(targets))
80*4882a593Smuzhiyunmodorder	:= $(addprefix $(obj)/,$(modorder))
81*4882a593Smuzhiyunobj-y		:= $(addprefix $(obj)/,$(obj-y))
82*4882a593Smuzhiyunobj-m		:= $(addprefix $(obj)/,$(obj-m))
83*4882a593Smuzhiyunlib-y		:= $(addprefix $(obj)/,$(lib-y))
84*4882a593Smuzhiyunsubdir-obj-y	:= $(addprefix $(obj)/,$(subdir-obj-y))
85*4882a593Smuzhiyunreal-objs-y	:= $(addprefix $(obj)/,$(real-objs-y))
86*4882a593Smuzhiyunreal-objs-m	:= $(addprefix $(obj)/,$(real-objs-m))
87*4882a593Smuzhiyunsingle-used-m	:= $(addprefix $(obj)/,$(single-used-m))
88*4882a593Smuzhiyunmulti-used-y	:= $(addprefix $(obj)/,$(multi-used-y))
89*4882a593Smuzhiyunmulti-used-m	:= $(addprefix $(obj)/,$(multi-used-m))
90*4882a593Smuzhiyunmulti-objs-y	:= $(addprefix $(obj)/,$(multi-objs-y))
91*4882a593Smuzhiyunmulti-objs-m	:= $(addprefix $(obj)/,$(multi-objs-m))
92*4882a593Smuzhiyunsubdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
93*4882a593Smuzhiyunobj-dirs	:= $(addprefix $(obj)/,$(obj-dirs))
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun# These flags are needed for modversions and compiling, so we define them here
96*4882a593Smuzhiyun# already
97*4882a593Smuzhiyun# $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will
98*4882a593Smuzhiyun# end up in (or would, if it gets compiled in)
99*4882a593Smuzhiyun# Note: Files that end up in two or more modules are compiled without the
100*4882a593Smuzhiyun#       KBUILD_MODNAME definition. The reason is that any made-up name would
101*4882a593Smuzhiyun#       differ in different configs.
102*4882a593Smuzhiyunname-fix = $(subst $(comma),_,$(subst -,_,$1))
103*4882a593Smuzhiyunbasename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))"
104*4882a593Smuzhiyunmodname_flags  = $(if $(filter 1,$(words $(modname))),\
105*4882a593Smuzhiyun                 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
106*4882a593Smuzhiyun
107*4882a593Smuzhiyunorig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
108*4882a593Smuzhiyun                 $(ccflags-y) $(CFLAGS_$(basetarget).o)
109*4882a593Smuzhiyun_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
110*4882a593Smuzhiyunorig_a_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \
111*4882a593Smuzhiyun                 $(asflags-y) $(AFLAGS_$(basetarget).o)
112*4882a593Smuzhiyun_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
113*4882a593Smuzhiyun_cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun#
116*4882a593Smuzhiyun# Enable gcov profiling flags for a file, directory or for all files depending
117*4882a593Smuzhiyun# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
118*4882a593Smuzhiyun# (in this order)
119*4882a593Smuzhiyun#
120*4882a593Smuzhiyunifeq ($(CONFIG_GCOV_KERNEL),y)
121*4882a593Smuzhiyun_c_flags += $(if $(patsubst n%,, \
122*4882a593Smuzhiyun		$(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
123*4882a593Smuzhiyun		$(CFLAGS_GCOV))
124*4882a593Smuzhiyunendif
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun#
127*4882a593Smuzhiyun# Enable address sanitizer flags for kernel except some files or directories
128*4882a593Smuzhiyun# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
129*4882a593Smuzhiyun#
130*4882a593Smuzhiyunifeq ($(CONFIG_KASAN),y)
131*4882a593Smuzhiyun_c_flags += $(if $(patsubst n%,, \
132*4882a593Smuzhiyun		$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
133*4882a593Smuzhiyun		$(CFLAGS_KASAN))
134*4882a593Smuzhiyunendif
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun# If building the kernel in a separate objtree expand all occurrences
137*4882a593Smuzhiyun# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
138*4882a593Smuzhiyun
139*4882a593Smuzhiyunifeq ($(KBUILD_SRC),)
140*4882a593Smuzhiyun__c_flags	= $(_c_flags)
141*4882a593Smuzhiyun__a_flags	= $(_a_flags)
142*4882a593Smuzhiyun__cpp_flags     = $(_cpp_flags)
143*4882a593Smuzhiyunelse
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun# -I$(obj) locates generated .h files
146*4882a593Smuzhiyun# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
147*4882a593Smuzhiyun#   and locates generated .h files
148*4882a593Smuzhiyun# FIXME: Replace both with specific CFLAGS* statements in the makefiles
149*4882a593Smuzhiyun__c_flags	= $(call addtree,-I$(obj)) $(call flags,_c_flags)
150*4882a593Smuzhiyun__a_flags	=                          $(call flags,_a_flags)
151*4882a593Smuzhiyun__cpp_flags     =                          $(call flags,_cpp_flags)
152*4882a593Smuzhiyunendif
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun# Modified for U-Boot: LINUXINCLUDE -> UBOOTINCLUDE
155*4882a593Smuzhiyunc_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE)     \
156*4882a593Smuzhiyun		 $(__c_flags) $(modkern_cflags)                           \
157*4882a593Smuzhiyun		 -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
158*4882a593Smuzhiyun
159*4882a593Smuzhiyuna_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE)     \
160*4882a593Smuzhiyun		 $(__a_flags) $(modkern_aflags)
161*4882a593Smuzhiyun
162*4882a593Smuzhiyuncpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE)     \
163*4882a593Smuzhiyun		 $(__cpp_flags)
164*4882a593Smuzhiyun
165*4882a593Smuzhiyunld_flags       = $(LDFLAGS) $(ldflags-y)
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun# Try these files in order to find the U-Boot-specific .dtsi include file
168*4882a593Smuzhiyunu_boot_dtsi_options = $(wildcard $(dir $<)$(basename $(notdir $<))-u-boot.dtsi) \
169*4882a593Smuzhiyun	$(wildcard $(dir $<)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi) \
170*4882a593Smuzhiyun	$(wildcard $(dir $<)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi) \
171*4882a593Smuzhiyun	$(wildcard $(dir $<)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi) \
172*4882a593Smuzhiyun	$(wildcard $(dir $<)u-boot.dtsi)
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun# Uncomment for debugging
175*4882a593Smuzhiyun# $(warning u_boot_dtsi_options: $(u_boot_dtsi_options))
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun# We use the first match
178*4882a593Smuzhiyunu_boot_dtsi = $(notdir $(firstword $(u_boot_dtsi_options)))
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun# Modified for U-Boot
181*4882a593Smuzhiyundtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
182*4882a593Smuzhiyun		 -I$(srctree)/arch/$(ARCH)/dts                           \
183*4882a593Smuzhiyun		 -I$(srctree)/arch/$(ARCH)/dts/include                   \
184*4882a593Smuzhiyun		 -Iinclude                                               \
185*4882a593Smuzhiyun		 -I$(srctree)/include                                    \
186*4882a593Smuzhiyun		 -I$(srctree)/arch/$(ARCH)/include                       \
187*4882a593Smuzhiyun		 -include $(srctree)/include/linux/kconfig.h             \
188*4882a593Smuzhiyun		 -D__ASSEMBLY__                                          \
189*4882a593Smuzhiyun		 -undef -D__DTS__
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun# Finds the multi-part object the current object will be linked into
192*4882a593Smuzhiyunmodname-multi = $(sort $(foreach m,$(multi-used),\
193*4882a593Smuzhiyun		$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun# Useful for describing the dependency of composite objects
196*4882a593Smuzhiyun# Usage:
197*4882a593Smuzhiyun#   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
198*4882a593Smuzhiyundefine multi_depend
199*4882a593Smuzhiyun$(foreach m, $(notdir $1), \
200*4882a593Smuzhiyun	$(eval $(obj)/$m: \
201*4882a593Smuzhiyun	$(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
202*4882a593Smuzhiyunendef
203*4882a593Smuzhiyun
204*4882a593Smuzhiyunifdef REGENERATE_PARSERS
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun# GPERF
207*4882a593Smuzhiyun# ---------------------------------------------------------------------------
208*4882a593Smuzhiyunquiet_cmd_gperf = GPERF $@
209*4882a593Smuzhiyun      cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun.PRECIOUS: $(src)/%.hash.c_shipped
212*4882a593Smuzhiyun$(src)/%.hash.c_shipped: $(src)/%.gperf
213*4882a593Smuzhiyun	$(call cmd,gperf)
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun# LEX
216*4882a593Smuzhiyun# ---------------------------------------------------------------------------
217*4882a593SmuzhiyunLEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
218*4882a593Smuzhiyun
219*4882a593Smuzhiyunquiet_cmd_flex = LEX     $@
220*4882a593Smuzhiyun      cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun.PRECIOUS: $(src)/%.lex.c_shipped
223*4882a593Smuzhiyun$(src)/%.lex.c_shipped: $(src)/%.l
224*4882a593Smuzhiyun	$(call cmd,flex)
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun# YACC
227*4882a593Smuzhiyun# ---------------------------------------------------------------------------
228*4882a593SmuzhiyunYACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
229*4882a593Smuzhiyun
230*4882a593Smuzhiyunquiet_cmd_bison = YACC    $@
231*4882a593Smuzhiyun      cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun.PRECIOUS: $(src)/%.tab.c_shipped
234*4882a593Smuzhiyun$(src)/%.tab.c_shipped: $(src)/%.y
235*4882a593Smuzhiyun	$(call cmd,bison)
236*4882a593Smuzhiyun
237*4882a593Smuzhiyunquiet_cmd_bison_h = YACC    $@
238*4882a593Smuzhiyun      cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun.PRECIOUS: $(src)/%.tab.h_shipped
241*4882a593Smuzhiyun$(src)/%.tab.h_shipped: $(src)/%.y
242*4882a593Smuzhiyun	$(call cmd,bison_h)
243*4882a593Smuzhiyun
244*4882a593Smuzhiyunendif
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun# Shipped files
247*4882a593Smuzhiyun# ===========================================================================
248*4882a593Smuzhiyun
249*4882a593Smuzhiyunquiet_cmd_shipped = SHIPPED $@
250*4882a593Smuzhiyuncmd_shipped = cat $< > $@
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun$(obj)/%: $(src)/%_shipped
253*4882a593Smuzhiyun	$(call cmd,shipped)
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun# Commands useful for building a boot image
256*4882a593Smuzhiyun# ===========================================================================
257*4882a593Smuzhiyun#
258*4882a593Smuzhiyun#	Use as following:
259*4882a593Smuzhiyun#
260*4882a593Smuzhiyun#	target: source(s) FORCE
261*4882a593Smuzhiyun#		$(if_changed,ld/objcopy/gzip)
262*4882a593Smuzhiyun#
263*4882a593Smuzhiyun#	and add target to extra-y so that we know we have to
264*4882a593Smuzhiyun#	read in the saved command line
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun# Linking
267*4882a593Smuzhiyun# ---------------------------------------------------------------------------
268*4882a593Smuzhiyun
269*4882a593Smuzhiyunquiet_cmd_ld = LD      $@
270*4882a593Smuzhiyuncmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \
271*4882a593Smuzhiyun	       $(filter-out FORCE,$^) -o $@
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun# Objcopy
274*4882a593Smuzhiyun# ---------------------------------------------------------------------------
275*4882a593Smuzhiyun
276*4882a593Smuzhiyunquiet_cmd_objcopy = OBJCOPY $@
277*4882a593Smuzhiyuncmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun# Gzip
280*4882a593Smuzhiyun# ---------------------------------------------------------------------------
281*4882a593Smuzhiyun
282*4882a593Smuzhiyunquiet_cmd_gzip = GZIP    $@
283*4882a593Smuzhiyuncmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
284*4882a593Smuzhiyun	(rm -f $@ ; false)
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun# DTC
287*4882a593Smuzhiyun# ---------------------------------------------------------------------------
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun# Generate an assembly file to wrap the output of the device tree compiler
290*4882a593Smuzhiyunquiet_cmd_dt_S_dtb= DTB     $@
291*4882a593Smuzhiyun# Modified for U-Boot
292*4882a593Smuzhiyuncmd_dt_S_dtb=						\
293*4882a593Smuzhiyun(							\
294*4882a593Smuzhiyun	echo '.section .dtb.init.rodata,"a"';		\
295*4882a593Smuzhiyun	echo '.balign 16';				\
296*4882a593Smuzhiyun	echo '.global __dtb_$(subst -,_,$(*F))_begin';	\
297*4882a593Smuzhiyun	echo '__dtb_$(subst -,_,$(*F))_begin:';		\
298*4882a593Smuzhiyun	echo '.incbin "$<" ';				\
299*4882a593Smuzhiyun	echo '__dtb_$(subst -,_,$(*F))_end:';		\
300*4882a593Smuzhiyun	echo '.global __dtb_$(subst -,_,$(*F))_end';	\
301*4882a593Smuzhiyun	echo '.balign 16';				\
302*4882a593Smuzhiyun) > $@
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun$(obj)/%.dtb.S: $(obj)/%.dtb
305*4882a593Smuzhiyun	$(call cmd,dt_S_dtb)
306*4882a593Smuzhiyun
307*4882a593Smuzhiyunquiet_cmd_dtc = DTC     $@
308*4882a593Smuzhiyun# Modified for U-Boot
309*4882a593Smuzhiyun# Bring in any U-Boot-specific include at the end of the file
310*4882a593Smuzhiyuncmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
311*4882a593Smuzhiyun	(cat $<; $(if $(u_boot_dtsi),echo '$(pound)include "$(u_boot_dtsi)"')) > $(pre-tmp); \
312*4882a593Smuzhiyun	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $(pre-tmp) ; \
313*4882a593Smuzhiyun	$(DTC) -O dtb -o $@ -b 0 \
314*4882a593Smuzhiyun		-i $(dir $<) $(DTC_FLAGS) \
315*4882a593Smuzhiyun		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
316*4882a593Smuzhiyun	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun$(obj)/%.dtb: $(src)/%.dts FORCE
319*4882a593Smuzhiyun	$(call if_changed_dep,dtc)
320*4882a593Smuzhiyun
321*4882a593Smuzhiyunpre-tmp = $(subst $(comma),_,$(dot-target).pre.tmp)
322*4882a593Smuzhiyundtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun# DTCO
325*4882a593Smuzhiyun# ---------------------------------------------------------------------------
326*4882a593Smuzhiyun
327*4882a593Smuzhiyunquiet_cmd_dtco = DTCO    $@
328*4882a593Smuzhiyun# Rule for objects only; does not put specific u-boot include at the end
329*4882a593Smuzhiyun# No generation of assembly file either
330*4882a593Smuzhiyun# Modified for U-Boot
331*4882a593Smuzhiyuncmd_dtco = mkdir -p $(dir ${dtc-tmp}) ; \
332*4882a593Smuzhiyun	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
333*4882a593Smuzhiyun	$(DTC) -@ -O dtb -o $@ -b 0 \
334*4882a593Smuzhiyun		-i $(dir $<) $(DTC_FLAGS) \
335*4882a593Smuzhiyun		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
336*4882a593Smuzhiyun	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun$(obj)/%.dtbo: $(src)/%.dts FORCE
339*4882a593Smuzhiyun	$(call if_changed_dep,dtco)
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun# Fonts
342*4882a593Smuzhiyun# ---------------------------------------------------------------------------
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun# Generate an assembly file to wrap the font data
345*4882a593Smuzhiyunquiet_cmd_S_ttf= TTF     $@
346*4882a593Smuzhiyun# Modified for U-Boot
347*4882a593Smuzhiyuncmd_S_ttf=						\
348*4882a593Smuzhiyun(							\
349*4882a593Smuzhiyun	echo '.section .rodata.ttf.init,"a"';		\
350*4882a593Smuzhiyun	echo '.balign 16';				\
351*4882a593Smuzhiyun	echo '.global __ttf_$(*F)_begin';		\
352*4882a593Smuzhiyun	echo '__ttf_$(*F)_begin:';			\
353*4882a593Smuzhiyun	echo '.incbin "$<" ';				\
354*4882a593Smuzhiyun	echo '__ttf_$(*F)_end:';			\
355*4882a593Smuzhiyun	echo '.global __ttf_$(*F)_end';			\
356*4882a593Smuzhiyun	echo '.balign 16';				\
357*4882a593Smuzhiyun) > $@
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun$(obj)/%.S: $(src)/%.ttf
360*4882a593Smuzhiyun	$(call cmd,S_ttf)
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun# EFI Hello World application
363*4882a593Smuzhiyun# ---------------------------------------------------------------------------
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun# Generate an assembly file to wrap the EFI app
366*4882a593Smuzhiyuncmd_S_efi=						\
367*4882a593Smuzhiyun(							\
368*4882a593Smuzhiyun	echo '.section .rodata.efi.init,"a"';		\
369*4882a593Smuzhiyun	echo '.balign 16';				\
370*4882a593Smuzhiyun	echo '.global __efi_hello_world_begin';		\
371*4882a593Smuzhiyun	echo '__efi_hello_world_begin:';		\
372*4882a593Smuzhiyun	echo '.incbin "$<" ';				\
373*4882a593Smuzhiyun	echo '__efi_hello_world_end:';			\
374*4882a593Smuzhiyun	echo '.global __efi_hello_world_end';		\
375*4882a593Smuzhiyun	echo '.balign 16';				\
376*4882a593Smuzhiyun) > $@
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun$(obj)/%_efi.S: $(obj)/%.efi
379*4882a593Smuzhiyun	$(call cmd,S_efi)
380*4882a593Smuzhiyun
381*4882a593Smuzhiyunquiet_cmd_efi_objcopy = OBJCOPY $@
382*4882a593Smuzhiyuncmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data -j \
383*4882a593Smuzhiyun		.dynamic -j .dynsym  -j .rel* -j .rela* -j .reloc \
384*4882a593Smuzhiyun		$(if $(EFI_TARGET),$(EFI_TARGET),-O binary) $^ $@
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun$(obj)/%.efi: $(obj)/%.so
387*4882a593Smuzhiyun	$(call cmd,efi_objcopy)
388*4882a593Smuzhiyun
389*4882a593Smuzhiyunquiet_cmd_efi_ld = LD      $@
390*4882a593Smuzhiyuncmd_efi_ld = $(LD) -nostdlib -znocombreloc -T $(EFI_LDS_PATH) -shared \
391*4882a593Smuzhiyun		-Bsymbolic $^ -o $@
392*4882a593Smuzhiyun
393*4882a593SmuzhiyunEFI_LDS_PATH = $(srctree)/arch/$(ARCH)/lib/$(EFI_LDS)
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun$(obj)/helloworld.so: $(obj)/helloworld.o arch/$(ARCH)/lib/$(EFI_CRT0) \
396*4882a593Smuzhiyun		arch/$(ARCH)/lib/$(EFI_RELOC)
397*4882a593Smuzhiyun	$(call cmd,efi_ld)
398*4882a593Smuzhiyun
399*4882a593Smuzhiyun# ACPI
400*4882a593Smuzhiyun# ---------------------------------------------------------------------------
401*4882a593Smuzhiyunquiet_cmd_acpi_c_asl= ASL     $<
402*4882a593Smuzhiyuncmd_acpi_c_asl=         \
403*4882a593Smuzhiyun	$(CPP) -x assembler-with-cpp -D__ASSEMBLY__ -P $(UBOOTINCLUDE) -o $<.tmp $<; \
404*4882a593Smuzhiyun	iasl -p $< -tc $<.tmp $(if $(KBUILD_VERBOSE:1=), >/dev/null) && \
405*4882a593Smuzhiyun	mv $(patsubst %.asl,%.hex,$<) $@
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun$(obj)/dsdt.c:    $(src)/dsdt.asl
408*4882a593Smuzhiyun	$(call cmd,acpi_c_asl)
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun# Bzip2
411*4882a593Smuzhiyun# ---------------------------------------------------------------------------
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun# Bzip2 and LZMA do not include size in file... so we have to fake that;
414*4882a593Smuzhiyun# append the size as a 32-bit littleendian number as gzip does.
415*4882a593Smuzhiyunsize_append = printf $(shell						\
416*4882a593Smuzhiyundec_size=0;								\
417*4882a593Smuzhiyunfor F in $1; do								\
418*4882a593Smuzhiyun	fsize=$$(stat -c "%s" $$F);					\
419*4882a593Smuzhiyun	dec_size=$$(expr $$dec_size + $$fsize);				\
420*4882a593Smuzhiyundone;									\
421*4882a593Smuzhiyunprintf "%08x\n" $$dec_size |						\
422*4882a593Smuzhiyun	sed 's/\(..\)/\1 /g' | {					\
423*4882a593Smuzhiyun		read ch0 ch1 ch2 ch3;					\
424*4882a593Smuzhiyun		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
425*4882a593Smuzhiyun			printf '%s%03o' '\\' $$((0x$$ch)); 		\
426*4882a593Smuzhiyun		done;							\
427*4882a593Smuzhiyun	}								\
428*4882a593Smuzhiyun)
429*4882a593Smuzhiyun
430*4882a593Smuzhiyunquiet_cmd_bzip2 = BZIP2   $@
431*4882a593Smuzhiyuncmd_bzip2 = (cat $(filter-out FORCE,$^) | \
432*4882a593Smuzhiyun	bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
433*4882a593Smuzhiyun	(rm -f $@ ; false)
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun# Lzma
436*4882a593Smuzhiyun# ---------------------------------------------------------------------------
437*4882a593Smuzhiyun
438*4882a593Smuzhiyunquiet_cmd_lzma = LZMA    $@
439*4882a593Smuzhiyuncmd_lzma = (cat $(filter-out FORCE,$^) | \
440*4882a593Smuzhiyun	lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
441*4882a593Smuzhiyun	(rm -f $@ ; false)
442*4882a593Smuzhiyun
443*4882a593Smuzhiyunquiet_cmd_lzo = LZO     $@
444*4882a593Smuzhiyuncmd_lzo = (cat $(filter-out FORCE,$^) | \
445*4882a593Smuzhiyun	lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
446*4882a593Smuzhiyun	(rm -f $@ ; false)
447*4882a593Smuzhiyun
448*4882a593Smuzhiyunquiet_cmd_lz4 = LZ4     $@
449*4882a593Smuzhiyuncmd_lz4 = (cat $(filter-out FORCE,$^) | \
450*4882a593Smuzhiyun	lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
451*4882a593Smuzhiyun	(rm -f $@ ; false)
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun# U-Boot mkimage
454*4882a593Smuzhiyun# ---------------------------------------------------------------------------
455*4882a593Smuzhiyun
456*4882a593SmuzhiyunMKIMAGE := $(srctree)/scripts/mkuboot.sh
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
459*4882a593Smuzhiyun# the number of overrides in arch makefiles
460*4882a593SmuzhiyunUIMAGE_ARCH ?= $(SRCARCH)
461*4882a593SmuzhiyunUIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
462*4882a593SmuzhiyunUIMAGE_OPTS-y ?=
463*4882a593SmuzhiyunUIMAGE_TYPE ?= kernel
464*4882a593SmuzhiyunUIMAGE_LOADADDR ?= arch_must_set_this
465*4882a593SmuzhiyunUIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
466*4882a593SmuzhiyunUIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
467*4882a593SmuzhiyunUIMAGE_IN ?= $<
468*4882a593SmuzhiyunUIMAGE_OUT ?= $@
469*4882a593Smuzhiyun
470*4882a593Smuzhiyunquiet_cmd_uimage = UIMAGE  $(UIMAGE_OUT)
471*4882a593Smuzhiyun      cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
472*4882a593Smuzhiyun			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
473*4882a593Smuzhiyun			-T $(UIMAGE_TYPE) \
474*4882a593Smuzhiyun			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
475*4882a593Smuzhiyun			-n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT)
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun# XZ
478*4882a593Smuzhiyun# ---------------------------------------------------------------------------
479*4882a593Smuzhiyun# Use xzkern to compress the kernel image and xzmisc to compress other things.
480*4882a593Smuzhiyun#
481*4882a593Smuzhiyun# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
482*4882a593Smuzhiyun# of the kernel decompressor. A BCJ filter is used if it is available for
483*4882a593Smuzhiyun# the target architecture. xzkern also appends uncompressed size of the data
484*4882a593Smuzhiyun# using size_append. The .xz format has the size information available at
485*4882a593Smuzhiyun# the end of the file too, but it's in more complex format and it's good to
486*4882a593Smuzhiyun# avoid changing the part of the boot code that reads the uncompressed size.
487*4882a593Smuzhiyun# Note that the bytes added by size_append will make the xz tool think that
488*4882a593Smuzhiyun# the file is corrupt. This is expected.
489*4882a593Smuzhiyun#
490*4882a593Smuzhiyun# xzmisc doesn't use size_append, so it can be used to create normal .xz
491*4882a593Smuzhiyun# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
492*4882a593Smuzhiyun# big dictionary would increase the memory usage too much in the multi-call
493*4882a593Smuzhiyun# decompression mode. A BCJ filter isn't used either.
494*4882a593Smuzhiyunquiet_cmd_xzkern = XZKERN  $@
495*4882a593Smuzhiyuncmd_xzkern = (cat $(filter-out FORCE,$^) | \
496*4882a593Smuzhiyun	sh $(srctree)/scripts/xz_wrap.sh && \
497*4882a593Smuzhiyun	$(call size_append, $(filter-out FORCE,$^))) > $@ || \
498*4882a593Smuzhiyun	(rm -f $@ ; false)
499*4882a593Smuzhiyun
500*4882a593Smuzhiyunquiet_cmd_xzmisc = XZMISC  $@
501*4882a593Smuzhiyuncmd_xzmisc = (cat $(filter-out FORCE,$^) | \
502*4882a593Smuzhiyun	xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
503*4882a593Smuzhiyun	(rm -f $@ ; false)
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun# Additional commands for U-Boot
506*4882a593Smuzhiyun#
507*4882a593Smuzhiyun# mkimage
508*4882a593Smuzhiyun# ---------------------------------------------------------------------------
509*4882a593SmuzhiyunMKIMAGEOUTPUT ?= /dev/null
510*4882a593Smuzhiyunquiet_cmd_mkimage = MKIMAGE $@
511*4882a593Smuzhiyuncmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
512*4882a593Smuzhiyun	$(if $(KBUILD_VERBOSE:1=), >$(MKIMAGEOUTPUT))
513