lkml.org 
[lkml]   [2002]   [Feb]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: How to check the kernel compile options ?
On Wed, 13 Feb 2002, Richard B. Johnson wrote:

| On Wed, 13 Feb 2002, Horst von Brand wrote:
|
| > Daniel Phillips <phillips@bonn-fries.net> said:
| > > On February 12, 2002 05:38 pm, Bill Davidsen wrote:
| >
| > [...]
| [SNIPPED...]
|
| My idea is to take the .config file and remove most of its
| redundancy and unnecessary verbage. Then, the result is
| compressed and written to a constant global array, linked
| into the kernel. Both the array and the array length will then
| be available from /proc/kcore for user-mode tools to recreate the
| .config file.

This is a bit similar to what I did last weekend (and attach
here). Mine goes into the kernel boot file, however, so that
it can be read even when the kernel isn't running.

I'll experiment with ideas from Andreas (thanks) or Ian Soboroff
to create a userspace get-config tool.

One small nit: you say "user-mode tools", but /proc/kcore
is read-only for root only -- right?
That's not desirable or required IMO.

| Here are tools and a test/documentation script that shows it
| will work. The .config on my machine generates a 1730 byte
| array. This is certainly small enough to not be considered
| bloat.

Not a problem to me, although most people seem to want to see
it as a config option.
I plan to add that to what I've done...
and probably strip the leading "CONFIG_" strings.

| The advantage, of course is that if you are executing the kernel,
| it can give you all the information necessary to recreate a
| new one from the sources because its .config is embeded into
| itself. Once you have the ".config" file, you just do `make oldconfig`
| and you are home free.

--
~Randy
--- linux-2416/Makefile.org Mon Nov 26 05:29:17 2001
+++ linux-2416/Makefile Wed Feb 13 09:16:39 2002
@@ -257,8 +257,8 @@
boot: vmlinux
@$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C arch/$(ARCH)/boot

-vmlinux: include/linux/version.h $(CONFIGURATION) init/main.o init/version.o linuxsubdirs
- $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \
+vmlinux: include/linux/version.h $(CONFIGURATION) init/main.o init/version.o init/configs.o linuxsubdirs
+ $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o init/configs.o \
--start-group \
$(CORE_FILES) \
$(DRIVERS) \
@@ -334,6 +334,13 @@

init/main.o: init/main.c include/config/MARKER
$(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -c -o $*.o $<
+
+scripts/mkconfigs: scripts/mkconfigs.c
+ $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkconfigs scripts/mkconfigs.c
+
+init/configs.o: scripts/mkconfigs $(TOPDIR)/.config include/config/MARKER
+ scripts/mkconfigs $(TOPDIR)/.config init/configs.c
+ $(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DEXPORT_SYMTAB -c -o init/configs.o init/configs.c

fs lib mm ipc kernel drivers net: dummy
$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" $(subst $@, _dir_$@, $@)
--- /home/rddunlap/doc/epoch Wed May 24 09:51:00 2000
+++ linux-2416/scripts/mkconfigs.c Wed Feb 13 09:07:20 2002
@@ -0,0 +1,155 @@
+/***************************************************************************
+ * mkconfigs.c
+ * (C) 2002 Randy Dunlap <rddunlap@osdl.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Rules for scripts/mkconfigs.c input.config output.c
+# to generate configs.c from linux/.config:
+# - drop lines that begin with '#'
+# - drop blank lines
+# - lines that use double-quotes must \\-escape-quote them
+
+################## skeleton configs.c file: ####################
+
+#include <linux/init.h>
+#include <linux/module.h>
+
+static char *configs[] __initdata =
+
+ <insert lines selected lines of .config, quoted, with added '\n'>,
+
+;
+
+################### end configs.c file ######################
+
+****************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#define VERSION "0.1"
+#define LINE_SIZE 1000
+
+void usage (const char *progname)
+{
+ fprintf (stderr, "%s ver. %s\n", progname, VERSION);
+ fprintf (stderr, "usage: %s input.config.name path/configs.c\n",
+ progname);
+ exit (1);
+}
+
+void make_intro (FILE *sourcefile)
+{
+ fprintf (sourcefile, "#include <linux/init.h>\n");
+ fprintf (sourcefile, "#include <linux/module.h>\n");
+ fprintf (sourcefile, "\n");
+ fprintf (sourcefile, "/*static*/ char /*__attribute__ ((unused))*/ *configs[] __initdata = {\n");
+ fprintf (sourcefile, " \"CONFIG_BEGIN=n \" ,\n");
+}
+
+void make_ending (FILE *sourcefile)
+{
+ fprintf (sourcefile, " \"CONFIG_END=n \"\n");
+ fprintf (sourcefile, "};\n");
+ fprintf (sourcefile, "EXPORT_SYMBOL (configs);\n");
+}
+
+void make_lines (FILE *configfile, FILE *sourcefile)
+{
+ char cfgline[LINE_SIZE];
+ char *ch;
+
+ while (fgets (cfgline, LINE_SIZE, configfile)) {
+ if (cfgline[0] == '#' ||
+ cfgline[0] == '\n')
+ continue;
+ /* kill the trailing newline in cfgline */
+ cfgline[strlen (cfgline) - 1] = '\0';
+
+ /*
+ * use strchr() to check for "-quote in cfgline;
+ * if not found, output the line, quoted;
+ * if found, output a char at a time, with \\-quote
+ * preceding double-quote chars
+ */
+ if (!strchr (cfgline, '"')) {
+ fprintf (sourcefile, " \"%s \" ,\n", cfgline);
+ continue;
+ }
+
+ /* go to char-at-a-time mode for this cfgline and
+ * precede any double-quote with a backslash */
+ fprintf (sourcefile, " \""); /* lead-in */
+ for (ch = cfgline; *ch; ch++) {
+ if (*ch == '"')
+ fputc ('\\', sourcefile);
+ fputc (*ch, sourcefile);
+ }
+ fprintf (sourcefile, " \" ,\n");
+ }
+}
+
+int make_configs (FILE *configfile, FILE *sourcefile)
+{
+ make_intro (sourcefile);
+ make_lines (configfile, sourcefile);
+ make_ending (sourcefile);
+}
+
+int main (int argc, char *argv[])
+{
+ char *progname = argv[0];
+ char *configname, *sourcename;
+ FILE *configfile, *sourcefile;
+
+ if (argc != 3)
+ usage (progname);
+
+ configname = argv[1];
+ sourcename = argv[2];
+
+ configfile = fopen (configname, "r");
+ if (!configfile) {
+ fprintf (stderr, "%s: cannot open '%s'\n",
+ progname, configname);
+ exit (2);
+ }
+ sourcefile = fopen (sourcename, "w");
+ if (!sourcefile) {
+ fprintf (stderr, "%s: cannot open '%s'\n",
+ progname, sourcename);
+ exit (2);
+ }
+
+ make_configs (configfile, sourcefile);
+
+ if (fclose (sourcefile)) {
+ fprintf (stderr, "%s: error %d closing '%s'\n",
+ progname, errno, sourcename);
+ exit (3);
+ }
+ if (fclose (configfile)) {
+ fprintf (stderr, "%s: error %d closing '%s'\n",
+ progname, errno, configname);
+ exit (3);
+ }
+
+ exit (0);
+}
+
+/* end mkconfigs.c */
\
 
 \ /
  Last update: 2005-03-22 13:18    [W:0.144 / U:2.352 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site