1#!/usr/bin/env bash 2 3# Copyright 2017 The Fuchsia Authors 4# 5# Use of this source code is governed by a MIT-style 6# license that can be found in the LICENSE file or at 7# https://opensource.org/licenses/MIT 8 9set -eo pipefail 10 11CMDLINE= 12EXTRA_ARGS=() 13 14SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 15ZIRCON_DIR="${SCRIPTS_DIR}/.." 16 17help() { 18 echo "usage: ${0} [options]" 19 echo " -b [build-dir] Use specified build directory." 20 echo " Defaults to build-kirin970/." 21 echo " -d [ramdisk] Use specified ramdisk file." 22 echo " Defaults to BUILD_DIR/bootdata.bin." 23 echo " -m Add mexec option to kernel command line to enable netboot." 24 echo " -h Show this help message." 25 exit 1 26} 27 28help_fastboot() { 29 echo 30 echo "Check that the device is in fastboot mode:" 31 echo " Auto Power up(Switch 1) closed/ON" 32 echo " Recovery(Switch 2) open/OFF" 33 echo " Fastboot(Switch 3) closed/ON" 34 35 read -p "Proceed (y|n)? " -n 1 -r 36 echo 37 if [[ ! $REPLY =~ ^[Yy]$ ]]; then 38 exit 1 39 fi 40} 41 42git_clone() { 43 git clone --depth 1 $@ 44} 45 46flash_kernel() { 47 "${ZIRCON_DIR}/kernel/target/arm64/board/hikey960/package-image.sh" -B "${BUILD_DIR}" "${EXTRA_ARGS[@]}" 48 49 fastboot flash boot $OUT_IMAGE 50 # Can't guarantee that the target has written image to flash before the 51 # fastboot command completes, so short delay here before reboot. 52 sleep 1 53 fastboot reboot 54} 55 56while getopts "b:d:fmnp:ruh" FLAG; do 57 case $FLAG in 58 b) BUILD_DIR="${OPTARG}";; 59 d) RAMDISK="${OPTARG}";; 60 f) FLAG_FIRMWARE=true;; 61 m) CMDLINE+=" netsvc.netboot=true";; 62 *) help;; 63 esac 64done 65shift $((OPTIND-1)) 66 67BUILD_DIR="${BUILD_DIR:-build-arm64}" 68RAMDISK="${RAMDISK:-${BUILD_DIR}/kirin970-bootdata.bin}" 69OUT_IMAGE="${BUILD_DIR}/kirin970-boot.img" 70 71if [[ -n "${CMDLINE}" ]]; then 72 EXTRA_ARGS+=(-c "${CMDLINE}") 73fi 74 75flash_kernel 76