blob: f92059bf7f22b0ad2347882ffda76c40fb0fcc69 [file] [log] [blame]
#!/bin/bash
# Copyright 2020 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#### CATEGORY=Run, inspect and debug
### start fuchsia in qemu with a FVM disk
## start fuchsia in qemu with a FVM disk
##
## This command delegates to //zircon/scripts/run-zircon. Flags are documented
## in that script, and can be discovered by passing -h or --help.
##
set -ex
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/../../../../../../tools/devshell/lib/image_build_vars.sh" || exit $?
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/../../../../../../tools/devshell/lib/fvm.sh" || exit $?
trailing_args=()
while (($#)); do
case "$1" in
-h|--help)
fx-command-help
"${FUCHSIA_DIR}/src/sys/pkg/tests/system-tests/bin/run-zircon" -h
exit 1
;;
*)
trailing_args+=("$1")
;;
esac
shift
done
qemu_dir="${PREBUILT_QEMU_DIR}/bin"
ovmf_dir="${PREBUILT_OVMF_DIR}"
imgdir="$(mktemp -d ${FUCHSIA_BUILD_DIR}/tmp.XXX)"
if [[ ! -d "${imgdir}" ]]; then
echo >&2 "Failed to create temporary directory"
exit 1
fi
function cleanup() {
# want to make sure we kill a long-running qemu if this shell dies.
local child_pids=$(jobs -p)
if [[ -n "${child_pids}" ]]; then
echo >&2 "killing child processes: ${child_pids}"
# Note: child_pids must be expanded to args here.
kill ${child_pids} 2> /dev/null
wait 2> /dev/null
fi
rm -rf "${imgdir}"
}
trap cleanup EXIT
# Copy in the OMVF_VARS.fd into our temp directory, which allows EFI data to be
# persisted across reboots.
cp "${ovmf_dir}/OVMF_VARS.fd" "${imgdir}/OVMF_VARS.fd"
# Make sure the OVMF_VARS file is writable.
chmod +w "${imgdir}/OVMF_VARS.fd"
# Ensure that the output is sent to the serial, and that we boot into zedboot.
cat << EOF > "${imgdir}/cmdline.txt"
kernel.serial=legacy
TERM=xterm-256color
kernel.halt-on-panic=true
bootloader.default=zedboot
bootloader.timeout=0
EOF
# Construct a Fuchsia image.
FVM_SIZE=$(( 2 * 1024 * 1024 * 1024))
PARTITION_SIZE=$(( 4 * 1024 * 1024 * 1024))
"${FUCHSIA_BUILD_DIR}/host-tools/make-fuchsia-vol" \
-cmdline "${imgdir}/cmdline.txt" \
-resize "$PARTITION_SIZE" \
-fvm-size "$FVM_SIZE" \
-abr-size 33554432 \
"${imgdir}/fuchsia.efi"
# Start the paver in the background.
"${FUCHSIA_BUILD_DIR}/pave.sh" \
-n 'fuchsia-5254-0063-5e7a' \
--authorized-keys "$(get-ssh-authkeys)" \
-1 &
# Launch QEMU.
"${FUCHSIA_DIR}/src/sys/pkg/tests/system-tests/bin/run-zircon" \
-a "${FUCHSIA_ARCH}" \
-q "${qemu_dir}" \
-N \
-d \
-D "${imgdir}/fuchsia.efi" \
--diskfmt=raw \
"--ovmf-code=${ovmf_dir}/OVMF_CODE.fd" \
"--ovmf-vars=${imgdir}/OVMF_VARS.fd" \
"${trailing_args[@]}"
exit $?