Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/eeprom several clean ups:



details:   https://anonhg.NetBSD.org/src/rev/9b0fbd84a346
branches:  trunk
changeset: 499768:9b0fbd84a346
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Nov 28 22:31:37 2000 +0000

description:
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.

diffstat:

 usr.sbin/eeprom/Makefile     |   13 +-
 usr.sbin/eeprom/defs.h       |    6 +-
 usr.sbin/eeprom/eehandlers.c |   56 +++++++++++++-
 usr.sbin/eeprom/eeprom.8     |   16 +--
 usr.sbin/eeprom/main.c       |  176 +++++++++---------------------------------
 usr.sbin/eeprom/ophandlers.c |   31 +++++++-
 6 files changed, 143 insertions(+), 155 deletions(-)

diffs (truncated from 519 to 300 lines):

diff -r 5c745c4eebdb -r 9b0fbd84a346 usr.sbin/eeprom/Makefile
--- a/usr.sbin/eeprom/Makefile  Tue Nov 28 21:58:12 2000 +0000
+++ b/usr.sbin/eeprom/Makefile  Tue Nov 28 22:31:37 2000 +0000
@@ -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 @@
 
 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
diff -r 5c745c4eebdb -r 9b0fbd84a346 usr.sbin/eeprom/defs.h
--- a/usr.sbin/eeprom/defs.h    Tue Nov 28 21:58:12 2000 +0000
+++ b/usr.sbin/eeprom/defs.h    Tue Nov 28 22:31:37 2000 +0000
@@ -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 @@
 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 @@
 #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__ */
diff -r 5c745c4eebdb -r 9b0fbd84a346 usr.sbin/eeprom/eehandlers.c
--- a/usr.sbin/eeprom/eehandlers.c      Tue Nov 28 21:58:12 2000 +0000
+++ b/usr.sbin/eeprom/eehandlers.c      Tue Nov 28 22:31:37 2000 +0000
@@ -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 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;                                                         \
@@ -92,6 +120,32 @@
 }
 
 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;
        char *arg;
diff -r 5c745c4eebdb -r 9b0fbd84a346 usr.sbin/eeprom/eeprom.8
--- a/usr.sbin/eeprom/eeprom.8  Tue Nov 28 21:58:12 2000 +0000
+++ b/usr.sbin/eeprom/eeprom.8  Tue Nov 28 22:31:37 2000 +0000
@@ -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 @@
 .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  "
diff -r 5c745c4eebdb -r 9b0fbd84a346 usr.sbin/eeprom/main.c
--- a/usr.sbin/eeprom/main.c    Tue Nov 28 21:58:12 2000 +0000
+++ b/usr.sbin/eeprom/main.c    Tue Nov 28 22:31:37 2000 +0000
@@ -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 @@
 #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    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 @@
 {
        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__ */



Home | Main Index | Thread Index | Old Index