| #!/usr/bin/env bash |
| |
| # Copyright 2017 The Fuchsia Authors |
| # |
| # Use of this source code is governed by a MIT-style |
| # license that can be found in the LICENSE file or at |
| # https://opensource.org/licenses/MIT |
| |
| set -eo pipefail |
| |
| CMDLINE= |
| EXTRA_ARGS=() |
| |
| SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| ZIRCON_DIR="${SCRIPTS_DIR}/.." |
| |
| help() { |
| echo "usage: ${0} [options]" |
| echo " -b [build-dir] Use specified build directory." |
| echo " Defaults to build-kirin970/." |
| echo " -d [ramdisk] Use specified ramdisk file." |
| echo " Defaults to BUILD_DIR/bootdata.bin." |
| echo " -m Add mexec option to kernel command line to enable netboot." |
| echo " -h Show this help message." |
| exit 1 |
| } |
| |
| help_fastboot() { |
| echo |
| echo "Check that the device is in fastboot mode:" |
| echo " Auto Power up(Switch 1) closed/ON" |
| echo " Recovery(Switch 2) open/OFF" |
| echo " Fastboot(Switch 3) closed/ON" |
| |
| read -p "Proceed (y|n)? " -n 1 -r |
| echo |
| if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| exit 1 |
| fi |
| } |
| |
| git_clone() { |
| git clone --depth 1 $@ |
| } |
| |
| flash_kernel() { |
| "${ZIRCON_DIR}/kernel/target/arm64/board/hikey960/package-image.sh" -B "${BUILD_DIR}" "${EXTRA_ARGS[@]}" |
| |
| fastboot flash boot $OUT_IMAGE |
| # Can't guarantee that the target has written image to flash before the |
| # fastboot command completes, so short delay here before reboot. |
| sleep 1 |
| fastboot reboot |
| } |
| |
| while getopts "b:d:fmnp:ruh" FLAG; do |
| case $FLAG in |
| b) BUILD_DIR="${OPTARG}";; |
| d) RAMDISK="${OPTARG}";; |
| f) FLAG_FIRMWARE=true;; |
| m) CMDLINE+=" netsvc.netboot=true";; |
| *) help;; |
| esac |
| done |
| shift $((OPTIND-1)) |
| |
| BUILD_DIR="${BUILD_DIR:-build-arm64}" |
| RAMDISK="${RAMDISK:-${BUILD_DIR}/kirin970-bootdata.bin}" |
| OUT_IMAGE="${BUILD_DIR}/kirin970-boot.img" |
| |
| if [[ -n "${CMDLINE}" ]]; then |
| EXTRA_ARGS+=(-c "${CMDLINE}") |
| fi |
| |
| flash_kernel |