Kernel configuration in kernel, kernel 2.4.20

Kernel configuration in kernel, kernel 2.4.20

Post by Paul Rollan » Mon, 30 Dec 2002 19:20:04



Hello,

Tired of keeping copy of the kernel .config file, I decided to create a kernel
patch to have a
/proc/config/config.gz
entry that would be created at boot time and that would
allow a :
zcat /proc/config/config.gz
to recover the .config file used to create the kernel.

Juste below is a patch, created against a 2.4.19, but that can also be
applied to a 2.4.20 (with a few warning).
Result is :
1 [17:53] rol@donald:~> ls -l /proc/config/
total 0
-r--r--r--    1 root     root            0 Dec 29 18:00 config.gz
-r--r--r--    1 root     root            0 Dec 29 18:00 version

Feedback welcome,
Regards,
Paul Rolland, r...@as2917.net

diff -urN linux-2.4.19/drivers/char/Config.in linux/drivers/char/Config.in
--- linux-2.4.19/drivers/char/Config.in Thu Dec 19 13:48:19 2002
+++ linux/drivers/char/Config.in        Thu Dec 19 13:47:19 2002
@@ -4,6 +4,7 @@
 mainmenu_option next_comment
 comment 'Character devices'

+bool 'Linux Kernel Configuration Driver' CONFIG_CONFIG
 bool 'Virtual terminal' CONFIG_VT
 if [ "$CONFIG_VT" = "y" ]; then
    bool '  Support for console on virtual terminal' CONFIG_VT_CONSOLE
diff -urN linux-2.4.19/drivers/char/Makefile linux/drivers/char/Makefile
--- linux-2.4.19/drivers/char/Makefile  Thu Dec 19 13:48:32 2002
+++ linux/drivers/char/Makefile Thu Dec 19 15:17:31 2002
@@ -136,6 +136,7 @@
   KEYBD = dummy_keyb.o
 endif

+obj-$(CONFIG_CONFIG) += config.o
 obj-$(CONFIG_VT) += vt.o vc_screen.o consolemap.o consolemap_deftbl.o $(CONSOLE) selection.o
 obj-$(CONFIG_SERIAL) += $(SERIAL)
 obj-$(CONFIG_SERIAL_HCDP) += hcdp_serial.o
@@ -287,3 +288,14 @@

 qtronixmap.c: qtronixmap.map
        set -e ; loadkeys --mktable $< | sed -e 's/^static *//' > $@
+
+config.o: config.h
+
+config.h: config.txt.gz
+       @cc -o dotHmaker dotHmaker.c
+       @./dotHmaker
+
+config.txt.gz::
+       @cp ../../.config config.txt
+       @gzip -f config.txt
+
diff -urN linux-2.4.19/drivers/char/config.c linux/drivers/char/config.c
--- linux-2.4.19/drivers/char/config.c  Thu Jan  1 00:00:00 1970
+++ linux/drivers/char/config.c Thu Dec 19 13:47:24 2002
@@ -0,0 +1,156 @@
+/*
+ * Linux Configuration Driver
+ * (c) 2002 Paul Rolland
+ *
+ * This driver is intended to give access to the .config file that was
+ * used to compile the kernel.
+ * It does include a gzip'd copy of the file, which can be access thru
+ * /proc/config/config.gz
+ *
+ */
+
+#define CONFIG_VERSION         "1.0"
+
+#include <linux/module.h>
+#include <linux/config.h>
+#include <linux/sched.h>
+#include <linux/smp_lock.h>
+
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/miscdevice.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <linux/fcntl.h>
+#include <linux/mc146818rtc.h>
+#include <linux/init.h>
+#include <linux/proc_fs.h>
+#include <linux/spinlock.h>
+
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+
+#include "config.h"
+
+static int config_read_proc(char * page, char ** start, off_t off,
+                            int count, int *eof, void *data);
+
+
+#ifndef CONFIG_PROC_FS
+#warn Attention
+static int config_read_proc( char *buffer, char **start, off_t offset,
+                           int size, int *eof, void *data) { return 0; }
+#else
+
+/* This macro frees the machine specific function from bounds checking and
+ * this like that... */
+#define        PRINT_PROC(fmt,args...)                                 \
+        do {                                                   \
+          *len += sprintf( buffer+*len, fmt, ##args );         \
+          if (*begin + *len > offset + size)                   \
+            return( 0 );                                       \
+          if (*begin + *len < offset) {                                \
+            *begin += *len;                                    \
+            *len = 0;                                          \
+           }                                                   \
+         } while(0)
+
+
+static int config_version_infos(char *buffer, int *len, off_t *begin,
+                                off_t offset, int size)
+{
+  PRINT_PROC("Linux Kernel Configuration driver version %s\n", CONFIG_VERSION);
+  PRINT_PROC("(c) P. Rolland - Dec 2002\n");
+
+  return(1);
+}
+
+static int config_gz_infos(char *buffer, int *len, off_t *begin, off_t offset,
+                           int size)
+{
+  int i;
+
+  for (i=0; i<CONFIG_SIZE; i++) {
+    PRINT_PROC("%c", config_gz[i]);
+  }
+
+  return(1);
+}
+
+static int config_read_proc( char *buffer, char **start, off_t offset,
+                            int size, int *eof, void *data )
+{
+  int len = 0;
+  off_t begin = 0;
+
+  *eof = config_version_infos(buffer, &len, &begin, offset, size);
+
+  if (offset >= begin + len)
+    return(0);
+  *start = buffer + (offset - begin);
+  return( size < begin + len - offset ? size : begin + len - offset );
+}
+
+static int config_gz_read_proc( char *buffer, char **start, off_t offset,
+                                int size, int *eof, void *data )
+{
+  int len = 0;
+  off_t begin = 0;
+
+  *eof = config_gz_infos(buffer, &len, &begin, offset, size);
+
+  if (offset >= begin + len)
+    return(0);
+  *start = buffer + (offset - begin);
+  return( size < begin + len - offset ? size : begin + len - offset );
+}
+
+static int __init config_init(void)
+{
+  struct proc_dir_entry * entry;
+
+  entry = create_proc_entry("config", S_IRUGO|S_IXUGO|S_IFDIR, NULL);
+  if (entry == NULL) {
+    printk(KERN_ERR "config: can't create /proc/config\n");
+    return(-ENOMEM);
+  }
+
+  if (!create_proc_read_entry("config/version",0,0,config_read_proc,NULL)) {
+    printk(KERN_ERR "config: can't create /proc/config/version\n");
+    return(-ENOMEM);
+  }
+  if (!create_proc_read_entry("config/config.gz",0,0,config_gz_read_proc,NULL)) {
+    printk(KERN_ERR "config: can't create /proc/config/config.gz\n");
+    return(-ENOMEM);
+  }
+
+  printk(KERN_INFO "Linux Kernel Configuration driver v" CONFIG_VERSION " (c)Paul Rolland\n");
+  return(0);
+}
+
+static void __exit config_cleanup_module (void)
+{
+  remove_proc_entry( "config/version", 0 );
+  remove_proc_entry( "config/config.gz", 0 );
+  remove_proc_entry( "config", 0 );
+}
+
+module_init(config_init);
+module_exit(config_cleanup_module);
+
+#endif /* CONFIG_PROC_FS */
+
+MODULE_AUTHOR("Paul Rolland");
+MODULE_DESCRIPTION("Driver for accessing kernel configuration");
+MODULE_LICENSE("GPL");
+
+EXPORT_NO_SYMBOLS;
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  tab-width: 4
+ * End:
+ */
+
diff -urN linux-2.4.19/drivers/char/dotHmaker.c linux/drivers/char/dotHmaker.c
--- linux-2.4.19/drivers/char/dotHmaker.c       Thu Jan  1 00:00:00 1970
+++ linux/drivers/char/dotHmaker.c      Thu Dec 19 13:47:24 2002
@@ -0,0 +1,57 @@
+#include <stdio.h>
+
+int main(void)
+{
+  FILE * in;
+  FILE * out;
+  int i;
+  unsigned char buf;
+
+  int size = 0;
+
+  in = fopen("config.txt.gz", "r");
+  if (in == NULL) {
+    printf("Unable to open config.txt.gz\n");
+    exit(-1);
+  } /* endif */
+
+  out = fopen("config.h", "w");
+  if (out == NULL) {
+    printf("Unable to create config.h\n");
+    exit(-1);
+  } /* endif */
+
+  fprintf(out, "/*\n");
+  fprintf(out, " * Automagically generated file, please don't edit !\n");
+  fprintf(out, " */\n");
+  fprintf(out, "\n");
+  fprintf(out, "static char config_gz[] = \\\n");
+
+  i = 0;
+
+  fread(&buf, sizeof(unsigned char), 1, in);
+  while (!feof(in)) {
+    if (i == 0) {
+      fprintf(out, "  \"");
+    } /* endif */
+    fprintf(out, "\\x%x", buf);
+    size ++;
+    i ++;
+    if (i == 10) {
+      i = 0;
+      fprintf(out, "\"\\\n");
+    } /* endif */
+    fread(&buf, sizeof(unsigned char), 1, in);
+  } /* endwhile */
+
+  if (i != 0) {
+    fprintf(out, "\";\n");
+  } /* endif */
+  fprintf(out, "\n");
+  fprintf(out, "#define CONFIG_SIZE %d\n\n", size);
+
+  fclose(in);
+  fclose(out);
+
+  exit(0);
+}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Kernel configuration in kernel, kernel 2.4.20

Post by J.A. Magallo » Tue, 31 Dec 2002 00:20:10



Quote:> Hello,

> Tired of keeping copy of the kernel .config file, I decided to create a kernel
> patch to have a
> /proc/config/config.gz

Why people does not read the archives before doing anything ?

http://www.it.uc3m.es/~ptb/proconfig/

--

werewolf.able.es                         \           It's better when it's free
Mandrake Linux release 9.1 (Cooker) for i586
Linux 2.4.21-pre2-jam2 (gcc 3.2.1 (Mandrake Linux 9.1 3.2.1-2mdk))
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Kernel configuration in kernel, kernel 2.4.20

Post by Peter T. Breue » Tue, 31 Dec 2002 01:20:12




>> Hello,

>> Tired of keeping copy of the kernel .config file, I decided to create a kernel
>> patch to have a
>> /proc/config/config.gz
> Why people does not read the archives before doing anything ?
> http://www.it.uc3m.es/~ptb/proconfig/

Uuumph. Thanks for reminding me. That made me update the page and the
Changelog in a hurry.

It does work for latest 2.4. I ported to 2.4.19 a couple of months ago.
Nowadays it uses string common prefix compression to reduce the
internal size. Probably 4-12K in total (there are a LOT of kernel
compilation params nowadays), but the output from /proc/config
is exactly as it should be.

   Module                  Size  Used by    Not tainted
   config                 10908   0 (unused)

   betty:/usr/oboe/ptb/lib/www/proconfig% cat /proc/config | wc
       855     855   18421

(855 kernel config options, with 18.4K of output chars)

   betty:/usr/oboe/ptb/lib/www/proconfig% head /proc/config
   CONFIG_X86=y
   CONFIG_ISA=y
   CONFIG_UID16=y
   CONFIG_EXPERIMENTAL=y
   CONFIG_MODULES=y
   ...

Now I suppose I need to port it to latest 2.5. Assuming I can compile a
2.5, that is! I haven't tried since 2.5.47, which was before that
modules change.

Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Kernel configuration in kernel, kernel 2.4.20

Post by Paul Rollan » Tue, 31 Dec 2002 09:00:16


Hello,

Quote:> > Tired of keeping copy of the kernel .config file, I decided
> to create
> > a kernel patch to have a /proc/config/config.gz

> Why people does not read the archives before doing anything ?

Maybe because they consider that there is not only one way to do
things... ;-)

OK, you don't like mine, no problem. I'm just expecting this
functionnality in the kernel, not MY solution.

On a technical basis, I prefer to have a solution that is using
full compression from gzip rather than relying on a set of keyword
that will need to be updated with kernel dev and growth.

But, I'm second...

Regards,
Paul

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. "kernel BUG at page_alloc.c:102!" (kernel 2.4.20)

Greetings.

On a relatively idle system (used mainly for syslog things) that had
been up for ~42 days, kswapd croaked and the kernel claimed (sorry if
these lines are wrapped):

kernel BUG at page_alloc.c:102!
invalid operand: 0000
CPU:    0
EIP:    0010:[__free_pages_ok+68/656]    Tainted: P
EFLAGS: 00010286
eax: c11703ec   ebx: c151fabc   ecx: c151fad8   edx: c0254c9c
esi: 00000000   edi: 00000010   ebp: 000001f5   esp: c16f5f14
ds: 0018   es: 0018   ss: 0018
Process kswapd (pid: 5, stackpage=c16f5000)
Stack: d7b64dc0 c151fabc 00000010 000001f5 c0136d2c c151fabc 000001d0 00000010
       000001f5 c01351b9 d7b64dc0 c151fabc c012cb52 c012db8b c012cb8b 00000020
       000001d0 00000020 00000006 00000006 c16f4000 000021dd 000001d0 c0254e34
Call Trace:    [try_to_free_buffers+140/224] [try_to_release_page+73/80] [shrink_cache+498/784] [__free_pages+27/32] [shrink_cache+555/784]
  [shrink_caches+86/128] [try_to_free_pages_zone+60/96] [kswapd_balance_pgdat+65/144] [kswapd_balance+22/48] [kswapd+157/192] [kernel_thread+40/64]

Code: 0f 0b 66 00 53 f6 21 c0 89 d8 2b 05 f0 20 2b c0 69 c0 a3 8b

The box is essentially a LinuxFromScratch (actually a severely
overhauled SuSE 6.2) box.  Vanilla kernel 2.4.20 (no patches), glibc
2.2.5, gcc 2.95.3.  It's all running on an Abit KT7A mainboard (Athlon
1.4GHz) with 640MB or so of RAM.

I rebooted the box but it hung when trying to turn off swap.  :-)  (BTW,
is there a means by which to "restart" kswapd if need be?)

I've been using 2.4.20 since a few days after its release.  This is the
first time I've seen this "kernel BUG"; I have absolutely no idea what
triggered it, nor how to reproduce it.

If you need more info, just ask!

Regards,
krjw.
--
Keith R. John Warno                         [SA, Valaran Corporation]
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. Transparent (?) firewalling / Arp problem

3. kernel 2.4.20 fatal kernel oops with isdn mppp

4. defining path for telnet session

5. gamecon (added support for Sega Saturn controller), kernel 2.4.20

6. NYLXS Weekly Announcements: Business Demo, Presentation: Installfest

7. drivers/scsi/scsi_scan.c, kernel 2.4.20-pre5

8. Which update of Sun Cluster 3.0

9. [Fwd: Bug in Kernel 2.4.20-8]

10. 2.4.20-rc1-ac1 kernel BUG at page_alloc.c:127!

11. KGDB for kernel 2.4.20?

12. Kernel 2.4.20 oops on devfs shutdown

13. kernel oops in 2.4.20-pre10aa1