several clean ups:
- don't include eeprom support on sparc64. - work out if we are eeprom or openprom from the results of open() and/or ioctl(), rather than grovelling the kernel. - move all eeprom specific code to eehandlers.c - update manpage for sparc64 usage, remove delete -N switch with these changes, eeprom(8) no longer needs to be setgid.
This commit is contained in:
parent
aa77dea4c2
commit
6ce96c999f
@ -1,5 +1,5 @@
|
||||
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
|
||||
# $NetBSD: Makefile,v 1.8 1999/01/17 20:02:29 eeh Exp $
|
||||
# $NetBSD: Makefile,v 1.9 2000/11/28 22:31:37 mrg Exp $
|
||||
|
||||
.if ${MACHINE} == "sun3" || ${MACHINE} == "sun3x" || ${MACHINE} == "sparc" \
|
||||
|| ${MACHINE} == "sparc64"
|
||||
@ -7,16 +7,15 @@ PROG= eeprom
|
||||
|
||||
YPREFIX=getdate_
|
||||
|
||||
BINGRP= kmem
|
||||
BINMODE=2555
|
||||
|
||||
SRCS= eehandlers.c getdate.y main.c
|
||||
SRCS= getdate.y main.c
|
||||
|
||||
.if ${MACHINE} == "sparc" || ${MACHINE} == "sparc64"
|
||||
SRCS+= ophandlers.c
|
||||
DPADD= ${LIBKVM}
|
||||
LDADD= -lkvm
|
||||
.endif
|
||||
.if ${MACHINE} != "sparc64"
|
||||
SRCS+= eehandlers.c
|
||||
.endif
|
||||
|
||||
.endif
|
||||
|
||||
MAN= eeprom.8
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: defs.h,v 1.5 2000/11/19 11:15:01 mrg Exp $ */
|
||||
/* $NetBSD: defs.h,v 1.6 2000/11/28 22:31:37 mrg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
@ -94,6 +94,8 @@ struct timeb;
|
||||
time_t get_date (char *, struct timeb *);
|
||||
|
||||
/* Sun 3/4 EEPROM handlers. */
|
||||
void ee_action (char *, char *);
|
||||
void ee_dump (void);
|
||||
void ee_hwupdate (struct keytabent *, char *);
|
||||
void ee_num8 (struct keytabent *, char *);
|
||||
void ee_num16 (struct keytabent *, char *);
|
||||
@ -114,5 +116,7 @@ void ee_verifychecksums (void);
|
||||
#ifdef __sparc__
|
||||
/* Sparc Openprom handlers. */
|
||||
char *op_handler (char *, char *);
|
||||
void op_action (char *, char *);
|
||||
void op_dump (void);
|
||||
int check_for_openprom (void);
|
||||
#endif /* __sparc__ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: eehandlers.c,v 1.8 2000/11/19 11:15:01 mrg Exp $ */
|
||||
/* $NetBSD: eehandlers.c,v 1.9 2000/11/28 22:31:37 mrg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
@ -71,6 +71,34 @@ static char err_str[BUFSIZE];
|
||||
static void badval (struct keytabent *, char *);
|
||||
static int doio (struct keytabent *, u_char *, ssize_t, int);
|
||||
|
||||
struct keytabent eekeytab[] = {
|
||||
{ "hwupdate", 0x10, ee_hwupdate },
|
||||
{ "memsize", 0x14, ee_num8 },
|
||||
{ "memtest", 0x15, ee_num8 },
|
||||
{ "scrsize", 0x16, ee_screensize },
|
||||
{ "watchdog_reboot", 0x17, ee_truefalse },
|
||||
{ "default_boot", 0x18, ee_truefalse },
|
||||
{ "bootdev", 0x19, ee_bootdev },
|
||||
{ "kbdtype", 0x1e, ee_kbdtype },
|
||||
{ "console", 0x1f, ee_constype },
|
||||
{ "keyclick", 0x21, ee_truefalse },
|
||||
{ "diagdev", 0x22, ee_bootdev },
|
||||
{ "diagpath", 0x28, ee_diagpath },
|
||||
{ "columns", 0x50, ee_num8 },
|
||||
{ "rows", 0x51, ee_num8 },
|
||||
{ "ttya_use_baud", 0x58, ee_truefalse },
|
||||
{ "ttya_baud", 0x59, ee_num16 },
|
||||
{ "ttya_no_rtsdtr", 0x5b, ee_truefalse },
|
||||
{ "ttyb_use_baud", 0x60, ee_truefalse },
|
||||
{ "ttyb_baud", 0x61, ee_num16 },
|
||||
{ "ttyb_no_rtsdtr", 0x63, ee_truefalse },
|
||||
{ "banner", 0x68, ee_banner },
|
||||
{ "secure", 0, ee_notsupp },
|
||||
{ "bad_login", 0, ee_notsupp },
|
||||
{ "password", 0, ee_notsupp },
|
||||
{ NULL, 0, ee_notsupp },
|
||||
};
|
||||
|
||||
#define BARF(kt) { \
|
||||
badval((kt), arg); \
|
||||
++eval; \
|
||||
@ -91,6 +119,32 @@ static int doio (struct keytabent *, u_char *, ssize_t, int);
|
||||
return; \
|
||||
}
|
||||
|
||||
void
|
||||
ee_action(keyword, arg)
|
||||
char *keyword, *arg;
|
||||
{
|
||||
struct keytabent *ktent;
|
||||
|
||||
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent) {
|
||||
if (strcmp(ktent->kt_keyword, keyword) == 0) {
|
||||
(*ktent->kt_handler)(ktent, arg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
warnx("unknown keyword %s", keyword);
|
||||
++eval;
|
||||
}
|
||||
|
||||
void
|
||||
ee_dump()
|
||||
{
|
||||
struct keytabent *ktent;
|
||||
|
||||
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent)
|
||||
(*ktent->kt_handler)(ktent, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
ee_hwupdate(ktent, arg)
|
||||
struct keytabent *ktent;
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: eeprom.8,v 1.4 2000/11/07 06:43:36 lukem Exp $
|
||||
.\" $NetBSD: eeprom.8,v 1.5 2000/11/28 22:31:37 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
@ -34,7 +34,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd May 25, 1995
|
||||
.Dd November 19, 2000
|
||||
.Dt EEPROM 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -51,14 +51,13 @@
|
||||
.Li = Ns Ar value
|
||||
.Oc ...
|
||||
.Oc
|
||||
.Sh SPARC SYNOPSIS
|
||||
.Sh SPARC and SPARC64 SYNOPSIS
|
||||
.Nm ""
|
||||
.Op Fl
|
||||
.Op Fl c
|
||||
.Op Fl f Ar device
|
||||
.Op Fl i
|
||||
.Op Fl v
|
||||
.Op Fl N Ar system
|
||||
.Oo
|
||||
.Ar field Ns Oo
|
||||
.Li = Ns Ar value
|
||||
@ -107,12 +106,11 @@ error when used on a Sun 3:
|
||||
.It Fl v
|
||||
On systems with an OpenProm, be verbose when setting a value. Systems
|
||||
with an EEPROM are always verbose.
|
||||
.It Fl N Ar system
|
||||
Use the system image
|
||||
.Ar system
|
||||
instead of the default
|
||||
.Pa /netbsd .
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Fl v
|
||||
option is also present on sparc64 systems.
|
||||
.Sh FIELDS AND VALUES
|
||||
The following fields and values are for systems with an EEPROM:
|
||||
.Bl -tag -width "watchdog_reboot "
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.11 2000/11/19 11:15:01 mrg Exp $ */
|
||||
/* $NetBSD: main.c,v 1.12 2000/11/28 22:31:37 mrg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
@ -40,7 +40,7 @@
|
||||
#ifndef lint
|
||||
__COPYRIGHT(
|
||||
"@(#) Copyright (c) 1996 The NetBSD Foundation, Inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: main.c,v 1.11 2000/11/19 11:15:01 mrg Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.12 2000/11/28 22:31:37 mrg Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -49,63 +49,25 @@ __RCSID("$NetBSD: main.c,v 1.11 2000/11/19 11:15:01 mrg Exp $");
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __sparc__
|
||||
#include <fcntl.h>
|
||||
#include <kvm.h>
|
||||
#include <limits.h>
|
||||
#include <nlist.h>
|
||||
|
||||
#include <machine/openpromio.h>
|
||||
|
||||
struct nlist nl[] = {
|
||||
{ "_cputyp" },
|
||||
#define SYM_CPUTYP 0
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
static char *system = NULL;
|
||||
#endif /* __sparc__ */
|
||||
|
||||
#include <machine/eeprom.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
struct keytabent eekeytab[] = {
|
||||
{ "hwupdate", 0x10, ee_hwupdate },
|
||||
{ "memsize", 0x14, ee_num8 },
|
||||
{ "memtest", 0x15, ee_num8 },
|
||||
{ "scrsize", 0x16, ee_screensize },
|
||||
{ "watchdog_reboot", 0x17, ee_truefalse },
|
||||
{ "default_boot", 0x18, ee_truefalse },
|
||||
{ "bootdev", 0x19, ee_bootdev },
|
||||
{ "kbdtype", 0x1e, ee_kbdtype },
|
||||
{ "console", 0x1f, ee_constype },
|
||||
{ "keyclick", 0x21, ee_truefalse },
|
||||
{ "diagdev", 0x22, ee_bootdev },
|
||||
{ "diagpath", 0x28, ee_diagpath },
|
||||
{ "columns", 0x50, ee_num8 },
|
||||
{ "rows", 0x51, ee_num8 },
|
||||
{ "ttya_use_baud", 0x58, ee_truefalse },
|
||||
{ "ttya_baud", 0x59, ee_num16 },
|
||||
{ "ttya_no_rtsdtr", 0x5b, ee_truefalse },
|
||||
{ "ttyb_use_baud", 0x60, ee_truefalse },
|
||||
{ "ttyb_baud", 0x61, ee_num16 },
|
||||
{ "ttyb_no_rtsdtr", 0x63, ee_truefalse },
|
||||
{ "banner", 0x68, ee_banner },
|
||||
{ "secure", 0, ee_notsupp },
|
||||
{ "bad_login", 0, ee_notsupp },
|
||||
{ "password", 0, ee_notsupp },
|
||||
{ NULL, 0, ee_notsupp },
|
||||
};
|
||||
#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
|
||||
|
||||
int main (int, char *[]);
|
||||
static void action (char *);
|
||||
static void dump_prom (void);
|
||||
static void usage (void);
|
||||
#ifdef __sparc__
|
||||
static int getcputype (void);
|
||||
#endif /* __sparc__ */
|
||||
|
||||
char *path_eeprom = _PATH_EEPROM;
|
||||
char *path_openprom = _PATH_OPENPROM;
|
||||
@ -115,8 +77,10 @@ int update_checksums = 0;
|
||||
int cksumfail = 0;
|
||||
u_short writecount;
|
||||
int eval = 0;
|
||||
int use_openprom = 0;
|
||||
#ifdef USE_OPENPROM
|
||||
int verbose = 0;
|
||||
int use_openprom;
|
||||
#endif
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
@ -127,11 +91,11 @@ main(argc, argv)
|
||||
{
|
||||
int ch, do_stdin = 0;
|
||||
char *cp, line[BUFSIZE];
|
||||
#ifdef __sparc__
|
||||
char *optstring = "-cf:ivN:";
|
||||
#ifdef USE_OPENPROM
|
||||
char *optstring = "-cf:iv";
|
||||
#else
|
||||
char *optstring = "-cf:i";
|
||||
#endif /* __sparc__ */
|
||||
#endif /* USE_OPENPROM */
|
||||
|
||||
while ((ch = getopt(argc, argv, optstring)) != -1)
|
||||
switch (ch) {
|
||||
@ -150,16 +114,12 @@ main(argc, argv)
|
||||
case 'i':
|
||||
ignore_checksum = 1;
|
||||
break;
|
||||
#ifdef __sparc__
|
||||
|
||||
#ifdef USE_OPENPROM
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
system = optarg;
|
||||
break;
|
||||
|
||||
#endif /* __sparc__ */
|
||||
#endif /* USE_OPENPROM */
|
||||
|
||||
case '?':
|
||||
default:
|
||||
@ -168,16 +128,9 @@ main(argc, argv)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
#ifdef __sparc__
|
||||
/*
|
||||
* Discard setgid setgid privileges if not the running kernel so
|
||||
* that bad guys can't print interesting stuff from kernel memory.
|
||||
*/
|
||||
if (system != NULL)
|
||||
setgid(getgid());
|
||||
if (getcputype() != CPU_SUN4)
|
||||
use_openprom = 1;
|
||||
#endif /* __sparc__ */
|
||||
#ifdef USE_OPENPROM
|
||||
use_openprom = check_for_openprom();
|
||||
#endif /* USE_OPENPROM */
|
||||
|
||||
if (use_openprom == 0) {
|
||||
ee_verifychecksums();
|
||||
@ -208,7 +161,9 @@ main(argc, argv)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_OPENPROM
|
||||
if (use_openprom == 0)
|
||||
#endif /* USE_OPENPROM */
|
||||
if (update_checksums) {
|
||||
++writecount;
|
||||
ee_updatechecksums();
|
||||
@ -217,36 +172,6 @@ main(argc, argv)
|
||||
exit(eval + cksumfail);
|
||||
}
|
||||
|
||||
#ifdef __sparc__
|
||||
#define KVM_ABORT(kd, str) { \
|
||||
(void)kvm_close((kd)); \
|
||||
errx(1, "%s: %s", (str), kvm_geterr((kd))); \
|
||||
}
|
||||
|
||||
static int
|
||||
getcputype()
|
||||
{
|
||||
char errbuf[_POSIX2_LINE_MAX];
|
||||
int cputype;
|
||||
kvm_t *kd;
|
||||
|
||||
memset(errbuf, 0, sizeof(errbuf));
|
||||
|
||||
if ((kd = kvm_openfiles(system, NULL, NULL, O_RDONLY, errbuf)) == NULL)
|
||||
errx(1, "can't open kvm: %s", errbuf);
|
||||
|
||||
if (kvm_nlist(kd, nl))
|
||||
KVM_ABORT(kd, "can't read symbol table");
|
||||
|
||||
if (kvm_read(kd, nl[SYM_CPUTYP].n_value, (char *)&cputype,
|
||||
sizeof(cputype)) != sizeof(cputype))
|
||||
KVM_ABORT(kd, "can't determine cpu type");
|
||||
|
||||
(void)kvm_close(kd);
|
||||
return (cputype);
|
||||
}
|
||||
#endif /* __sparc__ */
|
||||
|
||||
/*
|
||||
* Separate the keyword from the argument (if any), find the keyword in
|
||||
* the table, and call the corresponding handler function.
|
||||
@ -256,35 +181,17 @@ action(line)
|
||||
char *line;
|
||||
{
|
||||
char *keyword, *arg;
|
||||
struct keytabent *ktent;
|
||||
|
||||
keyword = strdup(line);
|
||||
if ((arg = strrchr(keyword, '=')) != NULL)
|
||||
*arg++ = '\0';
|
||||
|
||||
#ifdef __sparc__
|
||||
if (use_openprom) {
|
||||
char *cp;
|
||||
/*
|
||||
* The whole point of the Openprom is that one
|
||||
* isn't required to know the keywords. With this
|
||||
* in mind, we just dump the whole thing off to
|
||||
* the generic op_handler.
|
||||
*/
|
||||
if ((cp = op_handler(keyword, arg)) != NULL)
|
||||
warnx("%s", cp);
|
||||
return;
|
||||
} else
|
||||
#endif /* __sparc__ */
|
||||
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent) {
|
||||
if (strcmp(ktent->kt_keyword, keyword) == 0) {
|
||||
(*ktent->kt_handler)(ktent, arg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
warnx("unknown keyword %s", keyword);
|
||||
++eval;
|
||||
#ifdef USE_OPENPROM
|
||||
if (use_openprom)
|
||||
op_action(keyword, arg);
|
||||
else
|
||||
#endif /* USE_OPENPROM */
|
||||
ee_action(keyword, arg);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -293,31 +200,28 @@ action(line)
|
||||
static void
|
||||
dump_prom()
|
||||
{
|
||||
struct keytabent *ktent;
|
||||
|
||||
#ifdef __sparc__
|
||||
if (use_openprom) {
|
||||
#ifdef USE_OPENPROM
|
||||
if (use_openprom)
|
||||
/*
|
||||
* We have a special dump routine for this.
|
||||
*/
|
||||
op_dump();
|
||||
} else
|
||||
#endif /* __sparc__ */
|
||||
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent)
|
||||
(*ktent->kt_handler)(ktent, NULL);
|
||||
else
|
||||
#endif /* USE_OPENPROM */
|
||||
ee_dump();
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
#ifdef __sparc__
|
||||
fprintf(stderr, "usage: %s %s %s\n", __progname,
|
||||
"[-] [-c] [-f device] [-i] [-v]",
|
||||
"[-N system] [field[=value] ...]");
|
||||
#ifdef USE_OPENPROM
|
||||
fprintf(stderr, "usage: %s %s\n", __progname,
|
||||
"[-] [-c] [-f device] [-i] [-v] [field[=value] ...]");
|
||||
#else
|
||||
fprintf(stderr, "usage: %s %s\n", __progname,
|
||||
"[-] [-c] [-f device] [-i] [field[=value] ...]");
|
||||
#endif /* __sparc__ */
|
||||
#endif /* __us */
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ophandlers.c,v 1.7 2000/11/19 11:15:01 mrg Exp $ */
|
||||
/* $NetBSD: ophandlers.c,v 1.8 2000/11/28 22:31:37 mrg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
@ -76,6 +76,35 @@ static struct extabent opextab[] = {
|
||||
return (err_str); \
|
||||
};
|
||||
|
||||
void
|
||||
op_action(keyword, arg)
|
||||
char *keyword, *arg;
|
||||
{
|
||||
char *cp;
|
||||
|
||||
if ((cp = op_handler(keyword, arg)) != NULL)
|
||||
warnx("%s", cp);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(__sparc__) && !defined(__arch64__)
|
||||
int
|
||||
check_for_openprom()
|
||||
{
|
||||
int fd, rv, optnode;
|
||||
|
||||
/* if we can't open it, obviously we can't use it. */
|
||||
if ((fd = open(path_openprom, O_RDONLY)) < 0)
|
||||
return (0);
|
||||
|
||||
/* check for the presence of OpenFirmware with OPIOCGETOPTNODE */
|
||||
rv = ioctl(fd, OPIOCGETOPTNODE, (char *)&optnode);
|
||||
close (fd);
|
||||
|
||||
return (rv == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *
|
||||
op_handler(keyword, arg)
|
||||
char *keyword, *arg;
|
||||
|
Loading…
Reference in New Issue
Block a user