xref: /freebsd/release/powerpc/mkisoimages.sh (revision df21a004be237a1dccd03c7b47254625eea62fa9)
1#!/bin/sh
2#
3# Module: mkisoimages.sh
4# Author: Jordan K Hubbard
5# Date:   22 June 2001
6#
7#
8# This script is used by release/Makefile to build the (optional) ISO images
9# for a FreeBSD release.  It is considered architecture dependent since each
10# platform has a slightly unique way of making bootable CDs.  This script
11# is also allowed to generate any number of images since that is more of
12# publishing decision than anything else.
13#
14# Usage:
15#
16# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
17#
18# Where -b is passed if the ISO image should be made "bootable" by
19# whatever standards this architecture supports (may be unsupported),
20# image-label is the ISO image label, image-name is the filename of the
21# resulting ISO image, base-bits-dir contains the image contents and
22# extra-bits-dir, if provided, contains additional files to be merged
23# into base-bits-dir as part of making the image.
24
25set -e
26
27scriptdir=$(dirname $(realpath $0))
28. ${scriptdir}/../scripts/tools.subr
29
30if [ "$1" = "-b" ]; then
31	MAKEFSARG="$4"
32else
33	MAKEFSARG="$3"
34fi
35
36if [ -f ${MAKEFSARG} ]; then
37	BASEBITSDIR=`dirname ${MAKEFSARG}`
38	METALOG=${MAKEFSARG}
39elif [ -d ${MAKEFSARG} ]; then
40	BASEBITSDIR=${MAKEFSARG}
41	METALOG=
42else
43	echo "${MAKEFSARG} must exist"
44	exit 1
45fi
46
47if [ "$1" = "-b" ]; then
48	bootable=1
49	shift
50else
51	bootable=""
52fi
53
54if [ $# -lt 3 ]; then
55	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
56	exit 1
57fi
58
59LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
60NAME="$1"; shift
61# MAKEFSARG extracted already
62shift
63
64if [ -n "${METALOG}" ]; then
65	metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
66	cat ${METALOG} > ${metalogfilename}
67	MAKEFSARG=${metalogfilename}
68fi
69
70if [ -n "$bootable" ]; then
71	echo "Building bootable disc"
72
73	BOOTBLOCK=$(mktemp /tmp/hfs-boot-block.XXXXXX)
74
75	# Apple boot code
76	uudecode -p "`dirname "$0"`/hfs-boot.bz2.uu" | bunzip2 > $BOOTBLOCK
77	OFFSET=$(hd $BOOTBLOCK | grep 'Loader START' | cut -f 1 -d ' ')
78	OFFSET=0x$(echo 0x$OFFSET | awk '{printf("%x\n",$1/512);}')
79	dd if="$BASEBITSDIR/boot/loader" of=$BOOTBLOCK seek=$OFFSET conv=notrunc
80
81	bootable="-o bootimage=macppc;$BOOTBLOCK -o no-emul-boot"
82
83	# pSeries/PAPR boot code
84	mkdir -p "$BASEBITSDIR/ppc/chrp"
85	cp "$BASEBITSDIR/boot/loader" "$BASEBITSDIR/ppc/chrp"
86	cat > "$BASEBITSDIR/ppc/bootinfo.txt" << EOF
87<chrp-boot>
88<description>FreeBSD Install</description>
89<os-name>FreeBSD</os-name>
90<boot-script>boot &device;:,\ppc\chrp\loader</boot-script>
91</chrp-boot>
92EOF
93	bootable="$bootable -o chrp-boot"
94	if [ -n "${METALOG}" ]; then
95		echo "./ppc type=dir uname=root gname=wheel mode=0755" >> ${metalogfilename}
96		echo "./ppc/chrp type=dir uname=root gname=wheel mode=0755" >> ${metalogfilename}
97		echo "./ppc/chrp/loader type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
98		echo "./ppc/bootinfo.txt type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
99	fi
100
101	# Petitboot config for PS3/PowerNV
102	echo FreeBSD Install=\'/boot/kernel/kernel vfs.root.mountfrom=cd9660:/dev/iso9660/$LABEL\' > "$BASEBITSDIR/etc/kboot.conf"
103	if [ -n "${METALOG}" ]; then
104		echo "./etc/kboot.conf type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
105	fi
106fi
107
108publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
109echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
110if [ -n "${METALOG}" ]; then
111	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
112fi
113${MAKEFS} -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
114rm -f "$BASEBITSDIR/etc/fstab"
115if [ -n "$bootable" ]; then
116	rm $BOOTBLOCK
117fi
118rm -rf "$BASEBITSDIR/ppc"
119if [ -n "${METALOG}" ]; then
120	rm ${metalogfilename}
121fi
122