Vishal Bhoj | ca1fbcd | 2015-12-16 00:25:24 +0530 | [diff] [blame] | 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 | |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 8 | if [ ! -e "${1}" ] |
Vishal Bhoj | ca1fbcd | 2015-12-16 00:25:24 +0530 | [diff] [blame] | 9 | then |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 10 | echo "device: ${1} does not exist" |
Vishal Bhoj | ca1fbcd | 2015-12-16 00:25:24 +0530 | [diff] [blame] | 11 | exit |
| 12 | fi |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 13 | DEVICE_PORT="${1}" |
Dmitry Shmidt | 06cb4cd | 2016-01-27 11:00:33 -0800 | [diff] [blame] | 14 | PTABLE=ptable-aosp-8g.img |
| 15 | if [ $# -gt 1 ] |
| 16 | then |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 17 | if [ "${2}" == '4g' ] |
Dmitry Shmidt | 06cb4cd | 2016-01-27 11:00:33 -0800 | [diff] [blame] | 18 | then |
| 19 | PTABLE=ptable-aosp-4g.img |
| 20 | fi |
| 21 | fi |
| 22 | |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 23 | INSTALLER_DIR="`dirname ${0}`" |
| 24 | FIRMWARE_DIR="${INSTALLER_DIR}" |
| 25 | |
Amit Pundir | 048e1a6 | 2017-01-24 12:08:13 +0530 | [diff] [blame] | 26 | # for cases that not run "lunch hikey-userdebug" |
Yongqin Liu | 74aa066 | 2016-07-16 20:46:52 +0800 | [diff] [blame] | 27 | if [ -z "${ANDROID_BUILD_TOP}" ]; then |
Amit Pundir | 048e1a6 | 2017-01-24 12:08:13 +0530 | [diff] [blame] | 28 | ANDROID_BUILD_TOP=${INSTALLER_DIR}/../../../../../ |
Yongqin Liu | 74aa066 | 2016-07-16 20:46:52 +0800 | [diff] [blame] | 29 | ANDROID_PRODUCT_OUT="${ANDROID_BUILD_TOP}/out/target/product/hikey" |
| 30 | fi |
| 31 | |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 32 | if [ -z "${DIST_DIR}" ]; then |
| 33 | DIST_DIR="${ANDROID_BUILD_TOP}"/out/dist |
| 34 | fi |
Satish Patel | dc91c89 | 2016-03-28 10:03:21 +0530 | [diff] [blame] | 35 | |
| 36 | #get out directory path |
| 37 | while [ $# -ne 0 ]; do |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 38 | case "${1}" in |
| 39 | --out) OUT_IMGDIR=${2};shift;; |
| 40 | --use-compiled-binaries) FIRMWARE_DIR="${DIST_DIR}";shift;; |
Satish Patel | dc91c89 | 2016-03-28 10:03:21 +0530 | [diff] [blame] | 41 | esac |
| 42 | shift |
| 43 | done |
| 44 | |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 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}" |
Satish Patel | dc91c89 | 2016-03-28 10:03:21 +0530 | [diff] [blame] | 53 | fi |
| 54 | fi |
| 55 | |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 56 | if [ ! -d "${OUT_IMGDIR}" ]; then |
Satish Patel | dc91c89 | 2016-03-28 10:03:21 +0530 | [diff] [blame] | 57 | echo "error in locating out directory, check if it exist" |
| 58 | exit |
| 59 | fi |
Satish Patel | dc91c89 | 2016-03-28 10:03:21 +0530 | [diff] [blame] | 60 | |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 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}" |
Dmitry Shmidt | e9b656f | 2016-09-08 15:10:46 -0700 | [diff] [blame] | 64 | sleep 3 |
John Stultz | abe8022 | 2016-08-03 20:23:51 -0700 | [diff] [blame] | 65 | # set a unique serial number |
Dmitry Shmidt | e9b656f | 2016-09-08 15:10:46 -0700 | [diff] [blame] | 66 | serialno=`fastboot getvar serialno 2>&1 > /dev/null` |
| 67 | if [ "${serialno:10:6}" == "(null)" ]; then |
| 68 | fastboot oem serialno |
| 69 | else |
| 70 | if [ "${serialno:10:15}" == "0123456789abcde" ]; then |
| 71 | fastboot oem serialno |
| 72 | fi |
| 73 | fi |
Dmitry Shmidt | fd5e31a | 2018-05-07 15:55:52 -0700 | [diff] [blame] | 74 | fastboot getvar partition-size:ptable |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 75 | fastboot flash ptable "${INSTALLER_DIR}"/"${PTABLE}" |
| 76 | fastboot flash fastboot "${FIRMWARE_DIR}"/fip.bin |
| 77 | fastboot flash nvme "${INSTALLER_DIR}"/nvme.img |
| 78 | fastboot flash boot "${OUT_IMGDIR}"/boot.img |
| 79 | fastboot flash system "${OUT_IMGDIR}"/system.img |
Yongqin Liu | 7dff606 | 2018-04-24 11:29:39 +0800 | [diff] [blame] | 80 | fastboot flash vendor "${OUT_IMGDIR}"/vendor.img |
Vishal Bhoj | 2df2ca7 | 2016-07-12 17:14:56 +0100 | [diff] [blame] | 81 | fastboot flash cache "${OUT_IMGDIR}"/cache.img |
| 82 | fastboot flash userdata "${OUT_IMGDIR}"/userdata.img |