]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
kbuild: generate modules.builtin
authorMichal Marek <mmarek@suse.cz>
Mon, 7 Dec 2009 15:38:33 +0000 (16:38 +0100)
committerMichal Marek <mmarek@suse.cz>
Sat, 12 Dec 2009 12:08:16 +0000 (13:08 +0100)
To make it easier for module-init-tools and scripts like mkinitrd to
distinguish builtin and missing modules, install a modules.builtin file
listing all builtin modules. This is done by generating an additional
config file (tristate.conf) with tristate options set to uppercase 'Y'
or 'M'. If we source that config file, the builtin modules appear in
obj-Y.

Signed-off-by: Michal Marek <mmarek@suse.cz>
.gitignore
Documentation/kbuild/kbuild.txt
Documentation/kbuild/kconfig.txt
Makefile
scripts/Kbuild.include
scripts/Makefile.modbuiltin [new file with mode: 0644]
scripts/kconfig/confdata.c

index 002d5304968b1cbe9124872106bd31bd9d5a3193..fb2190c61af0982ae9b8792b51d970bddaafdf5f 100644 (file)
@@ -22,6 +22,7 @@
 *.lst
 *.symtypes
 *.order
+modules.builtin
 *.elf
 *.bin
 *.gz
index bb3bf38f03dac1e055dc973ce65d49d14defbe42..6f8c1cabbc5d1fefe2a18d3c77354b54426d3363 100644 (file)
@@ -1,3 +1,17 @@
+Output files
+
+modules.order
+--------------------------------------------------
+This file records the order in which modules appear in Makefiles. This
+is used by modprobe to deterministically resolve aliases that match
+multiple modules.
+
+modules.builtin
+--------------------------------------------------
+This file lists all modules that are built into the kernel. This is used
+by modprobe to not fail when trying to load something builtin.
+
+
 Environment variables
 
 KCPPFLAGS
index ab8dc3538988b97147c4db0da5ca551af0ec7790..49efae703979ca793383463bce7c2d1eda42468b 100644 (file)
@@ -103,6 +103,11 @@ 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
index aa608c2959f514bea3f0fa9cdc25455599e288e1..391fcb39632405ca659e66a6b014a321ca67c971 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -464,7 +464,7 @@ ifeq ($(KBUILD_EXTMOD),)
 # Carefully list dependencies so we do not try to build scripts twice
 # in parallel
 PHONY += scripts
-scripts: scripts_basic include/config/auto.conf
+scripts: scripts_basic include/config/auto.conf include/config/tristate.conf
        $(Q)$(MAKE) $(build)=$(@)
 
 # Objects we will link into vmlinux / subdirs we need to visit
@@ -491,7 +491,7 @@ $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
 # with it and forgot to run make oldconfig.
 # if auto.conf.cmd is missing then we are probably in a cleaned tree so
 # we execute the config step to be sure to catch updated Kconfig files
-include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
+include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
        $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
 else
 # external modules needs include/generated/autoconf.h and include/config/auto.conf
@@ -876,6 +876,9 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
 PHONY += $(vmlinux-dirs)
 $(vmlinux-dirs): prepare scripts
        $(Q)$(MAKE) $(build)=$@
+ifdef CONFIG_MODULES
+       $(Q)$(MAKE) $(modbuiltin)=$@
+endif
 
 # Build the kernel release string
 #
@@ -1080,6 +1083,7 @@ all: modules
 PHONY += modules
 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
        $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
+       $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.builtin) > $(objtree)/modules.builtin
        @$(kecho) '  Building modules, stage 2.';
        $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
        $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild
@@ -1109,6 +1113,7 @@ _modinst_:
                ln -s $(objtree) $(MODLIB)/build ; \
        fi
        @cp -f $(objtree)/modules.order $(MODLIB)/
+       @cp -f $(objtree)/modules.builtin $(MODLIB)/
        $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
 
 # This depmod is only for convenience to give the initial
@@ -1169,7 +1174,7 @@ clean: archclean $(clean-dirs)
                \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
                -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
                -o -name '*.symtypes' -o -name 'modules.order' \
-               -o -name '.tmp_*.o.*' \
+               -o modules.order -o -name '.tmp_*.o.*' \
                -o -name '*.gcno' \) -type f -print | xargs rm -f
 
 # mrproper - Delete all generated files, including .config
@@ -1367,7 +1372,8 @@ $(clean-dirs):
 
 clean: rm-dirs := $(MODVERDIR)
 clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers \
-                   $(KBUILD_EXTMOD)/modules.order
+                   $(KBUILD_EXTMOD)/modules.order \
+                   $(KBUILD_EXTMOD)/modules.builtin
 clean: $(clean-dirs)
        $(call cmd,rmdirs)
        $(call cmd,rmfiles)
index c67e73ecd5beac46e7212922737479568a95f919..ed2773edfe71bae99adc0a7b64a454912dfd4477 100644 (file)
@@ -149,6 +149,12 @@ ld-option = $(call try-run,\
 # $(Q)$(MAKE) $(build)=dir
 build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
 
+###
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
+# Usage:
+# $(Q)$(MAKE) $(modbuiltin)=dir
+modbuiltin := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.modbuiltin obj
+
 # Prefix -I with $(srctree) if it is not an absolute path.
 # skip if -I has no parameter
 addtree = $(if $(patsubst -I%,%,$(1)), \
diff --git a/scripts/Makefile.modbuiltin b/scripts/Makefile.modbuiltin
new file mode 100644 (file)
index 0000000..102a276
--- /dev/null
@@ -0,0 +1,55 @@
+# ==========================================================================
+# 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
+
+# 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 kernel/$$m; done;     \
+       cat /dev/null $(modbuiltin-subdirs)) > $@
+
+PHONY += FORCE
+
+FORCE:
+
+# Descending
+# ---------------------------------------------------------------------------
+
+PHONY += $(subdir-ym)
+$(subdir-ym):
+       $(Q)$(MAKE) $(modbuiltin)=$@
+
+
+# Declare the contents of the .PHONY variable as phony.  We keep that
+# information in a variable se we can use it in if_changed and friends.
+
+.PHONY: $(PHONY)
index 797a7410f69024470e1f695e7f974f9c46520232..c4dec80cfd8e14a94792af807da0e9705256257d 100644 (file)
@@ -677,7 +677,7 @@ int conf_write_autoconf(void)
        struct symbol *sym;
        const char *str;
        const char *name;
-       FILE *out, *out_h;
+       FILE *out, *tristate, *out_h;
        time_t now;
        int i, l;
 
@@ -692,9 +692,16 @@ int conf_write_autoconf(void)
        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;
        }
 
@@ -707,6 +714,9 @@ int conf_write_autoconf(void)
                     "# %s"
                     "#\n",
                     sym_get_string_value(sym), ctime(&now));
+       fprintf(tristate, "#\n"
+                         "# Automatically generated - do not edit\n"
+                         "\n");
        fprintf(out_h, "/*\n"
                       " * Automatically generated C config: don't edit\n"
                       " * Linux kernel version: %s\n"
@@ -727,10 +737,14 @@ int conf_write_autoconf(void)
                                break;
                        case mod:
                                fprintf(out, "CONFIG_%s=m\n", sym->name);
+                               fprintf(tristate, "CONFIG_%s=M\n", sym->name);
                                fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
                                break;
                        case yes:
                                fprintf(out, "CONFIG_%s=y\n", sym->name);
+                               if (sym->type == S_TRISTATE)
+                                       fprintf(tristate, "CONFIG_%s=Y\n",
+                                                       sym->name);
                                fprintf(out_h, "#define CONFIG_%s 1\n", sym->name);
                                break;
                        }
@@ -772,6 +786,7 @@ int conf_write_autoconf(void)
                }
        }
        fclose(out);
+       fclose(tristate);
        fclose(out_h);
 
        name = getenv("KCONFIG_AUTOHEADER");
@@ -779,6 +794,11 @@ int conf_write_autoconf(void)
                name = "include/generated/autoconf.h";
        if (rename(".tmpconfig.h", name))
                return 1;
+       name = getenv("KCONFIG_TRISTATE");
+       if (!name)
+               name = "include/config/tristate.conf";
+       if (rename(".tmpconfig_tristate", name))
+               return 1;
        name = conf_get_autoconfig_name();
        /*
         * This must be the last step, kbuild has a dependency on auto.conf