blob: 4707d06371f5d74cbbeec0d9e54c62a9d2666821 [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
Amit Pundir048e1a62017-01-24 12:08:13 +053026# for cases that not run "lunch hikey-userdebug"
Yongqin Liu74aa0662016-07-16 20:46:52 +080027if [ -z "${ANDROID_BUILD_TOP}" ]; then
Amit Pundir048e1a62017-01-24 12:08:13 +053028 ANDROID_BUILD_TOP=${INSTALLER_DIR}/../../../../../
Yongqin Liu74aa0662016-07-16 20:46:52 +080029 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}"
Dmitry Shmidte9b656f2016-09-08 15:10:46 -070064sleep 3
John Stultzabe80222016-08-03 20:23:51 -070065# set a unique serial number
Dmitry Shmidte9b656f2016-09-08 15:10:46 -070066serialno=`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
Dmitry Shmidtfd5e31a2018-05-07 15:55:52 -070074fastboot getvar partition-size:ptable
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010075fastboot 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
Yongqin Liu7dff6062018-04-24 11:29:39 +080080fastboot flash vendor "${OUT_IMGDIR}"/vendor.img
Vishal Bhoj2df2ca72016-07-12 17:14:56 +010081fastboot flash userdata "${OUT_IMGDIR}"/userdata.img