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