1#!/bin/bash 2if [ $# -eq 0 ] 3 then 4 echo "Provide the right /dev/ttyUSBX specific to recovery device" 5 exit 6fi 7 8if [ ! -e "${1}" ] 9 then 10 echo "device: ${1} does not exist" 11 exit 12fi 13DEVICE_PORT="${1}" 14PTABLE=ptable-aosp-8g.img 15if [ $# -gt 1 ] 16 then 17 if [ "${2}" == '4g' ] 18 then 19 PTABLE=ptable-aosp-4g.img 20 fi 21fi 22 23INSTALLER_DIR="`dirname ${0}`" 24FIRMWARE_DIR="${INSTALLER_DIR}" 25 26# for cases that not run "lunch hikey-userdebug" 27if [ -z "${ANDROID_BUILD_TOP}" ]; then 28 ANDROID_BUILD_TOP=${INSTALLER_DIR}/../../../../../ 29 ANDROID_PRODUCT_OUT="${ANDROID_BUILD_TOP}/out/target/product/hikey" 30fi 31 32if [ -z "${DIST_DIR}" ]; then 33 DIST_DIR="${ANDROID_BUILD_TOP}"/out/dist 34fi 35 36#get out directory path 37while [ $# -ne 0 ]; do 38 case "${1}" in 39 --out) OUT_IMGDIR=${2};shift;; 40 --use-compiled-binaries) FIRMWARE_DIR="${DIST_DIR}";shift;; 41 esac 42 shift 43done 44 45if [[ "${FIRMWARE_DIR}" == "${DIST_DIR}" && ! -e "${DIST_DIR}"/fip.bin && ! -e "${DIST_DIR}"/l-loader.bin ]]; then 46 echo "No binaries found at ${DIST_DIR}. Please build the bootloader first" 47 exit 48fi 49 50if [ -z "${OUT_IMGDIR}" ]; then 51 if [ ! -z "${ANDROID_PRODUCT_OUT}" ]; then 52 OUT_IMGDIR="${ANDROID_PRODUCT_OUT}" 53 fi 54fi 55 56if [ ! -d "${OUT_IMGDIR}" ]; then 57 echo "error in locating out directory, check if it exist" 58 exit 59fi 60 61echo "android out dir:${OUT_IMGDIR}" 62 63sudo python "${INSTALLER_DIR}"/hisi-idt.py --img1="${FIRMWARE_DIR}"/l-loader.bin -d "${DEVICE_PORT}" 64sleep 3 65# set a unique serial number 66serialno=`fastboot getvar serialno 2>&1 > /dev/null` 67if [ "${serialno:10:6}" == "(null)" ]; then 68 fastboot oem serialno 69else 70 if [ "${serialno:10:15}" == "0123456789abcde" ]; then 71 fastboot oem serialno 72 fi 73fi 74fastboot getvar partition-size:ptable 75fastboot flash ptable "${INSTALLER_DIR}"/"${PTABLE}" 76fastboot flash fastboot "${FIRMWARE_DIR}"/fip.bin 77fastboot flash nvme "${INSTALLER_DIR}"/nvme.img 78fastboot flash boot "${OUT_IMGDIR}"/boot.img 79fastboot flash system "${OUT_IMGDIR}"/system.img 80fastboot flash vendor "${OUT_IMGDIR}"/vendor.img 81fastboot flash userdata "${OUT_IMGDIR}"/userdata.img 82