| #!/bin/bash |
| # Copyright 2018 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=Device management |
| ### flash and, optionally, pave a connected device |
| ## usage: fx flash [-s <serial>] [--build|--no-build] [--pave] |
| ## --build | --no-build Build (or not) the required dependencies |
| ## --pave Pave device after flashing (recommended) |
| ## -s Serial of device you wish to flash to (only necessary |
| ## if multiple devices in fastboot mode) |
| ## |
| ## Defaults are defined by the "incremental" feature: |
| ## 'fx --enable=incremental flash' defaults to "--build" |
| ## 'fx --disable=incremental flash' defaults to "--no-build" |
| |
| 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/fx-flash.sh || exit $? |
| |
| usage() { |
| fx-command-help |
| echo "Available devices:" |
| fx-command-run host-tool fastboot devices -l |
| exit 1 |
| } |
| |
| build=false |
| if is_feature_enabled "incremental"; then |
| # In incremental workflows, these defaults have changed. |
| # Keep old behavior if incremental is not enabled. |
| build=true |
| fi |
| pave=false |
| serial= |
| device=$(get-device-name) |
| while [[ $# -ge 1 ]]; do |
| case "$1" in |
| -h|--help) |
| usage |
| ;; |
| --no-build) |
| build=false |
| ;; |
| --build) |
| build=true |
| ;; |
| --pave) |
| pave=true |
| ;; |
| --nopave|--no-pave) |
| pave=false |
| ;; |
| -s) |
| shift |
| serial="$1" |
| ;; |
| -device) |
| shift |
| device="$1" |
| ;; |
| *) |
| break |
| esac |
| shift |
| done |
| |
| if $build; then |
| artifacts=($(fx-command-run list-build-artifacts flash)) || exit $? |
| if $pave; then |
| artifacts+=($(fx-command-run list-build-artifacts pave)) || exit $? |
| fi |
| fx-info "Building/refreshing targets ${artifacts[@]}" |
| fx-command-run build "${artifacts[@]}" |
| fi |
| |
| cd "${FUCHSIA_BUILD_DIR}" |
| fx-flash "${serial}" "${device}" |
| |
| if $pave; then |
| # no need to build, since all dependencies were already built above. |
| fx-command-exec pave -1 --no-build |
| fi |