hikey960: Enabling dynamic partitions for HiKey960

This is basically a port of work Amit had done against HiKey
board awhile back:
  https://android-review.linaro.org/c/device/linaro/hikey/+/20550

Moving system vendor product and system_ext to the super
partition.

For now, instead of reworking the ptable, we simply flash the
super partition to the system partition. This will need to change
so that we change the ptable as well, but that needs some time
as the ptable flashing can be disruptive for testing.

Feedback would be appreciated.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Change-Id: Ie53fed6392116b16063f497978e369490a1fccd2
diff --git a/fstab.ramdisk960 b/fstab.ramdisk960
new file mode 100644
index 0000000..6192881
--- /dev/null
+++ b/fstab.ramdisk960
@@ -0,0 +1,4 @@
+system /system ext4 noatime,ro,errors=panic wait,logical,first_stage_mount
+vendor /vendor ext4 noatime,ro,errors=panic wait,logical,first_stage_mount
+system_ext /system_ext ext4 noatime,ro,errors=panic wait,logical,first_stage_mount
+product /product ext4 noatime,ro,errors=panic wait,logical,first_stage_mount
diff --git a/hikey960.mk b/hikey960.mk
index 09c5a7f..03d0b96 100644
--- a/hikey960.mk
+++ b/hikey960.mk
@@ -29,13 +29,6 @@
 $(call inherit-product, device/linaro/hikey/hikey960/device-hikey960.mk)
 $(call inherit-product, device/linaro/hikey/device-common.mk)
 
-#setup dm-verity configs
-PRODUCT_SYSTEM_VERITY_PARTITION := /dev/block/platform/soc/ff3b0000.ufs/by-name/system
-PRODUCT_VENDOR_VERITY_PARTITION := /dev/block/platform/soc/ff3b0000.ufs/by-name/vendor
-$(call inherit-product, build/target/product/verity.mk)
-PRODUCT_SUPPORTS_BOOT_SIGNER := false
-PRODUCT_SUPPORTS_VERITY_FEC := false
-
 PRODUCT_PROPERTY_OVERRIDES += ro.opengles.version=196608
 
 #
diff --git a/hikey960/BoardConfig.mk b/hikey960/BoardConfig.mk
index 3cd7a63..789b18f 100644
--- a/hikey960/BoardConfig.mk
+++ b/hikey960/BoardConfig.mk
@@ -41,15 +41,29 @@
 BOARD_MKBOOTIMG_ARGS := --base 0x0 --tags_offset 0x07a00000 --kernel_offset 0x00080000 --ramdisk_offset 0x07c00000
 
 BOARD_BOOTIMAGE_PARTITION_SIZE := 67108864
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 4915724288    # 4688MB
 BOARD_USERDATAIMAGE_PARTITION_SIZE := 25845301248 # 24648MB
 BOARD_FLASH_BLOCK_SIZE := 512
 
-# Vendor partition definitions
+# Vendor/system_ext/product partition definitions
 TARGET_COPY_OUT_VENDOR := vendor
-BOARD_VENDORIMAGE_PARTITION_SIZE := 822083584     # 784MB
 BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4
-BOARD_VENDORIMAGE_JOURNAL_SIZE := 0
-BOARD_VENDORIMAGE_EXTFS_INODE_COUNT := 2048
+TARGET_COPY_OUT_SYSTEM_EXT := system_ext
+BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE := ext4
+TARGET_COPY_OUT_PRODUCT := product
+BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE := ext4
+
+#Dynamic Partition details
+TARGET_USE_DYNAMIC_PARTITIONS := true
+BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT := true
+BOARD_SUPER_PARTITION_SIZE := 4915724288
+BOARD_SUPER_PARTITION_GROUPS := hikey960_dynamic_partitions
+BOARD_HIKEY960_DYNAMIC_PARTITIONS_PARTITION_LIST := system vendor system_ext product
+BOARD_HIKEY960_DYNAMIC_PARTITIONS_SIZE := 4915724288
+
+# !!! This HACK needs to be removed !!!
+# Until the ptable is updated, we flash super.img to system
+# but this is deprecated. We need to update the ptable and
+# roll that out. Then this can be removed.
+BOARD_SUPER_PARTITION_METADATA_DEVICE := system
 
 TARGET_RECOVERY_FSTAB := device/linaro/hikey/hikey960/fstab.hikey960
diff --git a/hikey960/device-hikey960.mk b/hikey960/device-hikey960.mk
index 301a16b..f1946ee 100644
--- a/hikey960/device-hikey960.mk
+++ b/hikey960/device-hikey960.mk
@@ -18,7 +18,7 @@
 			$(TARGET_PREBUILT_DTB):hi3660-hikey960.dtb
 
 PRODUCT_COPY_FILES +=	$(LOCAL_PATH)/fstab.hikey960:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.hikey960 \
-			device/linaro/hikey/fstab.ramdisk:$(TARGET_COPY_OUT_RAMDISK)/fstab.hikey960 \
+			device/linaro/hikey/fstab.ramdisk960:$(TARGET_COPY_OUT_RAMDISK)/fstab.hikey960 \
 			device/linaro/hikey/hikey960/init.hikey960.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.hikey960.rc \
 			device/linaro/hikey/init.hikey960.power.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.hikey960.power.rc \
 			device/linaro/hikey/hikey960/init.hikey960.usb.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.hikey960.usb.rc \
@@ -28,6 +28,10 @@
 			frameworks/native/data/etc/android.hardware.vulkan.version-1_0_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \
 			frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml
 
+PRODUCT_BUILD_SUPER_PARTITION := true
+PRODUCT_USE_DYNAMIC_PARTITIONS := true
+PRODUCT_USE_DYNAMIC_PARTITION_SIZE :=true
+
 # Copy BT firmware
 PRODUCT_COPY_FILES += \
 	device/linaro/hikey/bt-wifi-firmware-util/TIInit_11.8.32-pcm-960.bts:$(TARGET_COPY_OUT_VENDOR)/firmware/ti-connectivity/TIInit_11.8.32.bts
diff --git a/installer/hikey960/flash-all.sh b/installer/hikey960/flash-all.sh
index 2888020..dda34d3 100755
--- a/installer/hikey960/flash-all.sh
+++ b/installer/hikey960/flash-all.sh
@@ -24,7 +24,6 @@
 fastboot flash trustfirmware   "${INSTALLER_DIR}"/hisi-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 vendor "${ANDROID_PRODUCT_OUT}"/vendor.img
+fastboot flash system "${ANDROID_PRODUCT_OUT}"/super.img
 fastboot flash userdata "${ANDROID_PRODUCT_OUT}"/userdata.img
 fastboot reboot
diff --git a/installer/hikey960/uefi-flash-all.sh b/installer/hikey960/uefi-flash-all.sh
index fe42486..ce40203 100755
--- a/installer/hikey960/uefi-flash-all.sh
+++ b/installer/hikey960/uefi-flash-all.sh
@@ -44,9 +44,7 @@
 	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 vendor "${ANDROID_PRODUCT_OUT}"/vendor.img
-	fastboot flash cache "${ANDROID_PRODUCT_OUT}"/cache.img
+	fastboot flash system "${ANDROID_PRODUCT_OUT}"/super.img
 	fastboot flash userdata "${ANDROID_PRODUCT_OUT}"/userdata.img
 }