Merge "ENFORCE_VINTF_MANIFEST on hikey*"
diff --git a/hikey960.mk b/hikey960.mk
index 0612447..1b9799b 100644
--- a/hikey960.mk
+++ b/hikey960.mk
@@ -1,7 +1,7 @@
 ifndef TARGET_KERNEL_USE
 TARGET_KERNEL_USE=4.9
 endif
-TARGET_PREBUILT_KERNEL := device/linaro/hikey-kernel/Image.gz-hikey960-$(TARGET_KERNEL_USE)
+TARGET_PREBUILT_KERNEL := device/linaro/hikey-kernel/Image.gz-dtb-hikey960-$(TARGET_KERNEL_USE)
 TARGET_PREBUILT_DTB := device/linaro/hikey-kernel/hi3660-hikey960.dtb-$(TARGET_KERNEL_USE)
 
 ifeq ($(TARGET_KERNEL_USE), 4.4)
diff --git a/hikey960/BoardConfig.mk b/hikey960/BoardConfig.mk
index 0253141..a249cab 100644
--- a/hikey960/BoardConfig.mk
+++ b/hikey960/BoardConfig.mk
@@ -9,7 +9,7 @@
 TARGET_NO_DTIMAGE := false
 
 BOARD_KERNEL_CMDLINE := androidboot.hardware=hikey960 console=ttyFIQ0 androidboot.console=ttyFIQ0
-BOARD_KERNEL_CMDLINE += firmware_class.path=/system/etc/firmware loglevel=15
+BOARD_KERNEL_CMDLINE += firmware_class.path=/system/etc/firmware loglevel=15 efi=noruntime
 ifneq ($(TARGET_SENSOR_MEZZANINE),)
 BOARD_KERNEL_CMDLINE += overlay_mgr.overlay_dt_entry=hardware_cfg_$(TARGET_SENSOR_MEZZANINE)
 endif
diff --git a/installer/hikey960/fip.bin b/installer/hikey960/fip.bin
new file mode 100644
index 0000000..2649559
--- /dev/null
+++ b/installer/hikey960/fip.bin
Binary files differ
diff --git a/installer/hikey960/flash-all.sh b/installer/hikey960/flash-all.sh
index 62256b8..fd4e7ac 100755
--- a/installer/hikey960/flash-all.sh
+++ b/installer/hikey960/flash-all.sh
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 INSTALLER_DIR="`dirname ${0}`"
+ECHO_PREFIX="=== "
 
 # for cases that don't run "lunch hikey960-userdebug"
 if [ -z "${ANDROID_BUILD_TOP}" ]; then
@@ -9,22 +10,66 @@
 fi
 
 if [ ! -d "${ANDROID_PRODUCT_OUT}" ]; then
-    echo "error in locating out directory, check if it exist"
+    echo ${ECHO_PREFIX}"error in locating out directory, check if it exist"
     exit
 fi
 
-echo "android out dir:${ANDROID_PRODUCT_OUT}"
+echo ${ECHO_PREFIX}"android out dir:${ANDROID_PRODUCT_OUT}"
 
-fastboot flash xloader "${INSTALLER_DIR}"/hisi-sec_xloader.img
-fastboot flash ptable "${INSTALLER_DIR}"/hisi-ptable.img
-fastboot flash fastboot "${INSTALLER_DIR}"/hisi-fastboot.img
-fastboot reboot-bootloader
-fastboot flash nvme "${INSTALLER_DIR}"/nvme.img
-fastboot flash fw_lpm3   "${INSTALLER_DIR}"/lpm3.img
-fastboot flash trustfirmware   "${INSTALLER_DIR}"/bl31.bin
-fastboot flash boot "${ANDROID_PRODUCT_OUT}"/boot.img
-fastboot flash dts "${ANDROID_PRODUCT_OUT}"/dt.img
-fastboot flash system "${ANDROID_PRODUCT_OUT}"/system.img
-fastboot flash cache "${ANDROID_PRODUCT_OUT}"/cache.img
-fastboot flash userdata "${ANDROID_PRODUCT_OUT}"/userdata.img
+function check_partition_table_version () {
+	fastboot erase reserved
+	if [ $? -eq 0 ]
+	then
+		IS_PTABLE_1MB_ALIGNED=true
+	else
+		IS_PTABLE_1MB_ALIGNED=false
+	fi
+}
+
+function flashing_atf_uefi () {
+	fastboot flash ptable "${INSTALLER_DIR}"/prm_ptable.img
+	fastboot flash xloader "${INSTALLER_DIR}"/hisi-sec_xloader.img
+	fastboot reboot-bootloader
+
+	fastboot flash fastboot "${INSTALLER_DIR}"/l-loader.bin
+	fastboot flash fip "${INSTALLER_DIR}"/fip.bin
+	fastboot flash nvme "${INSTALLER_DIR}"/hisi-nvme.img
+	fastboot flash fw_lpm3   "${INSTALLER_DIR}"/hisi-lpm3.img
+	fastboot flash trustfirmware   "${INSTALLER_DIR}"/hisi-bl31.bin
+	fastboot reboot-bootloader
+
+	fastboot flash ptable "${INSTALLER_DIR}"/prm_ptable.img
+	fastboot flash xloader "${INSTALLER_DIR}"/hisi-sec_xloader.img
+	fastboot flash fastboot "${INSTALLER_DIR}"/l-loader.bin
+	fastboot flash fip "${INSTALLER_DIR}"/fip.bin
+
+	fastboot flash boot "${ANDROID_PRODUCT_OUT}"/boot.img
+	fastboot flash system "${ANDROID_PRODUCT_OUT}"/system.img
+	fastboot flash cache "${ANDROID_PRODUCT_OUT}"/cache.img
+	fastboot flash userdata "${ANDROID_PRODUCT_OUT}"/userdata.img
+}
+
+function upgrading_ptable_1mb_aligned () {
+	fastboot flash xloader "${INSTALLER_DIR}"/hisi-sec_xloader.img
+	fastboot flash ptable "${INSTALLER_DIR}"/hisi-ptable.img
+	fastboot flash fastboot "${INSTALLER_DIR}"/hisi-fastboot.img
+	fastboot reboot-bootloader
+}
+
+echo ${ECHO_PREFIX}"Checking partition table version..."
+check_partition_table_version
+
+if [ "${IS_PTABLE_1MB_ALIGNED}" == "true" ]
+then
+	echo ${ECHO_PREFIX}"Partition table is 1MB aligned. Flashing ATF/UEFI..."
+	flashing_atf_uefi
+else
+	echo ${ECHO_PREFIX}"Partition table is 512KB aligned."
+	echo ${ECHO_PREFIX}"Upgrading to 1MB aligned version..."
+	upgrading_ptable_1mb_aligned
+	echo ${ECHO_PREFIX}"Flasing ATF/UEFI..."
+	flashing_atf_uefi
+	echo ${ECHO_PREFIX}"Done"
+fi
+
 fastboot reboot
diff --git a/installer/hikey960/bl31.bin b/installer/hikey960/hisi-bl31.bin
similarity index 100%
rename from installer/hikey960/bl31.bin
rename to installer/hikey960/hisi-bl31.bin
Binary files differ
diff --git a/installer/hikey960/lpm3.img b/installer/hikey960/hisi-lpm3.img
similarity index 100%
rename from installer/hikey960/lpm3.img
rename to installer/hikey960/hisi-lpm3.img
Binary files differ
diff --git a/installer/hikey960/nvme.img b/installer/hikey960/hisi-nvme.img
similarity index 100%
rename from installer/hikey960/nvme.img
rename to installer/hikey960/hisi-nvme.img
Binary files differ
diff --git a/installer/hikey960/l-loader.bin b/installer/hikey960/l-loader.bin
new file mode 100644
index 0000000..e7a523f
--- /dev/null
+++ b/installer/hikey960/l-loader.bin
Binary files differ
diff --git a/installer/hikey960/prm_ptable.img b/installer/hikey960/prm_ptable.img
new file mode 100644
index 0000000..c81ffcf
--- /dev/null
+++ b/installer/hikey960/prm_ptable.img
Binary files differ