From 27f0c681499e80e47617c3d2f851ec260fd1cf5a Mon Sep 17 00:00:00 2001 From: tsutsui Date: Thu, 9 May 2024 15:11:11 +0000 Subject: [PATCH] Add a preliminary CD boot support to uboot for preparation of PR/54455. Briefly tested on mame, but not enalbed yet. --- sys/arch/hp300/stand/common/conf.c | 10 +++++-- sys/arch/hp300/stand/common/conf.h | 14 ++++++--- sys/arch/hp300/stand/common/devopen.c | 6 ++-- sys/arch/hp300/stand/common/scsi.c | 15 +++++++++- sys/arch/hp300/stand/common/scsireg.h | 5 +++- sys/arch/hp300/stand/common/scsivar.h | 3 +- sys/arch/hp300/stand/common/sd.c | 43 +++++++++++++++++++++++---- 7 files changed, 77 insertions(+), 19 deletions(-) diff --git a/sys/arch/hp300/stand/common/conf.c b/sys/arch/hp300/stand/common/conf.c index b06328e46247..a3c785fc2e97 100644 --- a/sys/arch/hp300/stand/common/conf.c +++ b/sys/arch/hp300/stand/common/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.14 2022/12/11 07:39:30 tsutsui Exp $ */ +/* $NetBSD: conf.c,v 1.15 2024/05/09 15:11:11 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -138,13 +139,16 @@ int npunit = __arraycount(punitsw); * Filesystem configuration */ struct fs_ops file_system_rawfs[1] = { FS_OPS(rawfs) }; -struct fs_ops file_system_ufs[NFSYS_UFS] = { +struct fs_ops file_system_ufs[NFSYS_FS] = { FS_OPS(ffsv1), #ifdef SUPPORT_UFS2 FS_OPS(ffsv2), #endif +#ifdef SUPPORT_CD + FS_OPS(cd9660), +#endif }; struct fs_ops file_system_nfs[1] = { FS_OPS(nfs) }; -struct fs_ops file_system[NFSYS_UFS]; +struct fs_ops file_system[NFSYS_FS]; int nfsys = 1; /* default value; should be overrieded */ diff --git a/sys/arch/hp300/stand/common/conf.h b/sys/arch/hp300/stand/common/conf.h index 2efcd9f73848..67a92ffcdc6c 100644 --- a/sys/arch/hp300/stand/common/conf.h +++ b/sys/arch/hp300/stand/common/conf.h @@ -1,4 +1,4 @@ -/* $NetBSD: conf.h,v 1.3 2022/12/11 07:39:30 tsutsui Exp $ */ +/* $NetBSD: conf.h,v 1.4 2024/05/09 15:11:11 tsutsui Exp $ */ /* * Copyright (c) 1982, 1990, 1993 @@ -53,10 +53,16 @@ int sdopen(struct open_file *, ...); int sdclose(struct open_file *); #endif #ifdef SUPPORT_UFS2 -#define NFSYS_UFS 2 +#define NFSYS_UFS2 1 #else -#define NFSYS_UFS 1 +#define NFSYS_UFS2 0 #endif +#ifdef SUPPORT_CD +#define NFSYS_CD9660 1 +#else +#define NFSYS_CD9660 0 +#endif +#define NFSYS_FS (1 + NFSYS_UFS2 + NFSYS_CD9660) #ifdef SUPPORT_ETHERNET extern struct netif_driver le_driver; @@ -72,5 +78,5 @@ extern struct punitsw punitsw[]; extern int npunit; extern struct fs_ops file_system_rawfs[1]; -extern struct fs_ops file_system_ufs[NFSYS_UFS]; +extern struct fs_ops file_system_ufs[NFSYS_FS]; extern struct fs_ops file_system_nfs[1]; diff --git a/sys/arch/hp300/stand/common/devopen.c b/sys/arch/hp300/stand/common/devopen.c index 7efbee036949..78b45e403c89 100644 --- a/sys/arch/hp300/stand/common/devopen.c +++ b/sys/arch/hp300/stand/common/devopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: devopen.c,v 1.14 2023/01/15 06:19:46 tsutsui Exp $ */ +/* $NetBSD: devopen.c,v 1.15 2024/05/09 15:11:11 tsutsui Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -105,7 +105,7 @@ devlookup(const char *d, int len) case 4: /* sd */ memcpy(file_system, file_system_ufs, sizeof(file_system_ufs)); - nfsys = NFSYS_UFS; + nfsys = NFSYS_FS; break; case 6: /* le */ @@ -263,7 +263,7 @@ devopen(struct open_file *f, const char *fname, char **file) case 4: /* sd */ memcpy(file_system, file_system_ufs, sizeof(file_system_ufs)); - nfsys = NFSYS_UFS; + nfsys = NFSYS_FS; break; case 6: /* le */ diff --git a/sys/arch/hp300/stand/common/scsi.c b/sys/arch/hp300/stand/common/scsi.c index 049413f03d66..f0a8c9452cc8 100644 --- a/sys/arch/hp300/stand/common/scsi.c +++ b/sys/arch/hp300/stand/common/scsi.c @@ -1,4 +1,4 @@ -/* $NetBSD: scsi.c,v 1.12 2023/01/15 06:19:46 tsutsui Exp $ */ +/* $NetBSD: scsi.c,v 1.13 2024/05/09 15:11:11 tsutsui Exp $ */ /* * This is reported to fix some odd failures when disklabeling @@ -400,6 +400,19 @@ scsi_read_capacity(int ctlr, int slave, uint8_t *buf, unsigned int len) DATA_IN_PHASE); } +#ifdef SUPPORT_CD +int +scsi_inquiry(int ctlr, int slave, uint8_t *buf, unsigned int len) +{ + struct scsi_softc *hs = &scsi_softc[ctlr]; + static struct scsi_cdb6 cdb = { CMD_INQUIRY }; + + cdb.len = len; + return scsiicmd(hs, slave, (uint8_t *)&cdb, sizeof(cdb), buf, len, + DATA_IN_PHASE); +} +#endif + int scsi_tt_read(int ctlr, int slave, uint8_t *buf, u_int len, daddr_t blk, u_int nblk) diff --git a/sys/arch/hp300/stand/common/scsireg.h b/sys/arch/hp300/stand/common/scsireg.h index 6b4fc0bb33e3..18886d576c89 100644 --- a/sys/arch/hp300/stand/common/scsireg.h +++ b/sys/arch/hp300/stand/common/scsireg.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsireg.h,v 1.5 2023/01/15 06:19:46 tsutsui Exp $ */ +/* $NetBSD: scsireg.h,v 1.6 2024/05/09 15:11:11 tsutsui Exp $ */ /* * Copyright (c) 1990, 1993 @@ -274,6 +274,9 @@ struct scsi_xsense { /* inquiry data */ struct scsi_inquiry { u_char type; +#define SID_TYPE 0x1f +#define T_DIRECT 0x00 +#define T_CDROM 0x05 u_char qual; u_char version; u_char rsvd; diff --git a/sys/arch/hp300/stand/common/scsivar.h b/sys/arch/hp300/stand/common/scsivar.h index 3d92f8b2cc9b..93914473f22a 100644 --- a/sys/arch/hp300/stand/common/scsivar.h +++ b/sys/arch/hp300/stand/common/scsivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsivar.h,v 1.4 2005/12/11 12:17:19 christos Exp $ */ +/* $NetBSD: scsivar.h,v 1.5 2024/05/09 15:11:11 tsutsui Exp $ */ /* * Copyright (c) 1982, 1990, 1993 @@ -52,5 +52,6 @@ void scsiabort(struct scsi_softc *, volatile struct scsidevice *); int scsi_test_unit_rdy(int, int); int scsi_request_sense(int, int, u_char *, unsigned int); int scsi_read_capacity(int, int, u_char *, unsigned int); +int scsi_inquiry(int, int, u_char *, unsigned int); int scsi_tt_read(int, int, u_char *, u_int, daddr_t, u_int); int scsi_tt_write(int, int, u_char *, u_int, daddr_t, u_int); diff --git a/sys/arch/hp300/stand/common/sd.c b/sys/arch/hp300/stand/common/sd.c index 24eeb6d2d6c9..db941d570f25 100644 --- a/sys/arch/hp300/stand/common/sd.c +++ b/sys/arch/hp300/stand/common/sd.c @@ -1,4 +1,4 @@ -/* $NetBSD: sd.c,v 1.12 2023/01/15 06:19:46 tsutsui Exp $ */ +/* $NetBSD: sd.c,v 1.13 2024/05/09 15:11:11 tsutsui Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -67,6 +67,9 @@ struct sd_softc { char sc_alive; short sc_blkshift; struct sdminilabel sc_pinfo; +#ifdef SUPPORT_CD + uint8_t sc_type; +#endif }; #define SDRETRY 2 @@ -82,6 +85,9 @@ sdinit(int ctlr, int unit) { struct sd_softc *ss = &sd_softc[ctlr][unit]; u_char stat; +#ifdef SUPPORT_CD + struct scsi_inquiry inqbuf; +#endif int capbuf[2]; stat = scsi_test_unit_rdy(ctlr, unit); @@ -97,6 +103,20 @@ sdinit(int ctlr, int unit) return 0; } } +#ifdef SUPPORT_CD + /* + * try to get the disk type. + */ + memset(&inqbuf, 0, sizeof(inqbuf)); + stat = scsi_inquiry(ctlr, unit, (u_char *)&inqbuf, sizeof(inqbuf)); + if (stat == 0) { + /* to fake a disklabel on CD-ROM */ + ss->sc_type = inqbuf.type & SID_TYPE; + } else { + /* assume a disk by default */ + ss->sc_type = T_DIRECT; + } +#endif /* * try to get the drive block size. */ @@ -141,11 +161,22 @@ sdgetinfo(struct sd_softc *ss) msg = getdisklabel(io_buf, lp); if (msg) { - printf("sd(%d,%d,%d): WARNING: %s\n", - ss->sc_ctlr, ss->sc_unit, ss->sc_part, msg); - pi->npart = 3; - pi->offset[0] = pi->offset[1] = -1; - pi->offset[2] = 0; +#ifdef SUPPORT_CD + if (ss->sc_type == T_CDROM) { + /* assume a whole disk region is ISO9660 */ + pi->npart = 3; + pi->offset[0] = 0; + pi->offset[1] = -1; + pi->offset[2] = 0; + } else +#endif + { + printf("sd(%d,%d,%d): WARNING: %s\n", + ss->sc_ctlr, ss->sc_unit, ss->sc_part, msg); + pi->npart = 3; + pi->offset[0] = pi->offset[1] = -1; + pi->offset[2] = 0; + } } else { pi->npart = lp->d_npartitions; for (i = 0; i < pi->npart; i++)