kern/145694: [patch] enable config(8) execution outside of the kernel source tree.

Aleksandr Rybalko ray at ddteam.net
Wed Apr 14 11:40:02 UTC 2010


>Number:         145694
>Category:       kern
>Synopsis:       [patch] enable config(8) execution outside of the kernel source tree.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 14 11:40:01 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Aleksandr Rybalko
>Release:        9.0-CURRENT
>Organization:
DDTeam.net
>Environment:
FreeBSD freebsd-dir-320.dlink.ua 9.0-CURRENT FreeBSD 9.0-CURRENT #2: Fri Apr  9 12:55:06 EEST 2010     ray at terran.dlink.ua:/usr/obj/D-Link_DIR-320_9.0.2/mips/usr/1/MIPS_FreeBSD/HEAD/head/sys/DIR-320_ipsec-router  mips
>Description:
I made a patch for the config utility, which enables execution of config outside of the kernel source tree.
The main purpose is to avoid large number of configuration files for many boards.
I work on D-Link DIR-320 device (Broadcom BCM5354) which must have more than 4 different profiles with different kernel
config files.
If every device have 3-5 configs (with different hints files), every chip have ~ 5-10 vendors (producing devices on this chip),
every chip family have 10-20 chips (BCM5354 is a BCM4700 family), and platform have 10-20 family's, so we get 40000 files in conf
directory of platform
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: mkoptions.c
===================================================================
--- mkoptions.c	(revision 206411)
+++ mkoptions.c	(working copy)
@@ -294,7 +294,11 @@ read_options(void)
 	char genopt[MAXPATHLEN];
 
 	SLIST_INIT(&otab);
-	(void) snprintf(fname, sizeof(fname), "../../conf/options");
+	if ( *ksrcdir != '\0' )
+		(void) snprintf(fname, sizeof(fname), "%s/conf/options", 
+		    ksrcdir);
+	else
+		(void) snprintf(fname, sizeof(fname), "../../conf/options");
 openit:
 	fp = fopen(fname, "r");
 	if (fp == 0) {
@@ -306,7 +310,12 @@ next:
 		(void) fclose(fp);
 		if (first == 1) {
 			first++;
-			(void) snprintf(fname, sizeof fname, "../../conf/options.%s", machinename);
+			if ( *ksrcdir != '\0' )
+				(void) snprintf(fname, sizeof fname, 
+				    "%s/conf/options.%s", ksrcdir, machinename);
+			else
+				(void) snprintf(fname, sizeof fname, 
+				    "../../conf/options.%s", machinename);
 			fp = fopen(fname, "r");
 			if (fp != 0)
 				goto next;
Index: main.c
===================================================================
--- main.c	(revision 206411)
+++ main.c	(working copy)
@@ -72,6 +72,7 @@ static const char rcsid[] =
 
 char *	PREFIX;
 char 	destdir[MAXPATHLEN];
+char 	ksrcdir[MAXPATHLEN];
 char 	srcdir[MAXPATHLEN];
 
 int	debugging;
@@ -110,8 +111,9 @@ main(int argc, char **argv)
 	char xxx[MAXPATHLEN];
 	char *kernfile;
 
+	*ksrcdir = '\0';
 	kernfile = NULL;
-	while ((ch = getopt(argc, argv, "Cd:gpVx:")) != -1)
+	while ((ch = getopt(argc, argv, "Cd:gk:pVx:")) != -1)
 		switch (ch) {
 		case 'C':
 			filebased = 1;
@@ -125,6 +127,12 @@ main(int argc, char **argv)
 		case 'g':
 			debugging++;
 			break;
+		case 'k':
+			if (*ksrcdir == '\0')
+				strlcpy(ksrcdir, optarg, sizeof(ksrcdir));
+			else
+				errx(EXIT_FAILURE, "Kernel ksrcdir already set");
+			break;
 		case 'p':
 			profiling++;
 			break;
@@ -164,7 +172,8 @@ main(int argc, char **argv)
 		len = strlen(destdir);
 		while (len > 1 && destdir[len - 1] == '/')
 			destdir[--len] = '\0';
-		get_srcdir();
+		if (*ksrcdir == '\0')
+			get_srcdir();
 	} else {
 		strlcpy(destdir, CDIR, sizeof(destdir));
 		strlcat(destdir, PREFIX, sizeof(destdir));
@@ -210,11 +219,14 @@ main(int argc, char **argv)
 	 * for "sys" (to make genassym.c work along with #include <sys/xxx>)
 	 * and similarly for "machine".
 	 */
-	if (*srcdir == '\0')
-		(void)snprintf(xxx, sizeof(xxx), "../../include");
-	else
+	if (*ksrcdir != '\0')
 		(void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
+		    ksrcdir, machinename);
+	else if (*srcdir != '\0')
+		(void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
 		    srcdir, machinename);
+	else
+		(void)snprintf(xxx, sizeof(xxx), "../../include");
 	(void) unlink(path("machine"));
 	(void) symlink(xxx, path("machine"));
 	if (strcmp(machinename, machinearch) != 0) {
@@ -222,12 +234,15 @@ main(int argc, char **argv)
 		 * make symbolic links in compilation directory for
 		 * machinearch, if it is different than machinename.
 		 */
-		if (*srcdir == '\0')
+		if (*ksrcdir != '\0')
+			(void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
+			    ksrcdir, machinearch);
+		else if (*srcdir != '\0')
+			(void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
+			    srcdir, machinearch);
+		else
 			(void)snprintf(xxx, sizeof(xxx), "../../../%s/include",
 			    machinearch);
-		else
-			(void)snprintf(xxx, sizeof(xxx), "%s/%s/include",
-			    srcdir, machinearch);
 		(void) unlink(path(machinearch));
 		(void) symlink(xxx, path(machinearch));
 	}
@@ -278,7 +293,7 @@ static void
 usage(void)
 {
 
-	fprintf(stderr, "usage: config [-CgpV] [-d destdir] sysname\n");
+	fprintf(stderr, "usage: config [-CgpV] [-k srcdir] [-d destdir] sysname\n");
 	fprintf(stderr, "       config -x kernel\n");
 	exit(EX_USAGE);
 }
Index: mkmakefile.c
===================================================================
--- mkmakefile.c	(revision 206411)
+++ mkmakefile.c	(working copy)
@@ -116,7 +116,12 @@ makefile(void)
 	int versreq;
 
 	read_files();
-	snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename);
+	if (*ksrcdir != '\0')
+		snprintf(line, sizeof(line), "%s/conf/Makefile.%s", 
+		    ksrcdir, machinename);
+	else
+		snprintf(line, sizeof(line), "../../conf/Makefile.%s", 
+		    machinename);
 	ifp = fopen(line, "r");
 	if (ifp == 0) {
 		snprintf(line, sizeof(line), "Makefile.%s", machinename);
@@ -139,7 +144,9 @@ makefile(void)
 		fprintf(ofp, "DEBUG=-g\n");
 	if (profiling)
 		fprintf(ofp, "PROFLEVEL=%d\n", profiling);
-	if (*srcdir != '\0')
+	if (*ksrcdir != '\0')
+		fprintf(ofp,"S=%s\n", ksrcdir);
+	else if (*srcdir != '\0')
 		fprintf(ofp,"S=%s\n", srcdir);
 	while (fgets(line, BUFSIZ, ifp) != 0) {
 		if (*line != '%') {
@@ -347,7 +354,12 @@ next:
 			printf("%s: missing include filename.\n", fname);
 			exit(1);
 		}
-		(void) snprintf(ifname, sizeof(ifname), "../../%s", wd);
+		if (*ksrcdir != '\0')
+			(void) snprintf(ifname, sizeof(ifname), "%s/%s", 
+			    ksrcdir, wd);
+		else
+			(void) snprintf(ifname, sizeof(ifname), "../../%s", 
+			    wd);
 		read_file(ifname);
 		while (((wd = get_word(fp)) != (char *)EOF) && wd)
 			;
@@ -544,9 +556,17 @@ read_files(void)
 	char fname[MAXPATHLEN];
 	struct files_name *nl, *tnl;
 	
-	(void) snprintf(fname, sizeof(fname), "../../conf/files");
+	if (*ksrcdir != '\0')
+		(void) snprintf(fname, sizeof(fname), "%s/conf/files", 
+		    ksrcdir);
+	else
+		(void) snprintf(fname, sizeof(fname), "../../conf/files");
 	read_file(fname);
-	(void) snprintf(fname, sizeof(fname),
+	if (*ksrcdir != '\0')
+		(void) snprintf(fname, sizeof(fname),
+		       	"%s/conf/files.%s", ksrcdir, machinename);
+	else
+		(void) snprintf(fname, sizeof(fname),
 		       	"../../conf/files.%s", machinename);
 	read_file(fname);
 	for (nl = STAILQ_FIRST(&fntab); nl != NULL; nl = tnl) {
Index: config.8
===================================================================
--- config.8	(revision 206411)
+++ config.8	(working copy)
@@ -38,6 +38,7 @@
 .Nm
 .Op Fl CVgp
 .Op Fl d Ar destdir
+.Op Fl k Ar ksrcdir
 .Ar SYSTEM_NAME
 .Nm
 .Op Fl x Ar kernel
@@ -78,6 +79,10 @@ Note that
 does not append
 .Ar SYSTEM_NAME
 to the directory given.
+.It Fl k Ar ksrcdir
+Use
+.Ar ksrcdir
+as the kernel source tree directory, instead of the default one.
 .It Fl g
 Configure a system for debugging.
 .It Fl x Ar kernel
Index: config.h
===================================================================
--- config.h	(revision 206411)
+++ config.h	(working copy)
@@ -196,6 +196,8 @@ extern int	maxusers;
 
 extern char *PREFIX;		/* Config file name - for error messages */
 extern char srcdir[];		/* root of the kernel source tree */
+extern char ksrcdir[];		/* root of the kernel source tree 
+				 * set by -k flag */
 
 #define eq(a,b)	(!strcmp(a,b))
 #define ns(s)	strdup(s)
Index: lang.l
===================================================================
--- lang.l	(revision 206411)
+++ lang.l	(working copy)
@@ -259,7 +259,10 @@ include(const char *fname, int ateof)
 	fnamebuf = NULL;
 	fp = fopen(fname, "r");
 	if (fp == NULL && fname[0] != '.' && fname[0] != '/') {
-		asprintf(&fnamebuf, "../../conf/%s", fname);
+		if (*ksrcdir != '\0')
+			asprintf(&fnamebuf, "%s/conf/%s", ksrcdir, fname);
+		else
+			asprintf(&fnamebuf, "../../conf/%s", fname);
 		if (fnamebuf != NULL) {
 			fp = fopen(fnamebuf, "r");
 			free(fnamebuf);


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list