]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/riscv/mkisoimages.sh
Merge llvm-project release/17.x llvmorg-17.0.2-0-gb2417f51dbbd
[FreeBSD/FreeBSD.git] / release / riscv / mkisoimages.sh
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
21 set -e
22
23 scriptdir=$(dirname $(realpath $0))
24 . ${scriptdir}/../../tools/boot/install-boot.sh
25
26 if [ -z $ETDUMP ]; then
27         ETDUMP=etdump
28 fi
29
30 if [ -z $MAKEFS ]; then
31         MAKEFS=makefs
32 fi
33
34 if [ -z $MKIMG ]; then
35         MKIMG=mkimg
36 fi
37
38 if [ "$1" = "-b" ]; then
39         MAKEFSARG="$4"
40 else
41         MAKEFSARG="$3"
42 fi
43
44 if [ -f ${MAKEFSARG} ]; then
45         BASEBITSDIR=`dirname ${MAKEFSARG}`
46         METALOG=${MAKEFSARG}
47 elif [ -d ${MAKEFSARG} ]; then
48         BASEBITSDIR=${MAKEFSARG}
49         METALOG=
50 else
51         echo "${MAKEFSARG} must exist"
52         exit 1
53 fi
54
55 if [ "$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
65 else
66         bootable=""
67 fi
68
69 if [ $# -lt 3 ]; then
70         echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
71         exit 1
72 fi
73
74 LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
75 NAME="$1"; shift
76 # MAKEFSARG extracted already
77 shift
78
79 publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
80 echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
81 if [ -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}
86 fi
87 $MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
88 rm -f "$BASEBITSDIR/etc/fstab"
89 rm -f ${espfilename}
90 if [ -n "${METALOG}" ]; then
91         rm ${metalogfilename}
92 fi
93
94 if [ "$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
122 fi