@@ -11,17 +11,18 @@ usage() {
1111Usage: $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
2122EOF
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
2728while getopts " ${CMDOPTS} " opt; do
@@ -77,14 +78,17 @@ case "$(uname -m)" in
7778esac
7879
7980DRIVE=()
81+ BFILES=()
8082INITRD=" ${TESTDIR} /initramfs-bootmenu.img"
83+ OVMF=" stubs/OVMF_CODE.fd"
8184MEMORY=" 2048M"
8285SMP=" 2"
8386CREATE=0
8487SERIAL=0
8588DISPLAY_TYPE=
8689SSH_INCLUDE=0
8790RESET=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
161178fi
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
166187fi
167188
168189if (( 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
178218fi
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} " )
187238fi
188239
189240SSH_PORT=2222
232283
233284# shellcheck disable=SC2086
234285" ${BIN} " \
235- -kernel " ${KERNEL} " \
236- -initrd " ${INITRD} " \
286+ " ${BFILES[@]} " \
237287 " ${DRIVE[@]} " \
238288 -m " ${MEMORY} " \
239289 -smp " ${SMP} " \
0 commit comments