2003-01-02 14:25:17

by Robert P. J. Day

[permalink] [raw]
Subject: kernel .config support?


whatever happened to that funky option from 2.4 --
for kernel .config support, which allegedly buried the
config file inside the kernel itself. (it never worked --
the alleged extraction script scripts/extract-ikconfig
depended on a program called "binoffset" that didn't
exist in that distribution.)

any plans to resurrect this, or something like it?

rday


2003-01-02 15:37:51

by Randy.Dunlap

[permalink] [raw]
Subject: Re: kernel .config support?

On Thu, 2 Jan 2003, Robert P. J. Day wrote:

| whatever happened to that funky option from 2.4 --
| for kernel .config support, which allegedly buried the
| config file inside the kernel itself. (it never worked --
| the alleged extraction script scripts/extract-ikconfig
| depended on a program called "binoffset" that didn't
| exist in that distribution.)
|
| any plans to resurrect this, or something like it?

Khalid Aziz et al (HP) have updated it to 2.5.
It's also part of the OSDL 2.5 DCL and CGL trees.
See http://developer.osdl.org/ for info on them.

I'll check to make sure there is a separate patch available for it
and repost it.

Thanks,
--
~Randy

2003-01-02 16:20:22

by Alan

[permalink] [raw]
Subject: Re: kernel .config support?

On Thu, 2003-01-02 at 14:32, Robert P. J. Day wrote:
>
> whatever happened to that funky option from 2.4 --
> for kernel .config support, which allegedly buried the
> config file inside the kernel itself. (it never worked --
> the alleged extraction script scripts/extract-ikconfig
> depended on a program called "binoffset" that didn't
> exist in that distribution.)

Its never been in the standard 2.4 kernel. The facility has been in the
-ac kernel, and was recently submitted for consideration in 2.5

2003-01-02 16:36:05

by Robert P. J. Day

[permalink] [raw]
Subject: Re: kernel .config support?

On 2 Jan 2003, Alan Cox wrote:

> On Thu, 2003-01-02 at 14:32, Robert P. J. Day wrote:
> >
> > whatever happened to that funky option from 2.4 --
> > for kernel .config support, which allegedly buried the
> > config file inside the kernel itself. (it never worked --
> > the alleged extraction script scripts/extract-ikconfig
> > depended on a program called "binoffset" that didn't
> > exist in that distribution.)
>
> Its never been in the standard 2.4 kernel. The facility has been in the
> -ac kernel, and was recently submitted for consideration in 2.5

that's odd. the selection for kernel .config support has been in
the red hat config menus for at least the last release, as well
as the extraction script .../scripts/extract-ikconfig. but this
never worked due to a missing "binoffset" utility. i even filed
a bugzilla on that (bug 65677).

just curious -- how did that ever end up in the distributed red hat
kernel if it was never standard? strange.

rday

2003-01-02 16:44:32

by Khalid Aziz

[permalink] [raw]
Subject: Re: kernel .config support?

"Robert P. J. Day" wrote:
>
> On 2 Jan 2003, Alan Cox wrote:
>
> >
> > Its never been in the standard 2.4 kernel. The facility has been in the
> > -ac kernel, and was recently submitted for consideration in 2.5
>
> that's odd. the selection for kernel .config support has been in
> the red hat config menus for at least the last release, as well
> as the extraction script .../scripts/extract-ikconfig. but this
> never worked due to a missing "binoffset" utility. i even filed
> a bugzilla on that (bug 65677).
>
> just curious -- how did that ever end up in the distributed red hat
> kernel if it was never standard? strange.
>

Redhat kernel is not the same as standard kernel (the official one, on
kernel.org). Redhat adds a number of patches to the standard kernel
before releasing it.

--
Khalid

====================================================================
Khalid Aziz Linux and Open Source Lab
(970)898-9214 Hewlett-Packard
[email protected] Fort Collins, CO

"The Linux kernel is subject to relentless development"
- Alessandro Rubini

2003-01-02 18:29:43

by Paul Rolland

[permalink] [raw]
Subject: Re: kernel .config support?

Hello,

Following some advices from the list, here is my patch updated,
to embed the .config in the kernel and give access to a gzip'ed
copy thru /proc/config/config.gz

Regards,
Paul


diff -urN linux-2.5.53-orig/drivers/char/Kconfig
linux-2.5.53/drivers/char/Kconfig
--- linux-2.5.53-orig/drivers/char/Kconfig Tue Dec 24 06:19:26 2002
+++ linux-2.5.53/drivers/char/Kconfig Mon Dec 30 08:35:54 2002
@@ -4,6 +4,13 @@

menu "Character devices"

+config CONFIG
+ bool "Linux Kernel Configuration Driver"
+ ---help---
+ If you say Y here, and if you have /proc support enabled,
you'll find
+ a /proc/config directory that will contain a copy of the
.config used
+ to generate the running kernel.
+
config VT
bool "Virtual terminal"
---help---
diff -urN linux-2.5.53-orig/drivers/char/Makefile
linux-2.5.53/drivers/char/Makefile
--- linux-2.5.53-orig/drivers/char/Makefile Tue Dec 24 06:21:17 2002
+++ linux-2.5.53/drivers/char/Makefile Mon Dec 30 12:06:53 2002
@@ -7,6 +7,9 @@
#
FONTMAPFILE = cp437.uni

+EXTRA_TARGETS := config.h
+host-progs := dotHmaker
+
obj-y += mem.o tty_io.o n_tty.o tty_ioctl.o pty.o misc.o random.o

# All of the (potential) objects that export symbols.
@@ -16,6 +19,7 @@
ite_gpio.o keyboard.o misc.o nvram.o random.o
rtc.o \
selection.o sonypi.o sysrq.o tty_io.o
tty_ioctl.o

+obj-$(CONFIG_CONFIG) += config.o
obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o
consolemap_deftbl.o selection.o keyboard.o
obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
@@ -85,7 +89,7 @@


# Files generated that shall be removed upon make clean
-clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c
+clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c dotHmaker
config.txt config.txt.gz config.h

$(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE)
$(call do_cmd,CONMK $@,$(objtree)/scripts/conmakehash $< > $@)
@@ -107,3 +111,13 @@
rm [email protected]

endif
+
+$(obj)/config.o: $(obj)/config.h
+
+$(obj)/config.h: $(obj)/config.txt.gz $(obj)/dotHmaker
+ $(obj)/dotHmaker < $< > $@
+
+$(obj)/config.txt.gz: .config FORCE
+ cp .config $(obj)/config.txt
+ $(call if_changed,gzip)
+
diff -urN linux-2.5.53-orig/drivers/char/config.c
linux-2.5.53/drivers/char/config.c
--- linux-2.5.53-orig/drivers/char/config.c Thu Jan 1 01:00:00 1970
+++ linux-2.5.53/drivers/char/config.c Mon Dec 30 08:33:48 2002
@@ -0,0 +1,149 @@
+/*
+ * 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 DOT_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",
+DOT_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<DOT_CONFIG_GZ_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"
DOT_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");
+
diff -urN linux-2.5.53-orig/drivers/char/dotHmaker.c
linux-2.5.53/drivers/char/dotHmaker.c
--- linux-2.5.53-orig/drivers/char/dotHmaker.c Thu Jan 1 01:00:00 1970
+++ linux-2.5.53/drivers/char/dotHmaker.c Mon Dec 30 08:33:04 2002
@@ -0,0 +1,41 @@
+#include <stdio.h>
+
+int main(void)
+{
+ FILE * in = stdin;
+ int i;
+ unsigned char buf;
+
+ int size = 0;
+
+ printf("/*\n");
+ printf(" * Automagically generated file, please don't edit !\n");
+ printf(" */\n"); printf("\n");
+ printf("static char config_gz[] = \\\n");
+
+ i = 0;
+
+ fread(&buf, sizeof(unsigned char), 1, in);
+ while (!feof(in)) {
+ if (i == 0) {
+ printf(" \"");
+ } /* endif */
+ printf("\\x%x", buf);
+ size ++;
+ i ++;
+ if (i == 10) {
+ i = 0;
+ printf("\"\\\n");
+ } /* endif */
+ fread(&buf, sizeof(unsigned char), 1, in);
+ } /* endwhile */
+
+ if (i != 0) {
+ printf(" ;\n");
+ } else {
+ printf("\";\n");
+ } /* endif */
+ printf("\n");
+ printf("#define DOT_CONFIG_GZ_SIZE %d\n\n", size);
+
+ exit(0);
+}
+

2003-01-02 23:16:36

by Randy.Dunlap

[permalink] [raw]
Subject: Re: kernel .config support?

On Thu, 2 Jan 2003, Robert P. J. Day wrote:

| On 2 Jan 2003, Alan Cox wrote:
|
| > On Thu, 2003-01-02 at 14:32, Robert P. J. Day wrote:
| > >
| > > whatever happened to that funky option from 2.4 --
| > > for kernel .config support, which allegedly buried the
| > > config file inside the kernel itself. (it never worked --
| > > the alleged extraction script scripts/extract-ikconfig
| > > depended on a program called "binoffset" that didn't
| > > exist in that distribution.)
| >
| > Its never been in the standard 2.4 kernel. The facility has been in the
| > -ac kernel, and was recently submitted for consideration in 2.5
|
| that's odd. the selection for kernel .config support has been in
| the red hat config menus for at least the last release, as well
| as the extraction script .../scripts/extract-ikconfig. but this
| never worked due to a missing "binoffset" utility. i even filed
| a bugzilla on that (bug 65677).

I wasn't aware of this...oh well.
"binoffset.c" is available at
http://www.osdl.org/archive/rddunlap/patches/

| just curious -- how did that ever end up in the distributed red hat
| kernel if it was never standard? strange.

Not really.

--
~Randy

2003-01-03 00:51:14

by Erik Hensema

[permalink] [raw]
Subject: Re: kernel .config support?

Robert P. J. Day ([email protected]) wrote:
>
> whatever happened to that funky option from 2.4 --
> for kernel .config support, which allegedly buried the
> config file inside the kernel itself. (it never worked --
> the alleged extraction script scripts/extract-ikconfig
> depended on a program called "binoffset" that didn't
> exist in that distribution.)
>
> any plans to resurrect this, or something like it?

It's never been part of the standard kernel distribution. Your distribution
probably has an extra patch compiled in in order to provide this.

It's IMO not very usefull: each distribution of a compiled kernel should
just include a seperate file containing the .config, just like it contains
seperate modules. The prefered name is $IMAGENAME.config, where $IMAGENAME
is the name of the installed kernel image. No need to bloat the kernel with
this information, IMHO.

I'd love to see a patch which copies the .config to /vmlinuz.config on a
standard make {zlilo|bzlilo|install} though.

(yes, I know that the .config won't be available on a bootfloppy without a
fs. Then again, on a bootfloppy /with/ fs, there won't be space for a
.config...)
--
Erik Hensema <[email protected]>

2003-01-03 00:45:41

by Randy.Dunlap

[permalink] [raw]
Subject: Re: kernel .config support?

On Thu, 2 Jan 2003, Randy.Dunlap wrote:

| On Thu, 2 Jan 2003, Robert P. J. Day wrote:
|
| | whatever happened to that funky option from 2.4 --
| | for kernel .config support, which allegedly buried the
| | config file inside the kernel itself. (it never worked --
| | the alleged extraction script scripts/extract-ikconfig
| | depended on a program called "binoffset" that didn't
| | exist in that distribution.)
| |
| | any plans to resurrect this, or something like it?
|
| Khalid Aziz et al (HP) have updated it to 2.5.
| It's also part of the OSDL 2.5 DCL and CGL trees.
| See http://developer.osdl.org/ for info on them.
|
| I'll check to make sure there is a separate patch available for it
| and repost it.


I have updated Khalid's 2.5.50 patch for 2.5.54 for comments or use.
It is below.
Here is Khalid's 2.5.50 email also.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am including a patch for 2.5.50 that allows a user to embed kernel
configuration in the kernel and retrieve it later either from a running
kernel or from the kernel image file. This is an enhancement to Randy's
patch that was discussed on LKML before and is part of -ac series
kernels.

This patch provides three choices for embedding kernel configuration:

1. Include configuration in running kernel image. This adds to the
footprint of the running kernel but allows configuration to be retrieved
using "cat /proc/ikconfig/config".

2. Include configuration in kernel image file but not in the running
kernel. This adds to the kernel image file size but not the footprint of
running kernel. Configuration can be extracted from kernel image file
using scripts/extract-ikconfig. This script is in principle the same as
what Randy had written originally. I have made it little more robust and
structured it to accomodate more than just x86 architecture.

3. Not include kernel configuration in the running kernel or kernel
image file.

With these three choices, users can make the appropriate tradeoff. This
feature is especially useful for support folks who need to know the
kernel configuration for a customer's kernel with fairly high degree of
confidence that they are getting the right configuration. This feature
is turned off in the default configuration.

[Linus, please apply.]

====================================================================
patch_name: ikconfig-2554.patch
patch_version: 2003.01.02
author: Randy Dunlap <[email protected]>
description: add in-kernel and /proc config options
product: linux
product_versions: 2.5.54
changelog: (a) add 2 options in General Setup
URL: http://www.osdl.org/archive/rddunlap/patches/
requires:
conflicts:
diffstat:
linux-2554-ikconfig/arch/alpha/defconfig | 2
linux-2554-ikconfig/arch/arm/defconfig | 2
linux-2554-ikconfig/arch/cris/defconfig | 2
linux-2554-ikconfig/arch/i386/defconfig | 2
linux-2554-ikconfig/arch/ia64/defconfig | 2
linux-2554-ikconfig/arch/m68k/defconfig | 2
linux-2554-ikconfig/arch/mips/defconfig | 2
linux-2554-ikconfig/arch/mips64/defconfig | 3
linux-2554-ikconfig/arch/ppc/defconfig | 2
linux-2554-ikconfig/arch/ppc64/defconfig | 2
linux-2554-ikconfig/arch/s390/defconfig | 2
linux-2554-ikconfig/arch/s390x/defconfig | 2
linux-2554-ikconfig/arch/sh/defconfig | 2
linux-2554-ikconfig/arch/sparc/defconfig | 2
linux-2554-ikconfig/arch/sparc64/defconfig | 2
linux-2554-ikconfig/arch/um/defconfig | 2
linux-2554-ikconfig/arch/x86_64/defconfig | 2
linux-2554-ikconfig/init/Kconfig | 25 +++
linux-2554-ikconfig/kernel/configs.c | 206 +++++++++++++++++++++++++++
linux-2554-ikconfig/scripts/extract-ikconfig | 101 +++++++++++++
linux-2554-ikconfig/scripts/mkconfigs | 81 ++++++++++
linux-2554/kernel/Makefile | 11 +
22 files changed, 459 insertions(+)


diff -urN --exclude-from=diff_exclude_file linux-2554/arch/alpha/defconfig linux-2554-ikconfig/arch/alpha/defconfig
--- linux-2554/arch/alpha/defconfig Wed Nov 27 15:36:00 2002
+++ linux-2554-ikconfig/arch/alpha/defconfig Mon Dec 2 12:50:12 2002
@@ -19,6 +19,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/arm/defconfig linux-2554-ikconfig/arch/arm/defconfig
--- linux-2554/arch/arm/defconfig Wed Nov 27 15:35:54 2002
+++ linux-2554-ikconfig/arch/arm/defconfig Mon Dec 2 12:50:12 2002
@@ -80,6 +80,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set
CONFIG_NWFPE=y
CONFIG_KCORE_ELF=y
# CONFIG_KCORE_AOUT is not set
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/cris/defconfig linux-2554-ikconfig/arch/cris/defconfig
--- linux-2554/arch/cris/defconfig Wed Nov 27 15:35:55 2002
+++ linux-2554-ikconfig/arch/cris/defconfig Mon Dec 2 12:50:12 2002
@@ -17,6 +17,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
# CONFIG_SYSCTL is not set
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set
CONFIG_BINFMT_ELF=y
# CONFIG_ETRAX_KGDB is not set
# CONFIG_ETRAX_WATCHDOG is not set
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/i386/defconfig linux-2554-ikconfig/arch/i386/defconfig
--- linux-2554/arch/i386/defconfig Wed Nov 27 15:36:15 2002
+++ linux-2554-ikconfig/arch/i386/defconfig Mon Dec 2 12:50:12 2002
@@ -19,6 +19,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/ia64/defconfig linux-2554-ikconfig/arch/ia64/defconfig
--- linux-2554/arch/ia64/defconfig Wed Nov 27 15:35:49 2002
+++ linux-2554-ikconfig/arch/ia64/defconfig Mon Dec 2 12:50:12 2002
@@ -14,6 +14,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/m68k/defconfig linux-2554-ikconfig/arch/m68k/defconfig
--- linux-2554/arch/m68k/defconfig Wed Nov 27 15:35:48 2002
+++ linux-2554-ikconfig/arch/m68k/defconfig Mon Dec 2 12:50:12 2002
@@ -42,6 +42,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set
CONFIG_KCORE_ELF=y
# CONFIG_KCORE_AOUT is not set
CONFIG_BINFMT_AOUT=y
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/mips/defconfig linux-2554-ikconfig/arch/mips/defconfig
--- linux-2554/arch/mips/defconfig Wed Nov 27 15:35:50 2002
+++ linux-2554-ikconfig/arch/mips/defconfig Mon Dec 2 12:50:12 2002
@@ -93,6 +93,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Memory Technology Devices (MTD)
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/mips64/defconfig linux-2554-ikconfig/arch/mips64/defconfig
--- linux-2554/arch/mips64/defconfig Wed Nov 27 15:36:16 2002
+++ linux-2554-ikconfig/arch/mips64/defconfig Mon Dec 2 12:50:12 2002
@@ -56,6 +56,9 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set
+
CONFIG_BINFMT_ELF=y
CONFIG_MIPS32_COMPAT=y
CONFIG_BINFMT_ELF32=y
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/ppc/defconfig linux-2554-ikconfig/arch/ppc/defconfig
--- linux-2554/arch/ppc/defconfig Wed Nov 27 15:36:17 2002
+++ linux-2554-ikconfig/arch/ppc/defconfig Mon Dec 2 12:50:12 2002
@@ -64,6 +64,8 @@
CONFIG_PCI=y
CONFIG_NET=y
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_KCORE_ELF=y
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/ppc64/defconfig linux-2554-ikconfig/arch/ppc64/defconfig
--- linux-2554/arch/ppc64/defconfig Wed Nov 27 15:35:53 2002
+++ linux-2554-ikconfig/arch/ppc64/defconfig Mon Dec 2 12:50:12 2002
@@ -20,6 +20,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/s390/defconfig linux-2554-ikconfig/arch/s390/defconfig
--- linux-2554/arch/s390/defconfig Wed Nov 27 15:36:18 2002
+++ linux-2554-ikconfig/arch/s390/defconfig Mon Dec 2 12:50:12 2002
@@ -19,6 +19,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/s390x/defconfig linux-2554-ikconfig/arch/s390x/defconfig
--- linux-2554/arch/s390x/defconfig Wed Nov 27 15:35:46 2002
+++ linux-2554-ikconfig/arch/s390x/defconfig Mon Dec 2 12:50:12 2002
@@ -19,6 +19,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/sh/defconfig linux-2554-ikconfig/arch/sh/defconfig
--- linux-2554/arch/sh/defconfig Wed Nov 27 15:36:01 2002
+++ linux-2554-ikconfig/arch/sh/defconfig Mon Dec 2 12:50:12 2002
@@ -45,6 +45,8 @@
# CONFIG_SYSVIPC is not set
# CONFIG_BSD_PROCESS_ACCT is not set
# CONFIG_SYSCTL is not set
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set
CONFIG_KCORE_ELF=y
# CONFIG_KCORE_AOUT is not set
CONFIG_BINFMT_ELF=y
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/sparc/defconfig linux-2554-ikconfig/arch/sparc/defconfig
--- linux-2554/arch/sparc/defconfig Wed Nov 27 15:36:16 2002
+++ linux-2554-ikconfig/arch/sparc/defconfig Mon Dec 2 12:50:12 2002
@@ -19,6 +19,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/sparc64/defconfig linux-2554-ikconfig/arch/sparc64/defconfig
--- linux-2554/arch/sparc64/defconfig Wed Nov 27 15:35:56 2002
+++ linux-2554-ikconfig/arch/sparc64/defconfig Mon Dec 2 12:50:12 2002
@@ -16,6 +16,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/um/defconfig linux-2554-ikconfig/arch/um/defconfig
--- linux-2554/arch/um/defconfig Wed Nov 27 15:36:15 2002
+++ linux-2554-ikconfig/arch/um/defconfig Mon Dec 2 12:50:12 2002
@@ -20,6 +20,8 @@
CONFIG_SYSVIPC=y
CONFIG_BSD_PROCESS_ACCT=y
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set
CONFIG_BINFMT_AOUT=y
CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_MISC=y
diff -urN --exclude-from=diff_exclude_file linux-2554/arch/x86_64/defconfig linux-2554-ikconfig/arch/x86_64/defconfig
--- linux-2554/arch/x86_64/defconfig Wed Nov 27 15:36:15 2002
+++ linux-2554-ikconfig/arch/x86_64/defconfig Mon Dec 2 12:50:12 2002
@@ -23,6 +23,8 @@
CONFIG_SYSVIPC=y
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_SYSCTL=y
+# CONFIG_IKCONFIG is not set
+# CONFIG_IKCONFIG_PROC is not set

#
# Loadable module support
diff -urN --exclude-from=diff_exclude_file linux-2554/init/Kconfig linux-2554-ikconfig/init/Kconfig
--- linux-2554/init/Kconfig Wed Nov 27 15:36:17 2002
+++ linux-2554-ikconfig/init/Kconfig Mon Dec 2 13:42:50 2002
@@ -98,6 +98,31 @@
building a kernel for install/rescue disks or your system is very
limited in memory.

+config IKCONFIG
+ bool "Kernel .config support"
+ ---help---
+ This option enables the complete Linux kernel ".config" file
+ contents, information on compiler used to build the kernel,
+ kernel running when this kernel was built and kernel version
+ from Makefile to be saved in kernel. It provides documentation
+ of which kernel options are used in a running kernel or in an
+ on-disk kernel. This information can be extracted from the kernel
+ image file with the script scripts/extract-ikconfig and used as
+ input to rebuild the current kernel or to build another kernel.
+ It can also be extracted from a running kernel by reading
+ /proc/ikconfig/config and /proc/ikconfig/built_with, if enabled.
+ /proc/ikconfig/config will list the configuration that was used
+ to build the kernel and /proc/ikconfig/built_with will list
+ information on the compiler and host machine that was used to
+ build the kernel.
+
+config IKCONFIG_PROC
+ bool "Enable access to .config through /proc/ikconfig"
+ depends on IKCONFIG
+ ---help---
+ This option enables access to kernel configuration file and build
+ information through /proc/ikconfig.
+
endmenu


diff -urN --exclude-from=diff_exclude_file linux-2554/kernel/configs.c linux-2554-ikconfig/kernel/configs.c
--- linux-2554/kernel/configs.c Wed Dec 31 17:00:00 1969
+++ linux-2554-ikconfig/kernel/configs.c Mon Dec 2 12:50:12 2002
@@ -0,0 +1,206 @@
+/*
+ * kernel/configs.c
+ *
+ * Copyright (C) 2002 Khalid Aziz <[email protected]>
+ * Copyright (C) 2002 Randy Dunlap <[email protected]>
+ * Copyright (C) 2002 Al Stone <[email protected]>
+ * Copyright (C) 2002 Hewlett-Packard Company
+ *
+ * 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, GOOD TITLE or
+ * NON INFRINGEMENT. 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.
+ *
+ *
+ * Echo the kernel .config file used to build the kernel
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+#include <linux/init.h>
+#include <linux/compile.h>
+#include <linux/version.h>
+#include <asm/uaccess.h>
+
+/**************************************************/
+/* globals and useful constants */
+
+static char *IKCONFIG_NAME = "ikconfig";
+static char *IKCONFIG_VERSION = "0.5";
+
+static int ikconfig_current_size = 0;
+
+static struct proc_dir_entry *ikconfig_dir, *current_config, *built_with;
+
+/**************************************************/
+/* the actual current config file */
+
+#include "ikconfig.h"
+
+static int
+ikconfig_permission_current(struct inode *inode, int op)
+{
+ /* anyone can read the device, no one can write to it */
+ if (op == MAY_READ)
+ return 0;
+ else
+ return -EACCES;
+}
+
+static ssize_t
+ikconfig_output_current(struct file *file, char *buf,
+ size_t len, loff_t * offset)
+{
+ int i, limit;
+ int cnt;
+
+ limit = (ikconfig_current_size > len) ? len : ikconfig_current_size;
+ for (i = file->f_pos, cnt = 0;
+ i < ikconfig_current_size && cnt < limit; i++, cnt++) {
+ put_user(ikconfig_config[i], buf + cnt);
+ }
+ file->f_pos = i;
+ return cnt;
+}
+
+static int
+ikconfig_open_current(struct inode *inode, struct file *file)
+{
+ if (file->f_mode & FMODE_READ) {
+ inode->i_size = ikconfig_current_size;
+ file->f_pos = 0;
+ }
+ MOD_INC_USE_COUNT;
+ return 0;
+}
+
+static int
+ikconfig_close_current(struct inode *inode, struct file *file)
+{
+ MOD_DEC_USE_COUNT;
+ return 0;
+}
+
+static struct file_operations ikconfig_file_ops = {
+ read:ikconfig_output_current,
+ write:NULL, /* file is not writable at all */
+ open:ikconfig_open_current,
+ release:ikconfig_close_current
+};
+
+static struct inode_operations ikconfig_inode_ops = {
+ permission:ikconfig_permission_current
+};
+
+/***************************************************/
+/* proc_read_built_with: let people read the info */
+/* we have on the tools used to build this kernel */
+
+static int
+proc_read_built_with(char *page, char **start,
+ off_t off, int count, int *eof, void *data)
+{
+ MOD_INC_USE_COUNT;
+
+ sprintf(page, "Kernel: %s\nCompiler: %s\nVersion_in_Makefile: %s\n",
+ ikconfig_built_with, LINUX_COMPILER, UTS_RELEASE);
+ *eof = 1;
+
+ MOD_DEC_USE_COUNT;
+ return strlen(page);
+}
+
+/***************************************************/
+/* ikconfig_init: start up everything we need to */
+
+int __init
+ikconfig_init(void)
+{
+ int result = 0;
+
+#ifdef CONFIG_IKCONFIG_PROC
+ printk(KERN_INFO "ikconfig %s with /proc/ikconfig\n",
+ IKCONFIG_VERSION);
+#else
+ printk(KERN_INFO "ikconfig %s without /proc/ikconfig\n",
+ IKCONFIG_VERSION);
+ return result;
+#endif
+
+ /* create the ikconfig directory */
+ ikconfig_dir = proc_mkdir(IKCONFIG_NAME, NULL);
+ if (ikconfig_dir == NULL) {
+ result = -ENOMEM;
+ goto leave;
+ }
+ ikconfig_dir->owner = THIS_MODULE;
+
+ /* create the current config file */
+ current_config = create_proc_entry("config", S_IFREG | S_IRUGO,
+ ikconfig_dir);
+ if (current_config == NULL) {
+ result = -ENOMEM;
+ goto leave2;
+ }
+ current_config->proc_iops = &ikconfig_inode_ops;
+ current_config->proc_fops = &ikconfig_file_ops;
+ current_config->owner = THIS_MODULE;
+ ikconfig_current_size = strlen(ikconfig_config);
+ current_config->size = ikconfig_current_size;
+
+ /* create the "built with" file */
+ built_with = create_proc_read_entry("built_with", 0444, ikconfig_dir,
+ proc_read_built_with, NULL);
+ if (built_with == NULL) {
+ result = -ENOMEM;
+ goto leave3;
+ }
+ built_with->owner = THIS_MODULE;
+ goto leave;
+
+leave3:
+ /* remove the file from proc */
+ remove_proc_entry("config", ikconfig_dir);
+
+leave2:
+ /* remove the ikconfig directory */
+ remove_proc_entry(IKCONFIG_NAME, NULL);
+
+leave:
+ return result;
+}
+
+/***************************************************/
+/* cleanup_ikconfig: clean up our mess */
+
+static void
+cleanup_ikconfig(void)
+{
+ /* remove the files */
+ remove_proc_entry("config", ikconfig_dir);
+ remove_proc_entry("built_with", ikconfig_dir);
+
+ /* remove the ikconfig directory */
+ remove_proc_entry(IKCONFIG_NAME, NULL);
+
+ printk(KERN_INFO "ikconfig unloaded\n");
+
+ return;
+}
+
+module_init(ikconfig_init);
+module_exit(cleanup_ikconfig);
+
+MODULE_LICENSE("GPL");
diff -urN --exclude-from=diff_exclude_file linux-2554/scripts/extract-ikconfig linux-2554-ikconfig/scripts/extract-ikconfig
--- linux-2554/scripts/extract-ikconfig Wed Dec 31 17:00:00 1969
+++ linux-2554-ikconfig/scripts/extract-ikconfig Mon Dec 2 12:50:12 2002
@@ -0,0 +1,101 @@
+#! /bin/bash
+# extracts .config info from a [b]zImage file
+# uses: binoffset (new), dd, zcat, strings, grep
+# $arg1 is [b]zImage filename
+
+HDR=0
+TMPFILE=""
+
+usage()
+{
+ echo " usage: extract-ikconfig [b]zImage_filename [architecture]"
+ echo " where architecture is one of i386, ia64"
+}
+
+clean_up()
+{
+ if [ $HDR -ne 0 ]
+ then
+ rm -f $TMPFILE
+ fi
+}
+
+if [ $# -lt 1 ]
+then
+ usage
+ exit
+fi
+
+image=$1
+arch=$2
+
+if [ "$arch" = "" ]
+then
+ arch=`uname -m`
+fi
+arch=`echo $arch | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/`
+
+case $arch in
+i386)
+ HDR=`binoffset $image 0x1f 0x8b 0x08 0x0 2> /dev/null`
+ if [ "$HDR" = "" ]
+ then
+ echo "ERROR: Failed to find the start of kernel in kernel image file."
+ echo " Please verify if binoffset is present on your system."
+ exit 1
+ fi
+ # If the kernel is uncompressed, binoffset will fail to find
+ # gzip signature
+ if [ $HDR -eq -1 ]
+ then
+ HDR=0
+ fi
+ ;;
+ia64)
+ HDR=0
+ ;;
+*)
+ # We do not know where the kernel image might start in this file,
+ # but we may be able to extract configuration information
+ # nevertheless if the kernel image is not compressed.
+ echo "WARNING: This script has not been ported to architecture $arch"
+ echo " Unless you passed in an uncompressed kernel image file,"
+ echo " this script may not produce correct result."
+ echo
+ HDR=0
+ ;;
+esac
+
+PID=$$
+
+# Extract the kernel image if necessary
+if [ $HDR -ne 0 ]
+then
+ TMPFILE="/tmp/`basename $image`.vmlin.$PID"
+ dd if=$image bs=1 skip=$HDR 2> /dev/null > $TMPFILE
+else
+ TMPFILE=$image
+fi
+
+# Check if the kernel image is compressed. If it is, uncompress it before
+# looking for strings.
+file $TMPFILE | grep "gzip compressed" > /dev/null
+if [ $? -eq 0 ]
+then
+ zcat $TMPFILE | strings | awk "/CONFIG_BEGIN=n/,/CONFIG_END=n/" > $image.oldconfig.$PID
+else
+ strings $TMPFILE | grep "CONFIG_BEGIN=n" > /dev/null
+ if [ $? -eq 0 ]
+ then
+ strings $TMPFILE | awk "/CONFIG_BEGIN=n/,/CONFIG_END=n/" > $image.oldconfig.$PID
+ else
+ echo "ERROR: Unable to extract kernel configuration information."
+ echo " This kernel image may not have the config info."
+ clean_up
+ exit 1
+ fi
+fi
+
+echo "Kernel configuration written to $image.oldconfig.$PID"
+clean_up
+exit 0
diff -urN --exclude-from=diff_exclude_file linux-2554/scripts/mkconfigs linux-2554-ikconfig/scripts/mkconfigs
--- linux-2554/scripts/mkconfigs Wed Dec 31 17:00:00 1969
+++ linux-2554-ikconfig/scripts/mkconfigs Mon Dec 2 12:50:12 2002
@@ -0,0 +1,81 @@
+#!/bin/sh
+#
+# Copyright (C) 2002 Khalid Aziz <[email protected]>
+# Copyright (C) 2002 Randy Dunlap <[email protected]>
+# Copyright (C) 2002 Al Stone <[email protected]>
+# Copyright (C) 2002 Hewlett-Packard Company
+#
+# 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 to generate ikconfig.h from linux/.config:
+# - Retain lines that begin with "CONFIG_"
+# - Retain lines that begin with "# CONFIG_"
+# - lines that use double-quotes must \\-escape-quote them
+
+
+kernel_version()
+{
+ KERNVER="`grep VERSION $1 | head -1 | cut -f3 -d' '`.`grep PATCHLEVEL $1 | head -1 | cut -f3 -d' '`.`grep SUBLEVEL $1 | head -1 | cut -f3 -d' '``grep EXTRAVERSION $1 | head -1 | cut -f3 -d' '`"
+}
+
+if [ $# -lt 2 ]
+then
+ echo "Usage: `basename $0` <configuration_file> <Makefile>"
+ exit 1
+fi
+
+config=$1
+makefile=$2
+
+echo "#ifndef _IKCONFIG_H"
+echo "#define _IKCONFIG_H"
+echo \
+"/*
+ *
+ * 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, GOOD TITLE or
+ * NON INFRINGEMENT. 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.
+ *
+ *
+ *
+ * This file is generated automatically by scripts/mkconfigs. Do not edit.
+ *
+ */"
+
+echo "static char *ikconfig_built_with ="
+echo " \"`uname -s` `uname -r` `uname -v` `uname -m`\";"
+echo
+kernel_version $makefile
+echo "#ifdef CONFIG_IKCONFIG_PROC"
+echo "static char *ikconfig_config = "
+echo "#else"
+echo "static char *ikconfig_config __initdata __attribute__((unused)) = "
+echo "#endif"
+echo "\"CONFIG_BEGIN=n\\n\\"
+echo "`cat $config | sed 's/\"/\\\\\"/g' | grep "^#\? \?CONFIG_" | awk '{ print $0, "\\\\n\\\\" }' `"
+echo "CONFIG_END=n\";"
+echo "#endif /* _IKCONFIG_H */"
--- linux-2554/kernel/Makefile%IKC Wed Jan 1 19:21:14 2003
+++ linux-2554/kernel/Makefile Thu Jan 2 15:31:38 2003
@@ -22,6 +22,10 @@
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
obj-$(CONFIG_COMPAT) += compat.o
+obj-$(CONFIG_IKCONFIG) += configs.o
+
+# files to be removed upon make clean
+clean-files := ikconfig.h

ifneq ($(CONFIG_IA64),y)
# According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
@@ -31,3 +35,10 @@
# to get a correct value for the wait-channel (WCHAN in ps). --davidm
CFLAGS_sched.o := $(PROFILING) -fno-omit-frame-pointer
endif
+
+$(obj)/ikconfig.h: $(TOPDIR)/scripts/mkconfigs $(TOPDIR)/.config $(TOPDIR)/Makefile
+ $(CONFIG_SHELL) $(TOPDIR)/scripts/mkconfigs $(TOPDIR)/.config $(TOPDIR)/Makefile > $(obj)/ikconfig.h
+
+$(obj)/configs.o: $(obj)/ikconfig.h $(obj)/configs.c \
+ $(TOPDIR)/include/linux/version.h \
+ $(TOPDIR)/include/linux/compile.h

2003-01-05 14:38:50

by Paul Rolland

[permalink] [raw]
Subject: [Patch 2.5] [Was: RE : kernel .config support?]

Hello,

I've just corrected two problems in the patch I submitted.

Here it is, just tested againt 2.5.54.

diff -urN linux-2.5.53-orig/drivers/char/Kconfig
linux-2.5.53/drivers/char/Kconfig
--- linux-2.5.53-orig/drivers/char/Kconfig Tue Dec 24 06:19:26 2002
+++ linux-2.5.53/drivers/char/Kconfig Mon Dec 30 08:35:54 2002
@@ -4,6 +4,13 @@

menu "Character devices"

+config CONFIG
+ bool "Linux Kernel Configuration Driver"
+ ---help---
+ If you say Y here, and if you have /proc support enabled,
you'll find
+ a /proc/config directory that will contain a copy of the
.config used
+ to generate the running kernel.
+
config VT
bool "Virtual terminal"
---help---
diff -urN linux-2.5.53-orig/drivers/char/Makefile
linux-2.5.53/drivers/char/Makefile
--- linux-2.5.53-orig/drivers/char/Makefile Tue Dec 24 06:21:17 2002
+++ linux-2.5.53/drivers/char/Makefile Mon Dec 30 12:06:53 2002
@@ -7,6 +7,9 @@
#
FONTMAPFILE = cp437.uni

+EXTRA_TARGETS := config.h
+host-progs := dotHmaker
+
obj-y += mem.o tty_io.o n_tty.o tty_ioctl.o pty.o misc.o random.o

# All of the (potential) objects that export symbols.
@@ -16,6 +19,7 @@
ite_gpio.o keyboard.o misc.o nvram.o random.o
rtc.o \
selection.o sonypi.o sysrq.o tty_io.o
tty_ioctl.o

+obj-$(CONFIG_CONFIG) += config.o
obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o
consolemap_deftbl.o selection.o keyboard.o
obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
@@ -85,7 +89,7 @@


# Files generated that shall be removed upon make clean
-clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c
+clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c dotHmaker
config.txt config.txt.gz config.h

$(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE)
$(call do_cmd,CONMK $@,$(objtree)/scripts/conmakehash $< > $@)
@@ -107,3 +111,13 @@
rm [email protected]

endif
+
+$(obj)/config.o: $(obj)/config.h
+
+$(obj)/config.h: $(obj)/config.txt.gz $(obj)/dotHmaker
+ $(obj)/dotHmaker < $< > $@
+
+$(obj)/config.txt.gz: .config FORCE
+ cp .config $(obj)/config.txt
+ $(call if_changed,gzip)
+
diff -urN linux-2.5.53-orig/drivers/char/config.c
linux-2.5.53/drivers/char/config.c
--- linux-2.5.53-orig/drivers/char/config.c Thu Jan 1 01:00:00 1970
+++ linux-2.5.53/drivers/char/config.c Mon Dec 30 08:33:48 2002
@@ -0,0 +1,152 @@
+/*
+ * 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 DOT_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 * buffer, char ** start, off_t offset,
+ int size, 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",
+DOT_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<DOT_CONFIG_GZ_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"
DOT_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");
+
diff -urN linux-2.5.53-orig/drivers/char/dotHmaker.c
linux-2.5.53/drivers/char/dotHmaker.c
--- linux-2.5.53-orig/drivers/char/dotHmaker.c Thu Jan 1 01:00:00 1970
+++ linux-2.5.53/drivers/char/dotHmaker.c Mon Dec 30 08:33:04 2002
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <unistd.h>
+
+int main(void)
+{
+ FILE * in = stdin;
+ int i;
+ unsigned char buf;
+
+ int size = 0;
+
+ printf("/*\n");
+ printf(" * Automagically generated file, please don't edit !\n");
+ printf(" */\n"); printf("\n");
+ printf("static char config_gz[] = \\\n");
+
+ i = 0;
+
+ fread(&buf, sizeof(unsigned char), 1, in);
+ while (!feof(in)) {
+ if (i == 0) {
+ printf(" \"");
+ } /* endif */
+ printf("\\x%x", buf);
+ size ++;
+ i ++;
+ if (i == 10) {
+ i = 0;
+ printf("\"\\\n");
+ } /* endif */
+ fread(&buf, sizeof(unsigned char), 1, in);
+ } /* endwhile */
+
+ if (i == 0) {
+ printf(" ;\n");
+ } else {
+ printf("\";\n");
+ } /* endif */
+ printf("\n");
+ printf("#define DOT_CONFIG_GZ_SIZE %d\n\n", size);
+
+ return(0);
+}
+

2003-01-06 14:53:43

by Miles Bader

[permalink] [raw]
Subject: Re: kernel .config support?

On Mon, Jan 06, 2003 at 08:15:07AM +0100, Paul Rolland wrote:
> > probability of a feature printing a copyright notice at init
> > time is inversely proportional to its importance!]
>
> This can be removed too, in fact I don't care. I just put it because many
> others are doing so

That's the problem.... :-)

I understand why people do this -- it's nice to see your name pop up and get
a bit credit -- but really, there are simply too many people working on linux
for it to really make sense.

I wish someone with a bit of pull would go through and just trash the whole
lot, leaving just the printks that give actual useful information (and even
those could often do with quite a bit of pruning)...

[I'm too chicken to brave the flames that would probably result from trying]

-Miles
--
o The existentialist, not having a pillow, goes everywhere with the book by
Sullivan, _I am going to spit on your graves_.

2003-01-12 14:11:23

by Paul Rolland

[permalink] [raw]
Subject: Re: kernel .config support?

Hello Miles,

> On Mon, Jan 06, 2003 at 08:15:07AM +0100, Paul Rolland wrote:
> > > probability of a feature printing a copyright notice at init
> > > time is inversely proportional to its importance!]
> >
> > This can be removed too, in fact I don't care. I just put
> it because
> > many others are doing so
>
> That's the problem.... :-)
>

Well, here is a new copy of the patch... I've implemented the changes
you requested :
- no more messages at boot time,
- one level /proc entry (/proc/config.gz)
- no more unnecessary version entry.

I've also added a Kconfig dependancy on PROC_FS. Compiling without
PROC_FS support is fine without this dependancy, but result in
nothing being present, which may be puzzling.

Regards,
Paul

diff -urN -S config.c linux-2.5.56/drivers/char/config.c
linux-2.5.56-work/drivers/char/config.c
--- linux-2.5.56/drivers/char/config.c 1970-01-01 01:00:00.000000000
+0100
+++ linux-2.5.56-work/drivers/char/config.c 2003-01-12
15:12:41.000000000 +0100
@@ -0,0 +1,107 @@
+/*
+ * Linux Configuration Driver
+ * (c) 2002-2003 Paul Rolland, [email protected]
+ *
+ * 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.gz
+ *
+ */
+
+#define DOT_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>
+
+#ifndef CONFIG_PROC_FS
+static int config_read_proc( char *buffer, char **start, off_t offset,
+ int size, int *eof, void *data)
+{
+ return 0;
+}
+#else
+
+#include "config.h"
+
+/* 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_gz_infos(char *buffer, int *len, off_t *begin, off_t
offset,
+ int size)
+{
+ int i;
+
+ for (i=0; i<DOT_CONFIG_GZ_SIZE; i++) {
+ PRINT_PROC("%c", config_gz[i]);
+ }
+
+ return(1);
+}
+
+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)
+{
+ if
(!create_proc_read_entry("config.gz",0,0,config_gz_read_proc,NULL)) {
+ printk(KERN_ERR "config: can't create /proc/config.gz\n");
+ return(-ENOMEM);
+ }
+
+ return( 0 );
+}
+
+static void __exit config_cleanup_module (void)
+{
+ remove_proc_entry( "config.gz", 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");
+
diff -urN -S config.c linux-2.5.56/drivers/char/dotHmaker.c
linux-2.5.56-work/drivers/char/dotHmaker.c
--- linux-2.5.56/drivers/char/dotHmaker.c 1970-01-01
01:00:00.000000000 +0100
+++ linux-2.5.56-work/drivers/char/dotHmaker.c 2003-01-12
15:12:33.000000000 +0100
@@ -0,0 +1,54 @@
+/*
+ * Linux Configuration Driver
+ * (c) 2002-2003 Paul Rolland, [email protected]
+ *
+ * This is a part of the /proc/config.gz module.
+ * this program is used to transform a config.txt.gz file to
+ * a variable that can then be included in config.c
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+int main(void)
+{
+ FILE * in = stdin;
+ int i;
+ unsigned char buf;
+
+ int size = 0;
+
+ printf("/*\n");
+ printf(" * Automagically generated file, please don't edit !\n");
+ printf(" */\n"); printf("\n");
+ printf("static char config_gz[] = \\\n");
+
+ i = 0;
+
+ fread(&buf, sizeof(unsigned char), 1, in);
+ while (!feof(in)) {
+ if (i == 0) {
+ printf(" \"");
+ } /* endif */
+ printf("\\x%x", buf);
+ size ++;
+ i ++;
+ if (i == 10) {
+ i = 0;
+ printf("\"\\\n");
+ } /* endif */
+ fread(&buf, sizeof(unsigned char), 1, in);
+ } /* endwhile */
+
+ if (i == 0) {
+ printf(" ;\n");
+ } else {
+ printf("\";\n");
+ } /* endif */
+ printf("\n");
+ printf("#define DOT_CONFIG_GZ_SIZE %d\n\n", size);
+
+ return(0);
+}
+
--- linux-2.5.56/drivers/char/Kconfig 2003-01-10 21:11:20.000000000
+0100
+++ linux-2.5.56-work/drivers/char/Kconfig 2003-01-12
14:50:40.000000000 +0100
@@ -4,6 +4,16 @@

menu "Character devices"

+config CONFIG
+ bool "Linux Kernel Configuration Driver"
+ depends on PROC_FS
+ ---help---
+ If you say Y here, and if you have /proc support enabled,
you'll find
+ a /proc/config.gz entry that will contain a gzipped copy of
the
+ .config used to generate the running kernel.
+
+ This adds about 4KB to the kernel size.
+
config VT
bool "Virtual terminal"
---help---
diff -urN -S config.c linux-2.5.56/drivers/char/Makefile
linux-2.5.56-work/drivers/char/Makefile
--- linux-2.5.56/drivers/char/Makefile 2003-01-10 21:12:21.000000000
+0100
+++ linux-2.5.56-work/drivers/char/Makefile 2003-01-12
11:30:39.000000000 +0100
@@ -7,6 +7,9 @@
#
FONTMAPFILE = cp437.uni

+EXTRA_TARGETS := config.h
+host-progs := dotHmaker
+
obj-y += mem.o tty_io.o n_tty.o tty_ioctl.o pty.o misc.o random.o

# All of the (potential) objects that export symbols.
@@ -16,6 +19,7 @@
ite_gpio.o keyboard.o misc.o nvram.o random.o
rtc.o \
selection.o sonypi.o sysrq.o tty_io.o
tty_ioctl.o

+obj-$(CONFIG_CONFIG) += config.o
obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o
consolemap_deftbl.o selection.o keyboard.o
obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
@@ -85,7 +89,7 @@


# Files generated that shall be removed upon make clean
-clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c
+clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c dotHmaker
config.txt config.txt.gz config.h

$(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE)
$(call do_cmd,CONMK $@,$(objtree)/scripts/conmakehash $< > $@)
@@ -107,3 +111,13 @@
rm [email protected]

endif
+
+$(obj)/config.o: $(obj)/config.h
+
+$(obj)/config.h: $(obj)/config.txt.gz $(obj)/dotHmaker
+ $(obj)/dotHmaker < $< > $@
+
+$(obj)/config.txt.gz: .config FORCE
+ cp .config $(obj)/config.txt
+ $(call if_changed,gzip)
+