xref: /freebsd/release/arm64/mkisoimages.sh (revision f81cdf24ba5436367377f7c8e8f51f6df2a75ca7)
1#!/bin/sh
2#
3#
4# This script is used by release/Makefile to build the (optional) ISO images
5# for a FreeBSD release.  It is considered architecture dependent since each
6# platform has a slightly unique way of making bootable CDs. This script is
7# also allowed to generate any number of images since that is more of
8# publishing decision than anything else.
9#
10# Usage:
11#
12# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
13#
14# Where -b is passed if the ISO image should be made "bootable" by
15# whatever standards this architecture supports (may be unsupported),
16# image-label is the ISO image label, image-name is the filename of the
17# resulting ISO image, base-bits-dir contains the image contents and
18# extra-bits-dir, if provided, contains additional files to be merged
19# into base-bits-dir as part of making the image.
20
21set -e
22
23scriptdir=$(dirname $(realpath $0))
24. ${scriptdir}/../../tools/boot/install-boot.sh
25
26if [ -z $ETDUMP ]; then
27	ETDUMP=etdump
28fi
29
30if [ -z $MAKEFS ]; then
31	MAKEFS=makefs
32fi
33
34if [ -z $MKIMG ]; then
35	MKIMG=mkimg
36fi
37
38if [ "$1" = "-b" ]; then
39	MAKEFSARG="$4"
40else
41	MAKEFSARG="$3"
42fi
43
44if [ -f ${MAKEFSARG} ]; then
45	BASEBITSDIR=`dirname ${MAKEFSARG}`
46	METALOG=${MAKEFSARG}
47elif [ -d ${MAKEFSARG} ]; then
48	BASEBITSDIR=${MAKEFSARG}
49	METALOG=
50else
51	echo "${MAKEFSARG} must exist"
52	exit 1
53fi
54
55if [ "$1" = "-b" ]; then
56	# Make an EFI system partition.
57	espfilename=$(mktemp /tmp/efiboot.XXXXXX)
58	# ESP file size in KB.
59	espsize="2048"
60	make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
61
62	bootable="-o bootimage=efi;${espfilename} -o no-emul-boot -o platformid=efi"
63
64	shift
65else
66	bootable=""
67fi
68
69if [ $# -lt 3 ]; then
70	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
71	exit 1
72fi
73
74LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
75NAME="$1"; shift
76# MAKEFSARG extracted already
77shift
78
79publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
80echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
81if [ -n "${METALOG}" ]; then
82	metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
83	cat ${METALOG} > ${metalogfilename}
84	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
85	MAKEFSARG=${metalogfilename}
86fi
87$MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
88rm -f "$BASEBITSDIR/etc/fstab"
89rm -f ${espfilename}
90if [ -n "${METALOG}" ]; then
91	rm ${metalogfilename}
92fi
93
94if [ "$bootable" != "" ]; then
95	# Look for the EFI System Partition image we dropped in the ISO image.
96	for entry in `$ETDUMP --format shell $NAME`; do
97		eval $entry
98		# XXX: etdump(8) returns "default" for the initial entry
99		if [ "$et_platform" = "default" ]; then
100			espstart=`expr $et_lba \* 2048`
101			espsize=`expr $et_sectors \* 512`
102			espparam="-p efi::$espsize:$espstart"
103			break
104		fi
105	done
106
107	# Create a GPT image containing the EFI partition.
108	efifilename=$(mktemp /tmp/efi.img.XXXXXX)
109	if [ "$(uname -s)" = "Linux" ]; then
110		imgsize=`stat -c %s "$NAME"`
111	else
112		imgsize=`stat -f %z "$NAME"`
113	fi
114	$MKIMG -s gpt \
115	    --capacity $imgsize \
116	    $espparam \
117	    -o $efifilename
118
119	# Drop the GPT into the System Area of the ISO.
120	dd if=$efifilename of="$NAME" bs=32k count=1 conv=notrunc
121	rm -f $efifilename
122fi
123