blob: 97e9bfaf36cbe8d4efaee5ce3ff58d8ea7507004 [file] [log] [blame]
#!/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|--pave|--bootfs] [--no-data]
## [--artifacts <dir>] [--zircon-dir <dir>] [--fuchsia-dir <dir>]
## [<type>] [bootserver arguments]
## <type> see "--help" for list (default: x64 for x64 / none for arm64)
## --netboot Boot from ramdisk containing FVM
## --pave Write Zircon and FVM to device storage before booting (default for x64)
## --bootfs (deprecated) boot user.bootfs (old ramdisk)
## --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
## --zircon-dir directory containing zircon
## --fuchsia-dir directory containing partitions images and bootdata to send
## to the device
##
## 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.
##
## If supplying --artifacts, --zircon-dir, or --fuchsia-dir some rules apply.
## Either supply only --artifacts OR both --zircon-dir and --fuchsia-dir. If
## none of these arguments is supplied the location of these directories is
## assumed based on the build directory.
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}"
add_fvm=true
usage() {
fx-command-help
fx-machine-types
echo
echo "Additional bootserver arguments:"
exec "${ZIRCON_TOOLS_DIR}/bootserver" --help
}
netboot=false
pave=false
bootfs=false
add_data=true
ip_targ=()
had_artifacts=false
had_imgdir=false
had_zirdir=false
zircon_tools="${ZIRCON_TOOLS_DIR}"
while [[ "$1" =~ ^- ]]; do
case "$1" in
-h|--help)
usage
;;
-a)
shift
ip_targ=("-a" "$1")
;;
--netboot)
netboot=true
;;
--pave)
pave=true
;;
--bootfs)
bootfs=true
;;
--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
;;
--artifacts)
shift
fuchsia_dir="${1}"
zircon_dir="${1}"
zircon_tools="${zircon_dir}/tools"
had_artifacts=true
;;
--images-dir)
shift
fuchsia_dir="${1}"
had_imgdir=true
;;
--zircon-dir)
shift
zircon_dir="${1}"
zircon_tools="${zircon_dir}/tools"
had_zirdir=true
;;
*)
break
esac
shift
done
if $had_artifacts && ( $had_zirdir || $had_imgdir ) ||
( ! $had_artifacts && ( $had_zirdir || $had_imgdir ) &&
( ! $had_zirdir || ! $had_imgdir ) ); then
echo >&2 "Invalid flags, either supply --artifacts or both --fuchsia-dir and --zircon-dir or none of these options to use defaults"
exit 1
fi
ramdisk="${fuchsia_dir}/${ramdisk_bin}"
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_dir}/images/zedboot-${board}.bin"
disks=()
add_fvm=false
;;
ram|netboot|--netboot)
ramdisk="${fuchsia_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_dir}/user.bootfs"
disks=()
add_fvm=false
;;
cros|pixel|vboot|efi|acer|nuc)
disks=("${disks[@]}" --efi "${fuchsia_dir}/${efi_block}")
disks=("${disks[@]}" --kernc "${fuchsia_dir}/${kernc_vboot}")
;;
*)
if [[ "$FUCHSIA_ARCH" == "x64" ]]; then
machine_type="x64"
disks=("${disks[@]}" --efi "${fuchsia_dir}/${efi_block}" \
--kernc "${fuchsia_dir}/${kernc_vboot}")
else
# For now ARM64 defaults to netboot, but can be overridden to pave with the --pave option
if $pave; then
# send combined kernel/bootdata image?
# disks=("${disks[@]}" --zircon-a "${fuchsia_dir}/zircon-boot-blob-${board}.bin")
echo "pave baby pave!"
else
ramdisk="${fuchsia_dir}/netboot-${board}.bin"
disks=()
add_fvm=false
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_dir}/${fvm_sparse_block}")
while [[ $# -gt 0 ]]; do
bootserver_args=("${bootserver_args[@]}" "$1")
shift
done
if $add_data; then
disks=("${disks[@]}" --fvm "${fuchsia_dir}/${fvm_data_sparse_block}")
fi
fi
echo "${zircon_tools}/bootserver" \
"${ip_targ[@]}" \
"${disks[@]}" \
"${zircon_dir}/${zircon_bin}" \
"${ramdisk}" \
"${bootserver_args[@]}"
exec "${zircon_tools}/bootserver" \
"${ip_targ[@]}" \
"${disks[@]}" \
"${zircon_dir}/${zircon_bin}" \
"${ramdisk}" \
"${bootserver_args[@]}"