Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/amiga/stand/bootblock/installboot Replace skript by...



details:   https://anonhg.NetBSD.org/src/rev/6065d28e65e9
branches:  trunk
changeset: 515450:6065d28e65e9
user:      is <is%NetBSD.org@localhost>
date:      Tue Sep 25 18:47:55 2001 +0000

description:
Replace skript by a C program, that knows how to manipulate the default
command line in the bootblock and to recompute the bootblock checksum.

diffstat:

 sys/arch/amiga/stand/bootblock/installboot/Makefile       |   11 +-
 sys/arch/amiga/stand/bootblock/installboot/installboot.c  |  107 ++++++++++++++
 sys/arch/amiga/stand/bootblock/installboot/installboot.sh |   27 ---
 3 files changed, 114 insertions(+), 31 deletions(-)

diffs (159 lines):

diff -r 1b5941aa53c7 -r 6065d28e65e9 sys/arch/amiga/stand/bootblock/installboot/Makefile
--- a/sys/arch/amiga/stand/bootblock/installboot/Makefile       Tue Sep 25 14:26:56 2001 +0000
+++ b/sys/arch/amiga/stand/bootblock/installboot/Makefile       Tue Sep 25 18:47:55 2001 +0000
@@ -1,6 +1,9 @@
-#      $NetBSD: Makefile,v 1.3 1999/02/13 02:54:37 lukem Exp $
-SCRIPTS=installboot.sh
-SCRIPTSNAME=installboot
-MKMAN= no
+#      $NetBSD: Makefile,v 1.4 2001/09/25 18:47:55 is Exp $
+PROG=installboot
+SRCS=installboot.c chksum.c
+
+MKMAN= no      # notyet
+
+.PATH: ${.CURDIR}/../aout2bb   # chksum.c
 
 .include <bsd.prog.mk>
diff -r 1b5941aa53c7 -r 6065d28e65e9 sys/arch/amiga/stand/bootblock/installboot/installboot.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amiga/stand/bootblock/installboot/installboot.c  Tue Sep 25 18:47:55 2001 +0000
@@ -0,0 +1,107 @@
+#include <err.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "../aout2bb/chksum.h"
+
+/* XXX Must be kept in sync with bbstart.s! */
+#define CMDLN_LOC 0x10
+#define CMDLN_LEN 0x20
+
+int main(int argc, char *argv[]);
+
+int main(int argc, char *argv[]){
+
+       char *line;
+       char *progname;
+       char *bootnam, *devnam;
+       int bootfd, devfd;
+       int rc; /* read,  write */
+       int c;  /* getopt */
+       int sumlen;
+       u_int32_t sum2, sum16;
+       
+       u_int32_t block[128*16];
+
+       progname = argv[0];
+       while ((c = getopt(argc, argv, "l:")) != -1) {
+               switch(c) {
+               case 'l':
+                       line = optarg;
+                       break;
+               default:
+                       errx(1,
+                       "usage: %s [-l newcommandline] bootblock device",
+                       progname);
+               }
+       }
+       argc -= optind;
+       argv += optind;
+       if (argc != 2) {
+               errx(1, "usage: %s [-l newcommandline] bootblock device",
+                       progname);
+               /* NOTREACHED */
+       }
+
+       bootnam = *argv++;
+       devnam = *argv;
+       
+       bootfd = open(bootnam, O_RDONLY, 0);
+       if (bootfd < 0) {
+               err(1, "Can't open bootblock for reading");
+               /* NOTREACHED */
+       }
+
+       devfd = open(devnam, O_CREAT|O_RDWR, 0666);
+       if (devfd < 0) {
+               err(1, "Can't open output device for writing");
+               /* NOTREACHED */
+       }
+
+       rc = read(bootfd, block, sizeof(block));
+
+       if (rc < sizeof(block)) {
+               err(1, "Can't read bootblock");
+               /* NOTREACHED */
+       }
+
+       /* XXX the choices should not be hardcoded */
+
+       sum2  = chksum(block, 1024/4);
+       sum16 = chksum(block, 8192/4);
+
+       if (sum16 == 0xffffffff) {
+               sumlen = 8192/4;
+       } else if (sum2 == 0xffffffff) {
+               sumlen = 1024/4;
+       } else {
+               errx(1, "%s: wrong checksum", bootnam);
+               /* NOTREACHED */
+       }
+
+       if (sum2 == sum16) {
+               warnx("eek - both sums are the same");
+       }
+       
+
+       if (line) {
+               (void)strncpy((char *)(&block[CMDLN_LOC/4]), line, CMDLN_LEN-1);
+
+               block[1] = 0;
+               block[1] = 0xffffffff - chksum(block, sumlen);
+       }
+
+       rc = write(devfd, block, sizeof(block));
+
+       if (rc < sizeof(block)) {
+               err(1, "Can't write bootblock");
+               /* NOTREACHED */
+       }
+
+       exit(1);
+       /* NOTREACHED */
+}
diff -r 1b5941aa53c7 -r 6065d28e65e9 sys/arch/amiga/stand/bootblock/installboot/installboot.sh
--- a/sys/arch/amiga/stand/bootblock/installboot/installboot.sh Tue Sep 25 14:26:56 2001 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#!/bin/sh
-#      $NetBSD: installboot.sh,v 1.1.1.1 1996/11/29 23:36:29 is Exp $
-
-# compatibility with old installboot program
-#
-#      @(#)installboot.sh      8.1 (Berkeley) 6/10/93
-#
-if [ $# != 2 ]
-then
-       echo "Usage: installboot bootprog device"
-       exit 1
-fi
-if [ ! -f $1 ]
-then
-       echo "Usage: installboot bootprog device"
-       echo "${1}: bootprog must be a regular file"
-       exit 1
-fi
-if [ ! -c $2 ]
-then
-       echo "Usage: installboot bootprog device"
-       echo "${2}: device must be a char special file"
-       exit 1
-fi
-#/sbin/disklabel -B -b $1 $2
-dd if=$1 of=$2 bs=512 count=16
-exit $?



Home | Main Index | Thread Index | Old Index