blob: 70bb43280776bc2b25d30ba105a43e1cd989ec76 [file] [log] [blame]
John Stultz479a7c92022-02-02 05:54:07 +00001#!/bin/bash
2
3INSTALLER_DIR="`dirname ${0}`"
4ECHO_PREFIX="=== "
5
6# for cases that don't run "lunch hikey960-userdebug"
7if [ -z "${ANDROID_BUILD_TOP}" ]; then
8 ANDROID_BUILD_TOP=${INSTALLER_DIR}/../../../../../
9 ANDROID_PRODUCT_OUT="${ANDROID_BUILD_TOP}/out/target/product/hikey960"
10fi
11
12if [ ! -d "${ANDROID_PRODUCT_OUT}" ]; then
13 echo ${ECHO_PREFIX}"error in locating out directory, check if it exist"
14 exit
15fi
16
17echo ${ECHO_PREFIX}"android out dir:${ANDROID_PRODUCT_OUT}"
18
19function check_partition_table_version () {
20 fastboot erase reserved
21 if [ $? -eq 0 ]
22 then
23 IS_PTABLE_1MB_ALIGNED=true
24 else
25 IS_PTABLE_1MB_ALIGNED=false
26 fi
27}
28
29function flashing_atf_uefi () {
30 fastboot flash ptable "${INSTALLER_DIR}"/prm_ptable.img
31 fastboot flash xloader "${INSTALLER_DIR}"/hisi-sec_xloader.img
32 fastboot reboot-bootloader
33
34 fastboot flash fastboot "${INSTALLER_DIR}"/l-loader.bin
35 fastboot flash fip "${INSTALLER_DIR}"/fip.bin
36 fastboot flash nvme "${INSTALLER_DIR}"/hisi-nvme.img
37 fastboot flash fw_lpm3 "${INSTALLER_DIR}"/hisi-lpm3.img
38 fastboot flash trustfirmware "${INSTALLER_DIR}"/hisi-bl31.bin
39 fastboot reboot-bootloader
40
41 fastboot flash ptable "${INSTALLER_DIR}"/prm_ptable.img
42 fastboot flash xloader "${INSTALLER_DIR}"/hisi-sec_xloader.img
43 fastboot flash fastboot "${INSTALLER_DIR}"/l-loader.bin
44 fastboot flash fip "${INSTALLER_DIR}"/fip.bin
45
46 fastboot flash boot "${ANDROID_PRODUCT_OUT}"/boot.img
47 fastboot flash super "${ANDROID_PRODUCT_OUT}"/super.img
48 fastboot flash userdata "${ANDROID_PRODUCT_OUT}"/userdata.img
49 fastboot format cache
50}
51
52function upgrading_ptable_1mb_aligned () {
53 fastboot flash xloader "${INSTALLER_DIR}"/hisi-sec_xloader.img
54 fastboot flash ptable "${INSTALLER_DIR}"/hisi-ptable.img
55 fastboot flash fastboot "${INSTALLER_DIR}"/hisi-fastboot.img
56 fastboot reboot-bootloader
57}
58
59echo ${ECHO_PREFIX}"Checking partition table version..."
60check_partition_table_version
61
62if [ "${IS_PTABLE_1MB_ALIGNED}" == "true" ]
63then
64 echo ${ECHO_PREFIX}"Partition table is 1MB aligned. Flashing ATF/UEFI..."
65 flashing_atf_uefi
66else
67 echo ${ECHO_PREFIX}"Partition table is 512KB aligned."
68 echo ${ECHO_PREFIX}"Upgrading to 1MB aligned version..."
69 upgrading_ptable_1mb_aligned
70 echo ${ECHO_PREFIX}"Flashing ATF/UEFI..."
71 flashing_atf_uefi
72 echo ${ECHO_PREFIX}"Done"
73fi
74
75fastboot reboot