| #!/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 $? |
| |
| ZBI_IMAGE="${FUCHSIA_BUILD_DIR}/${IMAGE_ZIRCONA_ZBI}" |
| |
| while [[ $# -gt 1 ]]; do |
| case "$1" in |
| -h|--help) |
| fx-command-help |
| "${FUCHSIA_DIR}/zircon/scripts/run-zircon" -h |
| exit 1 |
| ;; |
| -z) |
| shift |
| ZBI_IMAGE="$1" |
| ;; |
| *) |
| break |
| esac |
| shift |
| 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}" "${ZBI_IMAGE}" --entry "data/ssh/authorized_keys=${authkeys_path}" |
| |
| # Not all builds use an FVM so failing to find a source FVM is OK. |
| fvm_source=$(fx-fvm-find-raw-source) |
| if [[ -n "${fvm_source}" ]]; then |
| fvm_tool="${FUCHSIA_BUILD_DIR}/$(fx-command-run list-build-artifacts --name fvm --expect-one tools)" |
| fvm_raw="${imgdir}/fvm_raw.blk" |
| fx-fvm-extend-image "${fvm_tool}" "${fvm_source}" "${fvm_raw}" "${IMAGE_SIZE}" |
| args+=(-d -D "${fvm_raw}" --diskfmt=raw) |
| fi |
| |
| "${FUCHSIA_DIR}/zircon/scripts/run-zircon" "${args[@]}" "$@" |