Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sgimips Initial boot device determination code: ma...



details:   https://anonhg.NetBSD.org/src/rev/6ab8483b05cc
branches:  trunk
changeset: 516169:6ab8483b05cc
user:      mhitch <mhitch%NetBSD.org@localhost>
date:      Thu Oct 18 02:25:33 2001 +0000

description:
Initial boot device determination code:  makebootdev() to parse boot command
line parameters, and device_register() to try to match the boot device.  Works
on a Challenge S (and similar machines), but will need more work for other
SCSI adapters.

diffstat:

 sys/arch/sgimips/include/autoconf.h |    5 +-
 sys/arch/sgimips/sgimips/autoconf.c |  147 +++++++++++++++++++++++++++++++----
 2 files changed, 133 insertions(+), 19 deletions(-)

diffs (198 lines):

diff -r fddd4c030d07 -r 6ab8483b05cc sys/arch/sgimips/include/autoconf.h
--- a/sys/arch/sgimips/include/autoconf.h       Thu Oct 18 02:19:54 2001 +0000
+++ b/sys/arch/sgimips/include/autoconf.h       Thu Oct 18 02:25:33 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.h,v 1.3 2001/07/09 02:00:19 thorpej Exp $     */
+/*     $NetBSD: autoconf.h,v 1.4 2001/10/18 02:25:33 mhitch Exp $      */
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang
@@ -42,3 +42,6 @@
 };
 
 extern int ncpus;
+
+void   makebootdev __P((char *));
+
diff -r fddd4c030d07 -r 6ab8483b05cc sys/arch/sgimips/sgimips/autoconf.c
--- a/sys/arch/sgimips/sgimips/autoconf.c       Thu Oct 18 02:19:54 2001 +0000
+++ b/sys/arch/sgimips/sgimips/autoconf.c       Thu Oct 18 02:25:33 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.3 2001/08/08 11:35:12 wdk Exp $ */
+/*     $NetBSD: autoconf.c,v 1.4 2001/10/18 02:25:34 mhitch Exp $      */
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang
@@ -43,11 +43,19 @@
 #include <machine/cpu.h>
 #include <machine/sysconf.h>
 #include <machine/machtype.h>
+#include <machine/autoconf.h>
+
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsiconf.h>
+
+struct device *booted_device;
+static struct device *booted_controller;
+static int     booted_slot, booted_unit, booted_partition;
+static char    *booted_protocol;
 
 extern struct platform platform;
 
-static void    findroot(struct device **, int *);
-
 void
 cpu_configure()
 {
@@ -71,32 +79,135 @@
        _splnone();
 }
 
+/*
+ * Look at the string 'cp' and decode the boot device.  Boot names
+ * can be something like 'bootp(0)netbsd' or
+ * 'scsi(0)disk(1)rdisk(0)partition(0)netbsd' or
+ * 'dksc(0,1,0)netbsd'
+ */
+void
+makebootdev(cp)
+       char *cp;
+{
+       booted_device = NULL;
+       booted_slot = booted_unit = booted_partition = 0;
+       booted_protocol = NULL;
+
+       if (strncmp(cp, "scsi(", 5) == NULL) {
+               cp += 5;
+               if (*cp >= '0' && *cp <= '9')
+                       booted_slot = *cp++ - '0';
+               if (strncmp(cp, ")disk(", 6) == NULL) {
+                       cp += 6;
+                       if (*cp >= '0' && *cp <= '9')
+                               booted_unit = *cp++ - '0';
+               }
+               /* XXX can rdisk() ever be other than 0? */
+               if (strncmp(cp, ")rdisk(0)partition(", 19) == NULL) {
+                       cp += 19;
+                       while (*cp >= '0' && *cp <= '9')
+                               booted_partition = booted_partition * 10 + *cp++ - '0';
+               }
+               if (*cp != ')')
+                       return; /* XXX ? */
+               booted_protocol = "SCSI";
+               return;
+       }
+       if (strncmp(cp, "dksc(", 5) == NULL) {
+               cp += 5;
+               if (*cp >= '0' && *cp <= '9')
+                       booted_slot = *cp++ - '0';
+               if (*cp == ',') {
+                       ++cp;
+                       if (*cp >= '0' || *cp <= '9')
+                               booted_unit = *cp++ - '0';
+                       if (*cp == ',') {
+                               ++cp;
+                               if (*cp >= '0' && *cp <= '9')
+                                       booted_partition = *cp++ - '0';
+                       }
+               }
+               if (*cp != ')')
+                       return;         /* XXX ??? */
+               booted_protocol = "SCSI";
+               return;
+       }
+       if (strncmp(cp, "bootp(", 6) == 0) {
+               /* XXX controller number?  Needed to handle > 1 network controller */
+               booted_protocol = "BOOTP";
+               return;
+       }
+}
+
 void
 cpu_rootconf()
 {
-       struct device *booted_device;
-       int booted_partition;
-
-       findroot(&booted_device, &booted_partition);
-
        printf("boot device: %s\n",
                booted_device ? booted_device->dv_xname : "<unknown>");
 
        setroot(booted_device, booted_partition);
 }
 
-dev_t  bootdev = 0;
+/*
+ * Try to determine the boot device.
+ */
+void
+device_register(dev, aux)
+       struct device *dev;
+       void *aux;
+{
+       static int found, initted, scsiboot, netboot;
+       struct device *parent = dev->dv_parent;
+       struct cfdata *cf = dev->dv_cfdata;
+       struct cfdriver *cd = cf->cf_driver;
+
+       if (found)
+               return;
 
-static void
-findroot(devpp, partp)
-       struct device **devpp;
-       int *partp;
-{
+       if (!initted && booted_protocol) {
+               scsiboot = strcmp(booted_protocol, "SCSI") == 0;
+               netboot = (strcmp(booted_protocol, "BOOTP") == 0);
+               initted = 1;
+       }
+
+       /*
+        * Check for WDC controller
+        */
+       if (scsiboot && strcmp(cd->cd_name, "wdsc") == 0) {
+               /* XXX Check controller number == booted_slot */
+               booted_controller = dev;
+               return;
+       }
+
        /*
-        * Default to "not found".
+        * Other SCSI controllers ??
+        */
+
+       /*
+        * If we found the boot controller, if check disk/tape/cdrom device
+        * on that controller matches.
         */
-       *devpp = NULL;
-       *partp = 0;
+       if (booted_controller && (strcmp(cd->cd_name, "sd") == 0 ||
+           strcmp(cd->cd_name, "st") == 0 ||
+           strcmp(cd->cd_name, "cd") == 0)) {
+               struct scsipibus_attach_args *sa = aux;
 
-       return;
+               if (parent->dv_parent != booted_controller)
+                       return;
+               if (booted_unit != sa->sa_periph->periph_target)
+                       return;
+               booted_device = dev;
+               found = 1;
+               return;
+       }
+
+       /*
+        * Check if netboot device.
+        */
+       if (netboot && strcmp(cd->cd_name, "sq") == 0) {
+               /* XXX Check unit number? (Which we don't parse yet)  */
+               booted_device = dev;
+               found = 1;
+               return;
+       }
 }



Home | Main Index | Thread Index | Old Index