xref: /netbsd/distrib/common/sunbootcd.sh (revision 6550d01e)
1#! /bin/sh
2#
3# $NetBSD: sunbootcd.sh,v 1.5 2008/04/30 13:10:48 martin Exp $
4#
5# Copyright (c) 2003 The NetBSD Foundation, Inc.
6# All rights reserved.
7#
8# This code is derived from software contributed to The NetBSD Foundation
9# by Luke Mewburn.
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions
13# are met:
14# 1. Redistributions of source code must retain the above copyright
15#    notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright
17#    notice, this list of conditions and the following disclaimer in the
18#    documentation and/or other materials provided with the distribution.
19#
20# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31#
32
33: ${SUNLABEL:=sunlabel}		# sunlabel(8)
34: ${CYLSIZE:=640}		# Cylinder size, in 512byte blocks
35
36PROGNAME=${0##*/}
37FORMAT="%-8s offset %4d, size %4d, file %s\n"
38
39
40usage()
41{
42	cat 1>&2 << _USAGE_
43Usage: ${PROGNAME} fsimage sun4 [sun4c [sun4m [sun3|sun4d [sun3x|sun4u]]]]
44	Combine file system partitions for Sun Microsystems, Inc. computers
45	into a CD-ROM file system image suitable for booting on the
46	following platforms:
47		NetBSD/sun3:	sun3, sun3x
48		NetBSD/sparc:	sun4, sun4c, sun4d, sun4m
49		NetBSD/sparc64:	sun4u
50	The architecture arguments must be bootable file system image
51	for that architecture, or \`-' if no entry is desired.
52	\`fsimage' is typically an iso9660 file system image, although
53	any time of file system can be used as long as the first 512
54	bytes of the image are not used.  \`fsimage' is modified, and
55	the additional partitions are added in order.  If the same
56	filename is used more than once for different architectures,
57	it will only be copied once.
58_USAGE_
59	exit 1
60}
61
62if [ $# -lt 2 -o $# -gt 6 ]; then
63	usage
64fi
65
66for curfile in $*; do
67	[ "$curfile" = "-" ] && continue
68	if [ ! -f "$curfile" ]; then
69		echo 1>&2 "${PROGNAME}: ${curfile}: No such file."
70		exit 1
71	fi
72done
73
74ISOIMAGE="$1";	shift
75
76ISOSIZE=$( ls -l "${ISOIMAGE}" | awk '{print $5}' )
77ISOBLKS=$(( (${ISOSIZE} + 511) / 512 ))
78ISOCYLS=$(( (${ISOBLKS} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
79
80printf "${FORMAT}" "fsimage:" 0 ${ISOCYLS} "${ISOIMAGE}"
81
82ENDCYL=${ISOCYLS}
83curpart=0
84for curfile in $*; do
85	curpart=$(( ${curpart} + 1 ))
86	[ "$curfile" = "-" ] && continue
87
88	tpart=1
89	curoff=${ENDCYL}
90	while [ ${tpart} -lt ${curpart} ]; do
91		tfile=$(eval echo \$PART${tpart}FILE)
92		if [ "${curfile}" = "${tfile}" ]; then
93			curoff=$(eval echo \$PART${tpart}OFF)
94			break
95		fi
96		tpart=$(( ${tpart} + 1 ))
97	done
98
99	cursize=$( ls -l "${curfile}" | awk '{print $5}' )
100	curblks=$(( (${cursize} + 511) / 512 ))
101	curcyls=$(( (${curblks} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
102	printf "${FORMAT}" "Image ${curpart}:" ${curoff} ${curcyls} "${curfile}"
103
104	eval	PART${curpart}SIZE=${cursize} \
105		PART${curpart}BLKS=${curblks} \
106		PART${curpart}CYLS=${curcyls} \
107		PART${curpart}OFF=${curoff} \
108		PART${curpart}FILE="${curfile}"
109
110	if [ $curoff -eq $ENDCYL ]; then		# append ${curfile}
111		echo "    (appending ${curfile} to ${ISOIMAGE})"
112		dd if="${curfile}" of="${ISOIMAGE}" bs=${CYLSIZE}b \
113		    seek=${ENDCYL} conv=notrunc,sync 2>/dev/null
114		ENDCYL=$(( $ENDCYL + $curcyls ))
115	fi
116
117done
118
119printf "${FORMAT}" "Final:" 0 ${ENDCYL} "${ISOIMAGE}"
120
121${SUNLABEL} -nq "${ISOIMAGE}" << _partinfo_
122V nsect ${CYLSIZE}
123V nhead 1
124V rpm 300
125V pcyl ${ENDCYL}
126V ncyl ${ENDCYL}
127a 0 $(( ${ISOCYLS} * ${CYLSIZE} ))
128b ${PART1OFF:-0} $(( ${PART1CYLS:-0} * ${CYLSIZE} ))
129c ${PART2OFF:-0} $(( ${PART2CYLS:-0} * ${CYLSIZE} ))
130d ${PART3OFF:-0} $(( ${PART3CYLS:-0} * ${CYLSIZE} ))
131e ${PART4OFF:-0} $(( ${PART4CYLS:-0} * ${CYLSIZE} ))
132f ${PART5OFF:-0} $(( ${PART5CYLS:-0} * ${CYLSIZE} ))
133W
134_partinfo_
135