Source-Changes-HG archive

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

[src/netbsd-1-5]: src/sys/arch/sparc/stand/installboot pull up 1.6, 1.7. app...



details:   https://anonhg.NetBSD.org/src/rev/9e8b12acf25b
branches:  netbsd-1-5
changeset: 489245:9e8b12acf25b
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Aug 26 00:14:19 2000 +0000

description:
pull up 1.6, 1.7.  approved by thorpej:
1.6
>add sparc64 support.
1.7
>fix ultrasparc support.

diffstat:

 sys/arch/sparc/stand/installboot/installboot.c |  112 ++++++++++++++++++------
 1 files changed, 83 insertions(+), 29 deletions(-)

diffs (206 lines):

diff -r bf5155625840 -r 9e8b12acf25b sys/arch/sparc/stand/installboot/installboot.c
--- a/sys/arch/sparc/stand/installboot/installboot.c    Sat Aug 26 00:12:43 2000 +0000
+++ b/sys/arch/sparc/stand/installboot/installboot.c    Sat Aug 26 00:14:19 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: installboot.c,v 1.5 1999/11/13 12:09:41 pk Exp $ */
+/*     $NetBSD: installboot.c,v 1.5.4.1 2000/08/26 00:14:19 mrg Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -41,6 +41,8 @@
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/sysctl.h>
+#include <sys/mman.h>
+#include <sys/utsname.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/dir.h>
 #include <ufs/ffs/fs.h>
@@ -55,7 +57,7 @@
 
 #include "loadfile.h"
 
-int    verbose, nowrite, hflag = 1;
+int    verbose, nowrite, sparc64, uflag, hflag = 1;
 char   *boot, *proto, *dev;
 
 #if 0
@@ -83,20 +85,27 @@
 int32_t        *block_size_p;          /* filesystem block size */
 int32_t        max_block_count;
 
-char           *loadprotoblocks __P((char *, long *));
+char           *loadprotoblocks __P((char *, size_t *));
 int            loadblocknums __P((char *, int));
 static void    devread __P((int, void *, daddr_t, size_t, char *));
 static void    usage __P((void));
 int            main __P((int, char *[]));
 
-
 static void
 usage()
 {
        extern char *__progname;
-       (void)fprintf(stderr,
-           "Usage: %s [-n] [-v] <boot> <proto> <device>\n",
-           __progname);
+
+       if (sparc64)
+               (void)fprintf(stderr,
+                   "Usage: %s [-nv] <bootblk> <device>\n"
+                   "       %s -U [-nv] <boot> <proto> <device>\n",
+                   __progname, __progname);
+       else
+               (void)fprintf(stderr,
+                   "Usage: %s [-nv] <boot> <proto> <device>\n"
+                   "       %s -u [-n] [-v] <bootblk> <device>\n",
+                   __progname, __progname);
        exit(1);
 }
 
@@ -108,9 +117,18 @@
        int     c;
        int     devfd;
        char    *protostore;
-       long    protosize;
+       size_t  protosize;
+       struct  utsname utsname;
 
-       while ((c = getopt(argc, argv, "a:vnh")) != -1) {
+       /*
+        * For UltraSPARC machines, we turn on the uflag by default.
+        */
+       if (uname(&utsname) == -1)
+               err(1, "uname");
+       if (strcmp(utsname.machine, "sparc64") == 0)
+               sparc64 = uflag = 1;
+
+       while ((c = getopt(argc, argv, "a:nhuUv")) != -1) {
                switch (c) {
                case 'a':
                        warnx("-a option is obsolete");
@@ -123,6 +141,14 @@
                        /* Do not actually write the bootblock to disk */
                        nowrite = 1;
                        break;
+               case 'u':
+                       /* UltraSPARC boot block */
+                       uflag = 1;
+                       break;
+               case 'U':
+                       /* Force non-ultrasparc */
+                       uflag = 0;
+                       break;
                case 'v':
                        /* Chat */
                        verbose = 1;
@@ -132,33 +158,61 @@
                }
        }
 
-       if (argc - optind < 3) {
-               usage();
+       if (uflag) {
+               if (argc - optind < 2)
+                       usage();
+       } else {
+               if (argc - optind < 3)
+                       usage();
+               boot = argv[optind++];
        }
 
-       boot = argv[optind];
-       proto = argv[optind + 1];
-       dev = argv[optind + 2];
+       proto = argv[optind++];
+       dev = argv[optind];
 
        if (verbose) {
-               printf("boot: %s\n", boot);
+               if (!uflag)
+                       printf("boot: %s\n", boot);
                printf("proto: %s\n", proto);
                printf("device: %s\n", dev);
        }
 
        /* Load proto blocks into core */
-       if ((protostore = loadprotoblocks(proto, &protosize)) == NULL)
-               exit(1);
+       if (uflag == 0) {
+               if ((protostore = loadprotoblocks(proto, &protosize)) == NULL)
+                       exit(1);
+
+               /* Open and check raw disk device */
+               if ((devfd = open(dev, O_RDONLY, 0)) < 0)
+                       err(1, "open: %s", dev);
+
+               /* Extract and load block numbers */
+               if (loadblocknums(boot, devfd) != 0)
+                       exit(1);
+
+               (void)close(devfd);
+       } else {
+               struct stat sb;
+               int protofd;
+               size_t blanklen;
 
-       /* Open and check raw disk device */
-       if ((devfd = open(dev, O_RDONLY, 0)) < 0)
-               err(1, "open: %s", dev);
+               if ((protofd = open(proto, O_RDONLY)) < 0)
+                       err(1, "open: %s", proto);
+
+               if (fstat(protofd, &sb) < 0)
+                       err(1, "fstat: %s", proto);
 
-       /* Extract and load block numbers */
-       if (loadblocknums(boot, devfd) != 0)
-               exit(1);
-
-       (void)close(devfd);
+               /* there must be a better way */
+               blanklen = DEV_BSIZE - ((sb.st_size + DEV_BSIZE) & (DEV_BSIZE - 1));
+               protosize = sb.st_size + blanklen;
+               if ((protostore = mmap(0, (size_t)protosize,
+                   PROT_READ|PROT_WRITE, MAP_PRIVATE,
+                   protofd, 0)) == MAP_FAILED)
+                       err(1, "mmap: %s", proto);
+               /* and provide the rest of the block */
+               if (blanklen)
+                       memset(protostore + sb.st_size, 0, blanklen);
+       }
 
        if (nowrite)
                return 0;
@@ -185,7 +239,7 @@
 char *
 loadprotoblocks(fname, size)
        char *fname;
-       long *size;
+       size_t *size;
 {
        int     fd, sz;
        u_long  ap, bp, st, en;
@@ -233,19 +287,19 @@
        block_table = (daddr_t *) (bp + nl[X_BLOCKTABLE].n_value - st);
        block_count_p = (int32_t *)(bp + nl[X_BLOCKCOUNT].n_value - st);
        block_size_p = (int32_t *) (bp + nl[X_BLOCKSIZE].n_value - st);
-       if ((int)block_table & 3) {
+       if ((int)(u_long)block_table & 3) {
                warn("%s: invalid address: block_table = %p",
                     fname, block_table);
                free((void *)bp);
                return NULL;
        }
-       if ((int)block_count_p & 3) {
+       if ((int)(u_long)block_count_p & 3) {
                warn("%s: invalid address: block_count_p = %p",
                     fname, block_count_p);
                free((void *)bp);
                return NULL;
        }
-       if ((int)block_size_p & 3) {
+       if ((int)(u_long)block_size_p & 3) {
                warn("%s: invalid address: block_size_p = %p",
                     fname, block_size_p);
                free((void *)bp);



Home | Main Index | Thread Index | Old Index