| #!/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] [--no-data] |
| ## [--artifacts <dir>] |
| ## [--sign-tool <path_to_sign_tool>] |
| ## [--bootloader <path_to_prebuilt_bootloader>] |
| ## [<type>] -- [bootserver arguments] |
| ## <type> see "--help" for list (default: x64 for x64 / arm64 for arm64) |
| ## --netboot Boot from ramdisk containing FVM |
| ## --no-data Use FVM images without a /data partition (preserve existing |
| ## data) |
| ## --artifacts a directory to load files to send to the target where the |
| ## root of the directory base zircon.bin and its bootdata file |
| ## and an images sub-directory has all the images to pave |
| ## --sign-tool Optional executable to sign kernel images. |
| ## --bootloader Flash the bootloader in addition to other partitions. Only |
| ## works with a limited number of device types. |
| ## |
| ## 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. |
| |
| set -e |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/image_build_vars.sh |
| |
| declare -a disks=() |
| fuchsia_dir="${FUCHSIA_BUILD_DIR}" |
| zircon_dir="${ZIRCON_BUILD_DIR}" |
| zircon_tools="${ZIRCON_TOOLS_DIR}" |
| add_fvm=true |
| |
| usage() { |
| fx-command-help |
| fx-machine-types |
| echo |
| echo "Additional bootserver arguments:" |
| exec "${ZIRCON_TOOLS_DIR}/bootserver" --help |
| } |
| |
| netboot=false |
| add_data=true |
| ip_targ=() |
| bootserver_extra=() |
| sign_tool="" |
| machine_type= |
| while [[ $# -gt 0 ]]; do |
| case "$1" in |
| -h|--help) |
| usage |
| ;; |
| -a) |
| shift |
| ip_targ=("-a" "$1") |
| ;; |
| --netboot) |
| netboot=true |
| machine_type="netboot" |
| ;; |
| --no-data) |
| echo >&2 "##" |
| echo >&2 "## Note: if the target has no pre-existing data partition, then" |
| echo >&2 "## none will be created. The resultant system will behave in a" |
| echo >&2 "## kind of 'incognito' fashion, as /data will be backed by ram." |
| echo >&2 "##" |
| add_data=false |
| ;; |
| --sign-tool) |
| shift |
| sign_tool="$1" |
| ;; |
| --artifacts) |
| shift |
| fuchsia_dir="${1}" |
| zircon_dir="${1}" |
| zircon_tools="${zircon_dir}/tools" |
| |
| # Source the image paths from the artifacts directory, so we can find them. |
| source "${fuchsia_dir}"/zedboot_image_paths.sh |
| source "${fuchsia_dir}"/image_paths.sh |
| ;; |
| --bootloader) |
| shift |
| disks=("${disks[@]}" --bootloader "${1}") |
| ;; |
| --) |
| shift |
| while [[ $# -gt 0 ]]; do |
| bootserver_extra=("${bootserver_extra[@]}" "$1") |
| shift |
| done |
| break |
| ;; |
| -*) |
| echo >&2 "error: unknown flag: " "$1" |
| echo >&2 |
| echo >&2 "You may be intending to pass this to bootserver." |
| echo >&2 "Bootserver flags must be passed at the end of all other flags, e.g." |
| echo >&2 " fx boot -- -1" |
| echo >&2 |
| echo >&2 "See \`fx boot --help\` for more information." |
| exit 1 |
| ;; |
| *) |
| if [[ -n "$machine_type" ]]; then |
| echo >&2 "error: machine type already set (to $machine_type), argument \"$1\" not understood" |
| echo >&2 |
| usage |
| exit 1 |
| fi |
| machine_type="$1" |
| ;; |
| esac |
| shift |
| done |
| |
| ramdisk="${fuchsia_dir}/${IMAGE_BOOT_RAM}" |
| |
| case "${machine_type}" in |
| help) |
| usage |
| ;; |
| zedboot) |
| ramdisk="${fuchsia_dir}/${IMAGE_ZEDBOOT_ZBI}" |
| disks=() |
| add_fvm=false |
| ;; |
| ram|netboot) |
| ramdisk="${fuchsia_dir}/${IMAGE_NETBOOT_RAM}" |
| disks=() |
| add_fvm=false |
| ;; |
| cros|pixel|vboot|efi|acer|nuc) |
| disks=("${disks[@]}" --efi "${fuchsia_dir}/${IMAGE_ESP_RAW}") |
| disks=("${disks[@]}" --kernc "${fuchsia_dir}/${IMAGE_ZIRCON_VBOOT}") |
| ;; |
| arm|arm64) |
| disks=("${disks[@]}" --zircona "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}" |
| --zirconr "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}") |
| ;; |
| gauss) |
| if [[ ! -z "${sign_tool}" ]]; then |
| GAUSS_SIGN_TOOL="${sign_tool}" |
| elif [[ -z "${GAUSS_SIGN_TOOL}" ]]; then |
| echo "Sign tool is required." >&2 |
| usage |
| fi |
| "${GAUSS_SIGN_TOOL}" -z "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}" \ |
| -o "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}.gauss.signed" |
| "${GAUSS_SIGN_TOOL}" -z "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}" \ |
| -o "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}.gauss.signed" |
| disks=("${disks[@]}" --zircona "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}.gauss.signed" \ |
| --zirconr "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}.gauss.signed") |
| add_fvm=false |
| ;; |
| astro) |
| if [[ ! -z "${sign_tool}" ]]; then |
| ASTRO_SIGN_TOOL="${sign_tool}" |
| elif [[ -z "${ASTRO_SIGN_TOOL}" ]]; then |
| echo "Sign tool is required." >&2 |
| usage |
| fi |
| "${ASTRO_SIGN_TOOL}" -z "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}" \ |
| -o "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}.astro.signed" |
| "${ASTRO_SIGN_TOOL}" -z "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}" \ |
| -o "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}.astro.signed" |
| disks=("${disks[@]}" --zircona "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}.astro.signed"\ |
| --zirconr "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}.astro.signed") |
| add_fvm=false |
| ;; |
| ""|*) |
| if [[ -n "$machine_type" ]]; then |
| echo >&2 "Unknown machine type: \"$machine_type\", using ${FUCHSIA_ARCH}" |
| fi |
| |
| if [[ "$FUCHSIA_ARCH" == "x64" ]]; then |
| machine_type="x64" |
| disks=("${disks[@]}" --efi "${fuchsia_dir}/${IMAGE_ESP_RAW}" \ |
| --kernc "${fuchsia_dir}/${IMAGE_ZIRCON_VBOOT}") |
| else |
| machine_type="arm64" |
| disks=("${disks[@]}" --zircona "${fuchsia_dir}/${IMAGE_ZIRCONA_ZBI}" |
| --zirconr "${fuchsia_dir}/${IMAGE_ZIRCONR_ZBI}") |
| fi |
| esac |
| |
| if $add_fvm; then |
| disks=("${disks[@]}" --fvm "${fuchsia_dir}/${IMAGE_FVM_SPARSE}") |
| |
| if $add_data; then |
| disks=("${disks[@]}" --fvm "${fuchsia_dir}/${IMAGE_DATA_FVM_RAW}") |
| fi |
| fi |
| |
| exec "${zircon_tools}/bootserver" \ |
| "${ip_targ[@]}" \ |
| "${disks[@]}" \ |
| "${zircon_dir}/zircon.bin" \ |
| "${ramdisk}" \ |
| "${bootserver_extra[@]}" |