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