1#!/bin/sh
2#
3# Module: mkisoimages.sh
4# Author: Jordan K Hubbard
5# Date:   22 June 2001
6#
7# $FreeBSD$
8#
9# This script is used by release/Makefile to build the (optional) ISO images
10# for a FreeBSD release.  It is considered architecture dependent since each
11# platform has a slightly unique way of making bootable CDs.  This script
12# is also allowed to generate any number of images since that is more of
13# publishing decision than anything else.
14#
15# Usage:
16#
17# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
18#
19# Where -b is passed if the ISO image should be made "bootable" by
20# whatever standards this architecture supports (may be unsupported),
21# image-label is the ISO image label, image-name is the filename of the
22# resulting ISO image, base-bits-dir contains the image contents and
23# extra-bits-dir, if provided, contains additional files to be merged
24# into base-bits-dir as part of making the image.
25
26set -e
27
28if [ "x$1" = "x-b" ]; then
29    bootable=yes
30    shift
31else
32    bootable=no
33fi
34
35if [ $# -lt 3 ]; then
36    echo usage: $0 '[-b] label iso-name base-dir [extra-dir]'
37    exit 1
38fi
39
40LABEL=`echo $1 | tr '[:lower:]' '[:upper:]'`; shift
41NAME=$1; shift
42BASE=$1; shift
43
44EFIPART=efipart.sys
45
46# To create a bootable CD under EFI, the boot image should be an EFI
47# system partition.
48if [ $bootable = yes ]; then
49    EFISZ=65536
50    MNT=/mnt
51    dd if=/dev/zero of=$EFIPART count=$EFISZ
52    md=`mdconfig -a -t vnode -f $EFIPART`
53    newfs_msdos -F 12 -S 512 -h 4 -o 0 -s $EFISZ -u 16 $md
54    mount -t msdosfs /dev/$md $MNT
55    mkdir -p $MNT/efi/boot $MNT/boot $MNT/boot/kernel
56    cp -R $BASE/boot/defaults $MNT/boot
57    cp $BASE/boot/kernel/kernel $MNT/boot/kernel
58    if [ -s $BASE/boot/kernel/ispfw.ko ]; then
59	cp $BASE/boot/kernel/ispfw.ko $MNT/boot/kernel
60    fi
61    cp $BASE/boot/device.hints $MNT/boot
62    cp $BASE/boot/loader.* $MNT/boot
63    if [ -s $BASE/boot/mfsroot.gz ]; then
64	cp $BASE/boot/mfsroot.gz $MNT/boot
65    fi
66    cp $BASE/boot/color.4th $MNT/boot
67    cp $BASE/boot/support.4th $MNT/boot
68    cp $BASE/boot/check-password.4th $MNT/boot
69    cp $BASE/boot/screen.4th $MNT/boot
70    mv $MNT/boot/loader.efi $MNT/efi/boot/bootia64.efi
71    echo kern.cam.boot_delay=\"3000\" >> $MNT/boot/loader.conf
72    echo vfs.root.mountfrom=\"cd9660:iso9660/$LABEL\" >> $MNT/boot/loader.conf
73    umount $MNT
74    mdconfig -d -u $md
75    BOOTOPTS="-o bootimage=i386;$EFIPART -o no-emul-boot"
76else
77    BOOTOPTS=""
78fi
79
80publisher="The FreeBSD Project.  http://www.FreeBSD.org/"
81echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > $BASE/etc/fstab
82makefs -t cd9660 $BOOTOPTS -o rockridge -o label=$LABEL -o publisher="$publisher" $NAME $BASE $*
83rm $BASE/etc/fstab
84rm -f $EFIPART
85exit 0
86