1 #!/bin/bash 2 if [ $# -eq 0 ] 3 then 4 echo "Provide the right /dev/ttyUSBX specific to recovery device" 5 exit 6 fi 7 8 if [ ! -e "${1}" ] 9 then 10 echo "device: ${1} does not exist" 11 exit 12 fi 13 DEVICE_PORT="${1}" 14 PTABLE=ptable-aosp-8g.img 15 if [ $# -gt 1 ] 16 then 17 if [ "${2}" == '4g' ] 18 then 19 PTABLE=ptable-aosp-4g.img 20 fi 21 fi 22 23 INSTALLER_DIR="`dirname ${0}`" 24 FIRMWARE_DIR="${INSTALLER_DIR}" 25 26 # for cases that not run "lunch hikey-userdebu" 27 if [ -z "${ANDROID_BUILD_TOP}" ]; then 28 ANDROID_BUILD_TOP=${INSTALLER_DIR}/../../../../ 29 ANDROID_PRODUCT_OUT="${ANDROID_BUILD_TOP}/out/target/product/hikey" 30 fi 31 32 if [ -z "${DIST_DIR}" ]; then 33 DIST_DIR="${ANDROID_BUILD_TOP}"/out/dist 34 fi 35 36 #get out directory path 37 while [ $# -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 43 done 44 45 if [[ "${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 48 fi 49 50 if [ -z "${OUT_IMGDIR}" ]; then 51 if [ ! -z "${ANDROID_PRODUCT_OUT}" ]; then 52 OUT_IMGDIR="${ANDROID_PRODUCT_OUT}" 53 fi 54 fi 55 56 if [ ! -d "${OUT_IMGDIR}" ]; then 57 echo "error in locating out directory, check if it exist" 58 exit 59 fi 60 61 echo "android out dir:${OUT_IMGDIR}" 62 63 sudo python "${INSTALLER_DIR}"/hisi-idt.py --img1="${FIRMWARE_DIR}"/l-loader.bin -d "${DEVICE_PORT}" 64 fastboot flash ptable "${INSTALLER_DIR}"/"${PTABLE}" 65 fastboot flash fastboot "${FIRMWARE_DIR}"/fip.bin 66 fastboot flash nvme "${INSTALLER_DIR}"/nvme.img 67 fastboot flash boot "${OUT_IMGDIR}"/boot.img 68 fastboot flash system "${OUT_IMGDIR}"/system.img 69 fastboot flash cache "${OUT_IMGDIR}"/cache.img 70 fastboot flash userdata "${OUT_IMGDIR}"/userdata.img 71