Module Name:    src
Committed By:   isaki
Date:           Sun Jun 26 04:17:18 UTC 2016

Modified Files:
        src/sys/arch/x68k/stand/boot: boot.c
        src/sys/arch/x68k/stand/libsa: devopen.c libx68k.h

Log Message:
Add SCSI host adaptor selector to "boot" command of /boot.
By this function, /boot which booted from non-SCSI
(in other words, floppy) can load SCSI kernel.
Now, single /boot can load kernel of all supported filesystems
of all supported boot devices.

---
New "boot" command's syntax is: boot [hostadaptor@][dev:][file]

If you booted from SCSI, hostadaptor is already set (from IOCS)
and you can omit hostadaptor in this case.  You can type like
"boot sd0a:netbsd" as before.

If you booted from floppy (hostadaptor is not set) and want to
load the SCSI kernel (hostadaptor is needed), you have to select
your hostadaptor in boot command, like "boot spc0@sd0a:netbsd".


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x68k/stand/boot/boot.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x68k/stand/libsa/devopen.c \
    src/sys/arch/x68k/stand/libsa/libx68k.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x68k/stand/boot/boot.c
diff -u src/sys/arch/x68k/stand/boot/boot.c:1.28 src/sys/arch/x68k/stand/boot/boot.c:1.29
--- src/sys/arch/x68k/stand/boot/boot.c:1.28	Sat Jun 25 16:05:43 2016
+++ src/sys/arch/x68k/stand/boot/boot.c	Sun Jun 26 04:17:17 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.28 2016/06/25 16:05:43 isaki Exp $	*/
+/*	$NetBSD: boot.c,v 1.29 2016/06/26 04:17:17 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -78,13 +78,21 @@ extern struct fs_ops file_system_nfs[];
 static int
 get_scsi_host_adapter(void)
 {
+	uint32_t bootinf;
 	char *bootrom;
 	int ha;
 
-	bootrom = (char *) (IOCS_BOOTINF() & 0x00ffffe0);
+	bootinf = IOCS_BOOTINF();
+	if (bootinf < 0xa0) {
+		/* boot from FD */
+		return 0;
+	}
+
+	/* Or, bootinf indicates the boot address */
+	bootrom = (char *)(bootinf & 0x00ffffe0);
 	/*
-	 * bootrom+0x24	"SCSIIN" ... Internal SCSI (spc@0)
-	 *		"SCSIEX" ... External SCSI (spc@1 or mha@0)
+	 * bootrom+0x24	"SCSIIN" ... Internal SCSI (spc0@)
+	 *		"SCSIEX" ... External SCSI (spc1@ or mha0@)
 	 */
 	if (*(u_short *)(bootrom + 0x24 + 4) == 0x494e) {	/* "IN" */
 		ha = (X68K_BOOT_SCSIIF_SPC << 4) | 0;
@@ -101,7 +109,8 @@ static void
 help(void)
 {
 	printf("Usage:\n");
-	printf("boot [dev:][file] -[flags]\n");
+	printf("boot [ha@][dev:][file] -[flags]\n");
+	printf(" ha:    spc0, spc1, mha0\n");
 	printf(" dev:   sd<ID><PART>, ID=0-7, PART=a-p\n");
 	printf("        cd<ID>a, ID=0-7\n");
 	printf("        fd<UNIT>a, UNIT=0-3, format is detected.\n");
@@ -118,10 +127,12 @@ doboot(const char *file, int flags)
 {
 	u_long		marks[MARK_MAX];
 	int fd;
+	int ha;		/* host adaptor */
 	int dev;	/* device number in devspec[] */
 	int unit;
 	int part;
 	int bootdev;
+	int maj;
 	char *name;
 	short *p;
 	int loadflag;
@@ -129,7 +140,7 @@ doboot(const char *file, int flags)
 
 	printf("Starting %s, flags 0x%x\n", file, flags);
 
-	if (devparse(file, &dev, &unit, &part, &name) != 0) {
+	if (devparse(file, &ha, &dev, &unit, &part, &name) != 0) {
 		printf("XXX: unknown corruption in /boot.\n");
 	}
 
@@ -138,29 +149,40 @@ doboot(const char *file, int flags)
 		printf("dev = %x, unit = %d, name = %s\n",
 		       dev, unit, name);
 	} else {
-		printf("dev = %x, unit = %d, part = %c, name = %s\n",
-		       dev, unit, part + 'a', name);
+		printf("ha = 0x%x, dev = %x, unit = %d, part = %c, name = %s\n",
+		       ha, dev, unit, part + 'a', name);
 	}
 #endif
 
 	if (dev == 3) {		/* netboot */
 		bootdev = X68K_MAKEBOOTDEV(X68K_MAJOR_NE, unit, 0);
-	} else if (dev == 0) {		/* SCSI */
-		bootdev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_SD,
-					   hostadaptor >> 4,
-					   hostadaptor & 15,
-					   unit & 7, 0, 0);
-	} else {
+	} else if (dev == 2) {		/* FD */
 		bootdev = X68K_MAKEBOOTDEV(X68K_MAJOR_FD, unit & 3, 0);
+	} else {		/* SCSI */
+		if (ha != 0) {
+			hostadaptor = ha;
+		}
+		if (hostadaptor == 0) {
+			printf("host adaptor must be specified.\n");
+			return;
+		}
+
+		maj = (dev == 0) ? X68K_MAJOR_SD : X68K_MAJOR_CD;
+		bootdev = X68K_MAKESCSIBOOTDEV(maj,
+		    hostadaptor >> 4,
+		    hostadaptor & 15,
+		    unit & 7, 0, 0);
 	}
 #ifdef DEBUG
 	printf("boot device = %x\n", bootdev);
 	if (file[0] == 'n') {
-		printf("if = %d, unit = %d\n",
+		printf("type = %x, if = %d, unit = %d\n",
+		       B_TYPE(bootdev),
 		       B_X68K_SCSI_IF(bootdev),
 		       B_X68K_SCSI_IF_UN(bootdev));
 	} else {
-		printf("if = %d, unit = %d, id = %d, lun = %d, part = %c\n",
+		printf("type = %x, if = %d, unit = %d, id = %d, lun = %d, part = %c\n",
+		       B_TYPE(bootdev),
 		       B_X68K_SCSI_IF(bootdev),
 		       B_X68K_SCSI_IF_UN(bootdev),
 		       B_X68K_SCSI_ID(bootdev),

Index: src/sys/arch/x68k/stand/libsa/devopen.c
diff -u src/sys/arch/x68k/stand/libsa/devopen.c:1.6 src/sys/arch/x68k/stand/libsa/devopen.c:1.7
--- src/sys/arch/x68k/stand/libsa/devopen.c:1.6	Fri Oct 12 20:15:52 2012
+++ src/sys/arch/x68k/stand/libsa/devopen.c	Sun Jun 26 04:17:17 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: devopen.c,v 1.6 2012/10/12 20:15:52 tsutsui Exp $	*/
+/*	$NetBSD: devopen.c,v 1.7 2016/06/26 04:17:17 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -28,6 +28,7 @@
 
 #include <sys/param.h>
 #include <sys/disklabel.h>
+#include <machine/bootinfo.h>
 #include <lib/libkern/libkern.h>
 #include <lib/libsa/stand.h>
 #include "libx68k.h"
@@ -38,17 +39,34 @@ int devopen_open_dir = 0;
 /*
  * Parse a device spec.
  *
- * sd<unit><part>:<file>
+ * [ha@]<dev><unit><part>:<file>
+ *  ha   - host adaptor ("spc0", "spc1", "mha0")
+ *  dev  - device name (e.g., "sd")
  *  unit - 0-7
  *  part - a-p
  */
 int
-devparse(const char *fname, int *dev, int *unit, int *part, char **file)
+devparse(const char *fname, int *ha, int *dev, int *unit, int *part,
+	char **file)
 {
 	char const *s;
 	int i;
 
 	s = fname;
+
+	if (strncmp(s, "spc0@", 5) == 0) {
+		*ha = (X68K_BOOT_SCSIIF_SPC << 4) | 0;
+		s += 5;
+	} else if (strncmp(s, "spc1@", 5) == 0) {
+		*ha = (X68K_BOOT_SCSIIF_SPC << 4) | 1;
+		s += 5;
+	} else if (strncmp(s, "mha0@", 5) == 0) {
+		*ha = (X68K_BOOT_SCSIIF_MHA << 4) | 0;
+		s += 5;
+	} else {
+		*ha = 0;
+	}
+
 	for (i = 0; devspec[i].ds_name != 0; i++) {
 		if (strncmp (devspec[i].ds_name, s,
 			     strlen(devspec[i].ds_name)) == 0)
@@ -91,10 +109,10 @@ int
 devopen(struct open_file *f, const char *fname, char **file)
 {
 	int error;
-	int dev, unit, part;
+	int ha, dev, unit, part;
 	struct devsw *dp = &devsw[0];
 
-	error = devparse(fname, &dev, &unit, &part, file);
+	error = devparse(fname, &ha, &dev, &unit, &part, file);
 	if (error)
 		return error;
 
Index: src/sys/arch/x68k/stand/libsa/libx68k.h
diff -u src/sys/arch/x68k/stand/libsa/libx68k.h:1.6 src/sys/arch/x68k/stand/libsa/libx68k.h:1.7
--- src/sys/arch/x68k/stand/libsa/libx68k.h:1.6	Fri Oct 12 20:15:52 2012
+++ src/sys/arch/x68k/stand/libsa/libx68k.h	Sun Jun 26 04:17:17 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: libx68k.h,v 1.6 2012/10/12 20:15:52 tsutsui Exp $	*/
+/*	$NetBSD: libx68k.h,v 1.7 2016/06/26 04:17:17 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -64,7 +64,7 @@ int fdopen(struct open_file *, ...);
 int fdclose(struct open_file *);
 
 /* devopen.c */
-int devparse(const char *, int *, int *, int *, char **);
+int devparse(const char *, int *, int *, int *, int *, char **);
 extern int devopen_open_dir;
 
 /* chdsk.c */

Reply via email to