xref: /freebsd/release/arm64/mkisoimages.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
16dadc5d1SMitchell Horne#!/bin/sh
26dadc5d1SMitchell Horne#
36dadc5d1SMitchell Horne#
46dadc5d1SMitchell Horne# This script is used by release/Makefile to build the (optional) ISO images
56dadc5d1SMitchell Horne# for a FreeBSD release.  It is considered architecture dependent since each
66dadc5d1SMitchell Horne# platform has a slightly unique way of making bootable CDs. This script is
76dadc5d1SMitchell Horne# also allowed to generate any number of images since that is more of
86dadc5d1SMitchell Horne# publishing decision than anything else.
96dadc5d1SMitchell Horne#
106dadc5d1SMitchell Horne# Usage:
116dadc5d1SMitchell Horne#
126dadc5d1SMitchell Horne# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
136dadc5d1SMitchell Horne#
146dadc5d1SMitchell Horne# Where -b is passed if the ISO image should be made "bootable" by
156dadc5d1SMitchell Horne# whatever standards this architecture supports (may be unsupported),
166dadc5d1SMitchell Horne# image-label is the ISO image label, image-name is the filename of the
176dadc5d1SMitchell Horne# resulting ISO image, base-bits-dir contains the image contents and
186dadc5d1SMitchell Horne# extra-bits-dir, if provided, contains additional files to be merged
196dadc5d1SMitchell Horne# into base-bits-dir as part of making the image.
206dadc5d1SMitchell Horne
216dadc5d1SMitchell Horneset -e
226dadc5d1SMitchell Horne
236dadc5d1SMitchell Hornescriptdir=$(dirname $(realpath $0))
246dadc5d1SMitchell Horne. ${scriptdir}/../../tools/boot/install-boot.sh
256dadc5d1SMitchell Horne
266dadc5d1SMitchell Horneif [ -z $ETDUMP ]; then
276dadc5d1SMitchell Horne	ETDUMP=etdump
286dadc5d1SMitchell Hornefi
296dadc5d1SMitchell Horne
306dadc5d1SMitchell Horneif [ -z $MAKEFS ]; then
316dadc5d1SMitchell Horne	MAKEFS=makefs
326dadc5d1SMitchell Hornefi
336dadc5d1SMitchell Horne
346dadc5d1SMitchell Horneif [ -z $MKIMG ]; then
356dadc5d1SMitchell Horne	MKIMG=mkimg
366dadc5d1SMitchell Hornefi
376dadc5d1SMitchell Horne
386dadc5d1SMitchell Horneif [ "$1" = "-b" ]; then
3913cb0041SJessica Clarke	MAKEFSARG="$4"
4013cb0041SJessica Clarkeelse
4113cb0041SJessica Clarke	MAKEFSARG="$3"
4213cb0041SJessica Clarkefi
436dadc5d1SMitchell Horne
4413cb0041SJessica Clarkeif [ -f ${MAKEFSARG} ]; then
4513cb0041SJessica Clarke	BASEBITSDIR=`dirname ${MAKEFSARG}`
4613cb0041SJessica Clarke	METALOG=${MAKEFSARG}
4713cb0041SJessica Clarkeelif [ -d ${MAKEFSARG} ]; then
4813cb0041SJessica Clarke	BASEBITSDIR=${MAKEFSARG}
4913cb0041SJessica Clarke	METALOG=
5013cb0041SJessica Clarkeelse
5113cb0041SJessica Clarke	echo "${MAKEFSARG} must exist"
5213cb0041SJessica Clarke	exit 1
5313cb0041SJessica Clarkefi
5413cb0041SJessica Clarke
5513cb0041SJessica Clarkeif [ "$1" = "-b" ]; then
566dadc5d1SMitchell Horne	# Make an EFI system partition.
576dadc5d1SMitchell Horne	espfilename=$(mktemp /tmp/efiboot.XXXXXX)
58a0da9a62SGlen Barber	# ESP file size in KB.
59bdccfea1SGlen Barber	espsize="2048"
60a0da9a62SGlen Barber	make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
616dadc5d1SMitchell Horne
626dadc5d1SMitchell Horne	bootable="-o bootimage=efi;${espfilename} -o no-emul-boot -o platformid=efi"
636dadc5d1SMitchell Horne
646dadc5d1SMitchell Horne	shift
656dadc5d1SMitchell Horneelse
666dadc5d1SMitchell Horne	bootable=""
676dadc5d1SMitchell Hornefi
686dadc5d1SMitchell Horne
696dadc5d1SMitchell Horneif [ $# -lt 3 ]; then
706dadc5d1SMitchell Horne	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
716dadc5d1SMitchell Horne	exit 1
726dadc5d1SMitchell Hornefi
736dadc5d1SMitchell Horne
746dadc5d1SMitchell HorneLABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
756dadc5d1SMitchell HorneNAME="$1"; shift
7613cb0041SJessica Clarke# MAKEFSARG extracted already
7713cb0041SJessica Clarkeshift
786dadc5d1SMitchell Horne
796dadc5d1SMitchell Hornepublisher="The FreeBSD Project.  https://www.FreeBSD.org/"
806dadc5d1SMitchell Horneecho "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
8113cb0041SJessica Clarkeif [ -n "${METALOG}" ]; then
8213cb0041SJessica Clarke	metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
8313cb0041SJessica Clarke	cat ${METALOG} > ${metalogfilename}
8413cb0041SJessica Clarke	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
8513cb0041SJessica Clarke	MAKEFSARG=${metalogfilename}
8613cb0041SJessica Clarkefi
871a9b1c36SJessica Clarke$MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
886dadc5d1SMitchell Hornerm -f "$BASEBITSDIR/etc/fstab"
896dadc5d1SMitchell Hornerm -f ${espfilename}
9013cb0041SJessica Clarkeif [ -n "${METALOG}" ]; then
9113cb0041SJessica Clarke	rm ${metalogfilename}
9213cb0041SJessica Clarkefi
936dadc5d1SMitchell Horne
946dadc5d1SMitchell Horneif [ "$bootable" != "" ]; then
956dadc5d1SMitchell Horne	# Look for the EFI System Partition image we dropped in the ISO image.
966dadc5d1SMitchell Horne	for entry in `$ETDUMP --format shell $NAME`; do
976dadc5d1SMitchell Horne		eval $entry
986dadc5d1SMitchell Horne		# XXX: etdump(8) returns "default" for the initial entry
996dadc5d1SMitchell Horne		if [ "$et_platform" = "default" ]; then
1006dadc5d1SMitchell Horne			espstart=`expr $et_lba \* 2048`
1016dadc5d1SMitchell Horne			espsize=`expr $et_sectors \* 512`
1026dadc5d1SMitchell Horne			espparam="-p efi::$espsize:$espstart"
1036dadc5d1SMitchell Horne			break
1046dadc5d1SMitchell Horne		fi
1056dadc5d1SMitchell Horne	done
1066dadc5d1SMitchell Horne
1076dadc5d1SMitchell Horne	# Create a GPT image containing the EFI partition.
108045c8f52SJessica Clarke	efifilename=$(mktemp /tmp/efi.img.XXXXXX)
109*cefe5879SJessica Clarke	if [ "$(uname -s)" = "Linux" ]; then
110*cefe5879SJessica Clarke		imgsize=`stat -c %s "$NAME"`
111*cefe5879SJessica Clarke	else
1126dadc5d1SMitchell Horne		imgsize=`stat -f %z "$NAME"`
113*cefe5879SJessica Clarke	fi
1146dadc5d1SMitchell Horne	$MKIMG -s gpt \
1156dadc5d1SMitchell Horne	    --capacity $imgsize \
1166dadc5d1SMitchell Horne	    $espparam \
117045c8f52SJessica Clarke	    -o $efifilename
1186dadc5d1SMitchell Horne
1196dadc5d1SMitchell Horne	# Drop the GPT into the System Area of the ISO.
120045c8f52SJessica Clarke	dd if=$efifilename of="$NAME" bs=32k count=1 conv=notrunc
121045c8f52SJessica Clarke	rm -f $efifilename
1226dadc5d1SMitchell Hornefi
123