Module Name:    src
Committed By:   pooka
Date:           Wed Feb  3 21:00:49 UTC 2010

Modified Files:
        src/usr.bin/config: defs.h gram.y main.c mkheaders.c mkioconf.c scan.l

Log Message:
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 ;)


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/config/defs.h
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/config/gram.y
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/config/main.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/config/mkheaders.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/config/mkioconf.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/config/scan.l

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/config/defs.h
diff -u src/usr.bin/config/defs.h:1.30 src/usr.bin/config/defs.h:1.31
--- src/usr.bin/config/defs.h:1.30	Fri Mar 13 20:44:59 2009
+++ src/usr.bin/config/defs.h	Wed Feb  3 21:00:49 2010
@@ -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);

Index: src/usr.bin/config/gram.y
diff -u src/usr.bin/config/gram.y:1.19 src/usr.bin/config/gram.y:1.20
--- src/usr.bin/config/gram.y:1.19	Fri Mar 13 18:24:41 2009
+++ src/usr.bin/config/gram.y	Wed Feb  3 21:00:49 2010
@@ -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");
 	}
 }

Index: src/usr.bin/config/main.c
diff -u src/usr.bin/config/main.c:1.36 src/usr.bin/config/main.c:1.37
--- src/usr.bin/config/main.c:1.36	Fri Mar 13 20:44:59 2009
+++ src/usr.bin/config/main.c	Wed Feb  3 21:00:49 2010
@@ -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();

Index: src/usr.bin/config/mkheaders.c
diff -u src/usr.bin/config/mkheaders.c:1.16 src/usr.bin/config/mkheaders.c:1.17
--- src/usr.bin/config/mkheaders.c:1.16	Wed May 13 18:54:34 2009
+++ src/usr.bin/config/mkheaders.c	Wed Feb  3 21:00:49 2010
@@ -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;

Index: src/usr.bin/config/mkioconf.c
diff -u src/usr.bin/config/mkioconf.c:1.14 src/usr.bin/config/mkioconf.c:1.15
--- src/usr.bin/config/mkioconf.c:1.14	Sat Apr 11 12:41:10 2009
+++ src/usr.bin/config/mkioconf.c	Wed Feb  3 21:00:49 2010
@@ -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);

Index: src/usr.bin/config/scan.l
diff -u src/usr.bin/config/scan.l:1.13 src/usr.bin/config/scan.l:1.14
--- src/usr.bin/config/scan.l:1.13	Wed Oct 28 02:42:20 2009
+++ src/usr.bin/config/scan.l	Wed Feb  3 21:00:49 2010
@@ -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;

Reply via email to