Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/pmax/stand/common Check if `enet' environment varia...



details:   https://anonhg.NetBSD.org/src/rev/fcd78a6a7d8d
branches:  trunk
changeset: 760631:fcd78a6a7d8d
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sun Jan 09 16:28:40 2011 +0000

description:
Check if `enet' environment variable is available before reference to
get MAC address, and exit with appropriate warning messages if it isn't.
My 3MIN doesn't set the variable by default and netboot fails silently.
Also tidy up code that converts strings to enaddr.

diffstat:

 sys/arch/pmax/stand/common/if_prom.c |  41 ++++++++++++++++++++++-------------
 1 files changed, 26 insertions(+), 15 deletions(-)

diffs (67 lines):

diff -r 9db8ec204b23 -r fcd78a6a7d8d sys/arch/pmax/stand/common/if_prom.c
--- a/sys/arch/pmax/stand/common/if_prom.c      Sun Jan 09 16:22:07 2011 +0000
+++ b/sys/arch/pmax/stand/common/if_prom.c      Sun Jan 09 16:28:40 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_prom.c,v 1.7 2009/03/14 15:36:12 dsl Exp $ */
+/*      $NetBSD: if_prom.c,v 1.8 2011/01/09 16:28:40 tsutsui Exp $ */
 
 /* Copyright (c) 1999 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -123,8 +123,9 @@
 {
        char *device =
                ((struct netif *)desc->io_netif)->nif_driver->netif_bname;
-       char *c, *enet;
-       int i, j, num;
+       char *enet;
+       uint8_t *cp, *dest;
+       int i;
 
 #ifdef NET_DEBUG
        printf("prom_init: called\n");
@@ -138,23 +139,33 @@
          */
        enet = (*callv->_getenv)("enet");
 
+       if (enet == NULL) {
+               printf("No `enet' environment variable found.\n"
+                   "Set MAC address to `enet' manually by setenv command.\n");
+               (*callv->_halt)((int *)0, 0);   /* XXX */
+               /* NOTREACHED */
+       }
+
 #ifdef NET_DEBUG
        if (debug)
                printf("enet=%s\n", enet);
 #endif
 
-       i=0;
-       c = enet;
-       for (i=0; i<6; i++) {
-               j = *c - '0';
-               num = (j<10?j:j-39);
-               num <<= 4;
-               c++;
-               j = *c - '0';
-               num += (j<10?j:j-39);
-               desc->myea[i] = num;
-               c++;
-               c++; /* skip '-' */
+#define atox(c)        (((c) < '9') ? ((c) - '0') : ((toupper(c) - 'A') + 10))
+
+       cp = (uint8_t *)enet;
+       dest = desc->myea;
+       for (i = 0; i < 6; i++) {
+               if (isxdigit(*cp)) {
+                       *dest = atox(*cp);
+                       cp++;
+                       if (isxdigit(*cp)) {
+                               *dest = (*dest << 4) | atox(*cp);
+                               cp++;
+                       }
+               }
+               dest++;
+               cp++;   /* skip '-' or ':' etc. */
        }
 
        desc->xid = 0x66d30000;



Home | Main Index | Thread Index | Old Index