| #!/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. |
| |
| ### run bootserver in zedboot disk paver mode |
| |
| ## usage: fx boot [--netboot|--bootfs] [--board <board>] [--no-data] [<type>] [bootserver arguments] |
| ## <type> see "--help" for list (default: x64 for x64 / none for arm64) |
| ## --board Specify Zircon board (if <type> is used, it takes precendence) |
| ## --netboot Boot from ramdisk containing FVM |
| ## --bootfs (deprecated) boot user.bootfs (old ramdisk) |
| ## --no-data Use FVM images without a /data partition (preserve existing data) |
| ## |
| ## If <type> is omitted, a guess is made based on $FUCHSIA_ARCH. For x64, all |
| ## x64 images will be supplied (resulting in an FVM pave). For arm64 the default |
| ## <type> is netboot, and the default board is <qemu>. |
| |
| set -e |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/image_build_vars.sh |
| |
| declare -a disks=() |
| ramdisk="${FUCHSIA_BUILD_DIR}/${ramdisk_bin}" |
| add_fvm=true |
| |
| usage() { |
| fx-command-help |
| fx-machine-types |
| echo |
| echo "Additional bootserver arguments:" |
| exec "${ZIRCON_TOOLS_DIR}/bootserver" --help |
| } |
| |
| netboot=false |
| bootfs=false |
| add_data=true |
| |
| while [[ "$1" =~ ^- ]]; do |
| case "$1" in |
| -h|--help) |
| usage |
| ;; |
| --netboot) |
| netboot=true |
| ;; |
| --bootfs) |
| bootfs=true |
| ;; |
| --board) |
| if [[ "$2" =~ ^- ]]; then |
| echo >&2 "Invalid board: $2" |
| exit 1 |
| fi |
| if ! grep "$2" "${board_list_file}" > /dev/null; then |
| echo >&2 "Unrecognized board: $2" |
| echo >&2 "Known boards for ${FUCHSIA_ARCH}: $(<"${board_list_file}")" |
| fi |
| board="$2" |
| shift |
| ;; |
| --no-data) |
| echo "##" |
| echo "## Note: if the target has no pre-existing data partition, then" |
| echo "## none will be created. The resultant system will behave in a" |
| echo "## kind of 'incognito' fashion, as /data will be backed by ram." |
| echo "##" |
| add_data=false |
| ;; |
| *) |
| break |
| esac |
| shift |
| done |
| |
| if [[ "$1" =~ ^- ]]; then |
| machine_type="" |
| else |
| machine_type="$1" |
| # passing no arguments is valid, but shift will terminate with set -e |
| if [[ $# -ge 1 ]]; then |
| shift |
| fi |
| fi |
| |
| if [[ -z "$machine_type" ]]; then |
| if $bootfs; then |
| machine_type="bootfs" |
| fi |
| if $netboot; then |
| machine_type="netboot" |
| fi |
| fi |
| |
| case "${machine_type}" in |
| help) |
| usage |
| ;; |
| zedboot) |
| ramdisk="${FUCHSIA_BUILD_DIR}/images/zedboot-${board}.bin" |
| disks=() |
| add_fvm=false |
| ;; |
| ram|netboot|--netboot) |
| ramdisk="${FUCHSIA_BUILD_DIR}/netboot-${board}.bin" |
| disks=() |
| add_fvm=false |
| ;; |
| bootfs|--bootfs) |
| echo |
| echo "bootfs is deprecated, please try to use \"ram\" instead" |
| echo |
| sleep 5 |
| ramdisk="${FUCHSIA_BUILD_DIR}/user.bootfs" |
| disks=() |
| add_fvm=false |
| ;; |
| cros|pixel|vboot|efi|acer|nuc) |
| disks=("${disks[@]}" --efi "${FUCHSIA_BUILD_DIR}/${efi_block}") |
| disks=("${disks[@]}" --kernc "${FUCHSIA_BUILD_DIR}/${kernc_vboot}") |
| ;; |
| *) |
| if [[ "$FUCHSIA_ARCH" == "x64" ]]; then |
| machine_type="x64" |
| disks=("${disks[@]}" --efi "${FUCHSIA_BUILD_DIR}/${efi_block}" \ |
| --kernc "${FUCHSIA_BUILD_DIR}/${kernc_vboot}") |
| else |
| # For now all ARM64 boards are valid machine types and imply netboot. |
| if grep "$machine_type" "${board_list_file}" > /dev/null; then |
| board="$machine_type" |
| if [[ -z "$board" ]]; then |
| echo >&2 "Unknown board for ${FUCHSIA_ARCH}: \"$board\" Please supply a board name from:" |
| cat "${board_list_file}" >&2 |
| exit 1 |
| fi |
| ramdisk="${FUCHSIA_BUILD_DIR}/netboot-${board}.bin" |
| disks=() |
| add_fvm=false |
| else |
| echo "Unsupported machine type: \"${machine_type}\"" |
| fx-machine-types |
| exit 1 |
| fi |
| fi |
| esac |
| |
| # XXX(raggi): this is ugly, but we want to retain argument pass-through to |
| # bootserver |
| bootserver_args=() |
| if ! $add_fvm; then |
| bootserver_args=("$@") |
| else |
| disks=("${disks[@]}" --fvm "${FUCHSIA_BUILD_DIR}/${fvm_sparse_block}") |
| |
| while [[ $# -gt 0 ]]; do |
| bootserver_args=("${bootserver_args[@]}" "$1") |
| shift |
| done |
| |
| if $add_data; then |
| disks=("${disks[@]}" --fvm "${FUCHSIA_BUILD_DIR}/${fvm_data_sparse_block}") |
| fi |
| fi |
| |
| exec "${ZIRCON_TOOLS_DIR}/bootserver" \ |
| "${disks[@]}" \ |
| "${ZIRCON_BUILD_DIR}/${zircon_bin}" \ |
| "${ramdisk}" \ |
| "${bootserver_args[@]}" |