Export CONFIG_ options via #version/kconfig
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 15 Feb 2017 18:44:54 +0000 (13:44 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 15 Feb 2017 19:05:25 +0000 (14:05 -0500)
Raw text, one line per CONFIG option, taken directly from your .config
file.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
.gitignore
kern/drivers/dev/version.c
kern/src/Kbuild
scripts/make_kconfig_info.sh [new file with mode: 0755]

index 8d6d5a7..4061842 100644 (file)
@@ -20,6 +20,7 @@ kern/boot
 kern/include/arch
 kern/src/arch
 kern/src/build_info.*
+kern/src/kconfig_info.c
 kern/src/error.c
 user/parlib/include/parlib/arch
 user/parlib/syscall_tbl.c
index ea4d117..400b845 100644 (file)
@@ -21,6 +21,7 @@ enum {
        Kvercommitid,
        Kverversion,
        Kverversionname,
+       Kverkconfig,
        BUILD_ID_SZ = 20,
        BUILD_ID_OFFSET = 16,
 };
@@ -33,11 +34,14 @@ static struct dirtab vertab[] = {
        {"commitid",            {Kvercommitid},         0,      0444},
        {"version",                     {Kverversion},          0,      0444},
        {"version_name",        {Kverversionname},      0,      0444},
+       {"kconfig",                     {Kverkconfig},          0,      0444},
 };
 
 extern char __note_build_id_start[];
 extern char __note_build_id_end[];
 
+extern const char *__kconfig_str;
+
 static char *get_build_id_start(void)
 {
        return __note_build_id_start + BUILD_ID_OFFSET;
@@ -81,6 +85,7 @@ static void ver_init(void)
        vertab[Kvercommitid].length = ver_get_file_size(build_info_commitid);
        vertab[Kverversion].length = ver_get_file_size(build_info_version);
        vertab[Kverversionname].length = ver_get_file_size(build_info_version_name);
+       vertab[Kverkconfig].length = strlen(__kconfig_str) + 1;
 }
 
 static void ver_shutdown(void)
@@ -113,7 +118,6 @@ static struct chan *ver_open(struct chan *c, int omode)
 
 static void ver_close(struct chan *c)
 {
-
 }
 
 /* Returns a char representing the lowest 4 bits of x */
@@ -162,6 +166,8 @@ static long ver_read(struct chan *c, void *va, long n, int64_t off)
                if (build_info_version_name)
                        return ver_emit_nlstr(va, build_info_version_name, n, (long) off);
                break;
+       case Kverkconfig:
+               return readstr(off, va, n, __kconfig_str);
        default:
                error(EINVAL, ERROR_FIXME);
        }
index 85008f8..b0b94cc 100644 (file)
@@ -17,7 +17,10 @@ $(src)/build_info.c: $(src)/build_info.cid
        @echo "const char build_info_version_name[] = { \"$(VERNAME)\" };"\
                >> $(@)
 
-clean-files += build_info.c build_info.cid
+$(src)/kconfig_info.c: .config
+       @scripts/make_kconfig_info.sh $< $@
+
+clean-files += build_info.c build_info.cid kconfig_info.c
 
 obj-y                                          += alarm.o
 obj-y                                          += apipe.o
@@ -48,6 +51,7 @@ obj-y                                         += frontend.o
 obj-y                                          += hashtable.o
 obj-y                                          += hexdump.o
 obj-y                                          += init.o
+obj-y                                          += kconfig_info.o
 obj-y                                          += kdebug.o
 obj-y                                          += kfs.o
 obj-y                                          += kmalloc.o
diff --git a/scripts/make_kconfig_info.sh b/scripts/make_kconfig_info.sh
new file mode 100755 (executable)
index 0000000..7f71535
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+# Barret Rhoden <brho@cs.berkeley.edu>
+# Builds a giant string of Kconfig options
+
+if [ $# -ne 2 ]
+then
+       echo "Need your .config and output file args!"
+       exit -1
+fi
+
+CONFIG_FILE=$1
+KCONFIG_C=$2
+
+echo "// This was automatically generated with $0, do not edit" > $KCONFIG_C
+
+# Here's the guts of it.  Ignore the comments, ignore the empty lines, replace
+# all " with \" (since we're making a string), and print a record at a time.
+# It'll look like "CONFIG_foo\nCONFIG_bar\n".
+
+echo -n "const char *__kconfig_str = \"" >> $KCONFIG_C
+
+grep -v '^#' $CONFIG_FILE | grep -v '^$' \
+                          | sed 's/"/\\"/g' \
+                          | awk '{printf "%s\\n", $1}' \
+                          >> $KCONFIG_C
+echo "\";" >> $KCONFIG_C