1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2f77bf014SSam Ravnborg# Backward compatibility 3f77bf014SSam Ravnborgasflags-y += $(EXTRA_AFLAGS) 4f77bf014SSam Ravnborgccflags-y += $(EXTRA_CFLAGS) 5f77bf014SSam Ravnborgcppflags-y += $(EXTRA_CPPFLAGS) 6f77bf014SSam Ravnborgldflags-y += $(EXTRA_LDFLAGS) 7f77bf014SSam Ravnborg 88fdc3fbbSCao jin# flags that take effect in current and sub directories 94e13d47cSMasahiro YamadaKBUILD_AFLAGS += $(subdir-asflags-y) 104e13d47cSMasahiro YamadaKBUILD_CFLAGS += $(subdir-ccflags-y) 11720097d8SSam Ravnborg 121da177e4SLinus Torvalds# Figure out what we need to build from the various variables 131da177e4SLinus Torvalds# =========================================================================== 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds# When an object is listed to be built compiled-in and modular, 161da177e4SLinus Torvalds# only build the compiled-in version 171da177e4SLinus Torvaldsobj-m := $(filter-out $(obj-y),$(obj-m)) 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds# Libraries are always collected in one lib file. 201da177e4SLinus Torvalds# Filter out objects already built-in 211da177e4SLinus Torvaldslib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 221da177e4SLinus Torvalds 238fdc3fbbSCao jin# Determine modorder. 248fdc3fbbSCao jin# Unfortunately, we don't have information about ordering between -y 258fdc3fbbSCao jin# and -m subdirs. Just put -y's first. 268fdc3fbbSCao jinmodorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko)) 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds# Handle objects in subdirs 291da177e4SLinus Torvalds# --------------------------------------------------------------------------- 30f49821eeSNicholas Piggin# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a 311da177e4SLinus Torvalds# and add the directory to the list of dirs to descend into: $(subdir-y) 321da177e4SLinus Torvalds# o if we encounter foo/ in $(obj-m), remove it from $(obj-m) 331da177e4SLinus Torvalds# and add the directory to the list of dirs to descend into: $(subdir-m) 341da177e4SLinus Torvalds__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) 351da177e4SLinus Torvaldssubdir-y += $(__subdir-y) 361da177e4SLinus Torvalds__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) 371da177e4SLinus Torvaldssubdir-m += $(__subdir-m) 38f49821eeSNicholas Pigginobj-y := $(patsubst %/, %/built-in.a, $(obj-y)) 391da177e4SLinus Torvaldsobj-m := $(filter-out %/, $(obj-m)) 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds# Subdirectories we need to descend into 421da177e4SLinus Torvaldssubdir-ym := $(sort $(subdir-y) $(subdir-m)) 431da177e4SLinus Torvalds 448fdc3fbbSCao jin# if $(foo-objs), $(foo-y), or $(foo-m) exists, foo.o is a composite object 451da177e4SLinus Torvaldsmulti-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) 46cf4f2193SMichal Marekmulti-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m)))) 471da177e4SLinus Torvaldsmulti-used := $(multi-used-y) $(multi-used-m) 481da177e4SLinus Torvaldssingle-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) 491da177e4SLinus Torvalds 50f5fb9765SSam Ravnborg# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to 51f5fb9765SSam Ravnborg# tell kbuild to descend 52f49821eeSNicholas Pigginsubdir-obj-y := $(filter %/built-in.a, $(obj-y)) 531da177e4SLinus Torvalds 54f98fe47cSMasahiro Yamada# Replace multi-part objects by their individual parts, 55f98fe47cSMasahiro Yamada# including built-in.a from subdirectories 56f98fe47cSMasahiro Yamadareal-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) 57f5f33681SMasahiro Yamadareal-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))) 581da177e4SLinus Torvalds 597e7962ddSMasahiro Yamada# DTB 607e7962ddSMasahiro Yamada# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built 617e7962ddSMasahiro Yamadaextra-y += $(dtb-y) 627e7962ddSMasahiro Yamadaextra-$(CONFIG_OF_ALL_DTBS) += $(dtb-) 637e7962ddSMasahiro Yamada 641da177e4SLinus Torvalds# Add subdir path 651da177e4SLinus Torvalds 661da177e4SLinus Torvaldsextra-y := $(addprefix $(obj)/,$(extra-y)) 671da177e4SLinus Torvaldsalways := $(addprefix $(obj)/,$(always)) 681da177e4SLinus Torvaldstargets := $(addprefix $(obj)/,$(targets)) 69551559e1STejun Heomodorder := $(addprefix $(obj)/,$(modorder)) 701da177e4SLinus Torvaldsobj-m := $(addprefix $(obj)/,$(obj-m)) 711da177e4SLinus Torvaldslib-y := $(addprefix $(obj)/,$(lib-y)) 721da177e4SLinus Torvaldssubdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) 73f5f33681SMasahiro Yamadareal-obj-y := $(addprefix $(obj)/,$(real-obj-y)) 74f5f33681SMasahiro Yamadareal-obj-m := $(addprefix $(obj)/,$(real-obj-m)) 751da177e4SLinus Torvaldssingle-used-m := $(addprefix $(obj)/,$(single-used-m)) 761da177e4SLinus Torvaldsmulti-used-m := $(addprefix $(obj)/,$(multi-used-m)) 771da177e4SLinus Torvaldssubdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 781da177e4SLinus Torvalds 79c0152e9aSMasahiro Yamada# Finds the multi-part object the current object will be linked into. 80c0152e9aSMasahiro Yamada# If the object belongs to two or more multi-part objects, all of them are 81c0152e9aSMasahiro Yamada# concatenated with a colon separator. 82c0152e9aSMasahiro Yamadamodname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ 83c0152e9aSMasahiro Yamada $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))) 84c0152e9aSMasahiro Yamada 85c0152e9aSMasahiro Yamadamodname = $(if $(modname-multi),$(modname-multi),$(basetarget)) 86c0152e9aSMasahiro Yamada 871da177e4SLinus Torvalds# These flags are needed for modversions and compiling, so we define them here 888fdc3fbbSCao jin# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will 891da177e4SLinus Torvalds# end up in (or would, if it gets compiled in) 90b42841b7SMichal Marekname-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) 91b42841b7SMichal Marekbasename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) 92aeacb019SMasahiro Yamadamodname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) 931da177e4SLinus Torvalds 944e13d47cSMasahiro Yamadaorig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ 95d8672b40SSam Ravnborg $(ccflags-y) $(CFLAGS_$(basetarget).o) 96656ee82cSSteven Rostedt_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) 974e13d47cSMasahiro Yamadaorig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \ 98d8672b40SSam Ravnborg $(asflags-y) $(AFLAGS_$(basetarget).o) 99a7e137ebSHeiko Carstens_a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags)) 100f77bf014SSam Ravnborg_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) 1011da177e4SLinus Torvalds 1022521f2c2SPeter Oberparleiter# 1032521f2c2SPeter Oberparleiter# Enable gcov profiling flags for a file, directory or for all files depending 1042521f2c2SPeter Oberparleiter# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL 1052521f2c2SPeter Oberparleiter# (in this order) 1062521f2c2SPeter Oberparleiter# 1072521f2c2SPeter Oberparleiterifeq ($(CONFIG_GCOV_KERNEL),y) 1082521f2c2SPeter Oberparleiter_c_flags += $(if $(patsubst n%,, \ 1092521f2c2SPeter Oberparleiter $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ 1102521f2c2SPeter Oberparleiter $(CFLAGS_GCOV)) 1112521f2c2SPeter Oberparleiterendif 1122521f2c2SPeter Oberparleiter 1130b24beccSAndrey Ryabinin# 1140b24beccSAndrey Ryabinin# Enable address sanitizer flags for kernel except some files or directories 1150b24beccSAndrey Ryabinin# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE) 1160b24beccSAndrey Ryabinin# 1170b24beccSAndrey Ryabininifeq ($(CONFIG_KASAN),y) 1180b24beccSAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \ 1190b24beccSAndrey Ryabinin $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ 1200e410e15SAndrey Konovalov $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) 1210b24beccSAndrey Ryabininendif 1220b24beccSAndrey Ryabinin 123c6d30853SAndrey Ryabininifeq ($(CONFIG_UBSAN),y) 124c6d30853SAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \ 125c6d30853SAndrey Ryabinin $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \ 126c6d30853SAndrey Ryabinin $(CFLAGS_UBSAN)) 127c6d30853SAndrey Ryabininendif 128c6d30853SAndrey Ryabinin 1295c9a8750SDmitry Vyukovifeq ($(CONFIG_KCOV),y) 1305c9a8750SDmitry Vyukov_c_flags += $(if $(patsubst n%,, \ 131a4691deaSVegard Nossum $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \ 1325c9a8750SDmitry Vyukov $(CFLAGS_KCOV)) 1335c9a8750SDmitry Vyukovendif 1345c9a8750SDmitry Vyukov 1351da177e4SLinus Torvalds# If building the kernel in a separate objtree expand all occurrences 1361da177e4SLinus Torvalds# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),) 1391da177e4SLinus Torvalds__c_flags = $(_c_flags) 1401da177e4SLinus Torvalds__a_flags = $(_a_flags) 1411da177e4SLinus Torvalds__cpp_flags = $(_cpp_flags) 1421da177e4SLinus Torvaldselse 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds# -I$(obj) locates generated .h files 1451da177e4SLinus Torvalds# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files 1461da177e4SLinus Torvalds# and locates generated .h files 1471da177e4SLinus Torvalds# FIXME: Replace both with specific CFLAGS* statements in the makefiles 1484607ebf0SAllan, Bruce W__c_flags = $(if $(obj),$(call addtree,-I$(src)) -I$(obj)) \ 149db547ef1SArnd Bergmann $(call flags,_c_flags) 1501da177e4SLinus Torvalds__a_flags = $(call flags,_a_flags) 1511da177e4SLinus Torvalds__cpp_flags = $(call flags,_cpp_flags) 1521da177e4SLinus Torvaldsendif 1531da177e4SLinus Torvalds 154d8672b40SSam Ravnborgc_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 155a95b37e2SMasahiro Yamada -include $(srctree)/include/linux/compiler_types.h \ 1561da177e4SLinus Torvalds $(__c_flags) $(modkern_cflags) \ 157b42841b7SMichal Marek $(basename_flags) $(modname_flags) 1581da177e4SLinus Torvalds 159d8672b40SSam Ravnborga_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 1601da177e4SLinus Torvalds $(__a_flags) $(modkern_aflags) 1611da177e4SLinus Torvalds 162d8672b40SSam Ravnborgcpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 163d8672b40SSam Ravnborg $(__cpp_flags) 1641da177e4SLinus Torvalds 165d503ac53SMasahiro Yamadald_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) 1661da177e4SLinus Torvalds 16750f9ddafSMasahiro YamadaDTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes 16850f9ddafSMasahiro Yamada 169b0a4d8b3SIan Campbelldtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ 17050f9ddafSMasahiro Yamada $(addprefix -I,$(DTC_INCLUDE)) \ 171e570d7c1SStephen Warren -undef -D__DTS__ 172e570d7c1SStephen Warren 173c8589d1eSMasahiro Yamada# Useful for describing the dependency of composite objects 174c8589d1eSMasahiro Yamada# Usage: 175c8589d1eSMasahiro Yamada# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) 176c8589d1eSMasahiro Yamadadefine multi_depend 177c8589d1eSMasahiro Yamada$(foreach m, $(notdir $1), \ 178c8589d1eSMasahiro Yamada $(eval $(obj)/$m: \ 179c8589d1eSMasahiro Yamada $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s))))))) 180c8589d1eSMasahiro Yamadaendef 181c8589d1eSMasahiro Yamada 1827373f4f8SArnaud Lacombe# LEX 1837373f4f8SArnaud Lacombe# --------------------------------------------------------------------------- 1847373f4f8SArnaud Lacombequiet_cmd_flex = LEX $@ 185eea199b4SMasahiro Yamada cmd_flex = $(LEX) -o$@ -L $< 1867373f4f8SArnaud Lacombe 187833e6224SMasahiro Yamada$(obj)/%.lex.c: $(src)/%.l FORCE 188033dba2eSMasahiro Yamada $(call if_changed,flex) 1897373f4f8SArnaud Lacombe 1907373f4f8SArnaud Lacombe# YACC 1917373f4f8SArnaud Lacombe# --------------------------------------------------------------------------- 1927373f4f8SArnaud Lacombequiet_cmd_bison = YACC $@ 193eea199b4SMasahiro Yamada cmd_bison = $(YACC) -o$@ -t -l $< 1947373f4f8SArnaud Lacombe 195833e6224SMasahiro Yamada$(obj)/%.tab.c: $(src)/%.y FORCE 196033dba2eSMasahiro Yamada $(call if_changed,bison) 1977373f4f8SArnaud Lacombe 1987373f4f8SArnaud Lacombequiet_cmd_bison_h = YACC $@ 199d59fbbd0SMasahiro Yamada cmd_bison_h = $(YACC) -o/dev/null --defines=$@ -t -l $< 2007373f4f8SArnaud Lacombe 201833e6224SMasahiro Yamada$(obj)/%.tab.h: $(src)/%.y FORCE 202033dba2eSMasahiro Yamada $(call if_changed,bison_h) 203033dba2eSMasahiro Yamada 2041da177e4SLinus Torvalds# Shipped files 2051da177e4SLinus Torvalds# =========================================================================== 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvaldsquiet_cmd_shipped = SHIPPED $@ 2081da177e4SLinus Torvaldscmd_shipped = cat $< > $@ 2091da177e4SLinus Torvalds 210991d76c9SArnaud Lacombe$(obj)/%: $(src)/%_shipped 2111da177e4SLinus Torvalds $(call cmd,shipped) 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds# Commands useful for building a boot image 2141da177e4SLinus Torvalds# =========================================================================== 2151da177e4SLinus Torvalds# 2161da177e4SLinus Torvalds# Use as following: 2171da177e4SLinus Torvalds# 2181da177e4SLinus Torvalds# target: source(s) FORCE 2191da177e4SLinus Torvalds# $(if_changed,ld/objcopy/gzip) 2201da177e4SLinus Torvalds# 221836caba7SSam Ravnborg# and add target to extra-y so that we know we have to 2221da177e4SLinus Torvalds# read in the saved command line 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds# Linking 2251da177e4SLinus Torvalds# --------------------------------------------------------------------------- 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvaldsquiet_cmd_ld = LD $@ 2282fb9279fSMasahiro Yamadacmd_ld = $(LD) $(ld_flags) $(filter-out FORCE,$^) -o $@ 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds# Objcopy 2311da177e4SLinus Torvalds# --------------------------------------------------------------------------- 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvaldsquiet_cmd_objcopy = OBJCOPY $@ 2341da177e4SLinus Torvaldscmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds# Gzip 2371da177e4SLinus Torvalds# --------------------------------------------------------------------------- 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvaldsquiet_cmd_gzip = GZIP $@ 2406ae9ecb8SMichal Marekcmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \ 241d3dd3b5aSH. Peter Anvin (rm -f $@ ; false) 2421da177e4SLinus Torvalds 243aab94339SDirk Brandewie# DTC 244aab94339SDirk Brandewie# --------------------------------------------------------------------------- 2456b22b3d1SRob HerringDTC ?= $(objtree)/scripts/dtc/dtc 246aab94339SDirk Brandewie 247bc553986SRob Herring# Disable noisy checks by default 248f759625aSMasahiro Yamadaifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) 2498654cb8dSRob HerringDTC_FLAGS += -Wno-unit_address_vs_reg \ 2508654cb8dSRob Herring -Wno-unit_address_format \ 2514fd98e37SRob Herring -Wno-avoid_unnecessary_addr_size \ 2524fd98e37SRob Herring -Wno-alias_paths \ 25374656b68SRob Herring -Wno-graph_child_address \ 25474656b68SRob Herring -Wno-graph_port \ 255*70523a3cSRob Herring -Wno-simple_bus_reg \ 25674656b68SRob Herring -Wno-unique_unit_address \ 2578654cb8dSRob Herring -Wno-pci_device_reg 258bc553986SRob Herringendif 259bc553986SRob Herring 260f759625aSMasahiro Yamadaifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) 2618654cb8dSRob HerringDTC_FLAGS += -Wnode_name_chars_strict \ 2628654cb8dSRob Herring -Wproperty_name_chars_strict 263aab94339SDirk Brandewieendif 264aab94339SDirk Brandewie 265331f7416SFrank RowandDTC_FLAGS += $(DTC_FLAGS_$(basetarget)) 266331f7416SFrank Rowand 267aab94339SDirk Brandewie# Generate an assembly file to wrap the output of the device tree compiler 268aab94339SDirk Brandewiequiet_cmd_dt_S_dtb= DTB $@ 269aab94339SDirk Brandewiecmd_dt_S_dtb= \ 270aab94339SDirk Brandewie( \ 271aab94339SDirk Brandewie echo '\#include <asm-generic/vmlinux.lds.h>'; \ 272aab94339SDirk Brandewie echo '.section .dtb.init.rodata,"a"'; \ 273aab94339SDirk Brandewie echo '.balign STRUCT_ALIGNMENT'; \ 27455fe6da9SJames Hogan echo '.global __dtb_$(subst -,_,$(*F))_begin'; \ 27555fe6da9SJames Hogan echo '__dtb_$(subst -,_,$(*F))_begin:'; \ 276aab94339SDirk Brandewie echo '.incbin "$<" '; \ 27755fe6da9SJames Hogan echo '__dtb_$(subst -,_,$(*F))_end:'; \ 27855fe6da9SJames Hogan echo '.global __dtb_$(subst -,_,$(*F))_end'; \ 279aab94339SDirk Brandewie echo '.balign STRUCT_ALIGNMENT'; \ 280aab94339SDirk Brandewie) > $@ 281aab94339SDirk Brandewie 282a7f92419SMasahiro Yamada$(obj)/%.dtb.S: $(obj)/%.dtb FORCE 283a7f92419SMasahiro Yamada $(call if_changed,dt_S_dtb) 284aab94339SDirk Brandewie 285aab94339SDirk Brandewiequiet_cmd_dtc = DTC $@ 28677479b38SNathan Rossicmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \ 28737c8a5faSRob Herring $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 2886b22b3d1SRob Herring $(DTC) -O dtb -o $@ -b 0 \ 28950f9ddafSMasahiro Yamada $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \ 290b0a4d8b3SIan Campbell -d $(depfile).dtc.tmp $(dtc-tmp) ; \ 291b0a4d8b3SIan Campbell cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) 2921da177e4SLinus Torvalds 293b8fc5b21SRob Herring$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE 29490b335fbSStephen Warren $(call if_changed_dep,dtc) 29590b335fbSStephen Warren 296b0a4d8b3SIan Campbelldtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 29722435f38SStephen Warren 298bc22c17eSAlain Knaff# Bzip2 299bc22c17eSAlain Knaff# --------------------------------------------------------------------------- 300bc22c17eSAlain Knaff 301d3dd3b5aSH. Peter Anvin# Bzip2 and LZMA do not include size in file... so we have to fake that; 302d3dd3b5aSH. Peter Anvin# append the size as a 32-bit littleendian number as gzip does. 3034a2ff67cSMichael Tokarevsize_append = printf $(shell \ 304d3dd3b5aSH. Peter Anvindec_size=0; \ 305d3dd3b5aSH. Peter Anvinfor F in $1; do \ 306a670b0b4SMichael Forney fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \ 307d3dd3b5aSH. Peter Anvin dec_size=$$(expr $$dec_size + $$fsize); \ 308d3dd3b5aSH. Peter Anvindone; \ 3091373411aSJonathan Niederprintf "%08x\n" $$dec_size | \ 3101373411aSJonathan Nieder sed 's/\(..\)/\1 /g' | { \ 3111373411aSJonathan Nieder read ch0 ch1 ch2 ch3; \ 3121373411aSJonathan Nieder for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ 3131373411aSJonathan Nieder printf '%s%03o' '\\' $$((0x$$ch)); \ 3141373411aSJonathan Nieder done; \ 3151373411aSJonathan Nieder } \ 316d3dd3b5aSH. Peter Anvin) 317bc22c17eSAlain Knaff 318bc22c17eSAlain Knaffquiet_cmd_bzip2 = BZIP2 $@ 319d3dd3b5aSH. Peter Anvincmd_bzip2 = (cat $(filter-out FORCE,$^) | \ 320d3dd3b5aSH. Peter Anvin bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 321d3dd3b5aSH. Peter Anvin (rm -f $@ ; false) 322bc22c17eSAlain Knaff 323bc22c17eSAlain Knaff# Lzma 324bc22c17eSAlain Knaff# --------------------------------------------------------------------------- 325bc22c17eSAlain Knaff 326bc22c17eSAlain Knaffquiet_cmd_lzma = LZMA $@ 327d3dd3b5aSH. Peter Anvincmd_lzma = (cat $(filter-out FORCE,$^) | \ 328d3dd3b5aSH. Peter Anvin lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 329d3dd3b5aSH. Peter Anvin (rm -f $@ ; false) 3307dd65febSAlbin Tonnerre 3317dd65febSAlbin Tonnerrequiet_cmd_lzo = LZO $@ 3327dd65febSAlbin Tonnerrecmd_lzo = (cat $(filter-out FORCE,$^) | \ 3337dd65febSAlbin Tonnerre lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 3347dd65febSAlbin Tonnerre (rm -f $@ ; false) 335d61931d8SBorislav Petkov 336e76e1fdfSKyungsik Leequiet_cmd_lz4 = LZ4 $@ 337e76e1fdfSKyungsik Leecmd_lz4 = (cat $(filter-out FORCE,$^) | \ 338e76e1fdfSKyungsik Lee lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 339e76e1fdfSKyungsik Lee (rm -f $@ ; false) 340e76e1fdfSKyungsik Lee 341e3393645SStephen Warren# U-Boot mkimage 342e3393645SStephen Warren# --------------------------------------------------------------------------- 343e3393645SStephen Warren 344e3393645SStephen WarrenMKIMAGE := $(srctree)/scripts/mkuboot.sh 345e3393645SStephen Warren 346e3393645SStephen Warren# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces 347e3393645SStephen Warren# the number of overrides in arch makefiles 348e3393645SStephen WarrenUIMAGE_ARCH ?= $(SRCARCH) 349e3393645SStephen WarrenUIMAGE_COMPRESSION ?= $(if $(2),$(2),none) 350e3393645SStephen WarrenUIMAGE_OPTS-y ?= 351e3393645SStephen WarrenUIMAGE_TYPE ?= kernel 352e3393645SStephen WarrenUIMAGE_LOADADDR ?= arch_must_set_this 353e3393645SStephen WarrenUIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) 354e3393645SStephen WarrenUIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)' 355e3393645SStephen WarrenUIMAGE_IN ?= $< 356e3393645SStephen WarrenUIMAGE_OUT ?= $@ 357e3393645SStephen Warren 358e3393645SStephen Warrenquiet_cmd_uimage = UIMAGE $(UIMAGE_OUT) 359e3393645SStephen Warren cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ 360e3393645SStephen Warren -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ 361e3393645SStephen Warren -T $(UIMAGE_TYPE) \ 362e3393645SStephen Warren -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ 363e3393645SStephen Warren -n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT) 364e3393645SStephen Warren 36524fa0402SLasse Collin# XZ 36624fa0402SLasse Collin# --------------------------------------------------------------------------- 36724fa0402SLasse Collin# Use xzkern to compress the kernel image and xzmisc to compress other things. 36824fa0402SLasse Collin# 36924fa0402SLasse Collin# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage 37024fa0402SLasse Collin# of the kernel decompressor. A BCJ filter is used if it is available for 37124fa0402SLasse Collin# the target architecture. xzkern also appends uncompressed size of the data 37224fa0402SLasse Collin# using size_append. The .xz format has the size information available at 37324fa0402SLasse Collin# the end of the file too, but it's in more complex format and it's good to 37424fa0402SLasse Collin# avoid changing the part of the boot code that reads the uncompressed size. 37524fa0402SLasse Collin# Note that the bytes added by size_append will make the xz tool think that 37624fa0402SLasse Collin# the file is corrupt. This is expected. 37724fa0402SLasse Collin# 37824fa0402SLasse Collin# xzmisc doesn't use size_append, so it can be used to create normal .xz 37924fa0402SLasse Collin# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very 38024fa0402SLasse Collin# big dictionary would increase the memory usage too much in the multi-call 38124fa0402SLasse Collin# decompression mode. A BCJ filter isn't used either. 38224fa0402SLasse Collinquiet_cmd_xzkern = XZKERN $@ 38324fa0402SLasse Collincmd_xzkern = (cat $(filter-out FORCE,$^) | \ 38424fa0402SLasse Collin sh $(srctree)/scripts/xz_wrap.sh && \ 38524fa0402SLasse Collin $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 38624fa0402SLasse Collin (rm -f $@ ; false) 38724fa0402SLasse Collin 38824fa0402SLasse Collinquiet_cmd_xzmisc = XZMISC $@ 38924fa0402SLasse Collincmd_xzmisc = (cat $(filter-out FORCE,$^) | \ 39024fa0402SLasse Collin xz --check=crc32 --lzma2=dict=1MiB) > $@ || \ 39124fa0402SLasse Collin (rm -f $@ ; false) 392ebf003f0SMatthias Kaehlcke 393ebf003f0SMatthias Kaehlcke# ASM offsets 394ebf003f0SMatthias Kaehlcke# --------------------------------------------------------------------------- 395ebf003f0SMatthias Kaehlcke 396ebf003f0SMatthias Kaehlcke# Default sed regexp - multiline due to syntax constraints 397cf0c3e68SJeroen Hofstee# 398cf0c3e68SJeroen Hofstee# Use [:space:] because LLVM's integrated assembler inserts <tab> around 399cf0c3e68SJeroen Hofstee# the .ascii directive whereas GCC keeps the <space> as-is. 400ebf003f0SMatthias Kaehlckedefine sed-offsets 401cf0c3e68SJeroen Hofstee 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \ 402cf0c3e68SJeroen Hofstee /^->/{s:->#\(.*\):/* \1 */:; \ 403ebf003f0SMatthias Kaehlcke s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ 404cf0c3e68SJeroen Hofstee s:->::; p;}' 405ebf003f0SMatthias Kaehlckeendef 406ebf003f0SMatthias Kaehlcke 407ebf003f0SMatthias Kaehlcke# Use filechk to avoid rebuilds when a header changes, but the resulting file 408ebf003f0SMatthias Kaehlcke# does not 409ebf003f0SMatthias Kaehlckedefine filechk_offsets 410ebf003f0SMatthias Kaehlcke (set -e; \ 411ebf003f0SMatthias Kaehlcke echo "#ifndef $2"; \ 412ebf003f0SMatthias Kaehlcke echo "#define $2"; \ 413ebf003f0SMatthias Kaehlcke echo "/*"; \ 414ebf003f0SMatthias Kaehlcke echo " * DO NOT MODIFY."; \ 415ebf003f0SMatthias Kaehlcke echo " *"; \ 416ebf003f0SMatthias Kaehlcke echo " * This file was generated by Kbuild"; \ 417ebf003f0SMatthias Kaehlcke echo " */"; \ 418ebf003f0SMatthias Kaehlcke echo ""; \ 41943fee2b2SMasahiro Yamada sed -ne $(sed-offsets) < $<; \ 420ebf003f0SMatthias Kaehlcke echo ""; \ 421ebf003f0SMatthias Kaehlcke echo "#endif" ) 422ebf003f0SMatthias Kaehlckeendef 423