xref: /freebsd/release/riscv/mkisoimages.sh (revision 4757b351ea9d59d71d4a38b82506d2d16fcd560d)
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}/../scripts/tools.subr
25. ${scriptdir}/../../tools/boot/install-boot.sh
26
27if [ "$1" = "-b" ]; then
28	MAKEFSARG="$4"
29else
30	MAKEFSARG="$3"
31fi
32
33if [ -f ${MAKEFSARG} ]; then
34	BASEBITSDIR=`dirname ${MAKEFSARG}`
35	METALOG=${MAKEFSARG}
36elif [ -d ${MAKEFSARG} ]; then
37	BASEBITSDIR=${MAKEFSARG}
38	METALOG=
39else
40	echo "${MAKEFSARG} must exist"
41	exit 1
42fi
43
44if [ "$1" = "-b" ]; then
45	# Make an EFI system partition.
46	espfilename=$(mktemp /tmp/efiboot.XXXXXX)
47	# ESP file size in KB.
48	espsize="2048"
49	make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
50
51	bootable="-o bootimage=efi;${espfilename} -o no-emul-boot -o platformid=efi"
52
53	shift
54else
55	bootable=""
56fi
57
58if [ $# -lt 3 ]; then
59	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
60	exit 1
61fi
62
63LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
64NAME="$1"; shift
65# MAKEFSARG extracted already
66shift
67
68publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
69echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
70if [ -n "${METALOG}" ]; then
71	metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
72	cat ${METALOG} > ${metalogfilename}
73	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
74	MAKEFSARG=${metalogfilename}
75fi
76$MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
77rm -f "$BASEBITSDIR/etc/fstab"
78rm -f ${espfilename}
79if [ -n "${METALOG}" ]; then
80	rm ${metalogfilename}
81fi
82
83if [ "$bootable" != "" ]; then
84	# Look for the EFI System Partition image we dropped in the ISO image.
85	for entry in `$ETDUMP --format shell $NAME`; do
86		eval $entry
87		# XXX: etdump(8) returns "default" for the initial entry
88		if [ "$et_platform" = "default" ]; then
89			espstart=`expr $et_lba \* 2048`
90			espsize=`expr $et_sectors \* 512`
91			espparam="-p efi::$espsize:$espstart"
92			break
93		fi
94	done
95
96	# Create a GPT image containing the EFI partition.
97	efifilename=$(mktemp /tmp/efi.img.XXXXXX)
98	if [ "$(uname -s)" = "Linux" ]; then
99		imgsize=`stat -c %s "$NAME"`
100	else
101		imgsize=`stat -f %z "$NAME"`
102	fi
103	$MKIMG -s gpt \
104	    --capacity $imgsize \
105	    $espparam \
106	    -o $efifilename
107
108	# Drop the GPT into the System Area of the ISO.
109	dd if=$efifilename of="$NAME" bs=32k count=1 conv=notrunc
110	rm -f $efifilename
111fi
112