]> git.proxmox.com Git - pve-kernel-2.6.32.git/blame - kbuild-generate-mudules-builtin.patch
update to vzkernel-2.6.32-042stab113.12.src.rpm
[pve-kernel-2.6.32.git] / kbuild-generate-mudules-builtin.patch
CommitLineData
be4195cf
DM
1From bc081dd6e9f622c73334dc465359168543ccaabf Mon Sep 17 00:00:00 2001
2From: Michal Marek <mmarek@suse.cz>
3Date: Mon, 07 Dec 2009 15:38:33 +0000
4Subject: kbuild: generate modules.builtin
5
6To make it easier for module-init-tools and scripts like mkinitrd to
7distinguish builtin and missing modules, install a modules.builtin file
8listing all builtin modules. This is done by generating an additional
9config file (tristate.conf) with tristate options set to uppercase 'Y'
10or 'M'. If we source that config file, the builtin modules appear in
11obj-Y.
12
13Signed-off-by: Michal Marek <mmarek@suse.cz>
14
15Note form support@proxmox.com: We modified the patch to cleanly apply
16on our RHEL6 2.6.32 kernel.
17
18---
19diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt
20index bb3bf38..6f8c1ca 100644
21--- a/Documentation/kbuild/kbuild.txt
22+++ b/Documentation/kbuild/kbuild.txt
23@@ -1,3 +1,17 @@
24+Output files
25+
26+modules.order
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
30+multiple modules.
31+
32+modules.builtin
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.
36+
37+
38 Environment variables
39
40 KCPPFLAGS
41diff --git a/Documentation/kbuild/kconfig.txt b/Documentation/kbuild/kconfig.txt
42index 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".
48
49+KCONFIG_TRISTATE
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".
53+
54 KCONFIG_AUTOHEADER
55 --------------------------------------------------
56 This environment variable can be set to specify the path & name of the
57diff --git a/Makefile b/Makefile
58index aa608c2..391fcb3 100644
59--- a/Makefile
60+++ b/Makefile
61@@ -464,7 +464,7 @@ ifeq ($(KBUILD_EXTMOD),)
62 # Carefully list dependencies so we do not try to build scripts twice
63 # in parallel
64 PHONY += scripts
65-scripts: scripts_basic include/config/auto.conf
66+scripts: scripts_basic include/config/auto.conf include/config/tristate.conf
67 $(Q)$(MAKE) $(build)=$(@)
68
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
77 else
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)=$@
83+ifdef CONFIG_MODULES
84+ $(Q)$(MAKE) $(modbuiltin)=$@
85+endif
86
87 # Build the kernel release string
88 #
89@@ -1080,6 +1083,7 @@ all: modules
90 PHONY += 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 ; \
99 fi
100 @cp -f $(objtree)/modules.order $(MODLIB)/
101+ @cp -f $(objtree)/modules.builtin $(MODLIB)/
102 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
103
104 # This depmod is only for convenience to give the initial
105diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
106index 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
112
113+###
114+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
115+# Usage:
116+# $(Q)$(MAKE) $(modbuiltin)=dir
117+modbuiltin := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.modbuiltin obj
118+
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)), \
122diff --git a/scripts/Makefile.modbuiltin b/scripts/Makefile.modbuiltin
123new file mode 100644
124index 0000000..102a276
125--- /dev/null
126+++ b/scripts/Makefile.modbuiltin
127@@ -0,0 +1,55 @@
128+# ==========================================================================
129+# Generating modules.builtin
130+# ==========================================================================
131+
132+src := $(obj)
133+
134+PHONY := __modbuiltin
135+__modbuiltin:
136+
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
141+
142+include scripts/Kbuild.include
143+
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)
148+
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))
155+
156+modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym))
157+modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko))
158+modbuiltin-target := $(obj)/modules.builtin
159+
160+__modbuiltin: $(modbuiltin-target) $(subdir-ym)
161+ @:
162+
163+$(modbuiltin-target): $(subdir-ym) FORCE
164+ $(Q)(for m in $(modbuiltin-mods); do echo kernel/$$m; done; \
165+ cat /dev/null $(modbuiltin-subdirs)) > $@
166+
167+PHONY += FORCE
168+
169+FORCE:
170+
171+# Descending
172+# ---------------------------------------------------------------------------
173+
174+PHONY += $(subdir-ym)
175+$(subdir-ym):
176+ $(Q)$(MAKE) $(modbuiltin)=$@
177+
178+
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.
181+
182+.PHONY: $(PHONY)
183diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
184index 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)
188 struct symbol *sym;
189 const char *str;
190 const char *name;
191- FILE *out, *out_h;
192+ FILE *out, *tristate, *out_h;
193 time_t now;
194 int i, l;
195
196@@ -692,9 +692,16 @@ int conf_write_autoconf(void)
197 if (!out)
198 return 1;
199
200+ tristate = fopen(".tmpconfig_tristate", "w");
201+ if (!tristate) {
202+ fclose(out);
203+ return 1;
204+ }
205+
206 out_h = fopen(".tmpconfig.h", "w");
207 if (!out_h) {
208 fclose(out);
209+ fclose(tristate);
210 return 1;
211 }
212
213@@ -707,6 +714,9 @@ int conf_write_autoconf(void)
214 "# %s"
215 "#\n",
216 sym_get_string_value(sym), ctime(&now));
217+ fprintf(tristate, "#\n"
218+ "# Automatically generated - do not edit\n"
219+ "\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)
224 break;
225 case mod:
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);
229 break;
230 case yes:
231 fprintf(out, "CONFIG_%s=y\n", sym->name);
232+ if (sym->type == S_TRISTATE)
233+ fprintf(tristate, "CONFIG_%s=Y\n",
234+ sym->name);
235 fprintf(out_h, "#define CONFIG_%s 1\n", sym->name);
236 break;
237 }
238@@ -772,6 +786,7 @@ int conf_write_autoconf(void)
239 }
240 }
241 fclose(out);
242+ fclose(tristate);
243 fclose(out_h);
244
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))
249 return 1;
250+ name = getenv("KCONFIG_TRISTATE");
251+ if (!name)
252+ name = "include/config/tristate.conf";
253+ if (rename(".tmpconfig_tristate", name))
254+ return 1;
255 name = conf_get_autoconfig_name();
256 /*
257 * This must be the last step, kbuild has a dependency on auto.conf
258--
259cgit v0.9.1