Subject: port-sparc/3231: [dM] on sun4m/sun4c, installboot never strips header
To: None <gnats-bugs@gnats.netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: netbsd-bugs
Date: 02/18/1997 18:42:38
>Number:         3231
>Category:       port-sparc
>Synopsis:       [dM] on sun4m/sun4c, installboot never strips header
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 18 15:50:01 1997
>Last-Modified:
>Originator:     der Mouse
>Organization:
	Dis-
>Release:        1.2
>Environment:
	IPC, not that it matters
>Description:
	NetBSD/sparc installboot(8) cannot be made to strip the a.out
	header from the bootblocks it installs, when it's running on a
	machine on which the bootblocks should be preserved.  When
	using a sun4c/sun4m to build a boot disk for a sun4, this is a
	pain.
>How-To-Repeat:
	Build a system disk on a sun4c.  Try to install the boot blocks
	appropriate to a sun4.  Notice that the header is left on, no
	matter what flags you pass, and the disk doesn't work.
>Fix:
	In sys/arch/sparc/stand, apply these.  They create (and
	document) a -H flag to installboot, which says to strip the
	header no matter what kind of machine it's running on,
	complementary to the -h flag, which says to leave the header no
	matter what.  (I also documented a way I've found to install
	bootblocks in "secure" multi-user mode; this part of the
	manpage patch should arguably be a separate commit.)

	pk, say the word and I'll be glad to apply these myself,
	assuming installboot hasn't changed much since 1.2.

*** /sources/latest-usr-src/sys/arch/sparc/stand/installboot.8	Sat Sep 30 17:32:14 1995
--- /usr/src/sys/arch/sparc/stand/installboot.8	Tue Feb 18 14:37:33 1997
***************
*** 36,42 ****
  .Nd install a bootstrap on an FFS filesystem partition
  .Sh SYNOPSIS
  .Nm installboot
! .Op Fl nvh
  .Ar boot
  .Ar bootxx
  .Ar device
--- 36,42 ----
  .Nd install a bootstrap on an FFS filesystem partition
  .Sh SYNOPSIS
  .Nm installboot
! .Op Fl nvhH
  .Ar boot
  .Ar bootxx
  .Ar device
***************
*** 85,99 ****
  header on the installed
  .Ar bootxx
  program.
  Sun 4c models with
  .Tn Openboot
  PROMs need the header to be present, while Sun 4 systems with the
  .Dq old monitor
! interface require the header to be stripped off. This is normally taken
! care of by
  .Nm
! automatically.
! .El
  .Pp
  The arguments are:
  .Bl -tag -width bootxx
--- 85,111 ----
  header on the installed
  .Ar bootxx
  program.
+ .It Fl H
+ Strip the
+ .Xr a.out 5
+ header from the installed
+ .Ar bootxx
+ program.
+ .El
+ .Pp
  Sun 4c models with
  .Tn Openboot
  PROMs need the header to be present, while Sun 4 systems with the
  .Dq old monitor
! interface require the header to be stripped off.  By default,
  .Nm
! determines what kind of system it's running on and installs the boot
! blocks correctly for that machine; the
! .Fl h
! and
! .Fl H
! options exist to allow overriding the default in either direction, when
! building boot disks for other machines.
  .Pp
  The arguments are:
  .Bl -tag -width bootxx
***************
*** 130,140 ****
  .Nm installboot
  only works in single-user mode
  .Pq or insecure mode - see Xr init 8 .
  .Sh "SEE ALSO"
  .Xr disklabel 8 ,
  .Xr init 8
  .Sh HISTORY
- The
  .Nm
  first appeared in
  .Nx 1.1
--- 142,166 ----
  .Nm installboot
  only works in single-user mode
  .Pq or insecure mode - see Xr init 8 .
+ It is also possible to use
+ .Nm
+ in
+ .Dq secure
+ multi-user mode, if an unused partition begins at the same point on the
+ disk as the partition containing the filesystem the boot blocks reside
+ in.  For example, if sd1a begins at the beginning of sd1, then sd1c is
+ a suitable partition, and one can
+ .Bd -literal -offset indent
+ # mount /dev/sd1a /mnt
+ # cp /usr/mdec/boot /mnt/boot
+ # sync
+ # installboot /mnt/boot /usr/mdec/bootxx /dev/rsd1c
+ .Ed
+ This is arguably a bug, but in this instance it's useful.
  .Sh "SEE ALSO"
  .Xr disklabel 8 ,
  .Xr init 8
  .Sh HISTORY
  .Nm
  first appeared in
  .Nx 1.1


*** /sources/latest-usr-src/sys/arch/sparc/stand/installboot.c	Wed Nov  8 04:09:20 1995
--- /usr/src/sys/arch/sparc/stand/installboot.c	Tue Feb 18 14:40:18 1997
***************
*** 94,105 ****
  	int	mib[2];
  	size_t	size;
  
! 	while ((c = getopt(argc, argv, "vnh")) != EOF) {
  		switch (c) {
  		case 'h':
  			/* Don't strip a.out header */
  			hflag = 1;
  			break;
  		case 'n':
  			/* Do not actually write the bootblock to disk */
  			nowrite = 1;
--- 94,109 ----
  	int	mib[2];
  	size_t	size;
  
! 	while ((c = getopt(argc, argv, "vnhH")) != EOF) {
  		switch (c) {
  		case 'h':
  			/* Don't strip a.out header */
  			hflag = 1;
  			break;
+ 		case 'H':
+ 			/* Do strip a.out header */
+ 			hflag = -1;
+ 			break;
  		case 'n':
  			/* Do not actually write the bootblock to disk */
  			nowrite = 1;
***************
*** 127,141 ****
  		printf("device: %s\n", dev);
  	}
  
! 	mib[0] = CTL_HW;
! 	mib[1] = HW_MODEL;
! 	size = sizeof(cpumodel);
! 	if (sysctl(mib, 2, cpumodel, &size, NULL, 0) == -1)
! 		err(1, "sysctl");
! 
! 	if (size < 5 || strncmp(cpumodel, "SUN-4", 5) != 0) /*XXX*/ 
! 		/* Assume a sun4c/sun4m */
! 		hflag = 1;
  
  	/* Load proto blocks into core */
  	if ((protostore = loadprotoblocks(proto, &protosize)) == NULL)
--- 131,153 ----
  		printf("device: %s\n", dev);
  	}
  
! 	if (hflag == 0) {
! 
! 		mib[0] = CTL_HW;
! 		mib[1] = HW_MODEL;
! 		size = sizeof(cpumodel);
! 		if (sysctl(mib, 2, cpumodel, &size, NULL, 0) == -1)
! 			err(1, "sysctl");
! 	
! 		if (size < 5 || strncmp(cpumodel, "SUN-4", 5) != 0) /*XXX*/ 
! 			/* Assume a sun4c/sun4m */
! 			hflag = 1;
! 		else
! 			/* Looks like a sun4 */
! 			hflag = -1;
! 	}
! 
! 	if (hflag < 0) hflag = 0;
  
  	/* Load proto blocks into core */
  	if ((protostore = loadprotoblocks(proto, &protosize)) == NULL)

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
>Audit-Trail:
>Unformatted: