Subject: port-sparc64/33987: sysinst on sparc64 fails to install primary bootstrap loader
To: None <port-sparc64-maintainer@netbsd.org, gnats-admin@netbsd.org,>
From: None <he@NetBSD.org>
List: netbsd-bugs
Date: 07/12/2006 18:10:00
>Number:         33987
>Category:       port-sparc64
>Synopsis:       sysinst on sparc64 fails to install primary bootstrap loader
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-sparc64-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 12 18:10:00 +0000 2006
>Originator:     Havard Eidnes
>Release:        NetBSD 3.99.21 3 Jul 2006
>Organization:
>Environment:
System: NetBSD torbidinsu.urc.uninett.no 3.99.21 NetBSD 3.99.21 (GENERIC) #0: Fri Jul  7 15:42:53 CEST 2006  he@torbidinsu.urc.uninett.no:/usr/obj/sys/arch/sparc64/compile/GENERIC sparc64
Architecture: sparc64
Machine: sparc64
>Description:
	After installing NetBSD on a system with wiped harddisks,
	attempts to reboot from the recently-installed system gives

{0} ok boot disk netbsd
Resetting ... 
...
Rebooting with command: boot disk netbsd
Boot device: /pci@1f,4000/scsi@3/disk@0,0  File and args: netbsd
The file just loaded does not appear to be executable.
Boot device: /pci@1f,4000/scsi@3/disk@0,0:a  File and args: 
The file just loaded does not appear to be executable.

	Manually installing the primary bootstrap loader with

# installboot /dev/rsd0c /usr/mdec/bootblk

	fixed the problem.  ('c' starts at same offset as 'a').

	A closer inspection of the sysinst session from the serial
	console gives some clue as to the problem.  Sysinst runs

/usr/mdec/binstall ffs /targetroot

	to install the boot code.  This resulted in the following
	error message:

installboot: File system `/dev/rsd0a' is of an unknown type

	and thus, no primary boot loader was installed.	

	Before installing the new boot code I net-booted again to
	inspect the disk label sysinst had placed on the hard drive,
	and it looked like this:

# disklabel sd0
# /dev/rsd0c:
type: unknown
disk: torbidinsu
label: 
flags:
bytes/sector: 512
sectors/track: 248
tracks/cylinder: 19
sectors/cylinder: 4712
cylinders: 7506
total sectors: 35368272
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0 

8 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:  25124384         0     4.2BSD   2048 16384 28216  # (Cyl.      0 -   5331)
 b:  10243888  25124384       swap                     # (Cyl.   5332 -   7505)
 c:  35368272         0     unused      0     0        # (Cyl.      0 -   7505)
# 

	Modifying binstall to allow a test run in secure mode reveals
	what commands it would try to execute:

% /usr/mdec/binstall -t ffs /
Inspecting "/dev/sd0a on / type ffs (local)"
Boot device: /dev/rsd0a
Primary boot program: /usr/mdec/bootblk
Secondary boot program: //ofwboot
=> cp -p -f /usr/mdec/ofwboot //ofwboot
/usr/sbin/installboot -v -m sparc64 /dev/rsd0a /usr/mdec/bootblk ofwboot
=> /usr/sbin/installboot -v -m sparc64 /dev/rsd0a /usr/mdec/bootblk ofwboot
% 

	(except -t to binstall turns on -v to installboot as well)

>How-To-Repeat:
	Try to install -current on a sparc64 system with a wiped
	system disk, and watch it fail to install the primary boot
	loader.

>Fix:
	The problem appears to be that installboot for the install
	image is compiled with SMALLPROG, which ends up defining
	the NO_STAGE2 option, and the list of fs types to match
	against in fstypes[] is thus left empty!

	This is from installboot's Makefile, where we when SMALLPROG
	is defined only end up adding sparc64.c to ARCH_FILES:

.if !defined(SMALLPROG) && !defined(ARCH_FILES)
ARCH_FILES=  alpha.c amiga.c ews4800mips.c hp300.c hp700.c i386.c
ARCH_FILES+= macppc.c news.c next68k.c pmax.c
ARCH_FILES+= sparc.c sparc64.c sun68k.c vax.c x68k.c
.else
ARCH_FILES?= ${ARCH_XLAT:M${MACHINE}-*:S/${MACHINE}-//}
.if empty(ARCH_FILES)
ARCH_FILES= ${MACHINE}.c
.endif
.endif

	and since sparc64 is not in this match pattern:

.if empty(ARCH_FILES:C/(macppc|news|sparc|sun68k|x68k)/stg2/:Mstg2.c)
CPPFLAGS        += -DNO_STAGE2
.else
SRCS+= bbinfo.c

# fstypes are only needed for 'stage2' and then only from bbinfo.
SRCS+= ffs.c
.if SMALLPROG
CPPFLAGS+=      -DNO_FFS_SWAP
.else
SRCS+= ffs_bswap.c
.endif
.endif

	-DNO_STAGE2 gets added to CPPFLAGS.

	Now, I'm not entirely certain exactly how this is supposed to
	be fixed.  Perhaps by fixing the binstall script to not supply
	the name of the secondary boot loader (since it's installed by
	copying it to the root directory of the target file system
	anyway?), and presumably doesn't need to be given to
	installboot, at least not for sparc64?