1 From bc081dd6e9f622c73334dc465359168543ccaabf Mon Sep 17 00:00:00 2001
2 From: Michal Marek <mmarek@suse.cz>
3 Date: Mon, 07 Dec 2009 15:38:33 +0000
4 Subject: kbuild: generate modules.builtin
6 To make it easier for module-init-tools and scripts like mkinitrd to
7 distinguish builtin and missing modules, install a modules.builtin file
8 listing all builtin modules. This is done by generating an additional
9 config file (tristate.conf) with tristate options set to uppercase 'Y'
10 or 'M'. If we source that config file, the builtin modules appear in
13 Signed-off-by: Michal Marek <mmarek@suse.cz>
15 Note form support@proxmox.com: We modified the patch to cleanly apply
16 on our RHEL6 2.6.32 kernel.
19 diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt
20 index bb3bf38..6f8c1ca 100644
21 --- a/Documentation/kbuild/kbuild.txt
22 +++ b/Documentation/kbuild/kbuild.txt
27 +--------------------------------------------------
28 +This file records the order in which modules appear in Makefiles. This
29 +is used by modprobe to deterministically resolve aliases that match
33 +--------------------------------------------------
34 +This file lists all modules that are built into the kernel. This is used
35 +by modprobe to not fail when trying to load something builtin.
41 diff --git a/Documentation/kbuild/kconfig.txt b/Documentation/kbuild/kconfig.txt
42 index ab8dc35..49efae7 100644
43 --- a/Documentation/kbuild/kconfig.txt
44 +++ b/Documentation/kbuild/kconfig.txt
45 @@ -103,6 +103,11 @@ KCONFIG_AUTOCONFIG
46 This environment variable can be set to specify the path & name of the
47 "auto.conf" file. Its default value is "include/config/auto.conf".
50 +--------------------------------------------------
51 +This environment variable can be set to specify the path & name of the
52 +"tristate.conf" file. Its default value is "include/config/tristate.conf".
55 --------------------------------------------------
56 This environment variable can be set to specify the path & name of the
57 diff --git a/Makefile b/Makefile
58 index aa608c2..391fcb3 100644
61 @@ -464,7 +464,7 @@ ifeq ($(KBUILD_EXTMOD),)
62 # Carefully list dependencies so we do not try to build scripts twice
65 -scripts: scripts_basic include/config/auto.conf
66 +scripts: scripts_basic include/config/auto.conf include/config/tristate.conf
67 $(Q)$(MAKE) $(build)=$(@)
69 # Objects we will link into vmlinux / subdirs we need to visit
70 @@ -491,7 +491,7 @@ $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
71 # with it and forgot to run make oldconfig.
72 # if auto.conf.cmd is missing then we are probably in a cleaned tree so
73 # we execute the config step to be sure to catch updated Kconfig files
74 -include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
75 +include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
76 $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
78 # external modules needs include/generated/autoconf.h and include/config/auto.conf
79 @@ -876,6 +876,9 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
80 PHONY += $(vmlinux-dirs)
81 $(vmlinux-dirs): prepare scripts
82 $(Q)$(MAKE) $(build)=$@
84 + $(Q)$(MAKE) $(modbuiltin)=$@
87 # Build the kernel release string
89 @@ -1080,6 +1083,7 @@ all: modules
91 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
92 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
93 + $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.builtin) > $(objtree)/modules.builtin
94 @$(kecho) ' Building modules, stage 2.';
95 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
96 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild
97 @@ -1109,6 +1113,7 @@ _modinst_:
98 ln -s $(objtree) $(MODLIB)/build ; \
100 @cp -f $(objtree)/modules.order $(MODLIB)/
101 + @cp -f $(objtree)/modules.builtin $(MODLIB)/
102 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
104 # This depmod is only for convenience to give the initial
105 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
106 index c67e73e..ed2773e 100644
107 --- a/scripts/Kbuild.include
108 +++ b/scripts/Kbuild.include
109 @@ -149,6 +149,12 @@ ld-option = $(call try-run,\
110 # $(Q)$(MAKE) $(build)=dir
111 build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
114 +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
116 +# $(Q)$(MAKE) $(modbuiltin)=dir
117 +modbuiltin := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.modbuiltin obj
119 # Prefix -I with $(srctree) if it is not an absolute path.
120 # skip if -I has no parameter
121 addtree = $(if $(patsubst -I%,%,$(1)), \
122 diff --git a/scripts/Makefile.modbuiltin b/scripts/Makefile.modbuiltin
124 index 0000000..102a276
126 +++ b/scripts/Makefile.modbuiltin
128 +# ==========================================================================
129 +# Generating modules.builtin
130 +# ==========================================================================
134 +PHONY := __modbuiltin
137 +-include include/config/auto.conf
138 +# tristate.conf sets tristate variables to uppercase 'Y' or 'M'
139 +# That way, we get the list of built-in modules in obj-Y
140 +-include include/config/tristate.conf
142 +include scripts/Kbuild.include
144 +# The filename Kbuild has precedence over Makefile
145 +kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
146 +kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
147 +include $(kbuild-file)
149 +include scripts/Makefile.lib
150 +__subdir-Y := $(patsubst %/,%,$(filter %/, $(obj-Y)))
151 +subdir-Y += $(__subdir-Y)
152 +subdir-ym := $(sort $(subdir-y) $(subdir-Y) $(subdir-m))
153 +subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
154 +obj-Y := $(addprefix $(obj)/,$(obj-Y))
156 +modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym))
157 +modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko))
158 +modbuiltin-target := $(obj)/modules.builtin
160 +__modbuiltin: $(modbuiltin-target) $(subdir-ym)
163 +$(modbuiltin-target): $(subdir-ym) FORCE
164 + $(Q)(for m in $(modbuiltin-mods); do echo kernel/$$m; done; \
165 + cat /dev/null $(modbuiltin-subdirs)) > $@
172 +# ---------------------------------------------------------------------------
174 +PHONY += $(subdir-ym)
176 + $(Q)$(MAKE) $(modbuiltin)=$@
179 +# Declare the contents of the .PHONY variable as phony. We keep that
180 +# information in a variable se we can use it in if_changed and friends.
183 diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
184 index 797a741..c4dec80 100644
185 --- a/scripts/kconfig/confdata.c
186 +++ b/scripts/kconfig/confdata.c
187 @@ -677,7 +677,7 @@ int conf_write_autoconf(void)
192 + FILE *out, *tristate, *out_h;
196 @@ -692,9 +692,16 @@ int conf_write_autoconf(void)
200 + tristate = fopen(".tmpconfig_tristate", "w");
206 out_h = fopen(".tmpconfig.h", "w");
213 @@ -707,6 +714,9 @@ int conf_write_autoconf(void)
216 sym_get_string_value(sym), ctime(&now));
217 + fprintf(tristate, "#\n"
218 + "# Automatically generated - do not edit\n"
220 fprintf(out_h, "/*\n"
221 " * Automatically generated C config: don't edit\n"
222 " * Linux kernel version: %s\n"
223 @@ -727,10 +737,14 @@ int conf_write_autoconf(void)
226 fprintf(out, "CONFIG_%s=m\n", sym->name);
227 + fprintf(tristate, "CONFIG_%s=M\n", sym->name);
228 fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
231 fprintf(out, "CONFIG_%s=y\n", sym->name);
232 + if (sym->type == S_TRISTATE)
233 + fprintf(tristate, "CONFIG_%s=Y\n",
235 fprintf(out_h, "#define CONFIG_%s 1\n", sym->name);
238 @@ -772,6 +786,7 @@ int conf_write_autoconf(void)
245 name = getenv("KCONFIG_AUTOHEADER");
246 @@ -779,6 +794,11 @@ int conf_write_autoconf(void)
247 name = "include/generated/autoconf.h";
248 if (rename(".tmpconfig.h", name))
250 + name = getenv("KCONFIG_TRISTATE");
252 + name = "include/config/tristate.conf";
253 + if (rename(".tmpconfig_tristate", name))
255 name = conf_get_autoconfig_name();
257 * This must be the last step, kbuild has a dependency on auto.conf