John Stultz | 479a7c9 | 2022-02-02 05:54:07 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | INSTALLER_DIR="`dirname ${0}`" |
| 4 | ECHO_PREFIX="=== " |
| 5 | |
| 6 | # for cases that don't run "lunch hikey960-userdebug" |
| 7 | if [ -z "${ANDROID_BUILD_TOP}" ]; then |
| 8 | ANDROID_BUILD_TOP=${INSTALLER_DIR}/../../../../../ |
| 9 | ANDROID_PRODUCT_OUT="${ANDROID_BUILD_TOP}/out/target/product/hikey960" |
| 10 | fi |
| 11 | |
| 12 | if [ ! -d "${ANDROID_PRODUCT_OUT}" ]; then |
| 13 | echo ${ECHO_PREFIX}"error in locating out directory, check if it exist" |
| 14 | exit |
| 15 | fi |
| 16 | |
| 17 | echo ${ECHO_PREFIX}"android out dir:${ANDROID_PRODUCT_OUT}" |
| 18 | |
| 19 | function 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 | |
| 29 | function 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 | |
| 52 | function 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 | |
| 59 | echo ${ECHO_PREFIX}"Checking partition table version..." |
| 60 | check_partition_table_version |
| 61 | |
| 62 | if [ "${IS_PTABLE_1MB_ALIGNED}" == "true" ] |
| 63 | then |
| 64 | echo ${ECHO_PREFIX}"Partition table is 1MB aligned. Flashing ATF/UEFI..." |
| 65 | flashing_atf_uefi |
| 66 | else |
| 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" |
| 73 | fi |
| 74 | |
| 75 | fastboot reboot |