| #!/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 |
| |
| ## Usage: fx run [-S <disk_size>] [-- <run-zircon options>... [-- <qemu options>...]] |
| ## Use `fx run -- -h` to see options available for `run-zircon`. |
| ## Use `fx run -- -- -h` to see option available for `qemu`. |
| |
| 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" |
| |
| while getopts ":S:h" FLAG; do |
| case $FLAG in |
| S) QEMU_DISK_SIZE=$OPTARG;; |
| h) |
| fx-command-help |
| exit 1 |
| ;; |
| \?) |
| echo unrecognized option |
| fx-command-help |
| exit 1 |
| ;; |
| esac |
| done |
| shift $((OPTIND-1)) |
| |
| 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. |
| qcowdir="$(mktemp -d)" |
| if [[ ! -d "${qcowdir}" ]]; then |
| echo >&2 "Failed to create temporary directory" |
| exit 1 |
| fi |
| qimg="${qcowdir}/fuchsia.qcow2" |
| trap 'rm "${qimg}" && rmdir "${qcowdir}"' EXIT |
| |
| "${qemu_dir}/qemu-img" create -f qcow2 -b "${FUCHSIA_BUILD_DIR}/${IMAGE_FVM_RAW}" \ |
| "${qimg}" ${QEMU_DISK_SIZE} |
| |
| "${FUCHSIA_DIR}/zircon/scripts/run-zircon" \ |
| -a "${FUCHSIA_ARCH}" \ |
| -q "${qemu_dir}" \ |
| -G 3 \ |
| -t "${FUCHSIA_BUILD_DIR}/${IMAGE_QEMU_KERNEL_RAW}" \ |
| -z "${FUCHSIA_BUILD_DIR}/${IMAGE_ZIRCONA_ZBI}" \ |
| -d \ |
| -D "${qimg}" \ |
| --diskfmt="qcow2" \ |
| "$@" |