From 551197864ad5d8ed01137b7008448bd18b9731d5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 19 Dec 2019 00:34:21 +0900 Subject: [PATCH 01/34] kbuild: detect missing include guard for exported headers Adding an include guard to every header file is good practice in case it is included multiple times. Exported headers are compile-tested for the comprehensive sanity checks. Let's include the same header twice. If an include guard is missing, the header will fail to build due to redefinition of something. Signed-off-by: Masahiro Yamada Reviewed-by: Sam Ravnborg --- usr/include/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr/include/Makefile b/usr/include/Makefile index 84598469e6ff..e90f5f7903bb 100644 --- a/usr/include/Makefile +++ b/usr/include/Makefile @@ -93,10 +93,11 @@ header-test- += asm-generic/% extra-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) +# Include the header to detect missing include guard. quiet_cmd_hdrtest = HDRTEST $< cmd_hdrtest = \ $(CC) $(c_flags) -S -o /dev/null -x c /dev/null \ - $(if $(filter-out $(header-test-), $*.h), -include $<); \ + $(if $(filter-out $(header-test-), $*.h), -include $< -include $<); \ $(PERL) $(srctree)/scripts/headers_check.pl $(obj) $(SRCARCH) $<; \ touch $@ From 0186b1267b421f9169ead7dec6723294677443c8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 19 Dec 2019 00:34:22 +0900 Subject: [PATCH 02/34] kbuild: rename header-test- to no-header-test in usr/include/Makefile Since commit d2a99dbdade4 ("kbuild: update compile-test header list for v5.5-rc1"), this does not depend on any CONFIG option. no-header-test is clearer. Signed-off-by: Masahiro Yamada --- usr/include/Makefile | 106 +++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/usr/include/Makefile b/usr/include/Makefile index e90f5f7903bb..a339ef325aa5 100644 --- a/usr/include/Makefile +++ b/usr/include/Makefile @@ -16,80 +16,80 @@ override c_flags = $(UAPI_CFLAGS) -Wp,-MD,$(depfile) -I$(objtree)/usr/include # Please consider to fix the header first. # # Sorted alphabetically. -header-test- += asm/shmbuf.h -header-test- += asm/signal.h -header-test- += asm/ucontext.h -header-test- += drm/vmwgfx_drm.h -header-test- += linux/am437x-vpfe.h -header-test- += linux/android/binder.h -header-test- += linux/android/binderfs.h -header-test- += linux/coda.h -header-test- += linux/elfcore.h -header-test- += linux/errqueue.h -header-test- += linux/fsmap.h -header-test- += linux/hdlc/ioctl.h -header-test- += linux/ivtv.h -header-test- += linux/kexec.h -header-test- += linux/matroxfb.h -header-test- += linux/nfc.h -header-test- += linux/omap3isp.h -header-test- += linux/omapfb.h -header-test- += linux/patchkey.h -header-test- += linux/phonet.h -header-test- += linux/reiserfs_xattr.h -header-test- += linux/sctp.h -header-test- += linux/signal.h -header-test- += linux/sysctl.h -header-test- += linux/usb/audio.h -header-test- += linux/v4l2-mediabus.h -header-test- += linux/v4l2-subdev.h -header-test- += linux/videodev2.h -header-test- += linux/vm_sockets.h -header-test- += sound/asequencer.h -header-test- += sound/asoc.h -header-test- += sound/asound.h -header-test- += sound/compress_offload.h -header-test- += sound/emu10k1.h -header-test- += sound/sfnt_info.h -header-test- += xen/evtchn.h -header-test- += xen/gntdev.h -header-test- += xen/privcmd.h +no-header-test += asm/shmbuf.h +no-header-test += asm/signal.h +no-header-test += asm/ucontext.h +no-header-test += drm/vmwgfx_drm.h +no-header-test += linux/am437x-vpfe.h +no-header-test += linux/android/binder.h +no-header-test += linux/android/binderfs.h +no-header-test += linux/coda.h +no-header-test += linux/elfcore.h +no-header-test += linux/errqueue.h +no-header-test += linux/fsmap.h +no-header-test += linux/hdlc/ioctl.h +no-header-test += linux/ivtv.h +no-header-test += linux/kexec.h +no-header-test += linux/matroxfb.h +no-header-test += linux/nfc.h +no-header-test += linux/omap3isp.h +no-header-test += linux/omapfb.h +no-header-test += linux/patchkey.h +no-header-test += linux/phonet.h +no-header-test += linux/reiserfs_xattr.h +no-header-test += linux/sctp.h +no-header-test += linux/signal.h +no-header-test += linux/sysctl.h +no-header-test += linux/usb/audio.h +no-header-test += linux/v4l2-mediabus.h +no-header-test += linux/v4l2-subdev.h +no-header-test += linux/videodev2.h +no-header-test += linux/vm_sockets.h +no-header-test += sound/asequencer.h +no-header-test += sound/asoc.h +no-header-test += sound/asound.h +no-header-test += sound/compress_offload.h +no-header-test += sound/emu10k1.h +no-header-test += sound/sfnt_info.h +no-header-test += xen/evtchn.h +no-header-test += xen/gntdev.h +no-header-test += xen/privcmd.h # More headers are broken in some architectures ifeq ($(SRCARCH),arc) -header-test- += linux/bpf_perf_event.h +no-header-test += linux/bpf_perf_event.h endif ifeq ($(SRCARCH),ia64) -header-test- += asm/setup.h -header-test- += asm/sigcontext.h -header-test- += asm/perfmon.h -header-test- += asm/perfmon_default_smpl.h -header-test- += linux/if_bonding.h +no-header-test += asm/setup.h +no-header-test += asm/sigcontext.h +no-header-test += asm/perfmon.h +no-header-test += asm/perfmon_default_smpl.h +no-header-test += linux/if_bonding.h endif ifeq ($(SRCARCH),mips) -header-test- += asm/stat.h +no-header-test += asm/stat.h endif ifeq ($(SRCARCH),powerpc) -header-test- += asm/stat.h -header-test- += linux/bpf_perf_event.h +no-header-test += asm/stat.h +no-header-test += linux/bpf_perf_event.h endif ifeq ($(SRCARCH),riscv) -header-test- += linux/bpf_perf_event.h +no-header-test += linux/bpf_perf_event.h endif ifeq ($(SRCARCH),sparc) -header-test- += asm/stat.h -header-test- += asm/uctx.h -header-test- += asm/fbio.h +no-header-test += asm/stat.h +no-header-test += asm/uctx.h +no-header-test += asm/fbio.h endif # asm-generic/*.h is used by asm/*.h, and should not be included directly -header-test- += asm-generic/% +no-header-test += asm-generic/% extra-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) @@ -97,7 +97,7 @@ extra-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/d quiet_cmd_hdrtest = HDRTEST $< cmd_hdrtest = \ $(CC) $(c_flags) -S -o /dev/null -x c /dev/null \ - $(if $(filter-out $(header-test-), $*.h), -include $< -include $<); \ + $(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \ $(PERL) $(srctree)/scripts/headers_check.pl $(obj) $(SRCARCH) $<; \ touch $@ From 56d5893615727bce4a8769c6b22340e20f9a3c33 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 19 Dec 2019 01:04:28 +0900 Subject: [PATCH 03/34] kbuild: do not create orphan built-in.a or obj-y objects Both 'obj-y += foo/' and 'obj-m += foo/' request Kbuild to visit the sub-directory foo/, but the difference is that only the former combines foo/built-in.a into the built-in.a of the current directory because everything in sub-directories visited by obj-m is supposed to be modular. So, it makes sense to create built-in.a only if that sub-directory is reachable by the chain of obj-y. Otherwise, built-in.a will not be linked into vmlinux anyway. For the same reason, it is pointless to compile obj-y objects in the directory visited by obj-m. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 2 +- scripts/Makefile.lib | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index b734ac8a654e..e46b4ee9a120 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -66,7 +66,7 @@ lib-target := $(obj)/lib.a real-obj-y += $(obj)/lib-ksyms.o endif -ifneq ($(strip $(real-obj-y) $(need-builtin)),) +ifdef need-builtin builtin-target := $(obj)/built-in.a endif diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 3fa32f83b2d7..724aa3e9b4a8 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -35,7 +35,11 @@ __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) subdir-y += $(__subdir-y) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) subdir-m += $(__subdir-m) +ifdef need-builtin obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) +else +obj-y := $(filter-out %/, $(obj-y)) +endif obj-m := $(filter-out %/, $(obj-m)) # Subdirectories we need to descend into From a7499267976ce014fbc6f7defe9080367f94d6cc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 19 Dec 2019 01:05:14 +0900 Subject: [PATCH 04/34] kbuild: use pattern rule for building built-in.a in sub-directories The built-in.a in a sub-directory is created by descending into that directory. It does not depend on the other sub-directories. Loosen the dependency. Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index e46b4ee9a120..a562d695f0fa 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -372,7 +372,7 @@ $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler # --------------------------------------------------------------------------- # To build objects in subdirs, we need to descend into the directories -$(sort $(subdir-obj-y)): $(subdir-ym) ; +$(obj)/%/built-in.a: $(obj)/% ; # # Rule to compile a set of .o files into one .a file (without symbol table) From 7e826c44f5de3be00369d534dc38db485f6f26d5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 19 Dec 2019 17:33:27 +0900 Subject: [PATCH 05/34] kbuild: add stringify helper to quote a string passed to C files Make $(squote)$(quote)...$(quote)$(squote) a helper macro. I will reuse it in the next commit. Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 4 ++++ scripts/Makefile.lib | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index bc5f25763c1b..88c144787e57 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -32,6 +32,10 @@ real-prereqs = $(filter-out $(PHONY), $^) # Escape single quote for use in echo statements escsq = $(subst $(squote),'\$(squote)',$1) +### +# Quote a string to pass it to C files. foo => '"foo"' +stringify = $(squote)$(quote)$1$(quote)$(squote) + ### # Easy method for doing a status message kecho := : diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 724aa3e9b4a8..e5e5339bb575 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -97,7 +97,7 @@ target-stem = $(basename $(patsubst $(obj)/%,%,$@)) # These flags are needed for modversions and compiling, so we define them here # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will # end up in (or would, if it gets compiled in) -name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) +name-fix = $(call stringify,$(subst $(comma),_,$(subst -,_,$1))) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) From 1664a377908ed6096680e9d7cfd28facef2194f2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 19 Dec 2019 17:33:28 +0900 Subject: [PATCH 06/34] kbuild: pass KBUILD_MODFILE when compiling builtin objects When compiling, Kbuild passes KBUILD_BASENAME (basename of the object) and KBUILD_MODNAME (basename of the module). This commit adds another one, KBUILD_MODFILE, which is the path of the module. (or, the path of the module it would end up in if it were compiled as a module.) The next commit will use this to generate modules.builtin without tristate.conf. Signed-off-by: Masahiro Yamada --- scripts/Makefile.lib | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index e5e5339bb575..d10f7a03e0ee 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -84,12 +84,14 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) # Finds the multi-part object the current object will be linked into. -# If the object belongs to two or more multi-part objects, all of them are -# concatenated with a colon separator. -modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ - $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))) +# If the object belongs to two or more multi-part objects, list them all. +modname-multi = $(sort $(foreach m,$(multi-used),\ + $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))) -modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) +__modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) + +modname = $(subst $(space),:,$(__modname)) +modfile = $(addprefix $(obj)/,$(__modname)) # target with $(obj)/ and its suffix stripped target-stem = $(basename $(patsubst $(obj)/%,%,$@)) @@ -100,6 +102,7 @@ target-stem = $(basename $(patsubst $(obj)/%,%,$@)) name-fix = $(call stringify,$(subst $(comma),_,$(subst -,_,$1))) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) +modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile)) orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ $(ccflags-y) $(CFLAGS_$(target-stem).o) @@ -158,7 +161,7 @@ quiet_modtag = $(if $(part-of-module),[M], ) modkern_cflags = \ $(if $(part-of-module), \ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ - $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) + $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags)) modkern_aflags = $(if $(part-of-module), \ $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ From 8b41fc4454e36fbfdbb23f940d023d4dece2de29 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 19 Dec 2019 17:33:29 +0900 Subject: [PATCH 07/34] kbuild: create modules.builtin without Makefile.modbuiltin or tristate.conf Commit bc081dd6e9f6 ("kbuild: generate modules.builtin") added infrastructure to generate modules.builtin, the list of all builtin modules. Basically, it works like this: - Kconfig generates include/config/tristate.conf, the list of tristate CONFIG options with a value in a capital letter. - scripts/Makefile.modbuiltin makes Kbuild descend into directories to collect the information of builtin modules. I am not a big fan of it because Kbuild ends up with traversing the source tree twice. I am not sure how perfectly it should work, but this approach cannot avoid false positives; even if the relevant CONFIG option is tristate, some Makefiles forces obj-m to obj-y. Some examples are: arch/powerpc/platforms/powermac/Makefile: obj-$(CONFIG_NVRAM:m=y) += nvram.o net/ipv6/Makefile: obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o net/netlabel/Makefile: obj-$(subst m,y,$(CONFIG_IPV6)) += netlabel_calipso.o Nobody has complained about (or noticed) it, so it is probably fine to have false positives in modules.builtin. This commit simplifies the implementation. Let's exploit the fact that every module has MODULE_LICENSE(). (modpost shows a warning if MODULE_LICENSE is missing. If so, 0-day bot would already have blocked such a module.) I added MODULE_FILE to . When the code is being compiled as builtin, it will be filled with the file path of the module, and collected into modules.builtin.info. Then, scripts/link-vmlinux.sh extracts the list of builtin modules out of it. This new approach fixes the false-positives above, but adds another type of false-positives; non-modular code may have MODULE_LICENSE() by mistake. This is not a big deal, it is just the code is always orphan. We can clean it up if we like. You can see cleanup examples by: $ git log --grep='make.* explicitly non-modular' To sum up, this commits deletes lots of code, but still produces almost equivalent results. Please note it does not increase the vmlinux size at all. As you can see in include/asm-generic/vmlinux.lds.h, the .modinfo section is discarded in the link stage. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/kconfig.rst | 5 --- Makefile | 21 +++--------- include/linux/module.h | 12 ++++++- scripts/Kbuild.include | 6 ---- scripts/Makefile.modbuiltin | 57 -------------------------------- scripts/kconfig/confdata.c | 45 ++----------------------- scripts/link-vmlinux.sh | 4 +++ 7 files changed, 22 insertions(+), 128 deletions(-) delete mode 100644 scripts/Makefile.modbuiltin diff --git a/Documentation/kbuild/kconfig.rst b/Documentation/kbuild/kconfig.rst index a9a855f894b3..dce6801d66c9 100644 --- a/Documentation/kbuild/kconfig.rst +++ b/Documentation/kbuild/kconfig.rst @@ -154,11 +154,6 @@ KCONFIG_AUTOCONFIG This environment variable can be set to specify the path & name of the "auto.conf" file. Its default value is "include/config/auto.conf". -KCONFIG_TRISTATE ----------------- -This environment variable can be set to specify the path & name of the -"tristate.conf" file. Its default value is "include/config/tristate.conf". - KCONFIG_AUTOHEADER ------------------ This environment variable can be set to specify the path & name of the diff --git a/Makefile b/Makefile index e4c2d0327d8c..4f01de6cd43c 100644 --- a/Makefile +++ b/Makefile @@ -674,7 +674,7 @@ $(KCONFIG_CONFIG): # # This exploits the 'multi-target pattern rule' trick. # The syncconfig should be executed only once to make all the targets. -%/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG) +%/auto.conf %/auto.conf.cmd: $(KCONFIG_CONFIG) $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig else # !may-sync-config # External modules and some install targets need include/generated/autoconf.h @@ -1278,24 +1278,13 @@ all: modules # using awk while concatenating to the final file. PHONY += modules -modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order modules.builtin +modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh modules.order: descend $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ -modbuiltin-dirs := $(addprefix _modbuiltin_, $(build-dirs)) - -modules.builtin: $(modbuiltin-dirs) - $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ - -PHONY += $(modbuiltin-dirs) -# tristate.conf is not included from this Makefile. Add it as a prerequisite -# here to make it self-healing in case somebody accidentally removes it. -$(modbuiltin-dirs): include/config/tristate.conf - $(Q)$(MAKE) $(modbuiltin)=$(patsubst _modbuiltin_%,%,$@) - # Target to prepare building external modules PHONY += modules_prepare modules_prepare: prepare @@ -1315,7 +1304,7 @@ _modinst_: ln -s $(CURDIR) $(MODLIB)/build ; \ fi @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order - @sed 's:^:kernel/:' modules.builtin > $(MODLIB)/modules.builtin + @cp -f modules.builtin $(MODLIB)/ @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/ $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst @@ -1357,7 +1346,7 @@ endif # CONFIG_MODULES # Directories & files removed with 'make clean' CLEAN_DIRS += include/ksym -CLEAN_FILES += modules.builtin.modinfo modules.nsdeps +CLEAN_FILES += modules.builtin modules.builtin.modinfo modules.nsdeps # Directories & files removed with 'make mrproper' MRPROPER_DIRS += include/config include/generated \ @@ -1712,7 +1701,7 @@ clean: $(clean-dirs) -o -name '*.lex.c' -o -name '*.tab.[ch]' \ -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ - -o -name modules.builtin -o -name '.tmp_*.o.*' \ + -o -name '.tmp_*.o.*' \ -o -name '*.c.[012]*.*' \ -o -name '*.ll' \ -o -name '*.gcno' \) -type f -print | xargs rm -f diff --git a/include/linux/module.h b/include/linux/module.h index bd165ba68617..6877b3b191d0 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -169,6 +169,16 @@ extern void cleanup_module(void); */ #define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) +/* + * MODULE_FILE is used for generating modules.builtin + * So, make it no-op when this is being built as a module + */ +#ifdef MODULE +#define MODULE_FILE +#else +#define MODULE_FILE MODULE_INFO(file, KBUILD_MODFILE); +#endif + /* * The following license idents are currently accepted as indicating free * software modules @@ -213,7 +223,7 @@ extern void cleanup_module(void); * 2. So the community can ignore bug reports including proprietary modules * 3. So vendors can do likewise based on their own policies */ -#define MODULE_LICENSE(_license) MODULE_INFO(license, _license) +#define MODULE_LICENSE(_license) MODULE_FILE MODULE_INFO(license, _license) /* * Author(s), use "Name " or just "Name", for multiple diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 88c144787e57..3da8321efb74 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -163,12 +163,6 @@ ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4)) # $(Q)$(MAKE) $(build)=dir build := -f $(srctree)/scripts/Makefile.build obj -### -# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj= -# Usage: -# $(Q)$(MAKE) $(modbuiltin)=dir -modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj - ### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= # Usage: diff --git a/scripts/Makefile.modbuiltin b/scripts/Makefile.modbuiltin deleted file mode 100644 index 7d4711b88656..000000000000 --- a/scripts/Makefile.modbuiltin +++ /dev/null @@ -1,57 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# ========================================================================== -# Generating modules.builtin -# ========================================================================== - -src := $(obj) - -PHONY := __modbuiltin -__modbuiltin: - -include include/config/auto.conf -# tristate.conf sets tristate variables to uppercase 'Y' or 'M' -# That way, we get the list of built-in modules in obj-Y -include include/config/tristate.conf - -include scripts/Kbuild.include - -ifdef building_out_of_srctree -# Create output directory if not already present -_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) -endif - -# The filename Kbuild has precedence over Makefile -kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) -kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) -include $(kbuild-file) - -include scripts/Makefile.lib -__subdir-Y := $(patsubst %/,%,$(filter %/, $(obj-Y))) -subdir-Y += $(__subdir-Y) -subdir-ym := $(sort $(subdir-y) $(subdir-Y) $(subdir-m)) -subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) -obj-Y := $(addprefix $(obj)/,$(obj-Y)) - -modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym)) -modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko)) -modbuiltin-target := $(obj)/modules.builtin - -__modbuiltin: $(modbuiltin-target) $(subdir-ym) - @: - -$(modbuiltin-target): $(subdir-ym) FORCE - $(Q)(for m in $(modbuiltin-mods); do echo $$m; done; \ - cat /dev/null $(modbuiltin-subdirs)) > $@ - -PHONY += FORCE - -FORCE: - -# Descending -# --------------------------------------------------------------------------- - -PHONY += $(subdir-ym) -$(subdir-ym): - $(Q)$(MAKE) $(modbuiltin)=$@ - -.PHONY: $(PHONY) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 3569d2dec37c..fb675bd9a809 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -710,25 +710,6 @@ static struct conf_printer header_printer_cb = .print_comment = header_print_comment, }; -/* - * Tristate printer - * - * This printer is used when generating the `include/config/tristate.conf' file. - */ -static void -tristate_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ - - if (sym->type == S_TRISTATE && *value != 'n') - fprintf(fp, "%s%s=%c\n", CONFIG_, sym->name, (char)toupper(*value)); -} - -static struct conf_printer tristate_printer_cb = -{ - .print_symbol = tristate_print_symbol, - .print_comment = kconfig_print_comment, -}; - static void conf_write_symbol(FILE *fp, struct symbol *sym, struct conf_printer *printer, void *printer_arg) { @@ -1062,7 +1043,7 @@ int conf_write_autoconf(int overwrite) struct symbol *sym; const char *name; const char *autoconf_name = conf_get_autoconfig_name(); - FILE *out, *tristate, *out_h; + FILE *out, *out_h; int i; if (!overwrite && is_present(autoconf_name)) @@ -1077,23 +1058,13 @@ int conf_write_autoconf(int overwrite) if (!out) return 1; - tristate = fopen(".tmpconfig_tristate", "w"); - if (!tristate) { - fclose(out); - return 1; - } - out_h = fopen(".tmpconfig.h", "w"); if (!out_h) { fclose(out); - fclose(tristate); return 1; } conf_write_heading(out, &kconfig_printer_cb, NULL); - - conf_write_heading(tristate, &tristate_printer_cb, NULL); - conf_write_heading(out_h, &header_printer_cb, NULL); for_all_symbols(i, sym) { @@ -1101,15 +1072,11 @@ int conf_write_autoconf(int overwrite) if (!(sym->flags & SYMBOL_WRITE) || !sym->name) continue; - /* write symbol to auto.conf, tristate and header files */ + /* write symbols to auto.conf and autoconf.h */ conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1); - - conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1); - conf_write_symbol(out_h, sym, &header_printer_cb, NULL); } fclose(out); - fclose(tristate); fclose(out_h); name = getenv("KCONFIG_AUTOHEADER"); @@ -1120,14 +1087,6 @@ int conf_write_autoconf(int overwrite) if (rename(".tmpconfig.h", name)) return 1; - name = getenv("KCONFIG_TRISTATE"); - if (!name) - name = "include/config/tristate.conf"; - if (make_parent_dir(name)) - return 1; - if (rename(".tmpconfig_tristate", name)) - return 1; - if (make_parent_dir(autoconf_name)) return 1; /* diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 436379940356..bf0bf9063aaf 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -250,6 +250,10 @@ ${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1 info MODINFO modules.builtin.modinfo ${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo +info GEN modules.builtin +# The second line aids cases where multiple modules share the same object. +tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' | + tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin btf_vmlinux_bin_o="" if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then From 9945722afdc3443eab826b2da1122509a13a50a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Date: Sat, 4 Jan 2020 10:55:56 +0100 Subject: [PATCH 08/34] builddeb: make headers package thinner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove a bunch of files not used during external module builds: - foreign architecture headers - subtree Makefiles - Kconfig files - perl scripts On amd64 system this looses a third of the resulting .deb size. Signed-off-by: Michał Mirosław Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index c4c580f547ef..b60388051c7f 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -165,8 +165,8 @@ EOF done # Build kernel header package -(cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles" -(cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles" +(cd $srctree; find . arch/$SRCARCH -maxdepth 1 -name Makefile\*) > "$objtree/debian/hdrsrcfiles" +(cd $srctree; find include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles" (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles" (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles" if is_enabled CONFIG_STACK_VALIDATION; then From a2183c0437987409bbf87582621d096561bf321c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:26 +0900 Subject: [PATCH 09/34] initramfs: replace klibcdirs in Makefile with FORCE 'klibcdirs' was added by commit d39a206bc35d ("kbuild: rebuild initramfs if content of initramfs changes"). If this is just a matter of forcing execution of the recipe line, we can replace it with FORCE. The following code is currently useless: $(deps_initramfs): klibcdirs The original intent could be a hook for the klibc integration into the kernel tree, but klibc is a separate project, which can be built independently. Clean it up. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Thelen --- usr/Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/usr/Makefile b/usr/Makefile index e6f7cb2f81db..55c942da01cd 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -3,9 +3,6 @@ # kbuild file for usr/ - including initramfs image # -klibcdirs:; -PHONY += klibcdirs - suffix_y = $(subst $\",,$(CONFIG_INITRAMFS_COMPRESSION)) datafile_y = initramfs_data.cpio$(suffix_y) datafile_d_y = .$(datafile_y).d @@ -50,13 +47,12 @@ targets := $(datafile_y) # do not try to update files included in initramfs $(deps_initramfs): ; -$(deps_initramfs): klibcdirs # We rebuild initramfs_data.cpio if: # 1) Any included file is newer than initramfs_data.cpio # 2) There are changes in which files are included (added or deleted) # 3) If gen_init_cpio are newer than initramfs_data.cpio # 4) Arguments to gen_initramfs.sh changes -$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs +$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) FORCE $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y) $(call if_changed,initfs) From 9a04dc52982eb8f2ccd604b48f057217a39f243c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:27 +0900 Subject: [PATCH 10/34] gen_initramfs_list.sh: remove unused variable 'default_list' This is assigned, but not referenced. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Thelen --- usr/gen_initramfs_list.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/usr/gen_initramfs_list.sh b/usr/gen_initramfs_list.sh index 2bbac73e6477..909a7b865aa7 100755 --- a/usr/gen_initramfs_list.sh +++ b/usr/gen_initramfs_list.sh @@ -280,7 +280,6 @@ while [ $# -gt 0 ]; do shift ;; "-d") # display default initramfs list - default_list="$arg" ${dep_list}default_initramfs ;; "-h") From a4c968e70f68d81276def017fcb1468e3930aa1d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:28 +0900 Subject: [PATCH 11/34] gen_initramfs_list.sh: fix the tool name in the comment There is no tool named "gen_initramfs". The correct name is "gen_init_cpio". Signed-off-by: Masahiro Yamada Reviewed-by: Greg Thelen --- usr/gen_initramfs_list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/gen_initramfs_list.sh b/usr/gen_initramfs_list.sh index 909a7b865aa7..1fd93414fb37 100755 --- a/usr/gen_initramfs_list.sh +++ b/usr/gen_initramfs_list.sh @@ -189,7 +189,7 @@ dir_filelist() { # if only one file is specified and it is .cpio file then use it direct as fs # if a directory is specified then add all files in given direcotry to fs -# if a regular file is specified assume it is in gen_initramfs format +# if a regular file is specified assume it is in gen_init_cpio format input_file() { source="$1" if [ -f "$1" ]; then From 80e715a06c2d0a24dbb818bb1dba2ef0f20d7068 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:29 +0900 Subject: [PATCH 12/34] initramfs: rename gen_initramfs_list.sh to gen_initramfs.sh The comments in usr/Makefile wrongly refer to the script name (twice). Line 37: # The dependency list is generated by gen_initramfs.sh -l Line 54: # 4) Arguments to gen_initramfs.sh changes There does not exist such a script. I was going to fix the comments, but after some consideration, I thought "gen_initramfs.sh" would be more suitable than "gen_initramfs_list.sh" because it generates an initramfs image in the common usage. The script generates a list that can be fed to gen_init_cpio only when it is directly run without -o or -l option. Signed-off-by: Masahiro Yamada --- usr/Makefile | 2 +- usr/{gen_initramfs_list.sh => gen_initramfs.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename usr/{gen_initramfs_list.sh => gen_initramfs.sh} (100%) diff --git a/usr/Makefile b/usr/Makefile index 55c942da01cd..e44a66b8c051 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -24,7 +24,7 @@ $(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE # Generate the initramfs cpio archive hostprogs-y := gen_init_cpio -initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs_list.sh +initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs.sh ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \ $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d) ramfs-args := \ diff --git a/usr/gen_initramfs_list.sh b/usr/gen_initramfs.sh similarity index 100% rename from usr/gen_initramfs_list.sh rename to usr/gen_initramfs.sh From be1859bdc660213b11c417ebfaf9161938526d44 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:30 +0900 Subject: [PATCH 13/34] initramfs: remove redundant dependency on BLK_DEV_INITRD init/Kconfig includes usr/Kconfig inside the "if BLK_DEV_INITRD" ... "endif" block: if BLK_DEV_INITRD source "usr/Kconfig" endif Hence, all the defines in usr/Kconfig depend on BLK_DEV_INITRD. Remove the redundant "depends on BLK_DEV_INITRD". Signed-off-by: Masahiro Yamada Reviewed-by: Greg Thelen --- usr/Kconfig | 6 ------ 1 file changed, 6 deletions(-) diff --git a/usr/Kconfig b/usr/Kconfig index a6b68503d177..72f50a21c051 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -54,7 +54,6 @@ config INITRAMFS_ROOT_GID config RD_GZIP bool "Support initial ramdisk/ramfs compressed using gzip" - depends on BLK_DEV_INITRD default y select DECOMPRESS_GZIP help @@ -64,7 +63,6 @@ config RD_GZIP config RD_BZIP2 bool "Support initial ramdisk/ramfs compressed using bzip2" default y - depends on BLK_DEV_INITRD select DECOMPRESS_BZIP2 help Support loading of a bzip2 encoded initial ramdisk or cpio buffer @@ -73,7 +71,6 @@ config RD_BZIP2 config RD_LZMA bool "Support initial ramdisk/ramfs compressed using LZMA" default y - depends on BLK_DEV_INITRD select DECOMPRESS_LZMA help Support loading of a LZMA encoded initial ramdisk or cpio buffer @@ -81,7 +78,6 @@ config RD_LZMA config RD_XZ bool "Support initial ramdisk/ramfs compressed using XZ" - depends on BLK_DEV_INITRD default y select DECOMPRESS_XZ help @@ -91,7 +87,6 @@ config RD_XZ config RD_LZO bool "Support initial ramdisk/ramfs compressed using LZO" default y - depends on BLK_DEV_INITRD select DECOMPRESS_LZO help Support loading of a LZO encoded initial ramdisk or cpio buffer @@ -100,7 +95,6 @@ config RD_LZO config RD_LZ4 bool "Support initial ramdisk/ramfs compressed using LZ4" default y - depends on BLK_DEV_INITRD select DECOMPRESS_LZ4 help Support loading of a LZ4 encoded initial ramdisk or cpio buffer From ddd09bcc899fd374fe5567d9c35894a304f9e492 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:31 +0900 Subject: [PATCH 14/34] initramfs: make compression options not depend on INITRAMFS_SOURCE Even if INITRAMFS_SOURCE is empty, usr/gen_initramfs.sh generates a tiny default initramfs, which is embedded in vmlinux. So, defining INITRAMFS_COMPRESSION* options should be valid irrespective of INITRAMFS_SOURCE. Signed-off-by: Masahiro Yamada --- usr/Kconfig | 2 -- 1 file changed, 2 deletions(-) diff --git a/usr/Kconfig b/usr/Kconfig index 72f50a21c051..43934c128010 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -102,7 +102,6 @@ config RD_LZ4 choice prompt "Built-in initramfs compression mode" - depends on INITRAMFS_SOURCE!="" optional help This option allows you to decide by which algorithm the builtin @@ -211,7 +210,6 @@ config INITRAMFS_COMPRESSION_LZ4 endchoice config INITRAMFS_COMPRESSION - depends on INITRAMFS_SOURCE!="" string default "" if INITRAMFS_COMPRESSION_NONE default ".gz" if INITRAMFS_COMPRESSION_GZIP From f26661e1276537f5adda440a37e2a2c694147781 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:32 +0900 Subject: [PATCH 15/34] initramfs: make initramfs compression choice non-optional Currently, the choice of the initramfs compression mode is too complex because users are allowed to not specify the compression mode at all. I think it makes more sense to require users to choose the compression mode explicitly, and delete the fallback defaults of INITRAMFS_COMPRESSION. Signed-off-by: Masahiro Yamada --- usr/Kconfig | 8 -------- 1 file changed, 8 deletions(-) diff --git a/usr/Kconfig b/usr/Kconfig index 43934c128010..ab61e81165e0 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -102,7 +102,6 @@ config RD_LZ4 choice prompt "Built-in initramfs compression mode" - optional help This option allows you to decide by which algorithm the builtin initramfs will be compressed. Several compression algorithms are @@ -218,10 +217,3 @@ config INITRAMFS_COMPRESSION default ".xz" if INITRAMFS_COMPRESSION_XZ default ".lzo" if INITRAMFS_COMPRESSION_LZO default ".lz4" if INITRAMFS_COMPRESSION_LZ4 - default ".gz" if RD_GZIP - default ".lz4" if RD_LZ4 - default ".lzo" if RD_LZO - default ".xz" if RD_XZ - default ".lzma" if RD_LZMA - default ".bz2" if RD_BZIP2 - default "" From 3e176683634cfc53dfc04366510d2989804554df Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:33 +0900 Subject: [PATCH 16/34] initramfs: specify $(src)/gen_initramfs.sh as a prerequisite in Makefile Specify the dependency directly in the Makefile. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Thelen --- usr/Makefile | 7 +++---- usr/gen_initramfs.sh | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/usr/Makefile b/usr/Makefile index e44a66b8c051..f58101fb4574 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -24,7 +24,6 @@ $(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE # Generate the initramfs cpio archive hostprogs-y := gen_init_cpio -initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs.sh ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \ $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d) ramfs-args := \ @@ -40,7 +39,7 @@ ifneq ($(wildcard $(obj)/$(datafile_d_y)),) endif quiet_cmd_initfs = GEN $@ - cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input) + cmd_initfs = $(CONFIG_SHELL) $< -o $@ $(ramfs-args) $(ramfs-input) targets := $(datafile_y) @@ -52,8 +51,8 @@ $(deps_initramfs): ; # 2) There are changes in which files are included (added or deleted) # 3) If gen_init_cpio are newer than initramfs_data.cpio # 4) Arguments to gen_initramfs.sh changes -$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) FORCE - $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y) +$(obj)/$(datafile_y): $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE + $(Q)$< -l $(ramfs-input) > $(obj)/$(datafile_d_y) $(call if_changed,initfs) subdir-$(CONFIG_UAPI_HEADER_TEST) += include diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh index 1fd93414fb37..68b6ddfd5f96 100755 --- a/usr/gen_initramfs.sh +++ b/usr/gen_initramfs.sh @@ -235,7 +235,7 @@ arg="$1" case "$arg" in "-l") # files included in initramfs - used by kbuild dep_list="list_" - echo "deps_initramfs := $0 \\" + echo "deps_initramfs := \\" shift ;; "-o") # generate compressed cpio image named $1 From 9668097599aa5fb87351bc2263e06a1c24718d40 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:34 +0900 Subject: [PATCH 17/34] initramfs: generate dependency list and cpio at the same time Currently, this script is run twice, for the dependency list, and then for the cpio archive. The first one is re-run every time although its build log is suppressed so nobody notices it. Make it work more efficiently by generating the cpio and the dependency list at the same time. Signed-off-by: Masahiro Yamada --- usr/Makefile | 3 +- usr/gen_initramfs.sh | 108 ++++++++++++++++++------------------------- 2 files changed, 47 insertions(+), 64 deletions(-) diff --git a/usr/Makefile b/usr/Makefile index f58101fb4574..9c7387156c6b 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -39,7 +39,7 @@ ifneq ($(wildcard $(obj)/$(datafile_d_y)),) endif quiet_cmd_initfs = GEN $@ - cmd_initfs = $(CONFIG_SHELL) $< -o $@ $(ramfs-args) $(ramfs-input) + cmd_initfs = $(CONFIG_SHELL) $< -o $@ -l $(obj)/$(datafile_d_y) $(ramfs-args) $(ramfs-input) targets := $(datafile_y) @@ -52,7 +52,6 @@ $(deps_initramfs): ; # 3) If gen_init_cpio are newer than initramfs_data.cpio # 4) Arguments to gen_initramfs.sh changes $(obj)/$(datafile_y): $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE - $(Q)$< -l $(ramfs-input) > $(obj)/$(datafile_d_y) $(call if_changed,initfs) subdir-$(CONFIG_UAPI_HEADER_TEST) += include diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh index 68b6ddfd5f96..49a4e22147b5 100755 --- a/usr/gen_initramfs.sh +++ b/usr/gen_initramfs.sh @@ -15,9 +15,10 @@ set -e usage() { cat << EOF Usage: -$0 [-o ] [-u ] [-g ] {-d | } ... +$0 [-o ] [-l ] [-u ] [-g ] {-d | } ... -o Create compressed initramfs file named using gen_init_cpio and compressor depending on the extension + -l Create dependency list named -u User ID to map to user ID 0 (root). is only meaningful if is a directory. "squash" forces all files to uid 0. @@ -42,11 +43,6 @@ field() { shift $1 ; echo $1 } -list_default_initramfs() { - # echo usr/kinit/kinit - : -} - default_initramfs() { cat <<-EOF >> ${output} # This is a very simple, default initramfs @@ -81,10 +77,6 @@ filetype() { return 0 } -list_print_mtime() { - : -} - print_mtime() { local my_mtime="0" @@ -97,10 +89,10 @@ print_mtime() { } list_parse() { - if [ -L "$1" ]; then + if [ -z "$dep_list" -o -L "$1" ]; then return fi - echo "$1" | sed 's/:/\\:/g; s/$/ \\/' + echo "$1" | sed 's/:/\\:/g; s/$/ \\/' >> $dep_list } # for each file print a line in following format @@ -161,28 +153,25 @@ unknown_option() { exit 1 } -list_header() { - : -} - header() { printf "\n#####################\n# $1\n" >> ${output} } # process one directory (incl sub-directories) dir_filelist() { - ${dep_list}header "$1" + header "$1" srcdir=$(echo "$1" | sed -e 's://*:/:g') dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort) # If $dirlist is only one line, then the directory is empty if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then - ${dep_list}print_mtime "$1" + print_mtime "$1" echo "${dirlist}" | \ while read x; do - ${dep_list}parse ${x} + list_parse $x + parse $x done fi } @@ -193,22 +182,21 @@ dir_filelist() { input_file() { source="$1" if [ -f "$1" ]; then - ${dep_list}header "$1" + header "$1" is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then cpio_file=$1 echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" - [ ! -z ${dep_list} ] && echo "$1" + [ -n "$dep_list" ] && echo "$1" >> $dep_list return 0 fi - if [ -z ${dep_list} ]; then - print_mtime "$1" >> ${output} - cat "$1" >> ${output} - else - echo "$1 \\" + print_mtime "$1" >> ${output} + cat "$1" >> ${output} + if [ -n "$dep_list" ]; then + echo "$1 \\" >> $dep_list cat "$1" | while read type dir file perm ; do if [ "$type" = "file" ]; then - echo "$file \\"; + echo "$file \\" >> $dep_list fi done fi @@ -231,44 +219,40 @@ output_file="" is_cpio_compressed= compr="gzip -n -9 -f" -arg="$1" -case "$arg" in - "-l") # files included in initramfs - used by kbuild - dep_list="list_" - echo "deps_initramfs := \\" - shift - ;; - "-o") # generate compressed cpio image named $1 - shift - output_file="$1" - cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" - output=${cpio_list} - echo "$output_file" | grep -q "\.gz$" \ - && [ -x "`which gzip 2> /dev/null`" ] \ - && compr="gzip -n -9 -f" - echo "$output_file" | grep -q "\.bz2$" \ - && [ -x "`which bzip2 2> /dev/null`" ] \ - && compr="bzip2 -9 -f" - echo "$output_file" | grep -q "\.lzma$" \ - && [ -x "`which lzma 2> /dev/null`" ] \ - && compr="lzma -9 -f" - echo "$output_file" | grep -q "\.xz$" \ - && [ -x "`which xz 2> /dev/null`" ] \ - && compr="xz --check=crc32 --lzma2=dict=1MiB" - echo "$output_file" | grep -q "\.lzo$" \ - && [ -x "`which lzop 2> /dev/null`" ] \ - && compr="lzop -9 -f" - echo "$output_file" | grep -q "\.lz4$" \ - && [ -x "`which lz4 2> /dev/null`" ] \ - && compr="lz4 -l -9 -f" - echo "$output_file" | grep -q "\.cpio$" && compr="cat" - shift - ;; -esac while [ $# -gt 0 ]; do arg="$1" shift case "$arg" in + "-l") # files included in initramfs - used by kbuild + dep_list="$1" + echo "deps_initramfs := \\" > $dep_list + shift + ;; + "-o") # generate compressed cpio image named $1 + output_file="$1" + cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" + output=${cpio_list} + echo "$output_file" | grep -q "\.gz$" \ + && [ -x "`which gzip 2> /dev/null`" ] \ + && compr="gzip -n -9 -f" + echo "$output_file" | grep -q "\.bz2$" \ + && [ -x "`which bzip2 2> /dev/null`" ] \ + && compr="bzip2 -9 -f" + echo "$output_file" | grep -q "\.lzma$" \ + && [ -x "`which lzma 2> /dev/null`" ] \ + && compr="lzma -9 -f" + echo "$output_file" | grep -q "\.xz$" \ + && [ -x "`which xz 2> /dev/null`" ] \ + && compr="xz --check=crc32 --lzma2=dict=1MiB" + echo "$output_file" | grep -q "\.lzo$" \ + && [ -x "`which lzop 2> /dev/null`" ] \ + && compr="lzop -9 -f" + echo "$output_file" | grep -q "\.lz4$" \ + && [ -x "`which lz4 2> /dev/null`" ] \ + && compr="lz4 -l -9 -f" + echo "$output_file" | grep -q "\.cpio$" && compr="cat" + shift + ;; "-u") # map $1 to uid=0 (root) root_uid="$1" [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0) @@ -280,7 +264,7 @@ while [ $# -gt 0 ]; do shift ;; "-d") # display default initramfs list - ${dep_list}default_initramfs + default_initramfs ;; "-h") usage From 4538f41305c3f2c35463c996663dbf6307030ad7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:35 +0900 Subject: [PATCH 18/34] initramfs: add default_cpio_list, and delete -d option support When CONFIG_INITRAMFS_SOURCE is empty, the Makefile passes the -d option to gen_initramfs.sh to create the default initramfs, which contains /dev, /dev/console, and /root. This commit simplifies the default behavior; remove the -d option, and add the default cpio list. Signed-off-by: Masahiro Yamada --- usr/Makefile | 2 +- usr/default_cpio_list | 6 ++++++ usr/gen_initramfs.sh | 16 ---------------- 3 files changed, 7 insertions(+), 17 deletions(-) create mode 100644 usr/default_cpio_list diff --git a/usr/Makefile b/usr/Makefile index 9c7387156c6b..4ca452197834 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -25,7 +25,7 @@ $(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE hostprogs-y := gen_init_cpio ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \ - $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d) + $(shell echo $(CONFIG_INITRAMFS_SOURCE)),$(srctree)/$(src)/default_cpio_list) ramfs-args := \ $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \ $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) diff --git a/usr/default_cpio_list b/usr/default_cpio_list new file mode 100644 index 000000000000..37b3864066e8 --- /dev/null +++ b/usr/default_cpio_list @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# This is a very simple, default initramfs + +dir /dev 0755 0 0 +nod /dev/console 0600 0 0 c 5 1 +dir /root 0700 0 0 diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh index 49a4e22147b5..e6808a8c3b2b 100755 --- a/usr/gen_initramfs.sh +++ b/usr/gen_initramfs.sh @@ -28,7 +28,6 @@ $0 [-o ] [-l ] [-u ] [-g ] {-d | } ... File list or directory for cpio archive. If is a .cpio file it will be used as direct input to initramfs. - -d Output the default cpio list. All options except -o and -l may be repeated and are interpreted sequentially and immediately. -u and -g states are preserved across @@ -43,18 +42,6 @@ field() { shift $1 ; echo $1 } -default_initramfs() { - cat <<-EOF >> ${output} - # This is a very simple, default initramfs - - dir /dev 0755 0 0 - nod /dev/console 0600 0 0 c 5 1 - dir /root 0700 0 0 - # file /kinit usr/kinit/kinit 0755 0 0 - # slink /init kinit 0755 0 0 - EOF -} - filetype() { local argv1="$1" @@ -263,9 +250,6 @@ while [ $# -gt 0 ]; do [ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0) shift ;; - "-d") # display default initramfs list - default_initramfs - ;; "-h") usage exit 0 From 469e87e89fd61de804bd29f6dd0380a399b567a7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:36 +0900 Subject: [PATCH 19/34] gen_initramfs.sh: always output cpio even without -o option Currently, this script outputs a cpio file when -o option is given, but otherwise a text file in the format recognized by gen_init_cpio. This behavior is unclear. Make it always output a cpio file. Signed-off-by: Masahiro Yamada --- usr/gen_initramfs.sh | 58 +++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh index e6808a8c3b2b..1efb87bda545 100755 --- a/usr/gen_initramfs.sh +++ b/usr/gen_initramfs.sh @@ -6,7 +6,6 @@ # # Generate a cpio packed initramfs. It uses gen_init_cpio to generate # the cpio archive, and then compresses it. -# The script may also be used to generate the inputfile used for gen_init_cpio # This script assumes that gen_init_cpio is located in usr/ directory # error out on errors @@ -71,8 +70,8 @@ print_mtime() { my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1) fi - echo "# Last modified: ${my_mtime}" >> ${output} - echo "" >> ${output} + echo "# Last modified: ${my_mtime}" >> $cpio_list + echo "" >> $cpio_list } list_parse() { @@ -125,7 +124,7 @@ parse() { ;; esac - echo "${str}" >> ${output} + echo "${str}" >> $cpio_list return 0 } @@ -141,7 +140,7 @@ unknown_option() { } header() { - printf "\n#####################\n# $1\n" >> ${output} + printf "\n#####################\n# $1\n" >> $cpio_list } # process one directory (incl sub-directories) @@ -177,8 +176,8 @@ input_file() { [ -n "$dep_list" ] && echo "$1" >> $dep_list return 0 fi - print_mtime "$1" >> ${output} - cat "$1" >> ${output} + print_mtime "$1" >> $cpio_list + cat "$1" >> $cpio_list if [ -n "$dep_list" ]; then echo "$1 \\" >> $dep_list cat "$1" | while read type dir file perm ; do @@ -200,9 +199,9 @@ root_uid=0 root_gid=0 dep_list= cpio_file= -cpio_list= +cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX) output="/dev/stdout" -output_file="" +output_file="/dev/stdout" is_cpio_compressed= compr="gzip -n -9 -f" @@ -217,8 +216,7 @@ while [ $# -gt 0 ]; do ;; "-o") # generate compressed cpio image named $1 output_file="$1" - cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" - output=${cpio_list} + output=$cpio_list echo "$output_file" | grep -q "\.gz$" \ && [ -x "`which gzip 2> /dev/null`" ] \ && compr="gzip -n -9 -f" @@ -269,27 +267,25 @@ done # If output_file is set we will generate cpio archive and compress it # we are careful to delete tmp files -if [ ! -z ${output_file} ]; then - if [ -z ${cpio_file} ]; then - timestamp= - if test -n "$KBUILD_BUILD_TIMESTAMP"; then - timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" - if test -n "$timestamp"; then - timestamp="-t $timestamp" - fi +if [ -z ${cpio_file} ]; then + timestamp= + if test -n "$KBUILD_BUILD_TIMESTAMP"; then + timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" + if test -n "$timestamp"; then + timestamp="-t $timestamp" fi - cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)" - usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile} - else - cpio_tfile=${cpio_file} fi - rm ${cpio_list} - if [ "${is_cpio_compressed}" = "compressed" ]; then - cat ${cpio_tfile} > ${output_file} - else - (cat ${cpio_tfile} | ${compr} - > ${output_file}) \ - || (rm -f ${output_file} ; false) - fi - [ -z ${cpio_file} ] && rm ${cpio_tfile} + cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)" + usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile} +else + cpio_tfile=${cpio_file} fi +rm ${cpio_list} +if [ "${is_cpio_compressed}" = "compressed" ]; then + cat ${cpio_tfile} > ${output_file} +else + (cat ${cpio_tfile} | ${compr} - > ${output_file}) \ + || (rm -f ${output_file} ; false) +fi +[ -z ${cpio_file} ] && rm ${cpio_tfile} exit 0 From 65e00e04e5aea34b256814cfa21b32e3b94a2402 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:37 +0900 Subject: [PATCH 20/34] initramfs: refactor the initramfs build rules Currently, usr/gen_initramfs.sh takes care of all the use-cases: [1] generates a cpio file unless CONFIG_INITRAMFS_SOURCE points to a single cpio archive [2] If CONFIG_INITRAMFS_SOURCE is the path to a cpio archive, use it as-is. [3] Compress the cpio file according to CONFIG_INITRAMFS_COMPRESSION_* unless it is passed a compressed archive. To simplify the script, move [2] and [3] to usr/Makefile. If CONFIG_INITRAMFS_SOURCE is the path to a cpio archive, there is no need to run this shell script. For the cpio archive compression, you can re-use the rules from scripts/Makefile.lib . Signed-off-by: Masahiro Yamada --- usr/.gitignore | 8 +--- usr/Kconfig | 10 ----- usr/Makefile | 89 +++++++++++++++++++++++++++++--------------- usr/gen_initramfs.sh | 77 ++++++++------------------------------ usr/initramfs_data.S | 5 +-- 5 files changed, 78 insertions(+), 111 deletions(-) diff --git a/usr/.gitignore b/usr/.gitignore index be5eae1df7eb..610de736b75e 100644 --- a/usr/.gitignore +++ b/usr/.gitignore @@ -1,9 +1,3 @@ -# -# Generated files -# gen_init_cpio initramfs_data.cpio -initramfs_data.cpio.gz -initramfs_data.cpio.bz2 -initramfs_data.cpio.lzma -initramfs_list +/initramfs_inc_data diff --git a/usr/Kconfig b/usr/Kconfig index ab61e81165e0..529caab1a328 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -207,13 +207,3 @@ config INITRAMFS_COMPRESSION_LZ4 by default which could cause a build failure. endchoice - -config INITRAMFS_COMPRESSION - string - default "" if INITRAMFS_COMPRESSION_NONE - default ".gz" if INITRAMFS_COMPRESSION_GZIP - default ".bz2" if INITRAMFS_COMPRESSION_BZIP2 - default ".lzma" if INITRAMFS_COMPRESSION_LZMA - default ".xz" if INITRAMFS_COMPRESSION_XZ - default ".lzo" if INITRAMFS_COMPRESSION_LZO - default ".lz4" if INITRAMFS_COMPRESSION_LZ4 diff --git a/usr/Makefile b/usr/Makefile index 4ca452197834..244862bfb765 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -3,55 +3,86 @@ # kbuild file for usr/ - including initramfs image # -suffix_y = $(subst $\",,$(CONFIG_INITRAMFS_COMPRESSION)) -datafile_y = initramfs_data.cpio$(suffix_y) -datafile_d_y = .$(datafile_y).d -AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/$(datafile_y)" +# cmd_bzip2, cmd_lzma, cmd_lzo, cmd_lz4 from scripts/Makefile.lib appends the +# size at the end of the compressed file, which unfortunately does not work +# with unpack_to_rootfs(). Make size_append no-op. +override size_append := : -# clean rules do not have CONFIG_INITRAMFS_COMPRESSION. So clean up after all -# possible compression formats. -clean-files += initramfs_data.cpio* +compress-$(CONFIG_INITRAMFS_COMPRESSION_NONE) := shipped +compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip +compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2 +compress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA) := lzma +compress-$(CONFIG_INITRAMFS_COMPRESSION_XZ) := xzmisc +compress-$(CONFIG_INITRAMFS_COMPRESSION_LZO) := lzo +compress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4) := lz4 -# Generate builtin.o based on initramfs_data.o obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o -# initramfs_data.o contains the compressed initramfs_data.cpio image. -# The image is included using .incbin, a dependency which is not -# tracked automatically. -$(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE +$(obj)/initramfs_data.o: $(obj)/initramfs_inc_data -##### -# Generate the initramfs cpio archive +ramfs-input := $(strip $(shell echo $(CONFIG_INITRAMFS_SOURCE))) +cpio-data := + +# If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the +# default contents. +ifeq ($(ramfs-input),) +ramfs-input := $(srctree)/$(src)/default_cpio_list +endif + +ifeq ($(words $(ramfs-input)),1) + +# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with +# .cpio, use it directly as an initramfs. +ifneq ($(filter %.cpio,$(ramfs-input)),) +cpio-data := $(ramfs-input) +endif + +# If CONFIG_INITRAMFS_SOURCE specifies a single file, and it is suffixed with +# .cpio.*, use it directly as an initramfs, and avoid double compression. +ifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2) +cpio-data := $(ramfs-input) +compress-y := shipped +endif + +endif + +# For other cases, generate the initramfs cpio archive based on the contents +# specified by CONFIG_INITRAMFS_SOURCE. +ifeq ($(cpio-data),) + +cpio-data := $(obj)/initramfs_data.cpio hostprogs-y := gen_init_cpio -ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \ - $(shell echo $(CONFIG_INITRAMFS_SOURCE)),$(srctree)/$(src)/default_cpio_list) -ramfs-args := \ - $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \ - $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) -# $(datafile_d_y) is used to identify all files included +# .initramfs_data.cpio.d is used to identify all files included # in initramfs and to detect if any files are added/removed. # Removed files are identified by directory timestamp being updated # The dependency list is generated by gen_initramfs.sh -l -ifneq ($(wildcard $(obj)/$(datafile_d_y)),) - include $(obj)/$(datafile_d_y) -endif - -quiet_cmd_initfs = GEN $@ - cmd_initfs = $(CONFIG_SHELL) $< -o $@ -l $(obj)/$(datafile_d_y) $(ramfs-args) $(ramfs-input) - -targets := $(datafile_y) +-include $(obj)/.initramfs_data.cpio.d # do not try to update files included in initramfs $(deps_initramfs): ; +quiet_cmd_initfs = GEN $@ + cmd_initfs = \ + $(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \ + $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \ + $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \ + $(ramfs-input) + # We rebuild initramfs_data.cpio if: # 1) Any included file is newer than initramfs_data.cpio # 2) There are changes in which files are included (added or deleted) # 3) If gen_init_cpio are newer than initramfs_data.cpio # 4) Arguments to gen_initramfs.sh changes -$(obj)/$(datafile_y): $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE +$(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE $(call if_changed,initfs) +endif + +$(obj)/initramfs_inc_data: $(cpio-data) FORCE + $(call if_changed,$(compress-y)) + +targets += initramfs_data.cpio initramfs_inc_data + subdir-$(CONFIG_UAPI_HEADER_TEST) += include diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh index 1efb87bda545..4e6715f8ff7f 100755 --- a/usr/gen_initramfs.sh +++ b/usr/gen_initramfs.sh @@ -5,7 +5,7 @@ # Released under the terms of the GNU GPL # # Generate a cpio packed initramfs. It uses gen_init_cpio to generate -# the cpio archive, and then compresses it. +# the cpio archive. # This script assumes that gen_init_cpio is located in usr/ directory # error out on errors @@ -15,8 +15,7 @@ usage() { cat << EOF Usage: $0 [-o ] [-l ] [-u ] [-g ] {-d | } ... - -o Create compressed initramfs file named using - gen_init_cpio and compressor depending on the extension + -o Create initramfs file named by using gen_init_cpio -l Create dependency list named -u User ID to map to user ID 0 (root). is only meaningful if is a @@ -162,20 +161,12 @@ dir_filelist() { fi } -# if only one file is specified and it is .cpio file then use it direct as fs -# if a directory is specified then add all files in given direcotry to fs -# if a regular file is specified assume it is in gen_init_cpio format input_file() { source="$1" if [ -f "$1" ]; then + # If a regular file is specified, assume it is in + # gen_init_cpio format header "$1" - is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" - if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then - cpio_file=$1 - echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" - [ -n "$dep_list" ] && echo "$1" >> $dep_list - return 0 - fi print_mtime "$1" >> $cpio_list cat "$1" >> $cpio_list if [ -n "$dep_list" ]; then @@ -187,6 +178,7 @@ input_file() { done fi elif [ -d "$1" ]; then + # If a directory is specified then add all files in it to fs dir_filelist "$1" else echo " ${prog}: Cannot open '$1'" >&2 @@ -198,12 +190,8 @@ prog=$0 root_uid=0 root_gid=0 dep_list= -cpio_file= cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX) output="/dev/stdout" -output_file="/dev/stdout" -is_cpio_compressed= -compr="gzip -n -9 -f" while [ $# -gt 0 ]; do arg="$1" @@ -214,28 +202,8 @@ while [ $# -gt 0 ]; do echo "deps_initramfs := \\" > $dep_list shift ;; - "-o") # generate compressed cpio image named $1 - output_file="$1" - output=$cpio_list - echo "$output_file" | grep -q "\.gz$" \ - && [ -x "`which gzip 2> /dev/null`" ] \ - && compr="gzip -n -9 -f" - echo "$output_file" | grep -q "\.bz2$" \ - && [ -x "`which bzip2 2> /dev/null`" ] \ - && compr="bzip2 -9 -f" - echo "$output_file" | grep -q "\.lzma$" \ - && [ -x "`which lzma 2> /dev/null`" ] \ - && compr="lzma -9 -f" - echo "$output_file" | grep -q "\.xz$" \ - && [ -x "`which xz 2> /dev/null`" ] \ - && compr="xz --check=crc32 --lzma2=dict=1MiB" - echo "$output_file" | grep -q "\.lzo$" \ - && [ -x "`which lzop 2> /dev/null`" ] \ - && compr="lzop -9 -f" - echo "$output_file" | grep -q "\.lz4$" \ - && [ -x "`which lz4 2> /dev/null`" ] \ - && compr="lz4 -l -9 -f" - echo "$output_file" | grep -q "\.cpio$" && compr="cat" + "-o") # generate cpio image named $1 + output="$1" shift ;; "-u") # map $1 to uid=0 (root) @@ -258,34 +226,21 @@ while [ $# -gt 0 ]; do unknown_option ;; *) # input file/dir - process it - input_file "$arg" "$#" + input_file "$arg" ;; esac ;; esac done -# If output_file is set we will generate cpio archive and compress it +# If output_file is set we will generate cpio archive # we are careful to delete tmp files -if [ -z ${cpio_file} ]; then - timestamp= - if test -n "$KBUILD_BUILD_TIMESTAMP"; then - timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" - if test -n "$timestamp"; then - timestamp="-t $timestamp" - fi +timestamp= +if test -n "$KBUILD_BUILD_TIMESTAMP"; then + timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" + if test -n "$timestamp"; then + timestamp="-t $timestamp" fi - cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)" - usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile} -else - cpio_tfile=${cpio_file} fi -rm ${cpio_list} -if [ "${is_cpio_compressed}" = "compressed" ]; then - cat ${cpio_tfile} > ${output_file} -else - (cat ${cpio_tfile} | ${compr} - > ${output_file}) \ - || (rm -f ${output_file} ; false) -fi -[ -z ${cpio_file} ] && rm ${cpio_tfile} -exit 0 +usr/gen_init_cpio $timestamp $cpio_list > $output +rm $cpio_list diff --git a/usr/initramfs_data.S b/usr/initramfs_data.S index d07648f05bbf..cd67edc38797 100644 --- a/usr/initramfs_data.S +++ b/usr/initramfs_data.S @@ -22,12 +22,9 @@ in the ELF header, as required by certain architectures. */ -#include -#include - .section .init.ramfs,"a" __irf_start: -.incbin __stringify(INITRAMFS_IMAGE) +.incbin "usr/initramfs_inc_data" __irf_end: .section .init.ramfs.info,"a" .globl __initramfs_size From 7168965ec7b10b8a2c7dea1f82f1ebadf44d64ba Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:02:38 +0900 Subject: [PATCH 21/34] gen_initramfs.sh: remove intermediate cpio_list on errors This script sets the -e option, so it exits on any error, in which case it exits without cleaning up the intermediate cpio_list. Make sure to delete it on exit. Signed-off-by: Masahiro Yamada --- usr/gen_initramfs.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh index 4e6715f8ff7f..8ae831657e5d 100755 --- a/usr/gen_initramfs.sh +++ b/usr/gen_initramfs.sh @@ -193,6 +193,8 @@ dep_list= cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX) output="/dev/stdout" +trap "rm -f $cpio_list" EXIT + while [ $# -gt 0 ]; do arg="$1" shift @@ -243,4 +245,3 @@ if test -n "$KBUILD_BUILD_TIMESTAMP"; then fi fi usr/gen_init_cpio $timestamp $cpio_list > $output -rm $cpio_list From 5370d4acc590e5992ca4a1b9f606714fad69e88a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 5 Jan 2020 00:36:51 +0900 Subject: [PATCH 22/34] modpost: assume STT_SPARC_REGISTER is defined Commit 8d5290149ee1 ("[SPARC]: Deal with glibc changing macro names in modpost.c") was more than 14 years ago. STT_SPARC_REGISTER is hopefully defined in elf.h of recent C libraries. Signed-off-by: Masahiro Yamada Acked-by: David S. Miller --- scripts/mod/modpost.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 6e892c93d104..7edfdb2f4497 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -12,6 +12,7 @@ */ #define _GNU_SOURCE +#include #include #include #include @@ -729,12 +730,6 @@ static void handle_symbol(struct module *mod, struct elf_info *info, break; if (ignore_undef_symbol(info, symname)) break; -/* cope with newer glibc (2.3.4 or higher) STT_ definition in elf.h */ -#if defined(STT_REGISTER) || defined(STT_SPARC_REGISTER) -/* add compatibility with older glibc */ -#ifndef STT_SPARC_REGISTER -#define STT_SPARC_REGISTER STT_REGISTER -#endif if (info->hdr->e_machine == EM_SPARC || info->hdr->e_machine == EM_SPARCV9) { /* Ignore register directives. */ @@ -747,7 +742,6 @@ static void handle_symbol(struct module *mod, struct elf_info *info, symname = munged; } } -#endif mod->unres = alloc_symbol(symname, ELF_ST_BIND(sym->st_info) == STB_WEAK, From 94f7345b712405b79647a6a4bf8ccbd0d78fa69d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 6 Jan 2020 17:36:28 +0900 Subject: [PATCH 23/34] kbuild: remove PYTHON2 variable Python 2 has retired. There is no user of this variable. Signed-off-by: Masahiro Yamada --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4f01de6cd43c..4a0796b05324 100644 --- a/Makefile +++ b/Makefile @@ -423,7 +423,6 @@ INSTALLKERNEL := installkernel DEPMOD = /sbin/depmod PERL = perl PYTHON = python -PYTHON2 = python2 PYTHON3 = python3 CHECK = sparse BASH = bash @@ -474,7 +473,7 @@ CLANG_FLAGS := export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL -export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX +export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS From 88fe89a47153facd8cb2d06d5c8727f7224c43c2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 10 Jan 2020 14:02:24 +0900 Subject: [PATCH 24/34] kbuild: remove *.tmp file when filechk fails Bartosz Golaszewski reports that when "make {menu,n,g,x}config" fails due to missing packages, a temporary file is left over, which is not ignored by git. For example, if GTK+ is not installed: $ make gconfig * * Unable to find the GTK+ installation. Please make sure that * the GTK+ 2.0 development package is correctly installed. * You need gtk+-2.0 gmodule-2.0 libglade-2.0 * scripts/kconfig/Makefile:208: recipe for target 'scripts/kconfig/gconf-cfg' failed make[1]: *** [scripts/kconfig/gconf-cfg] Error 1 Makefile:567: recipe for target 'gconfig' failed make: *** [gconfig] Error 2 $ git status HEAD detached at v5.4 Untracked files: (use "git add ..." to include in what will be committed) scripts/kconfig/gconf-cfg.tmp nothing added to commit but untracked files present (use "git add" to track) This is because the check scripts are run with filechk, which misses to clean up the temporary file on failure. When the line { $(filechk_$(1)); } > $@.tmp; ... fails, it exits immediately due to the 'set -e'. Use trap to make sure to delete the temporary file on exit. For extra safety, I replaced $@.tmp with $(dot-target).tmp to make it a hidden file. Reported-by: Bartosz Golaszewski Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 3da8321efb74..6cabf20ce66a 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -59,14 +59,13 @@ kecho := $($(quiet)kecho) # - stdin is piped in from the first prerequisite ($<) so one has # to specify a valid file as first prerequisite (often the kbuild file) define filechk - $(Q)set -e; \ - mkdir -p $(dir $@); \ - { $(filechk_$(1)); } > $@.tmp; \ - if [ -r $@ ] && cmp -s $@ $@.tmp; then \ - rm -f $@.tmp; \ - else \ - $(kecho) ' UPD $@'; \ - mv -f $@.tmp $@; \ + $(Q)set -e; \ + mkdir -p $(dir $@); \ + trap "rm -f $(dot-target).tmp" EXIT; \ + { $(filechk_$(1)); } > $(dot-target).tmp; \ + if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \ + $(kecho) ' UPD $@'; \ + mv -f $(dot-target).tmp $@; \ fi endef From 9c9aa8fdf306cd7329e0a68bbcbe2f71b397dac1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 13 Jan 2020 16:30:17 +0900 Subject: [PATCH 25/34] kbuild: remove 'Building modules, stage 2.' log This log is displayed every time modules are built, but it is not so important. Signed-off-by: Masahiro Yamada --- scripts/Makefile.modpost | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 69897d5d3a70..b4d3f2d122ac 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -90,7 +90,6 @@ quiet_cmd_modpost = MODPOST $(words $(modules)) modules cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) __modpost: - @$(kecho) ' Building modules, stage 2.' $(call cmd,modpost) ifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal From 1a7f0a34ea7d05d1ffcd32c9b1b4e07ac0687538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Date: Tue, 14 Jan 2020 19:11:26 +0100 Subject: [PATCH 26/34] builddeb: allow selection of .deb compressor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Select deb compression using KDEB_COMPRESS make variable. This allows to use gzip compression for local or test builds, and that's way faster than now-default xz compression. Signed-off-by: Michał Mirosław Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index b60388051c7f..f903ba947daf 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -43,7 +43,7 @@ create_package() { # Create the package dpkg-gencontrol -p$pname -P"$pdir" - dpkg --build "$pdir" .. + dpkg-deb ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" .. } version=$KERNELRELEASE From 3bed1b7b9d79ca40e41e3af130931a3225e951a3 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 18 Jan 2020 02:14:35 +0900 Subject: [PATCH 27/34] kbuild: use -S instead of -E for precise cc-option test in Kconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, -E (stop after the preprocessing stage) is used to check whether the given compiler flag is supported. While it is faster than -S (or -c), it can be false-positive. You need to run the compilation proper to check the flag more precisely. For example, -E and -S disagree about the support of "--param asan-instrument-allocas=1". $ gcc -Werror --param asan-instrument-allocas=1 -E -x c /dev/null -o /dev/null $ echo $? 0 $ gcc -Werror --param asan-instrument-allocas=1 -S -x c /dev/null -o /dev/null cc1: error: invalid --param name ‘asan-instrument-allocas’; did you mean ‘asan-instrument-writes’? $ echo $? 1 Signed-off-by: Masahiro Yamada --- scripts/Kconfig.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index d4adfbe42690..bfb44b265a94 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -25,7 +25,7 @@ failure = $(if-success,$(1),n,y) # $(cc-option,) # Return y if the compiler supports , n otherwise -cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -E -x c /dev/null -o /dev/null) +cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null) # $(ld-option,) # Return y if the linker supports , n otherwise From 7e61b167eb29f949f74a465aa135c69fac3d1c8f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 25 Jan 2020 13:12:29 +0900 Subject: [PATCH 28/34] builddeb: remove unneeded files in hdrobjfiles for headers package - We do not need tools/objtool/fixdep or tools/objtool/sync-check.sh for building external modules. Including tools/objtool/objtool is enough. - gcc-common.h is a check-in file. I do not see any point to search for it in objtree. Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index f903ba947daf..d4bb28fbd3de 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -170,11 +170,11 @@ done (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles" (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles" if is_enabled CONFIG_STACK_VALIDATION; then - (cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles" + echo tools/objtool/objtool >> "$objtree/debian/hdrobjfiles" fi (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles" if is_enabled CONFIG_GCC_PLUGINS; then - (cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles" + (cd $objtree; find scripts/gcc-plugins -name \*.so) >> "$objtree/debian/hdrobjfiles" fi destdir=$kernel_headers_dir/usr/src/linux-headers-$version mkdir -p "$destdir" From 1694e94e4f4698b7fdd37e6700ca6c5b7e01d25a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 25 Jan 2020 13:12:30 +0900 Subject: [PATCH 29/34] builddeb: match temporary directory name to the package name The temporary directory names, debian/hdrtmp (linux-headers package) vs debian/headertmp (linux-libc-dev package), are confusing. Matching the directory name to the package name is clearer, IMHO. Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index d4bb28fbd3de..d72267835373 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -47,10 +47,10 @@ create_package() { } version=$KERNELRELEASE -tmpdir="$objtree/debian/tmp" -kernel_headers_dir="$objtree/debian/hdrtmp" -libc_headers_dir="$objtree/debian/headertmp" -dbg_dir="$objtree/debian/dbgtmp" +tmpdir="$objtree/debian/linux-image" +kernel_headers_dir="$objtree/debian/linux-headers" +libc_headers_dir="$objtree/debian/linux-libc-dev" +dbg_dir="$objtree/debian/linux-image-dbg" packagename=linux-image-$version kernel_headers_packagename=linux-headers-$version libc_headers_packagename=linux-libc-dev From f9a4711ebb248ad37c830b2715342ec60edb1330 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 25 Jan 2020 13:12:31 +0900 Subject: [PATCH 30/34] builddeb: remove redundant $objtree/ This script works only when it is invoked in the $objtree, that is, it is already relying on $objtree is '.' Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index d72267835373..15a76817e4ac 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -47,10 +47,10 @@ create_package() { } version=$KERNELRELEASE -tmpdir="$objtree/debian/linux-image" -kernel_headers_dir="$objtree/debian/linux-headers" -libc_headers_dir="$objtree/debian/linux-libc-dev" -dbg_dir="$objtree/debian/linux-image-dbg" +tmpdir=debian/linux-image +kernel_headers_dir=debian/linux-headers +libc_headers_dir=debian/linux-libc-dev +dbg_dir=debian/linux-image-dbg packagename=linux-image-$version kernel_headers_packagename=linux-headers-$version libc_headers_packagename=linux-libc-dev @@ -77,7 +77,7 @@ esac BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes) # Setup the directory structure -rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files +rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" debian/files mkdir -m 755 -p "$tmpdir/DEBIAN" mkdir -p "$tmpdir/lib" "$tmpdir/boot" mkdir -p "$kernel_headers_dir/lib/modules/$version/" @@ -165,24 +165,24 @@ EOF done # Build kernel header package -(cd $srctree; find . arch/$SRCARCH -maxdepth 1 -name Makefile\*) > "$objtree/debian/hdrsrcfiles" -(cd $srctree; find include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles" -(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles" -(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles" +(cd $srctree; find . arch/$SRCARCH -maxdepth 1 -name Makefile\*) > debian/hdrsrcfiles +(cd $srctree; find include scripts -type f -o -type l) >> debian/hdrsrcfiles +(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> debian/hdrsrcfiles +(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> debian/hdrsrcfiles if is_enabled CONFIG_STACK_VALIDATION; then - echo tools/objtool/objtool >> "$objtree/debian/hdrobjfiles" + echo tools/objtool/objtool >> debian/hdrobjfiles fi -(cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles" +find arch/$SRCARCH/include Module.symvers include scripts -type f >> debian/hdrobjfiles if is_enabled CONFIG_GCC_PLUGINS; then - (cd $objtree; find scripts/gcc-plugins -name \*.so) >> "$objtree/debian/hdrobjfiles" + find scripts/gcc-plugins -name \*.so >> debian/hdrobjfiles fi destdir=$kernel_headers_dir/usr/src/linux-headers-$version mkdir -p "$destdir" -(cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -) -(cd $objtree; tar -c -f - -T -) < "$objtree/debian/hdrobjfiles" | (cd $destdir; tar -xf -) -(cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be +(cd $srctree; tar -c -f - -T -) < debian/hdrsrcfiles | (cd $destdir; tar -xf -) +tar -c -f - -T - < debian/hdrobjfiles | (cd $destdir; tar -xf -) +cp $KCONFIG_CONFIG $destdir/.config # copy .config manually to be where it's expected to be ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build" -rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles" +rm -f debian/hdrsrcfiles debian/hdrobjfiles if [ "$ARCH" != "um" ]; then create_package "$kernel_headers_packagename" "$kernel_headers_dir" From 9a92eee38790c63b45b32876cb1967154f8b9ee5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 25 Jan 2020 13:12:32 +0900 Subject: [PATCH 31/34] builddeb: avoid invoking sub-shells where possible The commands surrounded by ( ... ) is run in a sub-shell, but you do not have to spawn a sub-shell for every single line. Use just one ( ... ) for creating debian/hdrsrcfiles. For tar, use -C option instead. Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index 15a76817e4ac..a73e0d5377e9 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -165,21 +165,30 @@ EOF done # Build kernel header package -(cd $srctree; find . arch/$SRCARCH -maxdepth 1 -name Makefile\*) > debian/hdrsrcfiles -(cd $srctree; find include scripts -type f -o -type l) >> debian/hdrsrcfiles -(cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> debian/hdrsrcfiles -(cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> debian/hdrsrcfiles -if is_enabled CONFIG_STACK_VALIDATION; then - echo tools/objtool/objtool >> debian/hdrobjfiles -fi -find arch/$SRCARCH/include Module.symvers include scripts -type f >> debian/hdrobjfiles -if is_enabled CONFIG_GCC_PLUGINS; then - find scripts/gcc-plugins -name \*.so >> debian/hdrobjfiles -fi +( + cd $srctree + find . arch/$SRCARCH -maxdepth 1 -name Makefile\* + find include scripts -type f -o -type l + find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform + find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f +) > debian/hdrsrcfiles + +{ + if is_enabled CONFIG_STACK_VALIDATION; then + echo tools/objtool/objtool + fi + + find arch/$SRCARCH/include Module.symvers include scripts -type f + + if is_enabled CONFIG_GCC_PLUGINS; then + find scripts/gcc-plugins -name \*.so + fi +} > debian/hdrobjfiles + destdir=$kernel_headers_dir/usr/src/linux-headers-$version mkdir -p "$destdir" -(cd $srctree; tar -c -f - -T -) < debian/hdrsrcfiles | (cd $destdir; tar -xf -) -tar -c -f - -T - < debian/hdrobjfiles | (cd $destdir; tar -xf -) +tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir +tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir cp $KCONFIG_CONFIG $destdir/.config # copy .config manually to be where it's expected to be ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build" rm -f debian/hdrsrcfiles debian/hdrobjfiles From aae6a6712440d566ae148fc3af223dc25fbd9794 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 25 Jan 2020 13:12:33 +0900 Subject: [PATCH 32/34] builddeb: remove redundant make for ARCH=um The kernel build has already been done before builddeb is invoked. Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index a73e0d5377e9..731b5d0b2422 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -82,10 +82,9 @@ mkdir -m 755 -p "$tmpdir/DEBIAN" mkdir -p "$tmpdir/lib" "$tmpdir/boot" mkdir -p "$kernel_headers_dir/lib/modules/$version/" -# Build and install the kernel +# Install the kernel if [ "$ARCH" = "um" ] ; then mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename" - $MAKE linux cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config" gzip "$tmpdir/usr/share/doc/$packagename/config" From 3126c17d28b696ba555bb959888fe4b5143bb389 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 25 Jan 2020 13:12:34 +0900 Subject: [PATCH 33/34] builddeb: split kernel headers deployment out into a function Deploy kernel headers (linux-headers package) in a separate function for readability. Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 76 ++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index 731b5d0b2422..c9287e57d398 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -46,13 +46,49 @@ create_package() { dpkg-deb ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" .. } +deploy_kernel_headers () { + pdir=$1 + + rm -rf $pdir + + ( + cd $srctree + find . arch/$SRCARCH -maxdepth 1 -name Makefile\* + find include scripts -type f -o -type l + find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform + find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f + ) > debian/hdrsrcfiles + + { + if is_enabled CONFIG_STACK_VALIDATION; then + echo tools/objtool/objtool + fi + + find arch/$SRCARCH/include Module.symvers include scripts -type f + + if is_enabled CONFIG_GCC_PLUGINS; then + find scripts/gcc-plugins -name \*.so + fi + } > debian/hdrobjfiles + + destdir=$pdir/usr/src/linux-headers-$version + mkdir -p $destdir + tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir + tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir + rm -f debian/hdrsrcfiles debian/hdrobjfiles + + # copy .config manually to be where it's expected to be + cp $KCONFIG_CONFIG $destdir/.config + + mkdir -p $pdir/lib/modules/$version/ + ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build +} + version=$KERNELRELEASE tmpdir=debian/linux-image -kernel_headers_dir=debian/linux-headers libc_headers_dir=debian/linux-libc-dev dbg_dir=debian/linux-image-dbg packagename=linux-image-$version -kernel_headers_packagename=linux-headers-$version libc_headers_packagename=linux-libc-dev dbg_packagename=$packagename-dbg @@ -77,10 +113,9 @@ esac BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes) # Setup the directory structure -rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" debian/files +rm -rf "$tmpdir" "$libc_headers_dir" "$dbg_dir" debian/files mkdir -m 755 -p "$tmpdir/DEBIAN" mkdir -p "$tmpdir/lib" "$tmpdir/boot" -mkdir -p "$kernel_headers_dir/lib/modules/$version/" # Install the kernel if [ "$ARCH" = "um" ] ; then @@ -163,37 +198,10 @@ EOF chmod 755 "$tmpdir/DEBIAN/$script" done -# Build kernel header package -( - cd $srctree - find . arch/$SRCARCH -maxdepth 1 -name Makefile\* - find include scripts -type f -o -type l - find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform - find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f -) > debian/hdrsrcfiles - -{ - if is_enabled CONFIG_STACK_VALIDATION; then - echo tools/objtool/objtool - fi - - find arch/$SRCARCH/include Module.symvers include scripts -type f - - if is_enabled CONFIG_GCC_PLUGINS; then - find scripts/gcc-plugins -name \*.so - fi -} > debian/hdrobjfiles - -destdir=$kernel_headers_dir/usr/src/linux-headers-$version -mkdir -p "$destdir" -tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir -tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir -cp $KCONFIG_CONFIG $destdir/.config # copy .config manually to be where it's expected to be -ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build" -rm -f debian/hdrsrcfiles debian/hdrobjfiles - if [ "$ARCH" != "um" ]; then - create_package "$kernel_headers_packagename" "$kernel_headers_dir" + deploy_kernel_headers debian/linux-headers + create_package linux-headers-$version debian/linux-headers + create_package "$libc_headers_packagename" "$libc_headers_dir" fi From 451dff37f0752cc8ad6f1bb82081a98d7b760310 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 25 Jan 2020 13:12:35 +0900 Subject: [PATCH 34/34] builddeb: split libc headers deployment out into a function Deploy user-space headers (linux-libc-dev package) in a separate function for readability. Signed-off-by: Masahiro Yamada --- scripts/package/builddeb | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index c9287e57d398..6df3c9f8b2da 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -84,12 +84,25 @@ deploy_kernel_headers () { ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build } +deploy_libc_headers () { + pdir=$1 + + rm -rf $pdir + + $MAKE -f $srctree/Makefile headers + $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr + + # move asm headers to /usr/include//asm to match the structure + # used by Debian-based distros (to support multi-arch) + host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH) + mkdir $pdir/usr/include/$host_arch + mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/ +} + version=$KERNELRELEASE tmpdir=debian/linux-image -libc_headers_dir=debian/linux-libc-dev dbg_dir=debian/linux-image-dbg packagename=linux-image-$version -libc_headers_packagename=linux-libc-dev dbg_packagename=$packagename-dbg if [ "$ARCH" = "um" ] ; then @@ -113,7 +126,7 @@ esac BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes) # Setup the directory structure -rm -rf "$tmpdir" "$libc_headers_dir" "$dbg_dir" debian/files +rm -rf "$tmpdir" "$dbg_dir" debian/files mkdir -m 755 -p "$tmpdir/DEBIAN" mkdir -p "$tmpdir/lib" "$tmpdir/boot" @@ -163,16 +176,6 @@ if is_enabled CONFIG_MODULES; then fi fi -if [ "$ARCH" != "um" ]; then - $MAKE -f $srctree/Makefile headers - $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH="$libc_headers_dir/usr" - # move asm headers to /usr/include//asm to match the structure - # used by Debian-based distros (to support multi-arch) - host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH) - mkdir $libc_headers_dir/usr/include/$host_arch - mv $libc_headers_dir/usr/include/asm $libc_headers_dir/usr/include/$host_arch/ -fi - # Install the maintainer scripts # Note: hook scripts under /etc/kernel are also executed by official Debian # kernel packages, as well as kernel packages built using make-kpkg. @@ -202,7 +205,8 @@ if [ "$ARCH" != "um" ]; then deploy_kernel_headers debian/linux-headers create_package linux-headers-$version debian/linux-headers - create_package "$libc_headers_packagename" "$libc_headers_dir" + deploy_libc_headers debian/linux-libc-dev + create_package linux-libc-dev debian/linux-libc-dev fi create_package "$packagename" "$tmpdir"