Kbuild updates for v5.6

- detect missing include guard in UAPI headers
 
  - do not create orphan built-in.a or obj-y objects
 
  - generate modules.builtin more simply, and drop tristate.conf
 
  - simplify built-in initramfs creation
 
  - make linux-headers deb package thinner
 
  - optimize the deb package build script
 
  - misc cleanups
 -----BEGIN PGP SIGNATURE-----
 
 iQJJBAABCgAzFiEEbmPs18K1szRHjPqEPYsBB53g2wYFAl409uwVHG1hc2FoaXJv
 eUBrZXJuZWwub3JnAAoJED2LAQed4NsG6vAP/jky7LSuv6lpIcYhxOmzFfs7qTlA
 llZDmzTPi26/doV1P9LYMw6Pd4HV6Zeo/aFLolirCsp0kFBW/5b2C68OsXfotJOD
 0YxPeFMIsumsmAVdQ7lGQerS19BDcMrFJiKoLUuULH3bH0mjL/YVlFVg0Dmq77j1
 PDsyTihROajVmJBf8UMK65nUdCSLZihBsKyvj7SxYnlHAS1EaAT+RiwE7qAHoYW9
 C3TYwOa1e8u/0FmosKxSChl9Pq5ti/gcK4dVLs7bm4LmJEsqmLeR8BDM8xlaT/FE
 lFl7iPLO2cvhy76NsK8YBnTcRD445gBn+M3XFKZ3sDTVj7TkdaIWtVurf5IYo+BN
 bTJHac1E9nbpv6L7QIXhxLCGozEi0+pv/8pyhIrAv8XxmZXp7HJbon+siEg8Glez
 rbwM44kNPQk8xovVcoixh4+qRH9l49+zzT0h0kY1PWfJ6hp0D1xmG/v3kai8dErt
 X4w7xi5gOssYwZ5M0LuOQprDeL5DV/Caz5R1+maqVb2yhn2EBsJ6wC24/vawxhFj
 Kjx1g/NZIW4lnBrF1Ay4geF+f+0jd1bcTBqtNmC09uSTIBvEysZ3HNBf4Z9PFTGW
 jdQ7Qpowgy9SOLqZuE+OAuojq7xhfm1fkm/MBUFUYh/HKOXoiLAnVK1+x0BM0yJB
 ZhMwvmj9fKoqVpzx
 =i/xZ
 -----END PGP SIGNATURE-----

Merge tag 'kbuild-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

 - detect missing include guard in UAPI headers

 - do not create orphan built-in.a or obj-y objects

 - generate modules.builtin more simply, and drop tristate.conf

 - simplify built-in initramfs creation

 - make linux-headers deb package thinner

 - optimize the deb package build script

 - misc cleanups

* tag 'kbuild-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (34 commits)
  builddeb: split libc headers deployment out into a function
  builddeb: split kernel headers deployment out into a function
  builddeb: remove redundant make for ARCH=um
  builddeb: avoid invoking sub-shells where possible
  builddeb: remove redundant $objtree/
  builddeb: match temporary directory name to the package name
  builddeb: remove unneeded files in hdrobjfiles for headers package
  kbuild: use -S instead of -E for precise cc-option test in Kconfig
  builddeb: allow selection of .deb compressor
  kbuild: remove 'Building modules, stage 2.' log
  kbuild: remove *.tmp file when filechk fails
  kbuild: remove PYTHON2 variable
  modpost: assume STT_SPARC_REGISTER is defined
  gen_initramfs.sh: remove intermediate cpio_list on errors
  initramfs: refactor the initramfs build rules
  gen_initramfs.sh: always output cpio even without -o option
  initramfs: add default_cpio_list, and delete -d option support
  initramfs: generate dependency list and cpio at the same time
  initramfs: specify $(src)/gen_initramfs.sh as a prerequisite in Makefile
  initramfs: make initramfs compression choice non-optional
  ...
This commit is contained in:
Linus Torvalds 2020-02-01 10:01:52 -08:00
commit 368d060bb4
20 changed files with 280 additions and 448 deletions

View File

@ -154,11 +154,6 @@ KCONFIG_AUTOCONFIG
This environment variable can be set to specify the path & name of the This environment variable can be set to specify the path & name of the
"auto.conf" file. Its default value is "include/config/auto.conf". "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 KCONFIG_AUTOHEADER
------------------ ------------------
This environment variable can be set to specify the path & name of the This environment variable can be set to specify the path & name of the

View File

@ -423,7 +423,6 @@ INSTALLKERNEL := installkernel
DEPMOD = /sbin/depmod DEPMOD = /sbin/depmod
PERL = perl PERL = perl
PYTHON = python PYTHON = python
PYTHON2 = python2
PYTHON3 = python3 PYTHON3 = python3
CHECK = sparse CHECK = sparse
BASH = bash BASH = bash
@ -474,7 +473,7 @@ CLANG_FLAGS :=
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC 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 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_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
@ -674,7 +673,7 @@ $(KCONFIG_CONFIG):
# #
# This exploits the 'multi-target pattern rule' trick. # This exploits the 'multi-target pattern rule' trick.
# The syncconfig should be executed only once to make all the targets. # 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 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
else # !may-sync-config else # !may-sync-config
# External modules and some install targets need include/generated/autoconf.h # External modules and some install targets need include/generated/autoconf.h
@ -1278,24 +1277,13 @@ all: modules
# using awk while concatenating to the final file. # using awk while concatenating to the final file.
PHONY += modules 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)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh
modules.order: descend modules.order: descend
$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ $(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 # Target to prepare building external modules
PHONY += modules_prepare PHONY += modules_prepare
modules_prepare: prepare modules_prepare: prepare
@ -1315,7 +1303,7 @@ _modinst_:
ln -s $(CURDIR) $(MODLIB)/build ; \ ln -s $(CURDIR) $(MODLIB)/build ; \
fi fi
@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order @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)/ @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
@ -1357,7 +1345,7 @@ endif # CONFIG_MODULES
# Directories & files removed with 'make clean' # Directories & files removed with 'make clean'
CLEAN_DIRS += include/ksym 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' # Directories & files removed with 'make mrproper'
MRPROPER_DIRS += include/config include/generated \ MRPROPER_DIRS += include/config include/generated \
@ -1712,7 +1700,7 @@ clean: $(clean-dirs)
-o -name '*.lex.c' -o -name '*.tab.[ch]' \ -o -name '*.lex.c' -o -name '*.tab.[ch]' \
-o -name '*.asn1.[ch]' \ -o -name '*.asn1.[ch]' \
-o -name '*.symtypes' -o -name 'modules.order' \ -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 '*.c.[012]*.*' \
-o -name '*.ll' \ -o -name '*.ll' \
-o -name '*.gcno' \) -type f -print | xargs rm -f -o -name '*.gcno' \) -type f -print | xargs rm -f

View File

@ -169,6 +169,16 @@ extern void cleanup_module(void);
*/ */
#define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) #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 * The following license idents are currently accepted as indicating free
* software modules * software modules
@ -213,7 +223,7 @@ extern void cleanup_module(void);
* 2. So the community can ignore bug reports including proprietary modules * 2. So the community can ignore bug reports including proprietary modules
* 3. So vendors can do likewise based on their own policies * 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 <email>" or just "Name", for multiple * Author(s), use "Name <email>" or just "Name", for multiple

View File

@ -32,6 +32,10 @@ real-prereqs = $(filter-out $(PHONY), $^)
# Escape single quote for use in echo statements # Escape single quote for use in echo statements
escsq = $(subst $(squote),'\$(squote)',$1) 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 # Easy method for doing a status message
kecho := : kecho := :
@ -55,14 +59,13 @@ kecho := $($(quiet)kecho)
# - stdin is piped in from the first prerequisite ($<) so one has # - stdin is piped in from the first prerequisite ($<) so one has
# to specify a valid file as first prerequisite (often the kbuild file) # to specify a valid file as first prerequisite (often the kbuild file)
define filechk define filechk
$(Q)set -e; \ $(Q)set -e; \
mkdir -p $(dir $@); \ mkdir -p $(dir $@); \
{ $(filechk_$(1)); } > $@.tmp; \ trap "rm -f $(dot-target).tmp" EXIT; \
if [ -r $@ ] && cmp -s $@ $@.tmp; then \ { $(filechk_$(1)); } > $(dot-target).tmp; \
rm -f $@.tmp; \ if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \
else \ $(kecho) ' UPD $@'; \
$(kecho) ' UPD $@'; \ mv -f $(dot-target).tmp $@; \
mv -f $@.tmp $@; \
fi fi
endef endef
@ -159,12 +162,6 @@ ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
# $(Q)$(MAKE) $(build)=dir # $(Q)$(MAKE) $(build)=dir
build := -f $(srctree)/scripts/Makefile.build obj 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= # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
# Usage: # Usage:

View File

@ -25,7 +25,7 @@ failure = $(if-success,$(1),n,y)
# $(cc-option,<flag>) # $(cc-option,<flag>)
# Return y if the compiler supports <flag>, n otherwise # Return y if the compiler supports <flag>, 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,<flag>) # $(ld-option,<flag>)
# Return y if the linker supports <flag>, n otherwise # Return y if the linker supports <flag>, n otherwise

View File

@ -66,7 +66,7 @@ lib-target := $(obj)/lib.a
real-obj-y += $(obj)/lib-ksyms.o real-obj-y += $(obj)/lib-ksyms.o
endif endif
ifneq ($(strip $(real-obj-y) $(need-builtin)),) ifdef need-builtin
builtin-target := $(obj)/built-in.a builtin-target := $(obj)/built-in.a
endif endif
@ -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 # 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) # Rule to compile a set of .o files into one .a file (without symbol table)

View File

@ -35,7 +35,11 @@ __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y += $(__subdir-y) subdir-y += $(__subdir-y)
__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m += $(__subdir-m) subdir-m += $(__subdir-m)
ifdef need-builtin
obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
else
obj-y := $(filter-out %/, $(obj-y))
endif
obj-m := $(filter-out %/, $(obj-m)) obj-m := $(filter-out %/, $(obj-m))
# Subdirectories we need to descend into # Subdirectories we need to descend into
@ -80,12 +84,14 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
# Finds the multi-part object the current object will be linked into. # 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 # If the object belongs to two or more multi-part objects, list them all.
# concatenated with a colon separator. modname-multi = $(sort $(foreach m,$(multi-used),\
modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))
$(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 with $(obj)/ and its suffix stripped
target-stem = $(basename $(patsubst $(obj)/%,%,$@)) target-stem = $(basename $(patsubst $(obj)/%,%,$@))
@ -93,9 +99,10 @@ target-stem = $(basename $(patsubst $(obj)/%,%,$@))
# These flags are needed for modversions and compiling, so we define them here # 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 # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
# end up in (or would, if it gets compiled in) # 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)) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))
orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
$(ccflags-y) $(CFLAGS_$(target-stem).o) $(ccflags-y) $(CFLAGS_$(target-stem).o)
@ -154,7 +161,7 @@ quiet_modtag = $(if $(part-of-module),[M], )
modkern_cflags = \ modkern_cflags = \
$(if $(part-of-module), \ $(if $(part-of-module), \
$(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
modkern_aflags = $(if $(part-of-module), \ modkern_aflags = $(if $(part-of-module), \
$(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \

View File

@ -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)

View File

@ -90,7 +90,6 @@ quiet_cmd_modpost = MODPOST $(words $(modules)) modules
cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST)
__modpost: __modpost:
@$(kecho) ' Building modules, stage 2.'
$(call cmd,modpost) $(call cmd,modpost)
ifneq ($(KBUILD_MODPOST_NOFINAL),1) ifneq ($(KBUILD_MODPOST_NOFINAL),1)
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal

View File

@ -710,25 +710,6 @@ static struct conf_printer header_printer_cb =
.print_comment = header_print_comment, .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, static void conf_write_symbol(FILE *fp, struct symbol *sym,
struct conf_printer *printer, void *printer_arg) struct conf_printer *printer, void *printer_arg)
{ {
@ -1062,7 +1043,7 @@ int conf_write_autoconf(int overwrite)
struct symbol *sym; struct symbol *sym;
const char *name; const char *name;
const char *autoconf_name = conf_get_autoconfig_name(); const char *autoconf_name = conf_get_autoconfig_name();
FILE *out, *tristate, *out_h; FILE *out, *out_h;
int i; int i;
if (!overwrite && is_present(autoconf_name)) if (!overwrite && is_present(autoconf_name))
@ -1077,23 +1058,13 @@ int conf_write_autoconf(int overwrite)
if (!out) if (!out)
return 1; return 1;
tristate = fopen(".tmpconfig_tristate", "w");
if (!tristate) {
fclose(out);
return 1;
}
out_h = fopen(".tmpconfig.h", "w"); out_h = fopen(".tmpconfig.h", "w");
if (!out_h) { if (!out_h) {
fclose(out); fclose(out);
fclose(tristate);
return 1; return 1;
} }
conf_write_heading(out, &kconfig_printer_cb, NULL); 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); conf_write_heading(out_h, &header_printer_cb, NULL);
for_all_symbols(i, sym) { for_all_symbols(i, sym) {
@ -1101,15 +1072,11 @@ int conf_write_autoconf(int overwrite)
if (!(sym->flags & SYMBOL_WRITE) || !sym->name) if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
continue; 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(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); conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
} }
fclose(out); fclose(out);
fclose(tristate);
fclose(out_h); fclose(out_h);
name = getenv("KCONFIG_AUTOHEADER"); name = getenv("KCONFIG_AUTOHEADER");
@ -1120,14 +1087,6 @@ int conf_write_autoconf(int overwrite)
if (rename(".tmpconfig.h", name)) if (rename(".tmpconfig.h", name))
return 1; 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)) if (make_parent_dir(autoconf_name))
return 1; return 1;
/* /*

View File

@ -250,6 +250,10 @@ ${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1
info MODINFO modules.builtin.modinfo info MODINFO modules.builtin.modinfo
${OBJCOPY} -j .modinfo -O binary vmlinux.o 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="" btf_vmlinux_bin_o=""
if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then

View File

@ -12,6 +12,7 @@
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
#include <elf.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
@ -729,12 +730,6 @@ static void handle_symbol(struct module *mod, struct elf_info *info,
break; break;
if (ignore_undef_symbol(info, symname)) if (ignore_undef_symbol(info, symname))
break; 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 || if (info->hdr->e_machine == EM_SPARC ||
info->hdr->e_machine == EM_SPARCV9) { info->hdr->e_machine == EM_SPARCV9) {
/* Ignore register directives. */ /* Ignore register directives. */
@ -747,7 +742,6 @@ static void handle_symbol(struct module *mod, struct elf_info *info,
symname = munged; symname = munged;
} }
} }
#endif
mod->unres = alloc_symbol(symname, mod->unres = alloc_symbol(symname,
ELF_ST_BIND(sym->st_info) == STB_WEAK, ELF_ST_BIND(sym->st_info) == STB_WEAK,

View File

@ -43,17 +43,66 @@ create_package() {
# Create the package # Create the package
dpkg-gencontrol -p$pname -P"$pdir" dpkg-gencontrol -p$pname -P"$pdir"
dpkg --build "$pdir" .. 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
}
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/<libc-machine>/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 version=$KERNELRELEASE
tmpdir="$objtree/debian/tmp" tmpdir=debian/linux-image
kernel_headers_dir="$objtree/debian/hdrtmp" dbg_dir=debian/linux-image-dbg
libc_headers_dir="$objtree/debian/headertmp"
dbg_dir="$objtree/debian/dbgtmp"
packagename=linux-image-$version packagename=linux-image-$version
kernel_headers_packagename=linux-headers-$version
libc_headers_packagename=linux-libc-dev
dbg_packagename=$packagename-dbg dbg_packagename=$packagename-dbg
if [ "$ARCH" = "um" ] ; then if [ "$ARCH" = "um" ] ; then
@ -77,15 +126,13 @@ esac
BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes) BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes)
# Setup the directory structure # Setup the directory structure
rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files rm -rf "$tmpdir" "$dbg_dir" debian/files
mkdir -m 755 -p "$tmpdir/DEBIAN" mkdir -m 755 -p "$tmpdir/DEBIAN"
mkdir -p "$tmpdir/lib" "$tmpdir/boot" 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 if [ "$ARCH" = "um" ] ; then
mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename" 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 System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config" cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
gzip "$tmpdir/usr/share/doc/$packagename/config" gzip "$tmpdir/usr/share/doc/$packagename/config"
@ -129,16 +176,6 @@ if is_enabled CONFIG_MODULES; then
fi fi
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/<libc-machine>/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 # Install the maintainer scripts
# Note: hook scripts under /etc/kernel are also executed by official Debian # Note: hook scripts under /etc/kernel are also executed by official Debian
# kernel packages, as well as kernel packages built using make-kpkg. # kernel packages, as well as kernel packages built using make-kpkg.
@ -164,29 +201,12 @@ EOF
chmod 755 "$tmpdir/DEBIAN/$script" chmod 755 "$tmpdir/DEBIAN/$script"
done 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 -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"
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"
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
ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build"
rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles"
if [ "$ARCH" != "um" ]; then if [ "$ARCH" != "um" ]; then
create_package "$kernel_headers_packagename" "$kernel_headers_dir" deploy_kernel_headers debian/linux-headers
create_package "$libc_headers_packagename" "$libc_headers_dir" create_package linux-headers-$version debian/linux-headers
deploy_libc_headers debian/linux-libc-dev
create_package linux-libc-dev debian/linux-libc-dev
fi fi
create_package "$packagename" "$tmpdir" create_package "$packagename" "$tmpdir"

8
usr/.gitignore vendored
View File

@ -1,9 +1,3 @@
#
# Generated files
#
gen_init_cpio gen_init_cpio
initramfs_data.cpio initramfs_data.cpio
initramfs_data.cpio.gz /initramfs_inc_data
initramfs_data.cpio.bz2
initramfs_data.cpio.lzma
initramfs_list

View File

@ -54,7 +54,6 @@ config INITRAMFS_ROOT_GID
config RD_GZIP config RD_GZIP
bool "Support initial ramdisk/ramfs compressed using gzip" bool "Support initial ramdisk/ramfs compressed using gzip"
depends on BLK_DEV_INITRD
default y default y
select DECOMPRESS_GZIP select DECOMPRESS_GZIP
help help
@ -64,7 +63,6 @@ config RD_GZIP
config RD_BZIP2 config RD_BZIP2
bool "Support initial ramdisk/ramfs compressed using bzip2" bool "Support initial ramdisk/ramfs compressed using bzip2"
default y default y
depends on BLK_DEV_INITRD
select DECOMPRESS_BZIP2 select DECOMPRESS_BZIP2
help help
Support loading of a bzip2 encoded initial ramdisk or cpio buffer Support loading of a bzip2 encoded initial ramdisk or cpio buffer
@ -73,7 +71,6 @@ config RD_BZIP2
config RD_LZMA config RD_LZMA
bool "Support initial ramdisk/ramfs compressed using LZMA" bool "Support initial ramdisk/ramfs compressed using LZMA"
default y default y
depends on BLK_DEV_INITRD
select DECOMPRESS_LZMA select DECOMPRESS_LZMA
help help
Support loading of a LZMA encoded initial ramdisk or cpio buffer Support loading of a LZMA encoded initial ramdisk or cpio buffer
@ -81,7 +78,6 @@ config RD_LZMA
config RD_XZ config RD_XZ
bool "Support initial ramdisk/ramfs compressed using XZ" bool "Support initial ramdisk/ramfs compressed using XZ"
depends on BLK_DEV_INITRD
default y default y
select DECOMPRESS_XZ select DECOMPRESS_XZ
help help
@ -91,7 +87,6 @@ config RD_XZ
config RD_LZO config RD_LZO
bool "Support initial ramdisk/ramfs compressed using LZO" bool "Support initial ramdisk/ramfs compressed using LZO"
default y default y
depends on BLK_DEV_INITRD
select DECOMPRESS_LZO select DECOMPRESS_LZO
help help
Support loading of a LZO encoded initial ramdisk or cpio buffer Support loading of a LZO encoded initial ramdisk or cpio buffer
@ -100,7 +95,6 @@ config RD_LZO
config RD_LZ4 config RD_LZ4
bool "Support initial ramdisk/ramfs compressed using LZ4" bool "Support initial ramdisk/ramfs compressed using LZ4"
default y default y
depends on BLK_DEV_INITRD
select DECOMPRESS_LZ4 select DECOMPRESS_LZ4
help help
Support loading of a LZ4 encoded initial ramdisk or cpio buffer Support loading of a LZ4 encoded initial ramdisk or cpio buffer
@ -108,8 +102,6 @@ config RD_LZ4
choice choice
prompt "Built-in initramfs compression mode" prompt "Built-in initramfs compression mode"
depends on INITRAMFS_SOURCE!=""
optional
help help
This option allows you to decide by which algorithm the builtin This option allows you to decide by which algorithm the builtin
initramfs will be compressed. Several compression algorithms are initramfs will be compressed. Several compression algorithms are
@ -215,21 +207,3 @@ config INITRAMFS_COMPRESSION_LZ4
by default which could cause a build failure. by default which could cause a build failure.
endchoice endchoice
config INITRAMFS_COMPRESSION
depends on INITRAMFS_SOURCE!=""
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
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 ""

View File

@ -3,61 +3,86 @@
# kbuild file for usr/ - including initramfs image # kbuild file for usr/ - including initramfs image
# #
klibcdirs:; # cmd_bzip2, cmd_lzma, cmd_lzo, cmd_lz4 from scripts/Makefile.lib appends the
PHONY += klibcdirs # 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 := :
suffix_y = $(subst $\",,$(CONFIG_INITRAMFS_COMPRESSION)) compress-$(CONFIG_INITRAMFS_COMPRESSION_NONE) := shipped
datafile_y = initramfs_data.cpio$(suffix_y) compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip
datafile_d_y = .$(datafile_y).d compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2
AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/$(datafile_y)" compress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA) := lzma
compress-$(CONFIG_INITRAMFS_COMPRESSION_XZ) := xzmisc
compress-$(CONFIG_INITRAMFS_COMPRESSION_LZO) := lzo
compress-$(CONFIG_INITRAMFS_COMPRESSION_LZ4) := lz4
# clean rules do not have CONFIG_INITRAMFS_COMPRESSION. So clean up after all
# possible compression formats.
clean-files += initramfs_data.cpio*
# Generate builtin.o based on initramfs_data.o
obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
# initramfs_data.o contains the compressed initramfs_data.cpio image. $(obj)/initramfs_data.o: $(obj)/initramfs_inc_data
# The image is included using .incbin, a dependency which is not
# tracked automatically.
$(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE
##### ramfs-input := $(strip $(shell echo $(CONFIG_INITRAMFS_SOURCE)))
# Generate the initramfs cpio archive 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 hostprogs-y := gen_init_cpio
initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs_list.sh
ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \
$(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
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. # in initramfs and to detect if any files are added/removed.
# Removed files are identified by directory timestamp being updated # Removed files are identified by directory timestamp being updated
# The dependency list is generated by gen_initramfs.sh -l # The dependency list is generated by gen_initramfs.sh -l
ifneq ($(wildcard $(obj)/$(datafile_d_y)),) -include $(obj)/.initramfs_data.cpio.d
include $(obj)/$(datafile_d_y)
endif
quiet_cmd_initfs = GEN $@
cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
targets := $(datafile_y)
# do not try to update files included in initramfs # do not try to update files included in initramfs
$(deps_initramfs): ; $(deps_initramfs): ;
$(deps_initramfs): klibcdirs 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: # We rebuild initramfs_data.cpio if:
# 1) Any included file is newer than initramfs_data.cpio # 1) Any included file is newer than initramfs_data.cpio
# 2) There are changes in which files are included (added or deleted) # 2) There are changes in which files are included (added or deleted)
# 3) If gen_init_cpio are newer than initramfs_data.cpio # 3) If gen_init_cpio are newer than initramfs_data.cpio
# 4) Arguments to gen_initramfs.sh changes # 4) Arguments to gen_initramfs.sh changes
$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs $(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE
$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
$(call if_changed,initfs) $(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 subdir-$(CONFIG_UAPI_HEADER_TEST) += include

6
usr/default_cpio_list Normal file
View File

@ -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

View File

@ -5,8 +5,7 @@
# Released under the terms of the GNU GPL # Released under the terms of the GNU GPL
# #
# Generate a cpio packed initramfs. It uses gen_init_cpio to generate # Generate a cpio packed initramfs. It uses gen_init_cpio to generate
# the cpio archive, and then compresses it. # the cpio archive.
# 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 # This script assumes that gen_init_cpio is located in usr/ directory
# error out on errors # error out on errors
@ -15,9 +14,9 @@ set -e
usage() { usage() {
cat << EOF cat << EOF
Usage: Usage:
$0 [-o <file>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ... $0 [-o <file>] [-l <dep_list>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
-o <file> Create compressed initramfs file named <file> using -o <file> Create initramfs file named <file> by using gen_init_cpio
gen_init_cpio and compressor depending on the extension -l <dep_list> Create dependency list named <dep_list>
-u <uid> User ID to map to user ID 0 (root). -u <uid> User ID to map to user ID 0 (root).
<uid> is only meaningful if <cpio_source> is a <uid> is only meaningful if <cpio_source> is a
directory. "squash" forces all files to uid 0. directory. "squash" forces all files to uid 0.
@ -27,7 +26,6 @@ $0 [-o <file>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
<cpio_source> File list or directory for cpio archive. <cpio_source> File list or directory for cpio archive.
If <cpio_source> is a .cpio file it will be used If <cpio_source> is a .cpio file it will be used
as direct input to initramfs. as direct input to initramfs.
-d Output the default cpio list.
All options except -o and -l may be repeated and are interpreted All options except -o and -l may be repeated and are interpreted
sequentially and immediately. -u and -g states are preserved across sequentially and immediately. -u and -g states are preserved across
@ -42,23 +40,6 @@ field() {
shift $1 ; echo $1 shift $1 ; echo $1
} }
list_default_initramfs() {
# echo usr/kinit/kinit
:
}
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() { filetype() {
local argv1="$1" local argv1="$1"
@ -81,10 +62,6 @@ filetype() {
return 0 return 0
} }
list_print_mtime() {
:
}
print_mtime() { print_mtime() {
local my_mtime="0" local my_mtime="0"
@ -92,15 +69,15 @@ print_mtime() {
my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1) my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1)
fi fi
echo "# Last modified: ${my_mtime}" >> ${output} echo "# Last modified: ${my_mtime}" >> $cpio_list
echo "" >> ${output} echo "" >> $cpio_list
} }
list_parse() { list_parse() {
if [ -L "$1" ]; then if [ -z "$dep_list" -o -L "$1" ]; then
return return
fi fi
echo "$1" | sed 's/:/\\:/g; s/$/ \\/' echo "$1" | sed 's/:/\\:/g; s/$/ \\/' >> $dep_list
} }
# for each file print a line in following format # for each file print a line in following format
@ -146,7 +123,7 @@ parse() {
;; ;;
esac esac
echo "${str}" >> ${output} echo "${str}" >> $cpio_list
return 0 return 0
} }
@ -161,58 +138,47 @@ unknown_option() {
exit 1 exit 1
} }
list_header() {
:
}
header() { header() {
printf "\n#####################\n# $1\n" >> ${output} printf "\n#####################\n# $1\n" >> $cpio_list
} }
# process one directory (incl sub-directories) # process one directory (incl sub-directories)
dir_filelist() { dir_filelist() {
${dep_list}header "$1" header "$1"
srcdir=$(echo "$1" | sed -e 's://*:/:g') srcdir=$(echo "$1" | sed -e 's://*:/:g')
dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort) dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort)
# If $dirlist is only one line, then the directory is empty # If $dirlist is only one line, then the directory is empty
if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then
${dep_list}print_mtime "$1" print_mtime "$1"
echo "${dirlist}" | \ echo "${dirlist}" | \
while read x; do while read x; do
${dep_list}parse ${x} list_parse $x
parse $x
done done
fi 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_initramfs format
input_file() { input_file() {
source="$1" source="$1"
if [ -f "$1" ]; then if [ -f "$1" ]; then
${dep_list}header "$1" # If a regular file is specified, assume it is in
is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" # gen_init_cpio format
if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then header "$1"
cpio_file=$1 print_mtime "$1" >> $cpio_list
echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" cat "$1" >> $cpio_list
[ ! -z ${dep_list} ] && echo "$1" if [ -n "$dep_list" ]; then
return 0 echo "$1 \\" >> $dep_list
fi
if [ -z ${dep_list} ]; then
print_mtime "$1" >> ${output}
cat "$1" >> ${output}
else
echo "$1 \\"
cat "$1" | while read type dir file perm ; do cat "$1" | while read type dir file perm ; do
if [ "$type" = "file" ]; then if [ "$type" = "file" ]; then
echo "$file \\"; echo "$file \\" >> $dep_list
fi fi
done done
fi fi
elif [ -d "$1" ]; then elif [ -d "$1" ]; then
# If a directory is specified then add all files in it to fs
dir_filelist "$1" dir_filelist "$1"
else else
echo " ${prog}: Cannot open '$1'" >&2 echo " ${prog}: Cannot open '$1'" >&2
@ -224,51 +190,24 @@ prog=$0
root_uid=0 root_uid=0
root_gid=0 root_gid=0
dep_list= dep_list=
cpio_file= cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)
cpio_list=
output="/dev/stdout" output="/dev/stdout"
output_file=""
is_cpio_compressed=
compr="gzip -n -9 -f"
arg="$1" trap "rm -f $cpio_list" EXIT
case "$arg" in
"-l") # files included in initramfs - used by kbuild
dep_list="list_"
echo "deps_initramfs := $0 \\"
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 while [ $# -gt 0 ]; do
arg="$1" arg="$1"
shift shift
case "$arg" in case "$arg" in
"-l") # files included in initramfs - used by kbuild
dep_list="$1"
echo "deps_initramfs := \\" > $dep_list
shift
;;
"-o") # generate cpio image named $1
output="$1"
shift
;;
"-u") # map $1 to uid=0 (root) "-u") # map $1 to uid=0 (root)
root_uid="$1" root_uid="$1"
[ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0) [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0)
@ -279,10 +218,6 @@ while [ $# -gt 0 ]; do
[ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0) [ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0)
shift shift
;; ;;
"-d") # display default initramfs list
default_list="$arg"
${dep_list}default_initramfs
;;
"-h") "-h")
usage usage
exit 0 exit 0
@ -293,36 +228,20 @@ while [ $# -gt 0 ]; do
unknown_option unknown_option
;; ;;
*) # input file/dir - process it *) # input file/dir - process it
input_file "$arg" "$#" input_file "$arg"
;; ;;
esac esac
;; ;;
esac esac
done 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 # we are careful to delete tmp files
if [ ! -z ${output_file} ]; then timestamp=
if [ -z ${cpio_file} ]; then if test -n "$KBUILD_BUILD_TIMESTAMP"; then
timestamp= timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)"
if test -n "$KBUILD_BUILD_TIMESTAMP"; then if test -n "$timestamp"; then
timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" timestamp="-t $timestamp"
if test -n "$timestamp"; then
timestamp="-t $timestamp"
fi
fi
cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)"
usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile}
else
cpio_tfile=${cpio_file}
fi 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}
fi fi
exit 0 usr/gen_init_cpio $timestamp $cpio_list > $output

View File

@ -16,87 +16,88 @@ override c_flags = $(UAPI_CFLAGS) -Wp,-MD,$(depfile) -I$(objtree)/usr/include
# Please consider to fix the header first. # Please consider to fix the header first.
# #
# Sorted alphabetically. # Sorted alphabetically.
header-test- += asm/shmbuf.h no-header-test += asm/shmbuf.h
header-test- += asm/signal.h no-header-test += asm/signal.h
header-test- += asm/ucontext.h no-header-test += asm/ucontext.h
header-test- += drm/vmwgfx_drm.h no-header-test += drm/vmwgfx_drm.h
header-test- += linux/am437x-vpfe.h no-header-test += linux/am437x-vpfe.h
header-test- += linux/android/binder.h no-header-test += linux/android/binder.h
header-test- += linux/android/binderfs.h no-header-test += linux/android/binderfs.h
header-test- += linux/coda.h no-header-test += linux/coda.h
header-test- += linux/elfcore.h no-header-test += linux/elfcore.h
header-test- += linux/errqueue.h no-header-test += linux/errqueue.h
header-test- += linux/fsmap.h no-header-test += linux/fsmap.h
header-test- += linux/hdlc/ioctl.h no-header-test += linux/hdlc/ioctl.h
header-test- += linux/ivtv.h no-header-test += linux/ivtv.h
header-test- += linux/kexec.h no-header-test += linux/kexec.h
header-test- += linux/matroxfb.h no-header-test += linux/matroxfb.h
header-test- += linux/nfc.h no-header-test += linux/nfc.h
header-test- += linux/omap3isp.h no-header-test += linux/omap3isp.h
header-test- += linux/omapfb.h no-header-test += linux/omapfb.h
header-test- += linux/patchkey.h no-header-test += linux/patchkey.h
header-test- += linux/phonet.h no-header-test += linux/phonet.h
header-test- += linux/reiserfs_xattr.h no-header-test += linux/reiserfs_xattr.h
header-test- += linux/sctp.h no-header-test += linux/sctp.h
header-test- += linux/signal.h no-header-test += linux/signal.h
header-test- += linux/sysctl.h no-header-test += linux/sysctl.h
header-test- += linux/usb/audio.h no-header-test += linux/usb/audio.h
header-test- += linux/v4l2-mediabus.h no-header-test += linux/v4l2-mediabus.h
header-test- += linux/v4l2-subdev.h no-header-test += linux/v4l2-subdev.h
header-test- += linux/videodev2.h no-header-test += linux/videodev2.h
header-test- += linux/vm_sockets.h no-header-test += linux/vm_sockets.h
header-test- += sound/asequencer.h no-header-test += sound/asequencer.h
header-test- += sound/asoc.h no-header-test += sound/asoc.h
header-test- += sound/asound.h no-header-test += sound/asound.h
header-test- += sound/compress_offload.h no-header-test += sound/compress_offload.h
header-test- += sound/emu10k1.h no-header-test += sound/emu10k1.h
header-test- += sound/sfnt_info.h no-header-test += sound/sfnt_info.h
header-test- += xen/evtchn.h no-header-test += xen/evtchn.h
header-test- += xen/gntdev.h no-header-test += xen/gntdev.h
header-test- += xen/privcmd.h no-header-test += xen/privcmd.h
# More headers are broken in some architectures # More headers are broken in some architectures
ifeq ($(SRCARCH),arc) ifeq ($(SRCARCH),arc)
header-test- += linux/bpf_perf_event.h no-header-test += linux/bpf_perf_event.h
endif endif
ifeq ($(SRCARCH),ia64) ifeq ($(SRCARCH),ia64)
header-test- += asm/setup.h no-header-test += asm/setup.h
header-test- += asm/sigcontext.h no-header-test += asm/sigcontext.h
header-test- += asm/perfmon.h no-header-test += asm/perfmon.h
header-test- += asm/perfmon_default_smpl.h no-header-test += asm/perfmon_default_smpl.h
header-test- += linux/if_bonding.h no-header-test += linux/if_bonding.h
endif endif
ifeq ($(SRCARCH),mips) ifeq ($(SRCARCH),mips)
header-test- += asm/stat.h no-header-test += asm/stat.h
endif endif
ifeq ($(SRCARCH),powerpc) ifeq ($(SRCARCH),powerpc)
header-test- += asm/stat.h no-header-test += asm/stat.h
header-test- += linux/bpf_perf_event.h no-header-test += linux/bpf_perf_event.h
endif endif
ifeq ($(SRCARCH),riscv) ifeq ($(SRCARCH),riscv)
header-test- += linux/bpf_perf_event.h no-header-test += linux/bpf_perf_event.h
endif endif
ifeq ($(SRCARCH),sparc) ifeq ($(SRCARCH),sparc)
header-test- += asm/stat.h no-header-test += asm/stat.h
header-test- += asm/uctx.h no-header-test += asm/uctx.h
header-test- += asm/fbio.h no-header-test += asm/fbio.h
endif endif
# asm-generic/*.h is used by asm/*.h, and should not be included directly # 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)) 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 $< quiet_cmd_hdrtest = HDRTEST $<
cmd_hdrtest = \ cmd_hdrtest = \
$(CC) $(c_flags) -S -o /dev/null -x c /dev/null \ $(CC) $(c_flags) -S -o /dev/null -x c /dev/null \
$(if $(filter-out $(header-test-), $*.h), -include $<); \ $(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \
$(PERL) $(srctree)/scripts/headers_check.pl $(obj) $(SRCARCH) $<; \ $(PERL) $(srctree)/scripts/headers_check.pl $(obj) $(SRCARCH) $<; \
touch $@ touch $@

View File

@ -22,12 +22,9 @@
in the ELF header, as required by certain architectures. in the ELF header, as required by certain architectures.
*/ */
#include <linux/stringify.h>
#include <asm-generic/vmlinux.lds.h>
.section .init.ramfs,"a" .section .init.ramfs,"a"
__irf_start: __irf_start:
.incbin __stringify(INITRAMFS_IMAGE) .incbin "usr/initramfs_inc_data"
__irf_end: __irf_end:
.section .init.ramfs.info,"a" .section .init.ramfs.info,"a"
.globl __initramfs_size .globl __initramfs_size