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