platform: msm_shared: Disable fstab nodes for dynamic partition support

For dynamic partition support disable fstab firmware nodes,
mounted as part for early mount

Change-Id: I4511290b0aac195f6876b64ba1702ad9dbc018e4
Signed-off-by: Mayank Grover <groverm@codeaurora.org>
diff --git a/platform/msm_shared/dev_tree.c b/platform/msm_shared/dev_tree.c
index 752a7e9..fa7b28a 100644
--- a/platform/msm_shared/dev_tree.c
+++ b/platform/msm_shared/dev_tree.c
@@ -74,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
 {
@@ -83,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/"
@@ -2101,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) {
@@ -2119,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)
 {
@@ -2135,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;
@@ -2175,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);
@@ -2201,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;