1994-05-26 05:23:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-09-15 06:37:10 +00:00
|
|
|
static const char copyright[] =
|
1994-05-26 05:23:31 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-09-15 06:37:10 +00:00
|
|
|
#if 0
|
1994-05-26 05:23:31 +00:00
|
|
|
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
|
1997-09-15 06:37:10 +00:00
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-26 05:23:31 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2007-05-12 19:38:18 +00:00
|
|
|
#include <sys/sbuf.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/file.h>
|
1996-01-12 08:57:10 +00:00
|
|
|
#include <sys/mman.h>
|
1999-10-30 10:55:48 +00:00
|
|
|
#include <sys/param.h>
|
2007-05-12 19:38:18 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <ctype.h>
|
1996-01-12 08:57:10 +00:00
|
|
|
#include <err.h>
|
1997-09-15 06:37:10 +00:00
|
|
|
#include <stdio.h>
|
2007-05-12 22:37:52 +00:00
|
|
|
#include <string.h>
|
1996-01-12 08:57:10 +00:00
|
|
|
#include <sysexits.h>
|
1997-09-15 06:37:10 +00:00
|
|
|
#include <unistd.h>
|
2001-01-29 09:34:43 +00:00
|
|
|
#include <dirent.h>
|
1996-06-02 17:22:01 +00:00
|
|
|
#include "y.tab.h"
|
1994-05-26 05:23:31 +00:00
|
|
|
#include "config.h"
|
2005-08-10 06:36:44 +00:00
|
|
|
#include "configvers.h"
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1995-02-22 15:37:32 +00:00
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE (1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE (0)
|
|
|
|
#endif
|
|
|
|
|
2001-06-30 06:28:12 +00:00
|
|
|
#define CDIR "../compile/"
|
1999-10-30 10:55:48 +00:00
|
|
|
|
1999-04-17 14:41:41 +00:00
|
|
|
char * PREFIX;
|
1999-10-30 10:55:48 +00:00
|
|
|
char destdir[MAXPATHLEN];
|
|
|
|
char srcdir[MAXPATHLEN];
|
|
|
|
|
1999-04-17 14:41:41 +00:00
|
|
|
int debugging;
|
|
|
|
int profiling;
|
2005-10-27 17:13:23 +00:00
|
|
|
int found_defaults;
|
2007-05-12 19:38:18 +00:00
|
|
|
int incignore;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preserve old behaviour in INCLUDE_CONFIG_FILE handling (files are included
|
|
|
|
* literally).
|
|
|
|
*/
|
|
|
|
int filebased = 0;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
static void configfile(void);
|
|
|
|
static void get_srcdir(void);
|
|
|
|
static void usage(void);
|
2001-01-31 08:42:35 +00:00
|
|
|
static void cleanheaders(char *);
|
2007-05-12 19:38:18 +00:00
|
|
|
static void kernconfdump(const char *);
|
2010-04-27 05:04:32 +00:00
|
|
|
static void checkversion(void);
|
2012-05-22 16:33:10 +00:00
|
|
|
extern int yyparse(void);
|
2001-01-31 08:42:35 +00:00
|
|
|
|
|
|
|
struct hdr_list {
|
|
|
|
char *h_name;
|
|
|
|
struct hdr_list *h_next;
|
|
|
|
} *htab;
|
1997-09-15 06:37:10 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
/*
|
|
|
|
* Config builds a set of files for building a UNIX
|
|
|
|
* system given a description of the desired system.
|
|
|
|
*/
|
1997-09-15 06:37:10 +00:00
|
|
|
int
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
main(int argc, char **argv)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
struct stat buf;
|
1999-10-30 10:55:48 +00:00
|
|
|
int ch, len;
|
1994-05-26 05:23:31 +00:00
|
|
|
char *p;
|
2007-05-12 19:38:18 +00:00
|
|
|
char *kernfile;
|
2010-07-13 04:08:08 +00:00
|
|
|
int printmachine;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2010-07-13 04:08:08 +00:00
|
|
|
printmachine = 0;
|
2007-05-12 19:38:18 +00:00
|
|
|
kernfile = NULL;
|
2010-07-13 04:08:08 +00:00
|
|
|
while ((ch = getopt(argc, argv, "Cd:gmpVx:")) != -1)
|
1994-05-26 05:23:31 +00:00
|
|
|
switch (ch) {
|
2007-05-12 19:38:18 +00:00
|
|
|
case 'C':
|
|
|
|
filebased = 1;
|
|
|
|
break;
|
2010-07-13 04:08:08 +00:00
|
|
|
case 'm':
|
|
|
|
printmachine = 1;
|
|
|
|
break;
|
1999-10-30 10:55:48 +00:00
|
|
|
case 'd':
|
|
|
|
if (*destdir == '\0')
|
2000-11-21 19:58:55 +00:00
|
|
|
strlcpy(destdir, optarg, sizeof(destdir));
|
1999-10-30 10:55:48 +00:00
|
|
|
else
|
2010-03-30 13:46:40 +00:00
|
|
|
errx(EXIT_FAILURE, "directory already set");
|
1999-10-30 10:55:48 +00:00
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
case 'g':
|
1999-04-11 03:40:11 +00:00
|
|
|
debugging++;
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
profiling++;
|
|
|
|
break;
|
2007-05-12 19:38:18 +00:00
|
|
|
case 'V':
|
|
|
|
printf("%d\n", CONFIGVERS);
|
|
|
|
exit(0);
|
|
|
|
case 'x':
|
|
|
|
kernfile = optarg;
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
1997-09-15 06:37:10 +00:00
|
|
|
usage();
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2007-05-12 19:38:18 +00:00
|
|
|
if (kernfile != NULL) {
|
|
|
|
kernconfdump(kernfile);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1997-09-15 06:37:10 +00:00
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2005-10-27 17:13:23 +00:00
|
|
|
PREFIX = *argv;
|
2008-04-10 22:57:54 +00:00
|
|
|
if (stat(PREFIX, &buf) != 0 || !S_ISREG(buf.st_mode))
|
|
|
|
err(2, "%s", PREFIX);
|
2007-05-17 04:53:52 +00:00
|
|
|
if (freopen("DEFAULTS", "r", stdin) != NULL) {
|
|
|
|
found_defaults = 1;
|
|
|
|
yyfile = "DEFAULTS";
|
|
|
|
} else {
|
|
|
|
if (freopen(PREFIX, "r", stdin) == NULL)
|
|
|
|
err(2, "%s", PREFIX);
|
|
|
|
yyfile = PREFIX;
|
|
|
|
}
|
1999-10-30 10:55:48 +00:00
|
|
|
if (*destdir != '\0') {
|
|
|
|
len = strlen(destdir);
|
|
|
|
while (len > 1 && destdir[len - 1] == '/')
|
|
|
|
destdir[--len] = '\0';
|
|
|
|
get_srcdir();
|
|
|
|
} else {
|
2000-11-21 19:58:55 +00:00
|
|
|
strlcpy(destdir, CDIR, sizeof(destdir));
|
|
|
|
strlcat(destdir, PREFIX, sizeof(destdir));
|
1999-10-30 10:55:48 +00:00
|
|
|
}
|
|
|
|
|
2007-05-12 19:38:18 +00:00
|
|
|
SLIST_INIT(&cputype);
|
|
|
|
SLIST_INIT(&mkopt);
|
|
|
|
SLIST_INIT(&opt);
|
|
|
|
SLIST_INIT(&rmopts);
|
|
|
|
STAILQ_INIT(&cfgfiles);
|
2003-02-15 02:26:13 +00:00
|
|
|
STAILQ_INIT(&dtab);
|
2004-05-09 22:29:00 +00:00
|
|
|
STAILQ_INIT(&fntab);
|
|
|
|
STAILQ_INIT(&ftab);
|
2006-10-24 00:31:59 +00:00
|
|
|
STAILQ_INIT(&hints);
|
1994-05-26 05:23:31 +00:00
|
|
|
if (yyparse())
|
|
|
|
exit(3);
|
2005-12-30 15:29:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure that required elements (machine, cpu, ident) are present.
|
|
|
|
*/
|
2001-02-04 13:17:38 +00:00
|
|
|
if (machinename == NULL) {
|
1999-04-18 13:36:29 +00:00
|
|
|
printf("Specify machine type, e.g. ``machine i386''\n");
|
1994-05-26 05:23:31 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2005-12-30 15:29:50 +00:00
|
|
|
if (ident == NULL) {
|
|
|
|
printf("no ident line specified\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (SLIST_EMPTY(&cputype)) {
|
|
|
|
printf("cpu type must be specified\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-04-27 05:04:32 +00:00
|
|
|
checkversion();
|
2005-12-30 15:29:50 +00:00
|
|
|
|
2010-07-13 04:08:08 +00:00
|
|
|
if (printmachine) {
|
|
|
|
printf("%s\t%s\n",machinename,machinearch);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make compile directory */
|
|
|
|
p = path((char *)NULL);
|
|
|
|
if (stat(p, &buf)) {
|
|
|
|
if (mkdir(p, 0777))
|
|
|
|
err(2, "%s", p);
|
|
|
|
} else if (!S_ISDIR(buf.st_mode))
|
|
|
|
errx(EXIT_FAILURE, "%s isn't a directory", p);
|
|
|
|
|
2007-05-12 19:38:18 +00:00
|
|
|
configfile(); /* put config file into kernel*/
|
1995-12-11 10:52:34 +00:00
|
|
|
options(); /* make options .h files */
|
1994-05-26 05:23:31 +00:00
|
|
|
makefile(); /* build Makefile */
|
2005-12-30 15:29:50 +00:00
|
|
|
makeenv(); /* build env.c */
|
|
|
|
makehints(); /* build hints.c */
|
1994-05-26 05:23:31 +00:00
|
|
|
headers(); /* make a lot of .h files */
|
2001-01-31 08:42:35 +00:00
|
|
|
cleanheaders(p);
|
1995-05-03 20:16:57 +00:00
|
|
|
printf("Kernel build directory is %s\n", p);
|
2006-01-14 08:12:25 +00:00
|
|
|
printf("Don't forget to do ``make cleandepend && make depend''\n");
|
1994-05-26 05:23:31 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1999-10-30 10:55:48 +00:00
|
|
|
/*
|
|
|
|
* get_srcdir
|
|
|
|
* determine the root of the kernel source tree
|
|
|
|
* and save that in srcdir.
|
|
|
|
*/
|
|
|
|
static void
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
get_srcdir(void)
|
1999-10-30 10:55:48 +00:00
|
|
|
{
|
2008-01-08 21:10:13 +00:00
|
|
|
struct stat lg, phy;
|
|
|
|
char *p, *pwd;
|
|
|
|
int i;
|
1999-10-30 10:55:48 +00:00
|
|
|
|
2001-01-04 22:08:20 +00:00
|
|
|
if (realpath("../..", srcdir) == NULL)
|
2010-03-30 13:46:40 +00:00
|
|
|
err(EXIT_FAILURE, "Unable to find root of source tree");
|
2008-01-08 21:10:13 +00:00
|
|
|
if ((pwd = getenv("PWD")) != NULL && *pwd == '/' &&
|
|
|
|
(pwd = strdup(pwd)) != NULL) {
|
|
|
|
/* Remove the last two path components. */
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if ((p = strrchr(pwd, '/')) == NULL) {
|
|
|
|
free(pwd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
if (stat(pwd, &lg) != -1 && stat(srcdir, &phy) != -1 &&
|
|
|
|
lg.st_dev == phy.st_dev && lg.st_ino == phy.st_ino)
|
|
|
|
strlcpy(srcdir, pwd, MAXPATHLEN);
|
|
|
|
free(pwd);
|
|
|
|
}
|
1999-10-30 10:55:48 +00:00
|
|
|
}
|
|
|
|
|
1997-09-15 06:37:10 +00:00
|
|
|
static void
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
usage(void)
|
1997-09-15 06:37:10 +00:00
|
|
|
{
|
2005-03-30 21:45:08 +00:00
|
|
|
|
2010-07-13 04:08:08 +00:00
|
|
|
fprintf(stderr, "usage: config [-CgmpV] [-d destdir] sysname\n");
|
2007-05-12 19:38:18 +00:00
|
|
|
fprintf(stderr, " config -x kernel\n");
|
|
|
|
exit(EX_USAGE);
|
1997-09-15 06:37:10 +00:00
|
|
|
}
|
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
/*
|
|
|
|
* get_word
|
|
|
|
* returns EOF on end of file
|
|
|
|
* NULL on end of line
|
|
|
|
* pointer to the word otherwise
|
|
|
|
*/
|
|
|
|
char *
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
get_word(FILE *fp)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
static char line[80];
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
int ch;
|
|
|
|
char *cp;
|
1994-11-17 20:30:01 +00:00
|
|
|
int escaped_nl = 0;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1994-11-17 20:30:01 +00:00
|
|
|
begin:
|
1994-05-26 05:23:31 +00:00
|
|
|
while ((ch = getc(fp)) != EOF)
|
|
|
|
if (ch != ' ' && ch != '\t')
|
|
|
|
break;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
1994-11-17 20:30:01 +00:00
|
|
|
if (ch == '\\'){
|
|
|
|
escaped_nl = 1;
|
|
|
|
goto begin;
|
|
|
|
}
|
1999-04-18 13:36:29 +00:00
|
|
|
if (ch == '\n') {
|
1994-11-17 20:30:01 +00:00
|
|
|
if (escaped_nl){
|
|
|
|
escaped_nl = 0;
|
|
|
|
goto begin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (NULL);
|
1999-04-18 13:36:29 +00:00
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
cp = line;
|
|
|
|
*cp++ = ch;
|
|
|
|
while ((ch = getc(fp)) != EOF) {
|
|
|
|
if (isspace(ch))
|
|
|
|
break;
|
|
|
|
*cp++ = ch;
|
|
|
|
}
|
|
|
|
*cp = 0;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
|
|
|
(void) ungetc(ch, fp);
|
|
|
|
return (line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_quoted_word
|
|
|
|
* like get_word but will accept something in double or single quotes
|
|
|
|
* (to allow embedded spaces).
|
|
|
|
*/
|
|
|
|
char *
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
get_quoted_word(FILE *fp)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
static char line[256];
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
int ch;
|
|
|
|
char *cp;
|
1994-11-17 20:30:01 +00:00
|
|
|
int escaped_nl = 0;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1994-11-17 20:30:01 +00:00
|
|
|
begin:
|
1994-05-26 05:23:31 +00:00
|
|
|
while ((ch = getc(fp)) != EOF)
|
|
|
|
if (ch != ' ' && ch != '\t')
|
|
|
|
break;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
1994-11-17 20:30:01 +00:00
|
|
|
if (ch == '\\'){
|
|
|
|
escaped_nl = 1;
|
|
|
|
goto begin;
|
|
|
|
}
|
1999-04-18 13:36:29 +00:00
|
|
|
if (ch == '\n') {
|
1994-11-17 20:30:01 +00:00
|
|
|
if (escaped_nl){
|
|
|
|
escaped_nl = 0;
|
|
|
|
goto begin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (NULL);
|
1999-04-18 13:36:29 +00:00
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
cp = line;
|
|
|
|
if (ch == '"' || ch == '\'') {
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
int quote = ch;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2013-03-26 23:58:13 +00:00
|
|
|
escaped_nl = 0;
|
1994-05-26 05:23:31 +00:00
|
|
|
while ((ch = getc(fp)) != EOF) {
|
2013-03-26 23:58:13 +00:00
|
|
|
if (ch == quote && !escaped_nl)
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
2013-03-26 23:58:13 +00:00
|
|
|
if (ch == '\n' && !escaped_nl) {
|
1994-05-26 05:23:31 +00:00
|
|
|
*cp = 0;
|
|
|
|
printf("config: missing quote reading `%s'\n",
|
|
|
|
line);
|
|
|
|
exit(2);
|
|
|
|
}
|
2013-03-26 23:58:13 +00:00
|
|
|
if (ch == '\\' && !escaped_nl) {
|
|
|
|
escaped_nl = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch != quote && escaped_nl)
|
|
|
|
*cp++ = '\\';
|
1994-05-26 05:23:31 +00:00
|
|
|
*cp++ = ch;
|
2013-03-26 23:58:13 +00:00
|
|
|
escaped_nl = 0;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*cp++ = ch;
|
|
|
|
while ((ch = getc(fp)) != EOF) {
|
|
|
|
if (isspace(ch))
|
|
|
|
break;
|
|
|
|
*cp++ = ch;
|
|
|
|
}
|
|
|
|
if (ch != EOF)
|
|
|
|
(void) ungetc(ch, fp);
|
|
|
|
}
|
|
|
|
*cp = 0;
|
|
|
|
if (ch == EOF)
|
|
|
|
return ((char *)EOF);
|
|
|
|
return (line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prepend the path to a filename
|
|
|
|
*/
|
|
|
|
char *
|
2001-02-19 04:43:21 +00:00
|
|
|
path(const char *file)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2000-11-21 19:58:55 +00:00
|
|
|
char *cp = NULL;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2000-11-21 19:58:55 +00:00
|
|
|
if (file)
|
|
|
|
asprintf(&cp, "%s/%s", destdir, file);
|
|
|
|
else
|
|
|
|
cp = strdup(destdir);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (cp);
|
|
|
|
}
|
1996-01-12 08:57:10 +00:00
|
|
|
|
2007-05-12 19:38:18 +00:00
|
|
|
/*
|
|
|
|
* Generate configuration file based on actual settings. With this mode, user
|
|
|
|
* will be able to obtain and build conifguration file with one command.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
configfile_dynamic(struct sbuf *sb)
|
|
|
|
{
|
|
|
|
struct cputype *cput;
|
|
|
|
struct device *d;
|
|
|
|
struct opt *ol;
|
|
|
|
char *lend;
|
2007-05-12 22:37:52 +00:00
|
|
|
unsigned int i;
|
2007-05-12 19:38:18 +00:00
|
|
|
|
|
|
|
asprintf(&lend, "\\n\\\n");
|
|
|
|
assert(lend != NULL);
|
|
|
|
sbuf_printf(sb, "options\t%s%s", OPT_AUTOGEN, lend);
|
|
|
|
sbuf_printf(sb, "ident\t%s%s", ident, lend);
|
|
|
|
sbuf_printf(sb, "machine\t%s%s", machinename, lend);
|
|
|
|
SLIST_FOREACH(cput, &cputype, cpu_next)
|
|
|
|
sbuf_printf(sb, "cpu\t%s%s", cput->cpu_name, lend);
|
|
|
|
SLIST_FOREACH(ol, &mkopt, op_next)
|
|
|
|
sbuf_printf(sb, "makeoptions\t%s=%s%s", ol->op_name,
|
|
|
|
ol->op_value, lend);
|
|
|
|
SLIST_FOREACH(ol, &opt, op_next) {
|
|
|
|
if (strncmp(ol->op_name, "DEV_", 4) == 0)
|
|
|
|
continue;
|
|
|
|
sbuf_printf(sb, "options\t%s", ol->op_name);
|
|
|
|
if (ol->op_value != NULL) {
|
2007-05-12 22:37:52 +00:00
|
|
|
sbuf_putc(sb, '=');
|
|
|
|
for (i = 0; i < strlen(ol->op_value); i++) {
|
|
|
|
if (ol->op_value[i] == '"')
|
|
|
|
sbuf_printf(sb, "\\%c",
|
|
|
|
ol->op_value[i]);
|
|
|
|
else
|
|
|
|
sbuf_printf(sb, "%c",
|
|
|
|
ol->op_value[i]);
|
|
|
|
}
|
|
|
|
sbuf_printf(sb, "%s", lend);
|
2007-05-12 19:38:18 +00:00
|
|
|
} else {
|
|
|
|
sbuf_printf(sb, "%s", lend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Mark this file as containing everything we need.
|
|
|
|
*/
|
|
|
|
STAILQ_FOREACH(d, &dtab, d_next)
|
|
|
|
sbuf_printf(sb, "device\t%s%s", d->d_name, lend);
|
|
|
|
free(lend);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate file from the configuration files.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
configfile_filebased(struct sbuf *sb)
|
|
|
|
{
|
|
|
|
FILE *cff;
|
|
|
|
struct cfgfile *cf;
|
|
|
|
int i;
|
|
|
|
|
2009-02-07 11:40:47 +00:00
|
|
|
/*
|
|
|
|
* Try to read all configuration files. Since those will be present as
|
|
|
|
* C string in the macro, we have to slash their ends then the line
|
|
|
|
* wraps.
|
|
|
|
*/
|
2007-05-12 19:38:18 +00:00
|
|
|
STAILQ_FOREACH(cf, &cfgfiles, cfg_next) {
|
|
|
|
cff = fopen(cf->cfg_path, "r");
|
|
|
|
if (cff == NULL) {
|
|
|
|
warn("Couldn't open file %s", cf->cfg_path);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while ((i = getc(cff)) != EOF) {
|
|
|
|
if (i == '\n')
|
|
|
|
sbuf_printf(sb, "\\n\\\n");
|
|
|
|
else if (i == '"' || i == '\'')
|
|
|
|
sbuf_printf(sb, "\\%c", i);
|
|
|
|
else
|
|
|
|
sbuf_putc(sb, i);
|
|
|
|
}
|
|
|
|
fclose(cff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-17 14:41:41 +00:00
|
|
|
static void
|
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the
resource table at boot time.
config(8) no longer generates an ioconf.c table - ie: the configuration
no longer has to be compiled into the kernel. You can reconfigure your
isa devices with the likes of this at loader(8) time:
set hint.ed.0.port=0x320
userconfig will be rewritten to use this style interface one day and will
move to /boot/userconfig.4th or something like that.
It is still possible to statically compile in a set of hints into a kernel
if you do not wish to use loader(8). See the "hints" directive in GENERIC
as an example.
All device wiring has been moved out of config(8). There is a set of
helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98)
that extract the 'at isa? port foo irq bar' from the old files and produces
a hints file. If you install this file as /boot/device.hints (and update
/boot/defaults/loader.conf - You can do a build/install in sys/boot) then
loader will load it automatically for you. You can also compile in the
hints directly with: hints "device.hints" as well.
There are a few things that I'm not too happy with yet. Under this scheme,
things like LINT would no longer be useful as "documentation" of settings.
I have renamed this file to 'NOTES' and stored the example hints strings
in it. However... this is not something that config(8) understands, so
there is a script that extracts the build-specific data from the
documentation file (NOTES) to produce a LINT that can be config'ed and
built. A stack of man4 pages will need updating. :-/
Also, since there is no longer a difference between 'device' and
'pseudo-device' I collapsed the two together, and the resulting 'device'
takes a 'number of units' for devices that still have it statically
allocated. eg: 'device fe 4' will compile the fe driver with NFE set
to 4. You can then set hints for 4 units (0 - 3). Also note that
'device fe0' will be interpreted as "zero units of 'fe'" which would be
bad, so there is a config warning for this. This is only needed for
old drivers that still have static limits on numbers of units.
All the statically limited drivers that I could find were marked.
Please exercise EXTREME CAUTION when transitioning!
Moral support by: phk, msmith, dfr, asmodai, imp, and others
2000-06-13 22:28:50 +00:00
|
|
|
configfile(void)
|
1996-06-08 23:27:16 +00:00
|
|
|
{
|
2007-05-12 19:38:18 +00:00
|
|
|
FILE *fo;
|
|
|
|
struct sbuf *sb;
|
1996-06-08 23:27:16 +00:00
|
|
|
char *p;
|
2007-05-12 19:38:18 +00:00
|
|
|
|
|
|
|
/* Add main configuration file to the list of files to be included */
|
|
|
|
cfgfile_add(PREFIX);
|
|
|
|
p = path("config.c.new");
|
|
|
|
fo = fopen(p, "w");
|
Further cleanup. Also remove the following unused or defunct tokens:
and, bio, cam, master, minor, net, priority, sequential, size, slave, trace
1999-10-10 17:36:11 +00:00
|
|
|
if (!fo)
|
1997-09-15 06:37:10 +00:00
|
|
|
err(2, "%s", p);
|
2007-05-12 19:38:18 +00:00
|
|
|
sb = sbuf_new(NULL, NULL, 2048, SBUF_AUTOEXTEND);
|
|
|
|
assert(sb != NULL);
|
|
|
|
sbuf_clear(sb);
|
|
|
|
if (filebased) {
|
|
|
|
/* Is needed, can be used for backward compatibility. */
|
|
|
|
configfile_filebased(sb);
|
|
|
|
} else {
|
|
|
|
configfile_dynamic(sb);
|
1996-06-08 23:27:16 +00:00
|
|
|
}
|
2007-05-12 19:38:18 +00:00
|
|
|
sbuf_finish(sb);
|
|
|
|
/*
|
2010-03-30 13:46:40 +00:00
|
|
|
* We print first part of the template, replace our tag with
|
2007-05-12 19:38:18 +00:00
|
|
|
* configuration files content and later continue writing our
|
|
|
|
* template.
|
|
|
|
*/
|
|
|
|
p = strstr(kernconfstr, KERNCONFTAG);
|
|
|
|
if (p == NULL)
|
|
|
|
errx(EXIT_FAILURE, "Something went terribly wrong!");
|
|
|
|
*p = '\0';
|
|
|
|
fprintf(fo, "%s", kernconfstr);
|
|
|
|
fprintf(fo, "%s", sbuf_data(sb));
|
|
|
|
p += strlen(KERNCONFTAG);
|
|
|
|
fprintf(fo, "%s", p);
|
|
|
|
sbuf_delete(sb);
|
1996-06-08 23:27:16 +00:00
|
|
|
fclose(fo);
|
1996-12-26 23:40:32 +00:00
|
|
|
moveifchanged(path("config.c.new"), path("config.c"));
|
2007-05-12 19:38:18 +00:00
|
|
|
cfgfile_removeall();
|
1996-06-08 23:27:16 +00:00
|
|
|
}
|
|
|
|
|
1996-01-12 08:57:10 +00:00
|
|
|
/*
|
|
|
|
* moveifchanged --
|
|
|
|
* compare two files; rename if changed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
moveifchanged(const char *from_name, const char *to_name)
|
|
|
|
{
|
|
|
|
char *p, *q;
|
|
|
|
int changed;
|
|
|
|
size_t tsize;
|
|
|
|
struct stat from_sb, to_sb;
|
|
|
|
int from_fd, to_fd;
|
|
|
|
|
|
|
|
changed = 0;
|
|
|
|
|
|
|
|
if ((from_fd = open(from_name, O_RDONLY)) < 0)
|
|
|
|
err(EX_OSERR, "moveifchanged open(%s)", from_name);
|
|
|
|
|
|
|
|
if ((to_fd = open(to_name, O_RDONLY)) < 0)
|
|
|
|
changed++;
|
|
|
|
|
|
|
|
if (!changed && fstat(from_fd, &from_sb) < 0)
|
|
|
|
err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
|
|
|
|
|
|
|
|
if (!changed && fstat(to_fd, &to_sb) < 0)
|
|
|
|
err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
|
|
|
|
|
|
|
|
if (!changed && from_sb.st_size != to_sb.st_size)
|
|
|
|
changed++;
|
|
|
|
|
|
|
|
tsize = (size_t)from_sb.st_size;
|
|
|
|
|
|
|
|
if (!changed) {
|
1997-01-16 21:58:40 +00:00
|
|
|
p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0);
|
|
|
|
if (p == MAP_FAILED)
|
1996-01-12 08:57:10 +00:00
|
|
|
err(EX_OSERR, "mmap %s", from_name);
|
1997-01-16 21:58:40 +00:00
|
|
|
q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0);
|
|
|
|
if (q == MAP_FAILED)
|
1996-01-12 08:57:10 +00:00
|
|
|
err(EX_OSERR, "mmap %s", to_name);
|
|
|
|
|
|
|
|
changed = memcmp(p, q, tsize);
|
|
|
|
munmap(p, tsize);
|
|
|
|
munmap(q, tsize);
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
if (rename(from_name, to_name) < 0)
|
|
|
|
err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
|
|
|
|
} else {
|
|
|
|
if (unlink(from_name) < 0)
|
1997-11-18 03:41:51 +00:00
|
|
|
err(EX_OSERR, "unlink(%s)", from_name);
|
1996-01-12 08:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-29 09:34:43 +00:00
|
|
|
|
|
|
|
static void
|
2001-01-31 08:42:35 +00:00
|
|
|
cleanheaders(char *p)
|
2001-01-29 09:34:43 +00:00
|
|
|
{
|
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
|
|
|
struct file_list *fl;
|
2001-01-31 08:42:35 +00:00
|
|
|
struct hdr_list *hl;
|
2011-07-03 20:59:57 +00:00
|
|
|
size_t len;
|
2001-01-29 09:34:43 +00:00
|
|
|
|
2001-01-31 08:42:35 +00:00
|
|
|
remember("y.tab.h");
|
|
|
|
remember("setdefs.h");
|
2003-02-15 02:26:13 +00:00
|
|
|
STAILQ_FOREACH(fl, &ftab, f_next)
|
2001-01-31 08:42:35 +00:00
|
|
|
remember(fl->f_fn);
|
2001-01-29 09:34:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the build directory and clean out stuff that looks like
|
|
|
|
* it might have been a leftover NFOO header, etc.
|
|
|
|
*/
|
2003-06-12 11:36:54 +00:00
|
|
|
if ((dirp = opendir(p)) == NULL)
|
|
|
|
err(EX_OSERR, "opendir %s", p);
|
2001-01-29 09:34:43 +00:00
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
2011-07-03 20:59:57 +00:00
|
|
|
len = strlen(dp->d_name);
|
2001-01-29 09:34:43 +00:00
|
|
|
/* Skip non-headers */
|
2011-07-03 20:59:57 +00:00
|
|
|
if (len < 2 || dp->d_name[len - 2] != '.' ||
|
|
|
|
dp->d_name[len - 1] != 'h')
|
2001-01-29 09:34:43 +00:00
|
|
|
continue;
|
|
|
|
/* Skip special stuff, eg: bus_if.h, but check opt_*.h */
|
2011-07-03 20:59:57 +00:00
|
|
|
if (strchr(dp->d_name, '_') &&
|
2001-01-29 09:34:43 +00:00
|
|
|
strncmp(dp->d_name, "opt_", 4) != 0)
|
|
|
|
continue;
|
|
|
|
/* Check if it is a target file */
|
2001-01-31 08:42:35 +00:00
|
|
|
for (hl = htab; hl != NULL; hl = hl->h_next) {
|
2005-11-30 17:55:49 +00:00
|
|
|
if (eq(dp->d_name, hl->h_name)) {
|
2001-01-29 09:34:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-01-31 08:42:35 +00:00
|
|
|
if (hl)
|
2001-01-29 09:34:43 +00:00
|
|
|
continue;
|
|
|
|
printf("Removing stale header: %s\n", dp->d_name);
|
2003-06-12 11:36:54 +00:00
|
|
|
if (unlink(path(dp->d_name)) == -1)
|
|
|
|
warn("unlink %s", dp->d_name);
|
2001-01-29 09:34:43 +00:00
|
|
|
}
|
|
|
|
(void)closedir(dirp);
|
2001-01-31 08:42:35 +00:00
|
|
|
}
|
2001-01-29 09:34:43 +00:00
|
|
|
|
2001-01-31 08:42:35 +00:00
|
|
|
void
|
2001-02-19 04:43:21 +00:00
|
|
|
remember(const char *file)
|
2001-01-31 08:42:35 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
struct hdr_list *hl;
|
|
|
|
|
|
|
|
if ((s = strrchr(file, '/')) != NULL)
|
2001-02-19 04:43:21 +00:00
|
|
|
s = ns(s + 1);
|
2001-01-31 08:42:35 +00:00
|
|
|
else
|
2001-02-19 04:43:21 +00:00
|
|
|
s = ns(file);
|
2001-01-31 08:42:35 +00:00
|
|
|
|
2012-01-03 18:51:58 +00:00
|
|
|
if (strchr(s, '_') && strncmp(s, "opt_", 4) != 0) {
|
2001-01-31 08:42:35 +00:00
|
|
|
free(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (hl = htab; hl != NULL; hl = hl->h_next) {
|
2005-11-30 17:55:49 +00:00
|
|
|
if (eq(s, hl->h_name)) {
|
2001-01-31 08:42:35 +00:00
|
|
|
free(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-06-07 01:43:26 +00:00
|
|
|
hl = calloc(1, sizeof(*hl));
|
2010-03-30 13:46:40 +00:00
|
|
|
if (hl == NULL)
|
|
|
|
err(EXIT_FAILURE, "calloc");
|
2001-01-31 08:42:35 +00:00
|
|
|
hl->h_name = s;
|
|
|
|
hl->h_next = htab;
|
|
|
|
htab = hl;
|
2001-01-29 09:34:43 +00:00
|
|
|
}
|
2007-05-12 19:38:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This one is quick hack. Will be probably moved to elf(3) interface.
|
|
|
|
* It takes kernel configuration file name, passes it as an argument to
|
|
|
|
* elfdump -a, which output is parsed by some UNIX tools...
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
kernconfdump(const char *file)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
FILE *fp, *pp;
|
|
|
|
int error, len, osz, r;
|
2010-05-01 07:25:28 +00:00
|
|
|
unsigned int i, off, size, t1, t2, align;
|
2007-05-12 19:38:18 +00:00
|
|
|
char *cmd, *o;
|
|
|
|
|
|
|
|
r = open(file, O_RDONLY);
|
|
|
|
if (r == -1)
|
2010-03-30 13:46:40 +00:00
|
|
|
err(EXIT_FAILURE, "Couldn't open file '%s'", file);
|
2007-05-12 19:38:18 +00:00
|
|
|
error = fstat(r, &st);
|
|
|
|
if (error == -1)
|
2010-03-30 13:46:40 +00:00
|
|
|
err(EXIT_FAILURE, "fstat() failed");
|
2007-05-12 19:38:18 +00:00
|
|
|
if (S_ISDIR(st.st_mode))
|
|
|
|
errx(EXIT_FAILURE, "'%s' is a directory", file);
|
|
|
|
fp = fdopen(r, "r");
|
|
|
|
if (fp == NULL)
|
2010-03-30 13:46:40 +00:00
|
|
|
err(EXIT_FAILURE, "fdopen() failed");
|
2007-05-12 19:38:18 +00:00
|
|
|
osz = 1024;
|
|
|
|
o = calloc(1, osz);
|
|
|
|
if (o == NULL)
|
2010-03-30 13:46:40 +00:00
|
|
|
err(EXIT_FAILURE, "Couldn't allocate memory");
|
2007-05-12 19:38:18 +00:00
|
|
|
/* ELF note section header. */
|
2010-05-01 07:25:28 +00:00
|
|
|
asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 8 kern_conf"
|
|
|
|
"| tail -5 | cut -d ' ' -f 2 | paste - - - - -", file);
|
2007-05-12 19:38:18 +00:00
|
|
|
if (cmd == NULL)
|
|
|
|
errx(EXIT_FAILURE, "asprintf() failed");
|
|
|
|
pp = popen(cmd, "r");
|
|
|
|
if (pp == NULL)
|
|
|
|
errx(EXIT_FAILURE, "popen() failed");
|
|
|
|
free(cmd);
|
|
|
|
len = fread(o, osz, 1, pp);
|
|
|
|
pclose(pp);
|
2010-05-01 07:25:28 +00:00
|
|
|
r = sscanf(o, "%d%d%d%d%d", &off, &size, &t1, &t2, &align);
|
2007-05-12 19:38:18 +00:00
|
|
|
free(o);
|
2010-05-01 07:25:28 +00:00
|
|
|
if (r != 5)
|
2007-05-12 19:38:18 +00:00
|
|
|
errx(EXIT_FAILURE, "File %s doesn't contain configuration "
|
|
|
|
"file. Either unsupported, or not compiled with "
|
|
|
|
"INCLUDE_CONFIG_FILE", file);
|
|
|
|
r = fseek(fp, off, SEEK_CUR);
|
|
|
|
if (r != 0)
|
2010-03-30 13:46:40 +00:00
|
|
|
err(EXIT_FAILURE, "fseek() failed");
|
2010-05-01 07:25:28 +00:00
|
|
|
for (i = 0; i < size; i++) {
|
2009-02-06 00:50:21 +00:00
|
|
|
r = fgetc(fp);
|
|
|
|
if (r == EOF)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* If '\0' is present in the middle of the configuration
|
|
|
|
* string, this means something very weird is happening.
|
2010-05-01 07:25:28 +00:00
|
|
|
* Make such case very visible. However, some architectures
|
|
|
|
* pad the length of the section with NULs to a multiple of
|
|
|
|
* sh_addralign, allow a NUL in that part of the section.
|
2009-02-06 00:50:21 +00:00
|
|
|
*/
|
2010-05-01 07:25:28 +00:00
|
|
|
if (r == '\0' && (size - i) < align)
|
|
|
|
break;
|
2009-02-06 00:50:21 +00:00
|
|
|
assert(r != '\0' && ("Char present in the configuration "
|
|
|
|
"string mustn't be equal to 0"));
|
2007-05-12 19:38:18 +00:00
|
|
|
fputc(r, stdout);
|
2009-02-06 00:50:21 +00:00
|
|
|
}
|
2007-05-12 19:38:18 +00:00
|
|
|
fclose(fp);
|
|
|
|
}
|
2010-04-27 05:04:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
badversion(int versreq)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
|
|
|
|
fprintf(stderr, "config version = %d, ", CONFIGVERS);
|
|
|
|
fprintf(stderr, "version required = %d\n\n", versreq);
|
|
|
|
fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
|
|
|
|
fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
|
|
|
|
fprintf(stderr, "before trying this again.\n\n");
|
|
|
|
fprintf(stderr, "If running the new config fails check your config\n");
|
|
|
|
fprintf(stderr, "file against the GENERIC or LINT config files for\n");
|
|
|
|
fprintf(stderr, "changes in config syntax, or option/device naming\n");
|
|
|
|
fprintf(stderr, "conventions\n\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
checkversion(void)
|
|
|
|
{
|
|
|
|
FILE *ifp;
|
|
|
|
char line[BUFSIZ];
|
|
|
|
int versreq;
|
|
|
|
|
|
|
|
ifp = open_makefile_template();
|
|
|
|
while (fgets(line, BUFSIZ, ifp) != 0) {
|
|
|
|
if (*line != '%')
|
|
|
|
continue;
|
|
|
|
if (strncmp(line, "%VERSREQ=", 9) != 0)
|
|
|
|
continue;
|
|
|
|
versreq = atoi(line + 9);
|
|
|
|
if (MAJOR_VERS(versreq) == MAJOR_VERS(CONFIGVERS) &&
|
|
|
|
versreq <= CONFIGVERS)
|
|
|
|
continue;
|
|
|
|
badversion(versreq);
|
|
|
|
}
|
|
|
|
fclose(ifp);
|
|
|
|
}
|