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`"
24ANDROID_TOP=${INSTALLER_DIR}/../../../../
25
26#get out directory path
27while [ $# -ne 0 ]; do
28    case "$1" in
29        --out) OUT_IMGDIR=$2;shift;
30    esac
31    shift
32done
33
34if [ -z $OUT_IMGDIR ]; then
35    if [ ! -z $ANDROID_PRODUCT_OUT ]; then
36        OUT_IMGDIR=${ANDROID_PRODUCT_OUT}
37    else
38        OUT_IMGDIR="${ANDROID_TOP}/out/target/product/hikey"
39    fi
40fi
41
42if [ ! -d $OUT_IMGDIR ]; then
43    echo "error in locating out directory, check if it exist"
44    exit
45fi
46echo "android out dir:$OUT_IMGDIR"
47
48python ${INSTALLER_DIR}/hisi-idt.py --img1=${INSTALLER_DIR}/l-loader.bin -d ${DEVICE_PORT}
49fastboot flash ptable ${INSTALLER_DIR}/${PTABLE}
50fastboot flash fastboot ${INSTALLER_DIR}/fip.bin
51fastboot flash nvme ${INSTALLER_DIR}/nvme.img
52fastboot flash boot ${OUT_IMGDIR}/boot_fat.uefi.img
53fastboot flash system ${OUT_IMGDIR}/system.img
54fastboot flash cache ${OUT_IMGDIR}/cache.img
55fastboot flash userdata ${OUT_IMGDIR}/userdata.img
56