| #!/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. |
| |
| #### 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 -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 $? |
| |
| for arg in "$@"; do |
| if [[ "$arg" = "-h" || "$arg" = "--help" ]]; then |
| fx-command-help |
| "${FUCHSIA_DIR}/zircon/scripts/run-zircon" -h |
| exit 1 |
| fi |
| done |
| |
| authkeys_path="$(get-ssh-authkeys)" || { |
| fx-error "Cannot continue without a valid authorized keys file." |
| exit 1 |
| } |
| |
| qemu_dir="${PREBUILT_QEMU_DIR}/bin" |
| |
| args=( |
| -a "${FUCHSIA_ARCH}" |
| -q "${qemu_dir}" |
| -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/fuchsia_authorized_keys for SSH |
| # access. |
| imgdir="$(mktemp -d ${FUCHSIA_BUILD_DIR}/tmp.XXX)" |
| 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}") |
| fx-zbi -o "${kernelzbi}" "${FUCHSIA_BUILD_DIR}/${IMAGE_ZIRCONA_ZBI}" \ |
| --entry "data/ssh/authorized_keys=${authkeys_path}" |
| |
| # Try raw image first if it exist. Otherwise see if we can find a fastboot format fvm. |
| fvm_image="${IMAGE_FVM_RAW}" |
| if [[ -z "${fvm_image}" ]] ; then |
| fvm_image="${IMAGE_FVM_FASTBOOT}" |
| fi |
| if [[ -n ${fvm_image} ]] ; then |
| fvm_initial="${FUCHSIA_BUILD_DIR}/${fvm_image}" |
| fvm_extended="${imgdir}/fvm.blk" |
| fx-fvm-extend-image "${fvm_initial}" "${fvm_extended}" |
| args+=(-d -D "${fvm_extended}" --diskfmt=raw) |
| fi |
| |
| "${FUCHSIA_DIR}/zircon/scripts/run-zircon" "${args[@]}" "$@" |