Merge "target: msm8952: Add SDM429 + PM660 support"
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index ea90598..584ba35 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -162,6 +162,8 @@
 #else
 static const char *emmc_cmdline = " androidboot.emmc=true";
 #endif
+static const char *dynamic_bootdev_cmdline =
+				" androidboot.boot_devices=soc/";
 static const char *usb_sn_cmdline = " androidboot.serialno=";
 static const char *androidboot_mode = " androidboot.mode=";
 
@@ -484,12 +486,19 @@
 	}
 	if (target_is_emmc_boot()) {
 		cmdline_len += strlen(emmc_cmdline);
-#if USE_BOOTDEV_CMDLINE
 		boot_dev_buf = (char *) malloc(sizeof(char) * BOOT_DEV_MAX_LEN);
-		ASSERT(boot_dev_buf);
-		platform_boot_dev_cmdline(boot_dev_buf);
-		cmdline_len += strlen(boot_dev_buf);
+		if (!boot_dev_buf) {
+			dprintf(CRITICAL, "ERROR: Failed to allocate boot_dev_buf\n");
+		} else {
+			platform_boot_dev_cmdline(boot_dev_buf);
+#if USE_BOOTDEV_CMDLINE
+			cmdline_len += strlen(boot_dev_buf);
 #endif
+			if (target_dynamic_partition_supported()) {
+				cmdline_len += strlen(dynamic_bootdev_cmdline);
+				cmdline_len += strlen(boot_dev_buf);
+			}
+		}
 	}
 
 	cmdline_len += strlen(usb_sn_cmdline);
@@ -663,7 +672,10 @@
 		partition_multislot_is_supported())
 	{
 		cmdline_len += strlen(sys_path_cmdline);
-		if (!boot_into_recovery)
+
+		/* For dynamic partition, support skip skip_initramfs */
+		if (!target_dynamic_partition_supported() &&
+			!boot_into_recovery)
 			cmdline_len += strlen(skip_ramfs);
 	}
 
@@ -723,9 +735,22 @@
 			while ((*dst++ = *src++));
 #if USE_BOOTDEV_CMDLINE
 			src = boot_dev_buf;
-			if (have_cmdline) --dst;
-			while ((*dst++ = *src++));
+			if (have_cmdline &&
+				boot_dev_buf) {
+				--dst;
+				while ((*dst++ = *src++));
+			}
 #endif
+			/* Dynamic partition append boot_devices */
+			if (target_dynamic_partition_supported() &&
+				boot_dev_buf) {
+				src = dynamic_bootdev_cmdline;
+				if (have_cmdline) --dst;
+				while ((*dst++ = *src++));
+				src = boot_dev_buf;
+				if (have_cmdline) --dst;
+				while ((*dst++ = *src++));
+			}
 		}
 
 #if VERIFIED_BOOT
@@ -923,7 +948,8 @@
 			partition_multislot_is_supported()) &&
 			have_cmdline)
 		{
-			if (!boot_into_recovery)
+			if (!target_dynamic_partition_supported() &&
+				!boot_into_recovery)
 			{
 				src = skip_ramfs;
 				--dst;
diff --git a/platform/init.c b/platform/init.c
index 46f934c..0488c53 100644
--- a/platform/init.c
+++ b/platform/init.c
@@ -28,6 +28,9 @@
 #include <boot_stats.h>
 #include <platform/iomap.h>
 #include <image_verify.h>
+#include <target.h>
+#include <boot_device.h>
+#include <mmc_wrapper.h>
 
 /*
  * default implementations of these routines, if the platform code
@@ -147,7 +150,7 @@
 	return 0;
 }
 
-__WEAK uint32_t use_hsonly_mode()
+__WEAK bool use_hsonly_mode()
 {
 	return 0;
 }
@@ -178,3 +181,24 @@
 #endif
 }
 
+/* function to update boot device base, for emmc targets. */
+__WEAK void platform_boot_dev_cmdline(char *buf)
+{
+	struct mmc_device *dev = NULL;
+	uint32_t boot_dev_str_sz = 0;
+
+	if (!buf) {
+		dprintf(CRITICAL,"ERROR: Invalid args- Failed to populate boot device");
+		return;
+	}
+
+	dev = (struct mmc_device *)target_mmc_device();
+	boot_dev_str_sz = ((sizeof(dev->host.base))*2) + 7;
+	if (boot_dev_str_sz > sizeof(char) * BOOT_DEV_MAX_LEN) {
+		dprintf(CRITICAL,"ERROR: Invalid buf sz - Failed to populate boot device");
+		return;
+	}
+
+	snprintf(buf, boot_dev_str_sz, "%x.sdhci", dev->host.base);
+	return;
+}
diff --git a/platform/msm_shared/dev_tree.c b/platform/msm_shared/dev_tree.c
index 5ad8faf..fa7b28a 100644
--- a/platform/msm_shared/dev_tree.c
+++ b/platform/msm_shared/dev_tree.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2015,2017-2018 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2015,2017-2019 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -49,7 +49,6 @@
 #include <boot_stats.h>
 #include <verifiedboot.h>
 
-#define BOOT_DEV_MAX_LEN        64
 #define NODE_PROPERTY_MAX_LEN   64
 #define ADD_OF(a, b) (UINT_MAX - b > a) ? (a + b) : UINT_MAX
 #define ADDR_ALIGNMENT 16
@@ -75,7 +74,7 @@
 	uint32_t size;
 };
 
-#if ENABLE_BOOTDEVICE_MOUNT
+#if ENABLE_BOOTDEVICE_MOUNT || DYNAMIC_PARTITION_SUPPORT
 /* Look up table for fstab node */
 struct fstab_node
 {
@@ -84,6 +83,11 @@
         const char *device_path_id;
 };
 
+static struct fstab_node dynamic_fstab_table =
+{
+	"/firmware/android/fstab", "status", ""
+};
+
 static struct fstab_node fstab_table =
 {
 	"/firmware/android/fstab", "dev", "/soc/"
@@ -2102,7 +2106,7 @@
 		}
 	}
 
-#if ENABLE_BOOTDEVICE_MOUNT
+#if ENABLE_BOOTDEVICE_MOUNT || DYNAMIC_PARTITION_SUPPORT
 	/* Update fstab node */
 	dprintf(SPEW, "Start of fstab node update:%zu ms\n", platform_get_sclk_count());
 	if (update_fstab_node(fdt) != 0) {
@@ -2120,7 +2124,7 @@
 	return ret;
 }
 
-#if ENABLE_BOOTDEVICE_MOUNT
+#if ENABLE_BOOTDEVICE_MOUNT || DYNAMIC_PARTITION_SUPPORT
 /*Update device tree for fstab node */
 static int update_fstab_node(void *fdt)
 {
@@ -2136,39 +2140,60 @@
 	char *prefix_str = NULL;
 	char *suffix_str = NULL;
 	const struct fdt_property *prop = NULL;
+	struct fstab_node table = target_dynamic_partition_supported() ?
+						dynamic_fstab_table :
+						fstab_table;
 
 	/* Find the parent node */
-	parent_offset = fdt_path_offset(fdt, fstab_table.parent_node);
+	parent_offset = fdt_path_offset(fdt, table.parent_node);
 	if (parent_offset < 0) {
 		dprintf(CRITICAL, "Failed to get parent node: fstab error: %d\n", parent_offset);
 		return -1;
 	}
 	dprintf(SPEW, "Node: %s found.\n", fdt_get_name(fdt, parent_offset, NULL));
 
-	/* Get boot device type */
-	boot_dev_buf = (char *) malloc(sizeof(char) * BOOT_DEV_MAX_LEN);
-	if (!boot_dev_buf) {
-		dprintf(CRITICAL, "Failed to allocate memory for boot device\n");
-		return -1;
+	if (!target_dynamic_partition_supported())
+	{
+		/* Get boot device type */
+		boot_dev_buf = (char *) malloc(sizeof(char) * BOOT_DEV_MAX_LEN);
+		if (!boot_dev_buf) {
+			dprintf(CRITICAL, "Failed to allocate memory for boot device\n");
+			return -1;
+		}
+
+		new_str = (char *) malloc(sizeof(char) * NODE_PROPERTY_MAX_LEN);
+		if (!new_str) {
+			dprintf(CRITICAL, "Failed to allocate memory for node property string\n");
+			return -1;
+		}
+
+		platform_boot_dev_cmdline(boot_dev_buf);
 	}
 
-	new_str = (char *) malloc(sizeof(char) * NODE_PROPERTY_MAX_LEN);
-	if (!new_str) {
-		dprintf(CRITICAL, "Failed to allocate memory for node property string\n");
-		return -1;
-	}
-
-
-	platform_boot_dev_cmdline(boot_dev_buf);
-
 	/* Get properties of all sub nodes */
-	for (subnode_offset = fdt_first_subnode(fdt, parent_offset); subnode_offset >= 0; subnode_offset = fdt_next_subnode(fdt, subnode_offset)) {
-		prop = fdt_get_property(fdt, subnode_offset, fstab_table.node_prop, &prop_length);
+	for (subnode_offset = fdt_first_subnode(fdt, parent_offset);
+		subnode_offset >= 0;
+		subnode_offset = fdt_next_subnode(fdt, subnode_offset)) {
+		prop = fdt_get_property(fdt, subnode_offset, table.node_prop, &prop_length);
 		node_name = (char *)(uintptr_t)fdt_get_name(fdt, subnode_offset, NULL);
 		if (!prop) {
-			dprintf(CRITICAL, "Property:%s is not found for sub node:%s\n", fstab_table.node_prop, node_name);
+			dprintf(CRITICAL, "Property:%s is not found for sub node:%s\n", table.node_prop, node_name);
 		} else {
-			dprintf(CRITICAL, "Property:%s found for sub node:%s\tproperty:%s\n", fstab_table.node_prop, node_name, prop->data);
+			dprintf(CRITICAL, "Property:%s found for sub node:%s\tproperty:%s\n", table.node_prop, node_name, prop->data);
+
+			/* For Dynamic partition support disable firmware fstab nodes. */
+			if (target_dynamic_partition_supported())
+			{
+				dprintf (INFO, "Disabling node status :%s\n", node_name);
+				ret = fdt_setprop (fdt, subnode_offset, table.node_prop, "disabled",
+						(strlen("disabled") + 1));
+				if (ret)
+				{
+					dprintf(CRITICAL, "ERROR: Failed to disable Node: %s\n", node_name);
+				}
+				continue;
+			}
+
 			/* Pointer to fdt 'dev' property string that needs to update based on the 'androidboot.bootdevice' */
 			memset(new_str, 0, NODE_PROPERTY_MAX_LEN);
 			prefix_str = (char *)prop->data;
@@ -2176,12 +2201,12 @@
 				dprintf(CRITICAL, "Property string length is greater than node property max length\n");
 				continue;
 			}
-			suffix_str = strstr(prefix_str, fstab_table.device_path_id);
+			suffix_str = strstr(prefix_str, table.device_path_id);
 			if (!suffix_str) {
 				dprintf(CRITICAL, "Property is not proper to update\n");
 				continue;
 			}
-			suffix_str += strlen(fstab_table.device_path_id);
+			suffix_str += strlen(table.device_path_id);
 			prefix_string_len = strlen(prefix_str) - (strlen(suffix_str) - 1);
 			suffix_str = strstr((suffix_str + 1), "/");
 			str_len = strlcpy(new_str, prefix_str, prefix_string_len);
@@ -2202,7 +2227,7 @@
 			/* Update the new property in the memory */
 			memscpy(prefix_str, strlen(prefix_str), new_str, strlen(new_str) + 1);
 			/* Update the property with new value */
-			ret = fdt_setprop(fdt, subnode_offset, fstab_table.node_prop, (const void *)prefix_str, strlen(prefix_str) + 1);
+			ret = fdt_setprop(fdt, subnode_offset, table.node_prop, (const void *)prefix_str, strlen(prefix_str) + 1);
 			if(ret) {
 				dprintf(CRITICAL, "Failed to update the node with new property\n");
 				continue;
diff --git a/platform/msm_shared/include/boot_device.h b/platform/msm_shared/include/boot_device.h
index a0897ec..4e281f7 100644
--- a/platform/msm_shared/include/boot_device.h
+++ b/platform/msm_shared/include/boot_device.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014,2016 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2014,2016,2019 The Linux Foundation. All rights reserved.
 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -59,6 +59,7 @@
 #ifndef MAX_GPT_NAME_SIZE
 #define MAX_GPT_NAME_SIZE 72
 #endif
+#define BOOT_DEV_MAX_LEN        64
 
 typedef struct {
 	char *name;
diff --git a/target/msm8953/oem_panel.c b/target/msm8953/oem_panel.c
index 4de8664..2a21713 100644
--- a/target/msm8953/oem_panel.c
+++ b/target/msm8953/oem_panel.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016,2018, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2016,2018-2019, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -371,13 +371,13 @@
 	switch (hw_id) {
 	case HW_PLATFORM_MTP:
 		panel_id = TRULY_1080P_VIDEO_PANEL;
-		if (platform_subtype == 0x03)
+		if (platform_subtype == 0x03 || platform_subtype == 0x04)
 			panel_id = HX8399C_FHD_PLUSE_VIDEO_PANEL;
 		break;
 	case HW_PLATFORM_SURF:
 	case HW_PLATFORM_RCM:
 		panel_id = TRULY_1080P_VIDEO_PANEL;
-		if (platform_subtype == 0x02)
+		if (platform_subtype == 0x02 || platform_subtype == 0x03)
 			 panel_id = HX8399C_FHD_PLUSE_VIDEO_PANEL;
 		break;
 	case HW_PLATFORM_QRD: