More .config fun.

Oliver Xymoron (oxymoron@waste.org)
Fri, 15 Jan 1999 18:14:03 -0600 (CST)


Having abandoned my initial approach to this feature, I've taken Nicholas'
patch from this morning and tweaked it a bit.

Note that this patch defaults to 'N' so adds no overhead by default. It
also includes an absolute minimum of new code, so the memory overhead
should be just slightly more than a gzipped .config file. This will be a
fraction of a page, so if you're lucky, it may not take up any extra pages
at all. A relatively small price to pay for the convenience of 'make
cloneconfig'..

Here's what I changed:

- Removed s/CONFIG_// stuff as requested by MEC, /proc/config.gz now has
same md5sum as .config
- Changed config.c to config_data.h - I don't think we should ever
generate .c files
- Changed crufty shell script to C program, bin2c
- version.c conditionally includes config_data.h (with the ugly side
effect that it now must include config.h to define CONFIG_PROC_CONFIG)
- config_data.h is built to build version.c, which happens every build
- proc/fs/array.c contains code locally
- other minor simplifications

An interesting thing happened with bin2c. After I wrote it, I discovered
it already exists in the kernel source! In drivers/sound, there's a file
called bin2hex used to build driver data into the kernel. Unfortunately,
it's both in the wrong place and has the wrong name. It makes C files, not
hex files, as best demonstrated by the absurdly named hex2hex in the same
directory. These files should both be in scripts/ as they are for
execution on the host machine and have applications outside of the sound
drivers. I left my scripts/bin2c in the patch because I think it's a nicer
implementation.

As discussed earlier, the best way to do this is by using the linker to
directly include files in the binary image. However, that would make this
patch much larger and force it to touch all architectures. Yuck. So I did
it this way. Hopefully, we can come up with a generic scheme to do file
inclusion in 2.3 and kill the tmppiggy/bin2c/bin2hex/hex2hex ugliness.

Finally, this patch includes a patchdesc file for use with my
previously posted patchnames patch. Ingo can feel free to delete it.

diff -Nur linux-2.2.0-pre6/Documentation/Configure.help linux/Documentation/Configure.help
--- linux-2.2.0-pre6/Documentation/Configure.help Mon Jan 4 14:57:44 1999
+++ linux/Documentation/Configure.help Fri Jan 15 11:43:35 1999
@@ -6774,6 +6774,14 @@
18 kB. Several programs depend on this, so everyone should say Y
here.

+/proc/config.gz support
+CONFIG_PROC_CONFIG
+ Say Y here if you want a copy of your current kernel configuration
+ saved in the kernel that you build. This is extremely useful if you
+ ever build more than one kernel. The cost is around 1K-4K of running
+ memory. Only say no if you really can't spare this. You can sneeze
+ and lose more on memory than this.
+
NFS filesystem support
CONFIG_NFS_FS
If you are connected to some other (usually local) Unix computer
diff -Nur linux-2.2.0-pre6/Makefile linux/Makefile
--- linux-2.2.0-pre6/Makefile Wed Jan 6 17:01:15 1999
+++ linux/Makefile Fri Jan 15 17:34:36 1999
@@ -247,6 +247,17 @@
scripts/split-include include/linux/autoconf.h include/config; \
fi

+cloneconfig: symlinks scripts/split-include
+ @if [ -f "/proc/config.gz" ]; then \
+ mv -f .config .config.bak; \
+ gzip -d < /proc/config.gz > .config; \
+ if [ -r include/linux/autoconf.h ]; then \
+ scripts/split-include include/linux/autoconf.h include/config; \
+ fi; \
+ else \
+ echo "Your current kernel does not support cloning."; \
+ fi
+
linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS))

$(patsubst %, _dir_%, $(SUBDIRS)) : dummy
@@ -280,13 +291,16 @@
@echo \#define LINUX_COMPILER \"`$(CC) -v 2>&1 | tail -1`\" >> .ver
@mv -f .ver $@

+include/linux/config_data.h: newversion scripts/bin2c
+ gzip -9 < .config | scripts/bin2c kernel_config_data > $@
+
include/linux/version.h: ./Makefile
@echo \#define UTS_RELEASE \"$(KERNELRELEASE)\" > .ver
@echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)` >> .ver
@echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' >>.ver
@mv -f .ver $@

-init/version.o: init/version.c include/linux/compile.h
+init/version.o: init/version.c include/linux/compile.h include/linux/config_data.h
$(CC) $(CFLAGS) -DUTS_MACHINE='"$(ARCH)"' -c -o init/version.o init/version.c

init/main.o: init/main.c
@@ -354,7 +368,7 @@
rm -f core `find . -name '*.[oas]' ! -regex '.*lxdialog/.*' -print`
rm -f core `find . -type f -name 'core' -print`
rm -f core `find . -name '.*.flags' -print`
- rm -f vmlinux System.map
+ rm -f vmlinux System.map include/linux/config_data.h
rm -f .tmp*
rm -f drivers/char/consolemap_deftbl.c drivers/video/promcon_tbl.c
rm -f drivers/char/conmakehash
@@ -380,7 +394,7 @@
rm -rf include/config
rm -f .depend `find . -name .depend -print`
rm -f core `find . -size 0 -print`
- rm -f .hdepend scripts/mkdep scripts/split-include
+ rm -f .hdepend scripts/mkdep scripts/split-include scripts/bin2c
rm -f $(TOPDIR)/include/linux/modversions.h
rm -rf $(TOPDIR)/include/linux/modules
rm -rf modules
@@ -449,3 +463,6 @@

scripts/split-include: scripts/split-include.c
$(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
+
+scripts/bin2c: scripts/bin2c.c
+ $(HOSTCC) $(HOSTCFLAGS) -o scripts/bin2c scripts/bin2c.c
diff -Nur linux-2.2.0-pre6/fs/Config.in linux/fs/Config.in
--- linux-2.2.0-pre6/fs/Config.in Mon Jan 4 14:05:11 1999
+++ linux/fs/Config.in Fri Jan 15 11:43:35 1999
@@ -34,6 +34,9 @@
fi
tristate 'OS/2 HPFS filesystem support (read only)' CONFIG_HPFS_FS
bool '/proc filesystem support' CONFIG_PROC_FS
+if [ "$CONFIG_PROC_FS" = "y" ] ; then
+ bool ' /proc/config.gz (kernel configuration)' CONFIG_PROC_CONFIG
+fi
if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then
tristate '/dev/pts filesystem for Unix98 PTYs' CONFIG_DEVPTS_FS
fi
diff -Nur linux-2.2.0-pre6/fs/proc/array.c linux/fs/proc/array.c
--- linux-2.2.0-pre6/fs/proc/array.c Wed Jan 6 11:26:15 1999
+++ linux/fs/proc/array.c Fri Jan 15 15:38:36 1999
@@ -402,6 +402,17 @@
return strlen(buffer);
}

+#ifdef CONFIG_PROC_CONFIG
+static int get_proc_config(char *buffer)
+{
+ extern char *kernel_config_data;
+ extern int kernel_config_data_size;
+
+ memcpy(buffer, kernel_config_data, kernel_config_data_size);
+ return kernel_config_data_size;
+}
+#endif
+
static int get_cmdline(char * buffer)
{
extern char saved_command_line[];
@@ -1361,6 +1372,11 @@
case PROC_STRAM:
return get_stram_list(page);
#endif
+#ifdef CONFIG_PROC_CONFIG
+ case PROC_CONFIG:
+ return get_proc_config(page);
+#endif
+
}
return -EBADF;
}
diff -Nur linux-2.2.0-pre6/fs/proc/root.c linux/fs/proc/root.c
--- linux-2.2.0-pre6/fs/proc/root.c Sun Dec 20 07:51:07 1998
+++ linux/fs/proc/root.c Fri Jan 15 11:43:35 1999
@@ -646,6 +646,13 @@
NULL, NULL /* parent, subdir */
};
#endif
+#ifdef CONFIG_PROC_CONFIG
+static struct proc_dir_entry proc_root_config = {
+ PROC_CONFIG, 9, "config.gz",
+ S_IFREG | S_IRUGO, 1, 0, 0,
+ 0, &proc_array_inode_operations
+};
+#endif

__initfunc(void proc_root_init(void))
{
@@ -720,7 +727,9 @@
#ifdef CONFIG_PROC_DEVICETREE
proc_device_tree_init();
#endif
-
+#ifdef CONFIG_PROC_CONFIG
+ proc_register(&proc_root, &proc_root_config);
+#endif
proc_bus = create_proc_entry("bus", S_IFDIR, 0);
}

diff -Nur linux-2.2.0-pre6/include/linux/proc_fs.h linux/include/linux/proc_fs.h
--- linux-2.2.0-pre6/include/linux/proc_fs.h Fri Jan 8 17:54:34 1999
+++ linux/include/linux/proc_fs.h Fri Jan 15 15:14:24 1999
@@ -53,6 +53,7 @@
PROC_SOUND,
PROC_MTRR, /* whether enabled or not */
PROC_FS,
+ PROC_CONFIG, /* whether enabled or not */
PROC_SWAPSTATS
};

diff -Nur linux-2.2.0-pre6/init/version.c linux/init/version.c
--- linux-2.2.0-pre6/init/version.c Mon Jan 5 03:41:01 1998
+++ linux/init/version.c Fri Jan 15 16:40:52 1999
@@ -6,10 +6,14 @@
* May be freely distributed as part of Linux.
*/

+#include <linux/config.h>
#include <linux/uts.h>
#include <linux/utsname.h>
#include <linux/version.h>
#include <linux/compile.h>
+#ifdef CONFIG_PROC_CONFIG
+#include <linux/config_data.h>
+#endif

#define version(a) Version_ ## a
#define version_string(a) version(a)
diff -Nur linux-2.2.0-pre6/patchdesc.cfg linux/patchdesc.cfg
--- linux-2.2.0-pre6/patchdesc.cfg Wed Dec 31 18:00:00 1969
+++ linux/patchdesc.cfg Fri Jan 15 17:34:02 1999
@@ -0,0 +1,7 @@
+This patch adds /proc/config.gz and make cloneconfig
+
+Oliver Xymoron <oxymoron@waste.org> Jan 15 1999
+
+Derived from a patch by Nicholas Leon <nicholas@binary9.net> with
+suggestions from Michael Chastain <mec@shout.net> and Peter T. Breuer
+<ptb@it.uc3m.es>
diff -Nur linux-2.2.0-pre6/scripts/bin2c.c linux/scripts/bin2c.c
--- linux-2.2.0-pre6/scripts/bin2c.c Wed Dec 31 18:00:00 1969
+++ linux/scripts/bin2c.c Fri Jan 15 15:32:12 1999
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ int ch,total=0;
+
+ if(argc>1) printf("const char *%s %s=\n",argv[1],argc>2?argv[2]:"");
+
+ do {
+ printf("\t\"");
+ while((ch=getchar())!=EOF)
+ {
+ total++;
+ printf("\\x%02x",ch);
+ if(total%16==0) break;
+ }
+ printf("\"\n");
+ } while(ch!=EOF);
+
+ if(argc>1) printf("\t;\n\nconst int %s_size = %d;\n",argv[1],total);
+
+ return 0;
+}

--
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/