2000-11-29 01:31:37 +03:00
|
|
|
/* $NetBSD: main.c,v 1.12 2000/11/28 22:31:37 mrg Exp $ */
|
1995-07-13 22:07:19 +04:00
|
|
|
|
1996-02-28 04:13:20 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
1995-07-13 22:07:19 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1996-02-28 04:13:20 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
1995-07-13 22:07:19 +04:00
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1996-02-28 04:13:20 +03:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1995-07-13 22:07:19 +04:00
|
|
|
*
|
1996-02-28 04:13:20 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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
|
1997-07-31 02:53:50 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1996-02-28 04:13:20 +03:00
|
|
|
* 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.
|
1995-07-13 22:07:19 +04:00
|
|
|
*/
|
|
|
|
|
1997-07-24 00:58:36 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
|
|
|
__COPYRIGHT(
|
|
|
|
"@(#) Copyright (c) 1996 The NetBSD Foundation, Inc. All rights reserved.");
|
2000-11-29 01:31:37 +03:00
|
|
|
__RCSID("$NetBSD: main.c,v 1.12 2000/11/28 22:31:37 mrg Exp $");
|
1997-07-24 00:58:36 +04:00
|
|
|
#endif
|
|
|
|
|
1995-07-13 22:07:19 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <machine/eeprom.h>
|
|
|
|
|
|
|
|
#include "defs.h"
|
2000-09-24 13:45:55 +04:00
|
|
|
#include "pathnames.h"
|
1995-07-13 22:07:19 +04:00
|
|
|
|
2000-11-29 01:31:37 +03:00
|
|
|
#if defined(__sparc__)
|
|
|
|
# define USE_OPENPROM
|
|
|
|
# if defined(__arch64__)
|
|
|
|
# define ee_action(a,b)
|
|
|
|
# define ee_dump()
|
|
|
|
# define ee_updatechecksums() (void)0
|
|
|
|
# define check_for_openprom() 1
|
|
|
|
# endif
|
|
|
|
#endif
|
1995-07-13 22:07:19 +04:00
|
|
|
|
2000-11-19 14:15:01 +03:00
|
|
|
int main (int, char *[]);
|
|
|
|
static void action (char *);
|
|
|
|
static void dump_prom (void);
|
|
|
|
static void usage (void);
|
1995-07-13 22:07:19 +04:00
|
|
|
|
2000-09-24 13:45:55 +04:00
|
|
|
char *path_eeprom = _PATH_EEPROM;
|
|
|
|
char *path_openprom = _PATH_OPENPROM;
|
1995-07-13 22:07:19 +04:00
|
|
|
int fix_checksum = 0;
|
|
|
|
int ignore_checksum = 0;
|
|
|
|
int update_checksums = 0;
|
|
|
|
int cksumfail = 0;
|
|
|
|
u_short writecount;
|
|
|
|
int eval = 0;
|
2000-11-29 01:31:37 +03:00
|
|
|
#ifdef USE_OPENPROM
|
1995-07-13 22:07:19 +04:00
|
|
|
int verbose = 0;
|
2000-11-29 01:31:37 +03:00
|
|
|
int use_openprom;
|
|
|
|
#endif
|
1995-07-13 22:07:19 +04:00
|
|
|
|
|
|
|
extern char *__progname;
|
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
1997-07-24 00:58:36 +04:00
|
|
|
char *argv[];
|
1995-07-13 22:07:19 +04:00
|
|
|
{
|
|
|
|
int ch, do_stdin = 0;
|
|
|
|
char *cp, line[BUFSIZE];
|
2000-11-29 01:31:37 +03:00
|
|
|
#ifdef USE_OPENPROM
|
|
|
|
char *optstring = "-cf:iv";
|
1995-07-13 22:07:19 +04:00
|
|
|
#else
|
|
|
|
char *optstring = "-cf:i";
|
2000-11-29 01:31:37 +03:00
|
|
|
#endif /* USE_OPENPROM */
|
1995-07-13 22:07:19 +04:00
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, optstring)) != -1)
|
|
|
|
switch (ch) {
|
|
|
|
case '-':
|
|
|
|
do_stdin = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
fix_checksum = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
path_eeprom = path_openprom = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
ignore_checksum = 1;
|
|
|
|
break;
|
2000-11-29 01:31:37 +03:00
|
|
|
|
|
|
|
#ifdef USE_OPENPROM
|
1995-07-13 22:07:19 +04:00
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
2000-11-29 01:31:37 +03:00
|
|
|
#endif /* USE_OPENPROM */
|
1995-07-13 22:07:19 +04:00
|
|
|
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2000-11-29 01:31:37 +03:00
|
|
|
#ifdef USE_OPENPROM
|
|
|
|
use_openprom = check_for_openprom();
|
|
|
|
#endif /* USE_OPENPROM */
|
1995-07-13 22:07:19 +04:00
|
|
|
|
|
|
|
if (use_openprom == 0) {
|
|
|
|
ee_verifychecksums();
|
|
|
|
if (fix_checksum || cksumfail)
|
|
|
|
exit(cksumfail);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_stdin) {
|
|
|
|
while (fgets(line, BUFSIZE, stdin) != NULL) {
|
|
|
|
if (line[0] == '\n')
|
|
|
|
continue;
|
|
|
|
if ((cp = strrchr(line, '\n')) != NULL)
|
|
|
|
*cp = '\0';
|
|
|
|
action(line);
|
|
|
|
}
|
|
|
|
if (ferror(stdin))
|
|
|
|
err(++eval, "stdin");
|
|
|
|
} else {
|
|
|
|
if (argc == 0) {
|
|
|
|
dump_prom();
|
|
|
|
exit(eval + cksumfail);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (argc) {
|
1996-05-16 20:00:55 +04:00
|
|
|
action(*argv);
|
1995-07-13 22:07:19 +04:00
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-29 01:31:37 +03:00
|
|
|
#ifdef USE_OPENPROM
|
1995-07-13 22:07:19 +04:00
|
|
|
if (use_openprom == 0)
|
2000-11-29 01:31:37 +03:00
|
|
|
#endif /* USE_OPENPROM */
|
1995-07-13 22:07:19 +04:00
|
|
|
if (update_checksums) {
|
|
|
|
++writecount;
|
|
|
|
ee_updatechecksums();
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(eval + cksumfail);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Separate the keyword from the argument (if any), find the keyword in
|
|
|
|
* the table, and call the corresponding handler function.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
action(line)
|
|
|
|
char *line;
|
|
|
|
{
|
1997-07-28 23:29:54 +04:00
|
|
|
char *keyword, *arg;
|
1995-07-13 22:07:19 +04:00
|
|
|
|
|
|
|
keyword = strdup(line);
|
|
|
|
if ((arg = strrchr(keyword, '=')) != NULL)
|
|
|
|
*arg++ = '\0';
|
|
|
|
|
2000-11-29 01:31:37 +03:00
|
|
|
#ifdef USE_OPENPROM
|
|
|
|
if (use_openprom)
|
|
|
|
op_action(keyword, arg);
|
|
|
|
else
|
|
|
|
#endif /* USE_OPENPROM */
|
|
|
|
ee_action(keyword, arg);
|
1995-07-13 22:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump the contents of the prom corresponding to all known keywords.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dump_prom()
|
|
|
|
{
|
|
|
|
|
2000-11-29 01:31:37 +03:00
|
|
|
#ifdef USE_OPENPROM
|
|
|
|
if (use_openprom)
|
1995-07-13 22:07:19 +04:00
|
|
|
/*
|
|
|
|
* We have a special dump routine for this.
|
|
|
|
*/
|
|
|
|
op_dump();
|
2000-11-29 01:31:37 +03:00
|
|
|
else
|
|
|
|
#endif /* USE_OPENPROM */
|
|
|
|
ee_dump();
|
1995-07-13 22:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
|
2000-11-29 01:31:37 +03:00
|
|
|
#ifdef USE_OPENPROM
|
|
|
|
fprintf(stderr, "usage: %s %s\n", __progname,
|
|
|
|
"[-] [-c] [-f device] [-i] [-v] [field[=value] ...]");
|
1995-07-13 22:07:19 +04:00
|
|
|
#else
|
|
|
|
fprintf(stderr, "usage: %s %s\n", __progname,
|
|
|
|
"[-] [-c] [-f device] [-i] [field[=value] ...]");
|
2000-11-29 01:31:37 +03:00
|
|
|
#endif /* __us */
|
1995-07-13 22:07:19 +04:00
|
|
|
exit(1);
|
|
|
|
}
|