From owner-freebsd-embedded@FreeBSD.ORG Wed Apr 14 10:02:30 2010 Return-Path: Delivered-To: embedded@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C9920106566B; Wed, 14 Apr 2010 10:02:30 +0000 (UTC) (envelope-from ray@dlink.ua) Received: from dlink.ua (smtp.dlink.ua [193.138.187.146]) by mx1.freebsd.org (Postfix) with ESMTP id 280A78FC1B; Wed, 14 Apr 2010 10:02:29 +0000 (UTC) Received: from gw ([192.168.10.10] helo=terran) by dlink.ua with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1O1zMX-00047o-Vj; Wed, 14 Apr 2010 12:58:26 +0300 Date: Wed, 14 Apr 2010 13:03:53 +0300 From: Alexandr Rybalko To: hackers@freebsd.org Message-Id: <20100414130353.c28d5128.ray@dlink.ua> Organization: D-Link X-Mailer: Sylpheed 2.7.1 (GTK+ 2.16.6; i386-portbld-freebsd8.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: embedded@FreeBSD.org Subject: Patch for config utility X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Apr 2010 10:02:31 -0000 Hi All, 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 :) 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 ) * 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); -- Alexandr Rybalko aka Alex RAY