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) 759721d4eSMasahiro Yamadaifneq ($(always),) 859721d4eSMasahiro Yamada$(warning 'always' is deprecated. Please use 'always-y' instead) 95f2fb52fSMasahiro Yamadaalways-y += $(always) 1059721d4eSMasahiro Yamadaendif 1159721d4eSMasahiro Yamadaifneq ($(hostprogs-y),) 1259721d4eSMasahiro Yamada$(warning 'hostprogs-y' is deprecated. Please use 'hostprogs' instead) 1359721d4eSMasahiro Yamadahostprogs += $(hostprogs-y) 1459721d4eSMasahiro Yamadaendif 1559721d4eSMasahiro Yamadaifneq ($(hostprogs-m),) 1659721d4eSMasahiro Yamada$(warning 'hostprogs-m' is deprecated. Please use 'hostprogs' instead) 1759721d4eSMasahiro Yamadahostprogs += $(hostprogs-m) 1859721d4eSMasahiro Yamadaendif 19f77bf014SSam Ravnborg 208fdc3fbbSCao jin# flags that take effect in current and sub directories 214e13d47cSMasahiro YamadaKBUILD_AFLAGS += $(subdir-asflags-y) 224e13d47cSMasahiro YamadaKBUILD_CFLAGS += $(subdir-ccflags-y) 23720097d8SSam Ravnborg 241da177e4SLinus Torvalds# Figure out what we need to build from the various variables 251da177e4SLinus Torvalds# =========================================================================== 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds# When an object is listed to be built compiled-in and modular, 281da177e4SLinus Torvalds# only build the compiled-in version 291da177e4SLinus Torvaldsobj-m := $(filter-out $(obj-y),$(obj-m)) 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds# Libraries are always collected in one lib file. 321da177e4SLinus Torvalds# Filter out objects already built-in 331da177e4SLinus Torvaldslib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 341da177e4SLinus Torvalds 350a8820e7SMasahiro Yamada# Subdirectories we need to descend into 360a8820e7SMasahiro Yamadasubdir-ym := $(sort $(subdir-y) $(subdir-m) \ 370a8820e7SMasahiro Yamada $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m)))) 380a8820e7SMasahiro Yamada 39b2c88554SMasahiro Yamada# Handle objects in subdirs: 40b2c88554SMasahiro Yamada# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and 41b2c88554SMasahiro Yamada# foo/modules.order 42b2c88554SMasahiro Yamada# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order 43b2c88554SMasahiro Yamada# 44b2c88554SMasahiro Yamada# Generate modules.order to determine modorder. Unfortunately, we don't have 45b2c88554SMasahiro Yamada# information about ordering between -y and -m subdirs. Just put -y's first. 46b2c88554SMasahiro Yamada 47b2c88554SMasahiro Yamadaifdef need-modorder 48b2c88554SMasahiro Yamadaobj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m)) 49b2c88554SMasahiro Yamadaelse 50b2c88554SMasahiro Yamadaobj-m := $(filter-out %/, $(obj-m)) 51b2c88554SMasahiro Yamadaendif 52b2c88554SMasahiro Yamada 5356d58936SMasahiro Yamadaifdef need-builtin 54f49821eeSNicholas Pigginobj-y := $(patsubst %/, %/built-in.a, $(obj-y)) 5556d58936SMasahiro Yamadaelse 5656d58936SMasahiro Yamadaobj-y := $(filter-out %/, $(obj-y)) 5756d58936SMasahiro Yamadaendif 581da177e4SLinus Torvalds 5933e84f2eSMasahiro Yamada# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object 6033e84f2eSMasahiro Yamadamulti-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-))), $(m)))) 6133e84f2eSMasahiro Yamadamulti-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)) $($(m:.o=-))), $(m)))) 621da177e4SLinus Torvaldsmulti-used := $(multi-used-y) $(multi-used-m) 631da177e4SLinus Torvalds 64f98fe47cSMasahiro Yamada# Replace multi-part objects by their individual parts, 65f98fe47cSMasahiro Yamada# including built-in.a from subdirectories 6633e84f2eSMasahiro Yamadareal-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) 6733e84f2eSMasahiro Yamadareal-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)) $($(m:.o=-))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) 681da177e4SLinus Torvalds 695f2fb52fSMasahiro Yamadaalways-y += $(always-m) 705f2fb52fSMasahiro Yamada 71faabed29SMasahiro Yamada# hostprogs-always-y += foo 72faabed29SMasahiro Yamada# ... is a shorthand for 73faabed29SMasahiro Yamada# hostprogs += foo 74faabed29SMasahiro Yamada# always-y += foo 75faabed29SMasahiro Yamadahostprogs += $(hostprogs-always-y) $(hostprogs-always-m) 76faabed29SMasahiro Yamadaalways-y += $(hostprogs-always-y) $(hostprogs-always-m) 77faabed29SMasahiro Yamada 78faabed29SMasahiro Yamada# userprogs-always-y is likewise. 79faabed29SMasahiro Yamadauserprogs += $(userprogs-always-y) $(userprogs-always-m) 80faabed29SMasahiro Yamadaalways-y += $(userprogs-always-y) $(userprogs-always-m) 81faabed29SMasahiro Yamada 827e7962ddSMasahiro Yamada# DTB 837e7962ddSMasahiro Yamada# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built 847e7962ddSMasahiro Yamadaextra-y += $(dtb-y) 857e7962ddSMasahiro Yamadaextra-$(CONFIG_OF_ALL_DTBS) += $(dtb-) 867e7962ddSMasahiro Yamada 874f0e3a57SRob Herringifneq ($(CHECK_DTBS),) 884f0e3a57SRob Herringextra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y)) 89*ce88c9c7SViresh Kumarextra-y += $(patsubst %.dtbo,%.dt.yaml, $(dtb-y)) 904f0e3a57SRob Herringextra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-)) 91*ce88c9c7SViresh Kumarextra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtbo,%.dt.yaml, $(dtb-)) 924f0e3a57SRob Herringendif 934f0e3a57SRob Herring 941da177e4SLinus Torvalds# Add subdir path 951da177e4SLinus Torvalds 961da177e4SLinus Torvaldsextra-y := $(addprefix $(obj)/,$(extra-y)) 975f2fb52fSMasahiro Yamadaalways-y := $(addprefix $(obj)/,$(always-y)) 981da177e4SLinus Torvaldstargets := $(addprefix $(obj)/,$(targets)) 991da177e4SLinus Torvaldsobj-m := $(addprefix $(obj)/,$(obj-m)) 1001da177e4SLinus Torvaldslib-y := $(addprefix $(obj)/,$(lib-y)) 101f5f33681SMasahiro Yamadareal-obj-y := $(addprefix $(obj)/,$(real-obj-y)) 102f5f33681SMasahiro Yamadareal-obj-m := $(addprefix $(obj)/,$(real-obj-m)) 1031da177e4SLinus Torvaldsmulti-used-m := $(addprefix $(obj)/,$(multi-used-m)) 1041da177e4SLinus Torvaldssubdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 1051da177e4SLinus Torvalds 106c0152e9aSMasahiro Yamada# Finds the multi-part object the current object will be linked into. 1071664a377SMasahiro Yamada# If the object belongs to two or more multi-part objects, list them all. 1081664a377SMasahiro Yamadamodname-multi = $(sort $(foreach m,$(multi-used),\ 1091664a377SMasahiro Yamada $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))) 110c0152e9aSMasahiro Yamada 1111664a377SMasahiro Yamada__modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) 1121664a377SMasahiro Yamada 1131664a377SMasahiro Yamadamodname = $(subst $(space),:,$(__modname)) 1141664a377SMasahiro Yamadamodfile = $(addprefix $(obj)/,$(__modname)) 115c0152e9aSMasahiro Yamada 11654b8ae66SMasahiro Yamada# target with $(obj)/ and its suffix stripped 11754b8ae66SMasahiro Yamadatarget-stem = $(basename $(patsubst $(obj)/%,%,$@)) 11854b8ae66SMasahiro Yamada 1191da177e4SLinus Torvalds# These flags are needed for modversions and compiling, so we define them here 1208fdc3fbbSCao jin# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will 1211da177e4SLinus Torvalds# end up in (or would, if it gets compiled in) 1227e826c44SMasahiro Yamadaname-fix = $(call stringify,$(subst $(comma),_,$(subst -,_,$1))) 123b42841b7SMichal Marekbasename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) 124aeacb019SMasahiro Yamadamodname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) 1251664a377SMasahiro Yamadamodfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile)) 1261da177e4SLinus Torvalds 12715d5761aSMasahiro Yamada_c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \ 12815d5761aSMasahiro Yamada $(filter-out $(ccflags-remove-y), \ 12915d5761aSMasahiro Yamada $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \ 13015d5761aSMasahiro Yamada $(CFLAGS_$(target-stem).o)) 13115d5761aSMasahiro Yamada_a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \ 13215d5761aSMasahiro Yamada $(filter-out $(asflags-remove-y), \ 13315d5761aSMasahiro Yamada $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \ 13415d5761aSMasahiro Yamada $(AFLAGS_$(target-stem).o)) 13554b8ae66SMasahiro Yamada_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) 1361da177e4SLinus Torvalds 1372521f2c2SPeter Oberparleiter# 1382521f2c2SPeter Oberparleiter# Enable gcov profiling flags for a file, directory or for all files depending 1392521f2c2SPeter Oberparleiter# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL 1402521f2c2SPeter Oberparleiter# (in this order) 1412521f2c2SPeter Oberparleiter# 1422521f2c2SPeter Oberparleiterifeq ($(CONFIG_GCOV_KERNEL),y) 1432521f2c2SPeter Oberparleiter_c_flags += $(if $(patsubst n%,, \ 1442521f2c2SPeter Oberparleiter $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ 1452521f2c2SPeter Oberparleiter $(CFLAGS_GCOV)) 1462521f2c2SPeter Oberparleiterendif 1472521f2c2SPeter Oberparleiter 1480b24beccSAndrey Ryabinin# 1490b24beccSAndrey Ryabinin# Enable address sanitizer flags for kernel except some files or directories 1500b24beccSAndrey Ryabinin# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE) 1510b24beccSAndrey Ryabinin# 1520b24beccSAndrey Ryabininifeq ($(CONFIG_KASAN),y) 1530fea6e9aSAndrey Konovalovifneq ($(CONFIG_KASAN_HW_TAGS),y) 1540b24beccSAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \ 1550b24beccSAndrey Ryabinin $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ 1560e410e15SAndrey Konovalov $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) 1570b24beccSAndrey Ryabininendif 1580fea6e9aSAndrey Konovalovendif 1590b24beccSAndrey Ryabinin 160c6d30853SAndrey Ryabininifeq ($(CONFIG_UBSAN),y) 161c6d30853SAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \ 162c6d30853SAndrey Ryabinin $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \ 163c6d30853SAndrey Ryabinin $(CFLAGS_UBSAN)) 164c6d30853SAndrey Ryabininendif 165c6d30853SAndrey Ryabinin 1665c9a8750SDmitry Vyukovifeq ($(CONFIG_KCOV),y) 1675c9a8750SDmitry Vyukov_c_flags += $(if $(patsubst n%,, \ 168a4691deaSVegard Nossum $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \ 1695c9a8750SDmitry Vyukov $(CFLAGS_KCOV)) 1705c9a8750SDmitry Vyukovendif 1715c9a8750SDmitry Vyukov 172dfd402a4SMarco Elver# 173dfd402a4SMarco Elver# Enable KCSAN flags except some files or directories we don't want to check 174dfd402a4SMarco Elver# (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE) 175dfd402a4SMarco Elver# 176dfd402a4SMarco Elverifeq ($(CONFIG_KCSAN),y) 177dfd402a4SMarco Elver_c_flags += $(if $(patsubst n%,, \ 178dfd402a4SMarco Elver $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \ 179dfd402a4SMarco Elver $(CFLAGS_KCSAN)) 180dfd402a4SMarco Elverendif 181dfd402a4SMarco Elver 182cdd750bfSMasahiro Yamada# $(srctree)/$(src) for including checkin headers from generated source files 183cdd750bfSMasahiro Yamada# $(objtree)/$(obj) for including generated headers from checkin source files 18458156ba4SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),) 185051f278eSMasahiro Yamadaifdef building_out_of_srctree 186cdd750bfSMasahiro Yamada_c_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj) 187cdd750bfSMasahiro Yamada_a_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj) 188cdd750bfSMasahiro Yamada_cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj) 1891da177e4SLinus Torvaldsendif 19058156ba4SMasahiro Yamadaendif 1911da177e4SLinus Torvalds 192eb27ea5cSMasahiro Yamadapart-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y) 193eb27ea5cSMasahiro Yamadaquiet_modtag = $(if $(part-of-module),[M], ) 194eb27ea5cSMasahiro Yamada 195eb27ea5cSMasahiro Yamadamodkern_cflags = \ 196eb27ea5cSMasahiro Yamada $(if $(part-of-module), \ 197eb27ea5cSMasahiro Yamada $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ 1981664a377SMasahiro Yamada $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags)) 199eb27ea5cSMasahiro Yamada 200eb27ea5cSMasahiro Yamadamodkern_aflags = $(if $(part-of-module), \ 201eb27ea5cSMasahiro Yamada $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ 202eb27ea5cSMasahiro Yamada $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)) 203eb27ea5cSMasahiro Yamada 20430a77297SMasahiro Yamadac_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 205a95b37e2SMasahiro Yamada -include $(srctree)/include/linux/compiler_types.h \ 206cdd750bfSMasahiro Yamada $(_c_flags) $(modkern_cflags) \ 207b42841b7SMichal Marek $(basename_flags) $(modname_flags) 2081da177e4SLinus Torvalds 20930a77297SMasahiro Yamadaa_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 210cdd750bfSMasahiro Yamada $(_a_flags) $(modkern_aflags) 2111da177e4SLinus Torvalds 21230a77297SMasahiro Yamadacpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 213cdd750bfSMasahiro Yamada $(_cpp_flags) 2141da177e4SLinus Torvalds 215d503ac53SMasahiro Yamadald_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) 2161da177e4SLinus Torvalds 21750f9ddafSMasahiro YamadaDTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes 21850f9ddafSMasahiro Yamada 21930a77297SMasahiro Yamadadtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \ 22050f9ddafSMasahiro Yamada $(addprefix -I,$(DTC_INCLUDE)) \ 221e570d7c1SStephen Warren -undef -D__DTS__ 222e570d7c1SStephen Warren 223c8589d1eSMasahiro Yamada# Useful for describing the dependency of composite objects 224c8589d1eSMasahiro Yamada# Usage: 225c8589d1eSMasahiro Yamada# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) 226c8589d1eSMasahiro Yamadadefine multi_depend 227c8589d1eSMasahiro Yamada$(foreach m, $(notdir $1), \ 228c8589d1eSMasahiro Yamada $(eval $(obj)/$m: \ 229c8589d1eSMasahiro Yamada $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s))))))) 230c8589d1eSMasahiro Yamadaendef 231c8589d1eSMasahiro Yamada 232dee9c0b5SMasahiro Yamadaquiet_cmd_copy = COPY $@ 233dee9c0b5SMasahiro Yamada cmd_copy = cp $< $@ 234dee9c0b5SMasahiro Yamada 2351da177e4SLinus Torvalds# Shipped files 2361da177e4SLinus Torvalds# =========================================================================== 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvaldsquiet_cmd_shipped = SHIPPED $@ 2391da177e4SLinus Torvaldscmd_shipped = cat $< > $@ 2401da177e4SLinus Torvalds 241991d76c9SArnaud Lacombe$(obj)/%: $(src)/%_shipped 2421da177e4SLinus Torvalds $(call cmd,shipped) 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds# Commands useful for building a boot image 2451da177e4SLinus Torvalds# =========================================================================== 2461da177e4SLinus Torvalds# 2471da177e4SLinus Torvalds# Use as following: 2481da177e4SLinus Torvalds# 2491da177e4SLinus Torvalds# target: source(s) FORCE 2501da177e4SLinus Torvalds# $(if_changed,ld/objcopy/gzip) 2511da177e4SLinus Torvalds# 252836caba7SSam Ravnborg# and add target to extra-y so that we know we have to 2531da177e4SLinus Torvalds# read in the saved command line 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds# Linking 2561da177e4SLinus Torvalds# --------------------------------------------------------------------------- 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvaldsquiet_cmd_ld = LD $@ 259afa974b7SMasahiro Yamada cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@ 2601da177e4SLinus Torvalds 261898f5a00SMasahiro Yamada# Archive 262898f5a00SMasahiro Yamada# --------------------------------------------------------------------------- 263898f5a00SMasahiro Yamada 264898f5a00SMasahiro Yamadaquiet_cmd_ar = AR $@ 26513dc8c02SMasahiro Yamada cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs) 266898f5a00SMasahiro Yamada 2671da177e4SLinus Torvalds# Objcopy 2681da177e4SLinus Torvalds# --------------------------------------------------------------------------- 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvaldsquiet_cmd_objcopy = OBJCOPY $@ 2711da177e4SLinus Torvaldscmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds# Gzip 2741da177e4SLinus Torvalds# --------------------------------------------------------------------------- 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvaldsquiet_cmd_gzip = GZIP $@ 277e4a42c82SDenis Efremov cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@ 2781da177e4SLinus Torvalds 279aab94339SDirk Brandewie# DTC 280aab94339SDirk Brandewie# --------------------------------------------------------------------------- 2816b22b3d1SRob HerringDTC ?= $(objtree)/scripts/dtc/dtc 2823eb619b2SRob HerringDTC_FLAGS += -Wno-interrupt_provider 283aab94339SDirk Brandewie 284bc553986SRob Herring# Disable noisy checks by default 285e27128dbSMasahiro Yamadaifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) 2868654cb8dSRob HerringDTC_FLAGS += -Wno-unit_address_vs_reg \ 2878654cb8dSRob Herring -Wno-unit_address_format \ 2884fd98e37SRob Herring -Wno-avoid_unnecessary_addr_size \ 2894fd98e37SRob Herring -Wno-alias_paths \ 29074656b68SRob Herring -Wno-graph_child_address \ 29170523a3cSRob Herring -Wno-simple_bus_reg \ 29274656b68SRob Herring -Wno-unique_unit_address \ 2938654cb8dSRob Herring -Wno-pci_device_reg 294bc553986SRob Herringendif 295bc553986SRob Herring 296e27128dbSMasahiro Yamadaifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),) 2978654cb8dSRob HerringDTC_FLAGS += -Wnode_name_chars_strict \ 2983eb619b2SRob Herring -Wproperty_name_chars_strict \ 2993eb619b2SRob Herring -Winterrupt_provider 300aab94339SDirk Brandewieendif 301aab94339SDirk Brandewie 302331f7416SFrank RowandDTC_FLAGS += $(DTC_FLAGS_$(basetarget)) 303331f7416SFrank Rowand 304aab94339SDirk Brandewie# Generate an assembly file to wrap the output of the device tree compiler 305aab94339SDirk Brandewiequiet_cmd_dt_S_dtb= DTB $@ 306aab94339SDirk Brandewiecmd_dt_S_dtb= \ 307b79c6aa6SMasahiro Yamada{ \ 308aab94339SDirk Brandewie echo '\#include <asm-generic/vmlinux.lds.h>'; \ 309aab94339SDirk Brandewie echo '.section .dtb.init.rodata,"a"'; \ 310aab94339SDirk Brandewie echo '.balign STRUCT_ALIGNMENT'; \ 31155fe6da9SJames Hogan echo '.global __dtb_$(subst -,_,$(*F))_begin'; \ 31255fe6da9SJames Hogan echo '__dtb_$(subst -,_,$(*F))_begin:'; \ 313aab94339SDirk Brandewie echo '.incbin "$<" '; \ 31455fe6da9SJames Hogan echo '__dtb_$(subst -,_,$(*F))_end:'; \ 31555fe6da9SJames Hogan echo '.global __dtb_$(subst -,_,$(*F))_end'; \ 316aab94339SDirk Brandewie echo '.balign STRUCT_ALIGNMENT'; \ 317b79c6aa6SMasahiro Yamada} > $@ 318aab94339SDirk Brandewie 319a7f92419SMasahiro Yamada$(obj)/%.dtb.S: $(obj)/%.dtb FORCE 320a7f92419SMasahiro Yamada $(call if_changed,dt_S_dtb) 321aab94339SDirk Brandewie 322aab94339SDirk Brandewiequiet_cmd_dtc = DTC $@ 323dd7699e3SMasahiro Yamadacmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 32478046fabSMasahiro Yamada $(DTC) -O $(patsubst .%,%,$(suffix $@)) -o $@ -b 0 \ 32550f9ddafSMasahiro Yamada $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \ 326b0a4d8b3SIan Campbell -d $(depfile).dtc.tmp $(dtc-tmp) ; \ 327b0a4d8b3SIan Campbell cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) 3281da177e4SLinus Torvalds 329b8fc5b21SRob Herring$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE 33078046fabSMasahiro Yamada $(call if_changed_dep,dtc) 3314f0e3a57SRob Herring 332*ce88c9c7SViresh Kumar$(obj)/%.dtbo: $(src)/%.dts $(DTC) FORCE 333*ce88c9c7SViresh Kumar $(call if_changed_dep,dtc) 334*ce88c9c7SViresh Kumar 3354f0e3a57SRob HerringDT_CHECKER ?= dt-validate 3364f0e3a57SRob HerringDT_BINDING_DIR := Documentation/devicetree/bindings 3372ba06cd8SRob Herring# DT_TMP_SCHEMA may be overridden from Documentation/devicetree/bindings/Makefile 338b8a49399SAndrei ZiureaevDT_TMP_SCHEMA ?= $(objtree)/$(DT_BINDING_DIR)/processed-schema.json 3394f0e3a57SRob Herring 3404f0e3a57SRob Herringquiet_cmd_dtb_check = CHECK $@ 341fd63fab4SMasahiro Yamada cmd_dtb_check = $(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ 3424f0e3a57SRob Herring 3437a049605SMasahiro Yamadadefine rule_dtc 34478046fabSMasahiro Yamada $(call cmd_and_fixdep,dtc) 345f5688663SMasahiro Yamada $(call cmd,dtb_check) 3464f0e3a57SRob Herringendef 3474f0e3a57SRob Herring 3484f0e3a57SRob Herring$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE 3493d4b2238SMasahiro Yamada $(call if_changed_rule,dtc,yaml) 35090b335fbSStephen Warren 351b0a4d8b3SIan Campbelldtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 35222435f38SStephen Warren 353bc22c17eSAlain Knaff# Bzip2 354bc22c17eSAlain Knaff# --------------------------------------------------------------------------- 355bc22c17eSAlain Knaff 356d3dd3b5aSH. Peter Anvin# Bzip2 and LZMA do not include size in file... so we have to fake that; 357d3dd3b5aSH. Peter Anvin# append the size as a 32-bit littleendian number as gzip does. 3584a2ff67cSMichael Tokarevsize_append = printf $(shell \ 359d3dd3b5aSH. Peter Anvindec_size=0; \ 360afa974b7SMasahiro Yamadafor F in $(real-prereqs); do \ 361a670b0b4SMichael Forney fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \ 362d3dd3b5aSH. Peter Anvin dec_size=$$(expr $$dec_size + $$fsize); \ 363d3dd3b5aSH. Peter Anvindone; \ 3641373411aSJonathan Niederprintf "%08x\n" $$dec_size | \ 3651373411aSJonathan Nieder sed 's/\(..\)/\1 /g' | { \ 3661373411aSJonathan Nieder read ch0 ch1 ch2 ch3; \ 3671373411aSJonathan Nieder for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ 3681373411aSJonathan Nieder printf '%s%03o' '\\' $$((0x$$ch)); \ 3691373411aSJonathan Nieder done; \ 3701373411aSJonathan Nieder } \ 371d3dd3b5aSH. Peter Anvin) 372bc22c17eSAlain Knaff 373bc22c17eSAlain Knaffquiet_cmd_bzip2 = BZIP2 $@ 374e4a42c82SDenis Efremov cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@ 375bc22c17eSAlain Knaff 376bc22c17eSAlain Knaff# Lzma 377bc22c17eSAlain Knaff# --------------------------------------------------------------------------- 378bc22c17eSAlain Knaff 379bc22c17eSAlain Knaffquiet_cmd_lzma = LZMA $@ 3808dfb61dcSDenis Efremov cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@ 3817dd65febSAlbin Tonnerre 3827dd65febSAlbin Tonnerrequiet_cmd_lzo = LZO $@ 383e4a42c82SDenis Efremov cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@ 384d61931d8SBorislav Petkov 385e76e1fdfSKyungsik Leequiet_cmd_lz4 = LZ4 $@ 3868dfb61dcSDenis Efremov cmd_lz4 = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \ 387b79c6aa6SMasahiro Yamada $(size_append); } > $@ 388e76e1fdfSKyungsik Lee 389e3393645SStephen Warren# U-Boot mkimage 390e3393645SStephen Warren# --------------------------------------------------------------------------- 391e3393645SStephen Warren 392e3393645SStephen WarrenMKIMAGE := $(srctree)/scripts/mkuboot.sh 393e3393645SStephen Warren 394e3393645SStephen Warren# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces 395e3393645SStephen Warren# the number of overrides in arch makefiles 396e3393645SStephen WarrenUIMAGE_ARCH ?= $(SRCARCH) 397e3393645SStephen WarrenUIMAGE_COMPRESSION ?= $(if $(2),$(2),none) 398e3393645SStephen WarrenUIMAGE_OPTS-y ?= 399e3393645SStephen WarrenUIMAGE_TYPE ?= kernel 400e3393645SStephen WarrenUIMAGE_LOADADDR ?= arch_must_set_this 401e3393645SStephen WarrenUIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) 402e3393645SStephen WarrenUIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)' 403e3393645SStephen Warren 404786ac51aSMasahiro Yamadaquiet_cmd_uimage = UIMAGE $@ 405858805b3SMasahiro Yamada cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ 406e3393645SStephen Warren -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ 407e3393645SStephen Warren -T $(UIMAGE_TYPE) \ 408e3393645SStephen Warren -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ 409786ac51aSMasahiro Yamada -n $(UIMAGE_NAME) -d $< $@ 410e3393645SStephen Warren 41124fa0402SLasse Collin# XZ 41224fa0402SLasse Collin# --------------------------------------------------------------------------- 41324fa0402SLasse Collin# Use xzkern to compress the kernel image and xzmisc to compress other things. 41424fa0402SLasse Collin# 41524fa0402SLasse Collin# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage 41624fa0402SLasse Collin# of the kernel decompressor. A BCJ filter is used if it is available for 41724fa0402SLasse Collin# the target architecture. xzkern also appends uncompressed size of the data 41824fa0402SLasse Collin# using size_append. The .xz format has the size information available at 41924fa0402SLasse Collin# the end of the file too, but it's in more complex format and it's good to 42024fa0402SLasse Collin# avoid changing the part of the boot code that reads the uncompressed size. 42124fa0402SLasse Collin# Note that the bytes added by size_append will make the xz tool think that 42224fa0402SLasse Collin# the file is corrupt. This is expected. 42324fa0402SLasse Collin# 42424fa0402SLasse Collin# xzmisc doesn't use size_append, so it can be used to create normal .xz 42524fa0402SLasse Collin# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very 42624fa0402SLasse Collin# big dictionary would increase the memory usage too much in the multi-call 42724fa0402SLasse Collin# decompression mode. A BCJ filter isn't used either. 42824fa0402SLasse Collinquiet_cmd_xzkern = XZKERN $@ 429b956c7a6SHarald Seiler cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \ 430b79c6aa6SMasahiro Yamada $(size_append); } > $@ 43124fa0402SLasse Collin 43224fa0402SLasse Collinquiet_cmd_xzmisc = XZMISC $@ 4338dfb61dcSDenis Efremov cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@ 434ebf003f0SMatthias Kaehlcke 43548f7ddf7SNick Terrell# ZSTD 43648f7ddf7SNick Terrell# --------------------------------------------------------------------------- 43748f7ddf7SNick Terrell# Appends the uncompressed size of the data using size_append. The .zst 43848f7ddf7SNick Terrell# format has the size information available at the beginning of the file too, 43948f7ddf7SNick Terrell# but it's in a more complex format and it's good to avoid changing the part 44048f7ddf7SNick Terrell# of the boot code that reads the uncompressed size. 44148f7ddf7SNick Terrell# 44248f7ddf7SNick Terrell# Note that the bytes added by size_append will make the zstd tool think that 44348f7ddf7SNick Terrell# the file is corrupt. This is expected. 44448f7ddf7SNick Terrell# 44548f7ddf7SNick Terrell# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of 44648f7ddf7SNick Terrell# 128 MB. zstd22 is used for kernel compression because it is decompressed in a 44748f7ddf7SNick Terrell# single pass, so zstd doesn't need to allocate a window buffer. When streaming 44848f7ddf7SNick Terrell# decompression is used, like initramfs decompression, zstd22 should likely not 44948f7ddf7SNick Terrell# be used because it would require zstd to allocate a 128 MB buffer. 45048f7ddf7SNick Terrell 45148f7ddf7SNick Terrellquiet_cmd_zstd = ZSTD $@ 45248f7ddf7SNick Terrell cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@ 45348f7ddf7SNick Terrell 45448f7ddf7SNick Terrellquiet_cmd_zstd22 = ZSTD22 $@ 45548f7ddf7SNick Terrell cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@ 45648f7ddf7SNick Terrell 457ebf003f0SMatthias Kaehlcke# ASM offsets 458ebf003f0SMatthias Kaehlcke# --------------------------------------------------------------------------- 459ebf003f0SMatthias Kaehlcke 460ebf003f0SMatthias Kaehlcke# Default sed regexp - multiline due to syntax constraints 461cf0c3e68SJeroen Hofstee# 462cf0c3e68SJeroen Hofstee# Use [:space:] because LLVM's integrated assembler inserts <tab> around 463cf0c3e68SJeroen Hofstee# the .ascii directive whereas GCC keeps the <space> as-is. 464ebf003f0SMatthias Kaehlckedefine sed-offsets 465cf0c3e68SJeroen Hofstee 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \ 466cf0c3e68SJeroen Hofstee /^->/{s:->#\(.*\):/* \1 */:; \ 467ebf003f0SMatthias Kaehlcke s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ 468cf0c3e68SJeroen Hofstee s:->::; p;}' 469ebf003f0SMatthias Kaehlckeendef 470ebf003f0SMatthias Kaehlcke 471ebf003f0SMatthias Kaehlcke# Use filechk to avoid rebuilds when a header changes, but the resulting file 472ebf003f0SMatthias Kaehlcke# does not 473ebf003f0SMatthias Kaehlckedefine filechk_offsets 474ebf003f0SMatthias Kaehlcke echo "#ifndef $2"; \ 475ebf003f0SMatthias Kaehlcke echo "#define $2"; \ 476ebf003f0SMatthias Kaehlcke echo "/*"; \ 477ebf003f0SMatthias Kaehlcke echo " * DO NOT MODIFY."; \ 478ebf003f0SMatthias Kaehlcke echo " *"; \ 479ebf003f0SMatthias Kaehlcke echo " * This file was generated by Kbuild"; \ 480ebf003f0SMatthias Kaehlcke echo " */"; \ 481ebf003f0SMatthias Kaehlcke echo ""; \ 48243fee2b2SMasahiro Yamada sed -ne $(sed-offsets) < $<; \ 483ebf003f0SMatthias Kaehlcke echo ""; \ 484ad774086SMasahiro Yamada echo "#endif" 485ebf003f0SMatthias Kaehlckeendef 486