| #!/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}/.." |
| |
| FIRMWARE_DIR=/tmp/hikey/hikey-firmware |
| FIRMWARE_GIT=https://android.googlesource.com/device/linaro/hikey |
| FIRMWARE_TAG=android-o-iot-preview-5 |
| |
| help() { |
| echo "usage: ${0} [options]" |
| echo " -b [build-dir] Use specified build directory." |
| echo " Defaults to build-hikey960/." |
| echo " -d [ramdisk] Use specified ramdisk file." |
| echo " Defaults to BUILD_DIR/bootdata.bin." |
| echo " -f Download and flash firmware." |
| echo " -m Add mexec option to kernel command line to enable netboot." |
| echo " -h Show this help message." |
| echo |
| echo "See docs/targets/hikey960.md for more details." |
| 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_firmware() { |
| if [[ ! -d $FIRMWARE_DIR ]]; then |
| git_clone -b $FIRMWARE_TAG $FIRMWARE_GIT $FIRMWARE_DIR |
| fi |
| |
| help_fastboot |
| fastboot flash ptable ${FIRMWARE_DIR}/installer/hikey960/ptable.img |
| fastboot flash xloader ${FIRMWARE_DIR}/installer/hikey960/sec_xloader.img |
| fastboot flash fastboot ${FIRMWARE_DIR}/installer/hikey960/fastboot.img |
| fastboot flash nvme ${FIRMWARE_DIR}/installer/hikey960/nvme.img |
| fastboot flash fw_lpm3 ${FIRMWARE_DIR}/installer/hikey960/lpm3.img |
| fastboot flash trustfirmware ${FIRMWARE_DIR}/installer/hikey960/bl31.bin |
| } |
| |
| 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}/hikey960-bootdata.bin}" |
| OUT_IMAGE="${BUILD_DIR}/hikey960-boot.img" |
| |
| if [[ $FLAG_FIRMWARE ]]; then |
| flash_firmware |
| exit 0 |
| fi |
| |
| if [[ -n "${CMDLINE}" ]]; then |
| EXTRA_ARGS+=(-c "${CMDLINE}") |
| fi |
| |
| flash_kernel |