blob: 9a613bf694a6c304b6faf26f196fd6537bcd8dc3 [file] [log] [blame]
#!/bin/bash
# Copyright 2017 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.
### 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 -e
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/image_build_vars.sh || exit $?
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/fvm.sh || exit $?
source "${FUCHSIA_DIR}/buildtools/vars.sh"
for arg in "$@"; do
if [[ "$arg" = "-h" || "$arg" = "--help" ]]; then
fx-command-help
"${FUCHSIA_DIR}/zircon/scripts/run-zircon" -h
exit 1
fi
done
qemu_dir="${BUILDTOOLS_QEMU_DIR}/bin"
args=(
-a "${FUCHSIA_ARCH}"
-q "${qemu_dir}"
-G 3
-t "${FUCHSIA_BUILD_DIR}/${IMAGE_QEMU_KERNEL_RAW}"
)
# Construction of a qcow image prevents qemu from writing back to the
# build-produced image file, which could cause timestamp issues with that file.
# Construction of the new ZBI adds //.ssh/authorized_keys for SSH access.
imgdir="$(mktemp -d)"
if [[ ! -d "${imgdir}" ]]; then
echo >&2 "Failed to create temporary directory"
exit 1
fi
trap 'rm -rf "$imgdir"' EXIT
kernelzbi="${imgdir}/fuchsia-ssh.zbi"
args+=(-z "${kernelzbi}")
"${ZIRCON_TOOLS_DIR}/zbi" -o "${kernelzbi}" "${FUCHSIA_BUILD_DIR}/${IMAGE_ZIRCONA_ZBI}" \
--entry "data/ssh/authorized_keys=${FUCHSIA_DIR}/.ssh/authorized_keys"
if [ -n "$IMAGE_FVM_RAW" ]; then
fvmimg="${imgdir}/fvm.blk"
fx-fvm-extend-image "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}" $fvmimg
args+=(-d -D "${fvmimg}" --diskfmt=raw)
ARGS+=("-drive" "file=${fvmimg},format=raw,if=none,id=mydisk")
ARGS+=("-device" "ich9-ahci,id=ahci" "-device" "ide-drive,drive=mydisk,bus=ahci.0")
fi
exec "${FUCHSIA_DIR}/zircon/scripts/run-zircon" "${args[@]}" "$@"