blob: 7476db380f22128cd2ae0b87e0049756d3916a1e [file] [log] [blame]
Vishal Bhojca1fbcd2015-12-16 00:25:24 +05301#!/bin/bash
2if [ $# -eq 0 ]
3 then
4 echo "Provide the right /dev/ttyUSBX specific to recovery device"
5 exit
6fi
7
Vishal Bhoj2df2ca72016-07-12 17:14:56 +01008if [ ! -e "${1}" ]
Vishal Bhojca1fbcd2015-12-16 00:25:24 +05309 then
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010010 echo "device: ${1} does not exist"
Vishal Bhojca1fbcd2015-12-16 00:25:24 +053011 exit
12fi
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010013DEVICE_PORT="${1}"
Dmitry Shmidt06cb4cd2016-01-27 11:00:33 -080014PTABLE=ptable-aosp-8g.img
15if [ $# -gt 1 ]
16 then
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010017 if [ "${2}" == '4g' ]
Dmitry Shmidt06cb4cd2016-01-27 11:00:33 -080018 then
19 PTABLE=ptable-aosp-4g.img
20 fi
21fi
22
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010023INSTALLER_DIR="`dirname ${0}`"
24FIRMWARE_DIR="${INSTALLER_DIR}"
25
Yongqin Liu74aa0662016-07-16 20:46:52 +080026# for cases that not run "lunch hikey-userdebu"
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
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010032if [ -z "${DIST_DIR}" ]; then
33 DIST_DIR="${ANDROID_BUILD_TOP}"/out/dist
34fi
Satish Pateldc91c892016-03-28 10:03:21 +053035
36#get out directory path
37while [ $# -ne 0 ]; do
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010038 case "${1}" in
39 --out) OUT_IMGDIR=${2};shift;;
40 --use-compiled-binaries) FIRMWARE_DIR="${DIST_DIR}";shift;;
Satish Pateldc91c892016-03-28 10:03:21 +053041 esac
42 shift
43done
44
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010045if [[ "${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}"
Satish Pateldc91c892016-03-28 10:03:21 +053053 fi
54fi
55
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010056if [ ! -d "${OUT_IMGDIR}" ]; then
Satish Pateldc91c892016-03-28 10:03:21 +053057 echo "error in locating out directory, check if it exist"
58 exit
59fi
Satish Pateldc91c892016-03-28 10:03:21 +053060
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010061echo "android out dir:${OUT_IMGDIR}"
62
63sudo python "${INSTALLER_DIR}"/hisi-idt.py --img1="${FIRMWARE_DIR}"/l-loader.bin -d "${DEVICE_PORT}"
John Stultzabe80222016-08-03 20:23:51 -070064# set a unique serial number
65fastboot oem serialno
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010066fastboot flash ptable "${INSTALLER_DIR}"/"${PTABLE}"
67fastboot flash fastboot "${FIRMWARE_DIR}"/fip.bin
68fastboot flash nvme "${INSTALLER_DIR}"/nvme.img
69fastboot flash boot "${OUT_IMGDIR}"/boot.img
70fastboot flash system "${OUT_IMGDIR}"/system.img
71fastboot flash cache "${OUT_IMGDIR}"/cache.img
72fastboot flash userdata "${OUT_IMGDIR}"/userdata.img