msm8953 & msm8996 : Append "rootfstype=" and "root=" to kernel command line

This change is to get the system partition index and append it to kernel
command line instead of hardcoding the value in .conf files
used during the LE build process

Change-Id: I1b9e7744e0b95246e45911682cbb5c3ff61e9dab
diff --git a/target/msm8953/init.c b/target/msm8953/init.c
index 3d26442..91e36cb 100644
--- a/target/msm8953/init.c
+++ b/target/msm8953/init.c
@@ -76,6 +76,7 @@
 #define FASTBOOT_MODE           0x77665500
 #define RECOVERY_MODE           0x77665502
 #define PON_SOFT_RB_SPARE       0x88F
+#define EXT4_CMDLINE  " rootfstype=ext4 root=/dev/mmcblk0p"
 
 #define CE1_INSTANCE            1
 #define CE_EE                   1
@@ -107,6 +108,44 @@
 #endif
 }
 
+#if _APPEND_CMDLINE
+int get_target_boot_params(const char *cmdline, const char *part, char **buf)
+{
+	int system_ptn_index = -1;
+	uint32_t buflen;
+	int ret = -1;
+
+	if (!cmdline || !part ) {
+		dprintf(CRITICAL, "WARN: Invalid input param\n");
+		return -1;
+	}
+
+	if (!strstr(cmdline, "root=/dev/ram")) /* This check is to handle kdev boot */
+	{
+		if (target_is_emmc_boot()) {
+			buflen = strlen(EXT4_CMDLINE) + sizeof(int) +1;
+			*buf = (char *)malloc(buflen);
+			if(!(*buf)) {
+				dprintf(CRITICAL,"Unable to allocate memory for boot params\n");
+				return -1;
+			}
+			/* Below is for emmc boot */
+			system_ptn_index = partition_get_index(part) + 1; /* Adding +1 as offsets for eMMC start at 1 and NAND at 0 */
+			if (system_ptn_index < 0) {
+				dprintf(CRITICAL,
+						"WARN: Cannot get partition index for %s\n", part);
+				free(*buf);
+				return -1;
+			}
+			snprintf(*buf, buflen, EXT4_CMDLINE"%d", system_ptn_index);
+			ret = 0;
+		}
+	}
+	/*in success case buf will be freed in the calling function of this*/
+	return ret;
+}
+#endif
+
 static void set_sdc_power_ctrl()
 {
 	/* Drive strength configs for sdc pins */