Skip to content

Commit f0d402c

Browse files
committed
Support creating EFI bundles in run.sh, along with booting them.
1 parent 2c58479 commit f0d402c

File tree

4 files changed

+65
-11
lines changed

4 files changed

+65
-11
lines changed

testing/run.sh

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ usage() {
1111
Usage: $0 [options]
1212
-a Set kernel command line
1313
-A+ Append additional arguments to kernel command line
14-
-d+ Set one or more non-standard disk images
14+
-d+ Set one or more non-standard disk images
1515
-f Force recreation of the initramfs
1616
-s Enable serial console on stdio
1717
-v Set type of qemu display to use
1818
-D Set test directory
1919
-i Write SSH config include
2020
-n Do not reset the controlling terminal after the VM exits
21+
-e Boot the VM with an EFI bundle
2122
EOF
2223
}
2324

24-
CMDOPTS="D:A:a:d:fsv:hin"
25+
CMDOPTS="D:A:a:d:fsv:hine"
2526

2627
# First-pass option parsing just looks for test directory
2728
while getopts "${CMDOPTS}" opt; do
@@ -77,14 +78,17 @@ case "$(uname -m)" in
7778
esac
7879

7980
DRIVE=()
81+
BFILES=()
8082
INITRD="${TESTDIR}/initramfs-bootmenu.img"
83+
OVMF="stubs/OVMF_CODE.fd"
8184
MEMORY="2048M"
8285
SMP="2"
8386
CREATE=0
8487
SERIAL=0
8588
DISPLAY_TYPE=
8689
SSH_INCLUDE=0
8790
RESET=1
91+
EFI=0
8892

8993
# Override any default variables
9094
#shellcheck disable=SC1091
@@ -125,6 +129,19 @@ while getopts "${CMDOPTS}" opt; do
125129
n)
126130
RESET=0
127131
;;
132+
e)
133+
case "$(uname -m)" in
134+
x86_64)
135+
BUNDLE="${TESTDIR}/vmlinuz.EFI"
136+
KERNEL=
137+
INITRD=
138+
EFI=1
139+
;;
140+
*)
141+
echo "EFI bundles unsupported on $(uname -m)"
142+
;;
143+
esac
144+
;;
128145
*)
129146
;;
130147
esac
@@ -161,29 +178,63 @@ if [ "${#AAPPEND[@]}" -gt 0 ]; then
161178
fi
162179

163180
# Creation is required if either kernel or initramfs is missing
164-
if [ ! -f "${KERNEL}" ] || [ ! -f "${INITRD}" ]; then
165-
CREATE=1
181+
if ((EFI)) ; then
182+
[ ! -f "${BUNDLE}" ] && CREATE=1
183+
else
184+
if [ -n "${KERNEL}" ] && [ ! -f "${KERNEL}" ] || [ -n "${INITRD}" ] && [ ! -f "${INITRD}" ]; then
185+
CREATE=1
186+
fi
166187
fi
167188

168189
if ((CREATE)) ; then
169-
# Create our initramfs
170-
[ -f "${KERNEL}" ] && rm "${KERNEL}"
171-
[ -f "${INITRD}" ] && rm "${INITRD}"
190+
yamlconf="${TESTDIR}/local.yaml"
191+
STUBS="$(realpath -e stubs)"
192+
193+
if ((EFI)) ; then
194+
# toggle only EFI bundle creation
195+
[ -f "${BUNDLE}" ] && rm "${BUNDLE}"
196+
yq-go eval ".EFI.Enabled = true" -i "${yamlconf}"
197+
yq-go eval ".Components.Enabled = false" -i "${yamlconf}"
198+
yq-go eval ".EFI.Stub = \"${STUBS}/linuxx64.efi.stub\"" -i "${yamlconf}"
199+
else
200+
# toggle only component creation
201+
[ -f "${KERNEL}" ] && rm "${KERNEL}"
202+
[ -f "${INITRD}" ] && rm "${INITRD}"
203+
yq-go eval ".EFI.Enabled = false" -i "${yamlconf}"
204+
yq-go eval ".Components.Enabled = true" -i "${yamlconf}"
205+
fi
172206

173207
# Try to find the local dracut and generate-zbm first
174208
if ! ( cd "${TESTDIR}" && PATH=./dracut:${PATH} ./generate-zbm -c ./local.yaml ); then
175209
echo "ERROR: unable to create ZFSBootMenu images"
176210
exit 1
177211
fi
212+
213+
# always revert to component builds
214+
if ((EFI)) ; then
215+
yq-go eval ".EFI.Enabled = false" -i "${yamlconf}"
216+
yq-go eval ".Components.Enabled = true" -i "${yamlconf}"
217+
fi
178218
fi
179219

180220
# Ensure kernel and initramfs exist
181-
if [ ! -f "${KERNEL}" ] ; then
221+
if [ -n "${KERNEL}" ] && [ ! -f "${KERNEL}" ] ; then
182222
echo "Missing kernel: ${KERNEL}"
183223
exit 1
184-
elif [ ! -f "${INITRD}" ] ; then
224+
elif [ -n "${INITRD}" ] && [ ! -f "${INITRD}" ] ; then
185225
echo "Missing initramfs: ${INITRD}"
186226
exit 1
227+
elif [ -n "${BUNDLE}" ] && [ ! -f "${BUNDLE}" ] ; then
228+
echo "Missing EFI bundle: ${BUNDLE}"
229+
exit 1
230+
fi
231+
232+
if ((EFI)) ; then
233+
BFILES+=( "-bios" "${OVMF}" )
234+
BFILES+=( "-kernel" "${BUNDLE}" )
235+
else
236+
BFILES+=( "-kernel" "${KERNEL}" )
237+
BFILES+=( "-initrd" "${INITRD}" )
187238
fi
188239

189240
SSH_PORT=2222
@@ -232,8 +283,7 @@ fi
232283

233284
# shellcheck disable=SC2086
234285
"${BIN}" \
235-
-kernel "${KERNEL}" \
236-
-initrd "${INITRD}" \
286+
"${BFILES[@]}" \
237287
"${DRIVE[@]}" \
238288
-m "${MEMORY}" \
239289
-smp "${SMP}" \

testing/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,13 @@ fi
157157
if ((YAML)) ; then
158158
echo "Configuring local.yaml"
159159
yamlconf="${TESTDIR}/local.yaml"
160+
STUBS="$(realpath -e stubs)"
160161
cp ../etc/zfsbootmenu/config.yaml "${yamlconf}"
161162
yq-go eval ".Components.ImageDir = \"${TESTDIR}\"" -i "${yamlconf}"
162163
yq-go eval ".Components.Versions = false" -i "${yamlconf}"
164+
yq-go eval ".EFI.ImageDir = \"${TESTDIR}\"" -i "${yamlconf}"
165+
yq-go eval ".EFI.Versions = false" -i "${yamlconf}"
166+
yq-go eval ".EFI.Stub = \"${STUBS}/linuxx64.efi.stub\"" -i "${yamlconf}"
163167
yq-go eval ".Global.ManageImages = true" -i "${yamlconf}"
164168
yq-go eval ".Global.DracutConfDir = \"${TESTDIR}/dracut.conf.d\"" -i "${yamlconf}"
165169
yq-go eval ".Global.DracutFlags = [ \"--local\" ]" -i "${yamlconf}"

testing/stubs/OVMF_CODE.fd

1.88 MB
Binary file not shown.

testing/stubs/linuxx64.efi.stub

51.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)