On 2021-11-18 6:25 p.m., Ted Bullock wrote: > On 2021-11-15 2:41 p.m., Ted Bullock wrote: >> On 2021-11-15 2:21 p.m., Theo de Raadt wrote: >>> I do want fchmod for random reuse on most sparc64 machines. But if >>> OFW "write" >>> support isn't working on some machines, we should nop it out. Luckily >>> this is >>> in MD code. >> >> It's probably reasonable for any version older than OpenBoot 4.17.1 >> should get this treatment (This is the most recent ofw for the blade >> 100/150) >> > > I've had some difficulty trying to figure out how the OFW actually is > programmed, specifically how to query the PROM version. >
So after reading the openfirmware documents for a few days and learning to read forth, I determined that using the sun prom fcode firmware-version will not do the trick here. The data it returns is not granular enough and the 1275 spec says it's obsolete too. That said, it got me to thinking about something else I had reported, I've only encountered the problem on older sun gear using IDE devices (ultra 5 and blade 100). I think the writing bug on the sun proms is specific to IDE drives (though the nature of the bug is still a mystery to me). Theo, you said that you want the majority of the sparc64 systems to continue to be able to prevent re-use of the seed on boot, so I propose that OpenBSD just no-op the fchmod call for IDE devices only, which should work around the problem for the broken(?) prom systems and everything else that uses some variant of SCSI and its decedents will work as before. This patch disables fchmod in the bootblock for IDE drives on sparc64 I can confirm that this allows my sunblade 100 to boot -current Index: arch/sparc64/stand/ofwboot/ofdev.c =================================================================== RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/ofdev.c,v retrieving revision 1.31 diff -u -p -u -p -r1.31 ofdev.c --- arch/sparc64/stand/ofwboot/ofdev.c 9 Dec 2020 18:10:19 -0000 1.31 +++ arch/sparc64/stand/ofwboot/ofdev.c 20 Nov 2021 12:36:10 -0000 @@ -520,7 +520,7 @@ devopen(struct open_file *of, const char char fname[256]; char buf[DEV_BSIZE]; struct disklabel label; - int handle, part; + int handle, part, parent; int error = 0; #ifdef SOFTRAID char volno; @@ -649,6 +649,9 @@ devopen(struct open_file *of, const char #endif if ((handle = OF_finddevice(fname)) == -1) return ENOENT; + + parent = OF_parent(handle); + DNPRINTF(BOOT_D_OFDEV, "devopen: found %s\n", fname); if (OF_getprop(handle, "name", buf, sizeof buf) < 0) return ENXIO; @@ -685,6 +688,13 @@ devopen(struct open_file *of, const char of->f_dev = devsw; of->f_devdata = &ofdev; + + /* Some PROMS have bugged writing code for ide block devices */ + if (OF_getprop(parent, "name", buf, sizeof buf) < 0) + return ENXIO; + if (!strcmp(buf, "ide")) + of->f_flags |= F_NOWRITE; + #ifdef SPARC_BOOT_UFS bcopy(&file_system_ufs, &file_system[nfsys++], sizeof file_system[0]); bcopy(&file_system_ufs2, &file_system[nfsys++], sizeof file_system[0]); Index: arch/sparc64/stand/ofwboot/vers.c =================================================================== RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/vers.c,v retrieving revision 1.22 diff -u -p -u -p -r1.22 vers.c --- arch/sparc64/stand/ofwboot/vers.c 9 Dec 2020 18:10:19 -0000 1.22 +++ arch/sparc64/stand/ofwboot/vers.c 20 Nov 2021 12:36:11 -0000 @@ -1 +1 @@ -const char version[] = "1.21"; +const char version[] = "1.22"; Index: lib/libsa/fchmod.c =================================================================== RCS file: /cvs/src/sys/lib/libsa/fchmod.c,v retrieving revision 1.1 diff -u -p -u -p -r1.1 fchmod.c --- lib/libsa/fchmod.c 3 Aug 2019 15:22:17 -0000 1.1 +++ lib/libsa/fchmod.c 20 Nov 2021 12:36:12 -0000 @@ -53,6 +53,11 @@ fchmod(int fd, mode_t m) errno = EOPNOTSUPP; return (-1); } + /* writing is broken or unsupported */ + if (f->f_flags & F_NOWRITE) { + errno = EOPNOTSUPP; + return (-1); + } errno = (f->f_ops->fchmod)(f, m); return (0); Index: lib/libsa/stand.h =================================================================== RCS file: /cvs/src/sys/lib/libsa/stand.h,v retrieving revision 1.71 diff -u -p -u -p -r1.71 stand.h --- lib/libsa/stand.h 24 Oct 2021 17:49:19 -0000 1.71 +++ lib/libsa/stand.h 20 Nov 2021 12:36:12 -0000 @@ -107,10 +107,11 @@ struct open_file { extern struct open_file files[]; /* f_flags values */ -#define F_READ 0x0001 /* file opened for reading */ -#define F_WRITE 0x0002 /* file opened for writing */ -#define F_RAW 0x0004 /* raw device open - no file system */ -#define F_NODEV 0x0008 /* network open - no device */ +#define F_READ 0x0001 /* file opened for reading */ +#define F_WRITE 0x0002 /* file opened for writing */ +#define F_RAW 0x0004 /* raw device open - no file system */ +#define F_NODEV 0x0008 /* network open - no device */ +#define F_NOWRITE 0x0010 /* bootblock writing broken or unsupported */ #define isupper(c) ((c) >= 'A' && (c) <= 'Z') #define islower(c) ((c) >= 'a' && (c) <= 'z') -- Ted Bullock <tbull...@comlore.com>