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