| #!/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. | |
| #### CATEGORY=Software delivery | |
| #### PREBUILTS=${PREBUILT_CGPT_DIR} | |
| ### make a zedboot USB key | |
| ## usage: fx mkzedboot [-f] [--build|--no-build] <usb device> | |
| ## | |
| ## --build | --no-build build (or not) the image required to run mkzedboot. | |
| ## -f force writing to a non-usb target. | |
| ## | |
| ## The default for --build is defined by the "incremental" feature: | |
| ## 'fx --enable=incremental mkzedboot' defaults to '--build' | |
| ## 'fx --disable=incremental mkzedboot' defaults to '--no-build' | |
| set -e | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/fx-mkzedboot.sh || exit $? | |
| fx-config-read | |
| force=false | |
| 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 | |
| while (( $# )); do | |
| case "$1" in | |
| --help) | |
| fx-command-help | |
| exit 0 | |
| ;; | |
| --no-build) | |
| build=false | |
| ;; | |
| --build) | |
| build=true | |
| ;; | |
| -f) | |
| force=true | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| shift | |
| done | |
| if [[ $# -gt 1 ]]; then | |
| fx-error "Invalid syntax" | |
| fx-command-help | |
| exit 1 | |
| fi | |
| if [[ $# -eq 0 ]]; then | |
| fx-error "Device argument required!" | |
| fx-command-help | |
| echo | |
| echo "USB disks:" | |
| fx-command-run list-usb-disks | |
| exit 1 | |
| fi | |
| USB_DEVICE="$1" | |
| image="" | |
| type="" | |
| # Try to get image for efi, if not found, try to get vboot image for chromebook | |
| image="$(fx-command-run list-build-artifacts --allow-empty --type blk mkzedboot)" | |
| type="efi" | |
| if [[ -z "${image}" ]]; then | |
| image="$(fx-command-run list-build-artifacts --allow-empty --type zbi.signed mkzedboot)" | |
| type="vboot" | |
| fi | |
| if [[ -z "${image}" ]]; then | |
| fx-error "Cannot find image to run mkzedboot. Re-check build board and product." | |
| exit 1 | |
| fi | |
| if ! $build && [[ ! -f "${FUCHSIA_BUILD_DIR}/${image}" ]]; then | |
| fx-warn "Cannot find image to run mkzedboot: $image, will attempt to build it." | |
| build=true | |
| fi | |
| if $build; then | |
| fx-command-run build "${image}" | |
| fi | |
| fx-mkzedboot "${USB_DEVICE}" "${type}" "${FUCHSIA_BUILD_DIR}/${image}" $force |