blob: ad62596b9a9c8085bec10b9fdd1209bb8d440149 [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
set -e
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/image_build_vars.sh || exit $?
source "${FUCHSIA_DIR}/buildtools/vars.sh"
qemu_dir="${BUILDTOOLS_QEMU_DIR}/bin"
# 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
fvmimg="${imgdir}/fvm.blk"
kernelzbi="${imgdir}/fuchsia-ssh.zbi"
trap 'rm "${fvmimg}" "${kernelzbi}" && rmdir "${imgdir}"' EXIT
stat_flags=()
if [[ $(uname) == "Darwin" ]]; then
stat_flags+=("-x")
fi
stat_output=$(stat "${stat_flags[@]}" "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}")
if [[ "$stat_output" =~ Size:\ ([0-9]+) ]]; then
size="${BASH_REMATCH[1]}"
newsize=$(($size * 2))
# We must take a copy of the build artifact, rather than re-use it, as we
# need to modify it in order to extend it.
echo -n "Creating disk image..."
cp "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}" "${fvmimg}"
"${ZIRCON_TOOLS_DIR}/fvm" "${fvmimg}" extend --length "${newsize}"
echo "done"
else
fx-error "could not extend fvm, unable to stat fvm image"
fi
"${ZIRCON_TOOLS_DIR}/zbi" -o "${kernelzbi}" "${FUCHSIA_BUILD_DIR}/${IMAGE_ZIRCONA_ZBI}" \
--entry "data/ssh/authorized_keys=${FUCHSIA_DIR}/.ssh/authorized_keys"
"${FUCHSIA_DIR}/zircon/scripts/run-zircon" \
-a "${FUCHSIA_ARCH}" \
-q "${qemu_dir}" \
-G 3 \
-t "${FUCHSIA_BUILD_DIR}/${IMAGE_QEMU_KERNEL_RAW}" \
-z "${kernelzbi}" \
-d \
-D "${fvmimg}" \
--diskfmt="raw" \
"$@"