Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/config Introduce experimental support for ioconf-onl...



details:   https://anonhg.NetBSD.org/src/rev/aa1fcaa5de4e
branches:  trunk
changeset: 751424:aa1fcaa5de4e
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed Feb 03 21:00:49 2010 +0000

description:
Introduce experimental support for ioconf-only configuration files.
This is done by giving the "ioconf" keyword in the config file.
As a result, config produces only ioconf.c and locators.h.  Currently,
only "monolithic" configurations with the device path starting from
root are supported.  Eventually, the goal is to support a local
root in the input file from any point along the device tree using
files.* in our kernel tree.  This will make autogenerating the
config glue for device modules possible instead of having to write
it by hand like is currently required (yes, it sounds simple to
implement, but ...).

reviewed by cube.
(the next part will demand major discussions with you, so prepare ;)

diffstat:

 usr.bin/config/defs.h      |   4 +++-
 usr.bin/config/gram.y      |  29 +++++++++++++++++++----------
 usr.bin/config/main.c      |  35 +++++++++++++++++++++++++++++------
 usr.bin/config/mkheaders.c |   5 ++---
 usr.bin/config/mkioconf.c  |  25 +++++++++++++++++--------
 usr.bin/config/scan.l      |   3 ++-
 6 files changed, 72 insertions(+), 29 deletions(-)

diffs (286 lines):

diff -r d450a878f7c4 -r aa1fcaa5de4e usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Wed Feb 03 20:56:54 2010 +0000
+++ b/usr.bin/config/defs.h     Wed Feb 03 21:00:49 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.30 2009/03/13 20:44:59 cube Exp $   */
+/*     $NetBSD: defs.h,v 1.31 2010/02/03 21:00:49 pooka Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -387,6 +387,7 @@
 const char *machinearch;       /* machine arch, e.g., "sparc" or "m68k" */
 struct nvlist *machinesubarches;
                                /* machine subarches, e.g., "sun68k" or "hpc" */
+const char *ioconfname;                /* ioconf name, mutually exclusive to machine */
 const char *srcdir;            /* path to source directory (rel. to build) */
 const char *builddir;          /* path to build directory */
 const char *defbuilddir;       /* default build directory */
@@ -523,6 +524,7 @@
 /* mkheaders.c */
 int    mkheaders(void);
 int    moveifchanged(const char *, const char *);
+int    emitlocs(void);
 
 /* mkioconf.c */
 int    mkioconf(void);
diff -r d450a878f7c4 -r aa1fcaa5de4e usr.bin/config/gram.y
--- a/usr.bin/config/gram.y     Wed Feb 03 20:56:54 2010 +0000
+++ b/usr.bin/config/gram.y     Wed Feb 03 21:00:49 2010 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.19 2009/03/13 18:24:41 cube Exp $   */
+/*     $NetBSD: gram.y,v 1.20 2010/02/03 21:00:49 pooka Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -80,7 +80,7 @@
 #define        fx_or(e1, e2)   new0(NULL, NULL, e1, FX_OR, e2)
 
 static void    cleanup(void);
-static void    setmachine(const char *, const char *, struct nvlist *);
+static void    setmachine(const char *, const char *, struct nvlist *, int);
 static void    check_maxpart(void);
 
 static void    app(struct nvlist *, struct nvlist *);
@@ -107,7 +107,7 @@
 %token DEVICE DEVCLASS DUMPS DEVICE_MAJOR
 %token ENDFILE
 %token XFILE FILE_SYSTEM FLAGS
-%token IDENT
+%token IDENT IOCONF
 %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
 %token NEEDS_COUNT NEEDS_FLAG NO
 %token XOBJECT OBSOLETE ON OPTIONS
@@ -186,9 +186,10 @@
        '\n';
 
 machine_spec:
-       XMACHINE WORD '\n'              { setmachine($2,NULL,NULL); } |
-       XMACHINE WORD WORD subarches_opt '\n'   { setmachine($2,$3,$4); } |
-       error { stop("cannot proceed without machine specifier"); };
+       XMACHINE WORD '\n'              { setmachine($2,NULL,NULL,0); } |
+       XMACHINE WORD WORD subarches_opt '\n'   { setmachine($2,$3,$4,0); } |
+       IOCONF WORD '\n'                { setmachine($2,NULL,NULL,1); } |
+       error { stop("cannot proceed without machine or ioconf specifier"); };
 
 subarches_opt:
        subarches                       |
@@ -618,11 +619,20 @@
 }
 
 static void
-setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
+setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches,
+       int isioconf)
 {
        char buf[MAXPATHLEN];
        struct nvlist *nv;
 
+       if (isioconf) {
+               fprintf(stderr, "warning: ioconf is an experimental feature\n");
+               if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
+                       exit(1);
+               ioconfname = mch;
+               return;
+       }
+
        machine = mch;
        machinearch = mcharch;
        machinesubarches = mchsubarches;
@@ -643,8 +653,7 @@
         * Set up the file inclusion stack.  This empty include tells
         * the parser there are no more device definitions coming.
         */
-       strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
-       if (include(buf, ENDDEFS, 0, 0) != 0)
+       if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
                exit(1);
 
        /* Include arch/${MACHINE}/conf/files.${MACHINE} */
@@ -684,7 +693,7 @@
 check_maxpart(void)
 {
 
-       if (maxpartitions <= 0) {
+       if (maxpartitions <= 0 && ioconfname == NULL) {
                stop("cannot proceed without maxpartitions specifier");
        }
 }
diff -r d450a878f7c4 -r aa1fcaa5de4e usr.bin/config/main.c
--- a/usr.bin/config/main.c     Wed Feb 03 20:56:54 2010 +0000
+++ b/usr.bin/config/main.c     Wed Feb 03 21:00:49 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.36 2009/03/13 20:44:59 cube Exp $   */
+/*     $NetBSD: main.c,v 1.37 2010/02/03 21:00:49 pooka Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -212,15 +212,17 @@
                }
        }
 
+       if (optind != 1) {
+               if (xflag)
+                       errx(EXIT_FAILURE, "-x must be used alone");
+       }
+
        argc -= optind;
        argv += optind;
        if (argc > 1) {
                usage();
        }
 
-       if (xflag && (builddir != NULL || srcdir != NULL || Pflag || pflag ||
-           vflag || Lflag))
-               errx(EXIT_FAILURE, "-x must be used alone");
        if (Lflag && (builddir != NULL || Pflag || pflag))
                errx(EXIT_FAILURE, "-L can only be used with -s and -v");
 
@@ -347,13 +349,24 @@
                firstfile(cname);
        }
 
+        /*
+         * Log config file.  We don't know until yyparse() if we're
+         * going to need config_file.h (i.e. if we're doing ioconf-only
+         * or not).  Just start creating the file, and when we know
+         * later, we'll just keep or discard our work here.
+         */
+       logconfig_start();
+
        /*
         * Parse config file (including machine definitions).
         */
-       logconfig_start();
        if (yyparse())
                stop();
-       logconfig_end();
+
+       if (ioconfname && cfg)
+               fclose(cfg);
+       else
+               logconfig_end();
 
        if (removeit)
                unlink(cname);
@@ -370,6 +383,16 @@
                stop();
 
        /*
+        * If working on an ioconf-only config, process here and exit
+        */
+       if (ioconfname) {
+               pack();
+               mkioconf();
+               emitlocs();
+               return 0;
+       }
+
+       /*
         * Deal with option dependencies.
         */
        dependopts();
diff -r d450a878f7c4 -r aa1fcaa5de4e usr.bin/config/mkheaders.c
--- a/usr.bin/config/mkheaders.c        Wed Feb 03 20:56:54 2010 +0000
+++ b/usr.bin/config/mkheaders.c        Wed Feb 03 21:00:49 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkheaders.c,v 1.16 2009/05/13 18:54:34 cube Exp $      */
+/*     $NetBSD: mkheaders.c,v 1.17 2010/02/03 21:00:49 pooka Exp $     */
 
 /*
  * Copyright (c) 1992, 1993
@@ -58,7 +58,6 @@
 #include <crc_extern.h>
 
 static int emitcnt(struct nvlist *);
-static int emitlocs(void);
 static int emitopts(void);
 static int emitioconfh(void);
 static int emittime(void);
@@ -350,7 +349,7 @@
  * locators in the configuration.  Do this by enumerating the attribute
  * hash table and emitting all the locators for each attribute.
  */
-static int
+int
 emitlocs(void)
 {
        const char *tfname;
diff -r d450a878f7c4 -r aa1fcaa5de4e usr.bin/config/mkioconf.c
--- a/usr.bin/config/mkioconf.c Wed Feb 03 20:56:54 2010 +0000
+++ b/usr.bin/config/mkioconf.c Wed Feb 03 21:00:49 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkioconf.c,v 1.14 2009/04/11 12:41:10 lukem Exp $      */
+/*     $NetBSD: mkioconf.c,v 1.15 2010/02/03 21:00:49 pooka Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -89,17 +89,19 @@
                return (1);
        }
 
+       if (ioconfname == NULL) {
+               emitcfattachinit(fp);
+               emitroots(fp);
+               emitpseudo(fp);
+               if (!do_devsw)
+                       emitname2blk(fp);
+       }
        emithdr(fp);
        emitcfdrivers(fp);
        emitexterns(fp);
-       emitcfattachinit(fp);
        emitloc(fp);
        emitparents(fp);
        emitcfdata(fp);
-       emitroots(fp);
-       emitpseudo(fp);
-       if (!do_devsw)
-               emitname2blk(fp);
 
        fflush(fp);
        if (ferror(fp)) {
@@ -233,6 +235,11 @@
        }
 
        NEWLINE;
+
+       /* the initial list is not added to ioconf-only configs */
+       if (ioconfname)
+               return;
+
        fprintf(fp, "struct cfdriver * const cfdriver_list_initial[] = {\n");
        TAILQ_FOREACH(d, &allbases, d_next) {
                if (!devbase_has_instances(d, WILD))
@@ -361,9 +368,11 @@
                "#define NORM FSTATE_NOTFOUND\n"
                "#define STAR FSTATE_STAR\n"
                "\n"
-               "struct cfdata cfdata[] = {\n"
+               "struct cfdata cfdata%s%s[] = {\n"
                "    /* driver           attachment    unit state "
-               "loc   flags pspec */\n");
+               "loc   flags pspec */\n",
+                   ioconfname ? "_" : "",
+                   ioconfname ? ioconfname : "");
        for (p = packed; (i = *p) != NULL; p++) {
                /* the description */
                fprintf(fp, "/*%3d: %s at ", i->i_cfindex, i->i_name);
diff -r d450a878f7c4 -r aa1fcaa5de4e usr.bin/config/scan.l
--- a/usr.bin/config/scan.l     Wed Feb 03 20:56:54 2010 +0000
+++ b/usr.bin/config/scan.l     Wed Feb 03 21:00:49 2010 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: scan.l,v 1.13 2009/10/28 02:42:20 christos Exp $       */
+/*     $NetBSD: scan.l,v 1.14 2010/02/03 21:00:49 pooka Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -145,6 +145,7 @@
 file-system    return FILE_SYSTEM;
 flags          return FLAGS;
 ident          return IDENT;
+ioconf         return IOCONF;
 machine                return XMACHINE;
 major          return MAJOR;
 makeoptions    return MAKEOPTIONS;



Home | Main Index | Thread Index | Old Index