target: apq8084: Implement target specific ssd api

Implement target specific ssd api to load keystore when entering
fastboot to enable flashing encrypted images.

CRs-Fixed: 586343
Change-Id: Ie81576948ccfe6921b48ef8310e91a5027571304
diff --git a/target/apq8084/init.c b/target/apq8084/init.c
index 08b0c5b..698e62f 100644
--- a/target/apq8084/init.c
+++ b/target/apq8084/init.c
@@ -60,6 +60,8 @@
 
 #define BOOT_DEVICE_MASK(val)   ((val & 0x3E) >>1)
 
+#define SSD_CE_INSTANCE         1
+
 enum cdp_subtype
 {
 	CDP_SUBTYPE_SMB349 = 0,
@@ -315,6 +317,58 @@
 #endif
 }
 
+void target_load_ssd_keystore(void)
+{
+	uint64_t ptn;
+	int      index;
+	uint64_t size;
+	uint32_t *buffer = NULL;
+
+	if (!target_is_ssd_enabled())
+		return;
+
+	index = partition_get_index("ssd");
+
+	ptn = partition_get_offset(index);
+	if (ptn == 0){
+		dprintf(CRITICAL, "Error: ssd partition not found\n");
+		return;
+	}
+
+	size = partition_get_size(index);
+	if (size == 0) {
+		dprintf(CRITICAL, "Error: invalid ssd partition size\n");
+		return;
+	}
+
+	buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
+	if (!buffer) {
+		dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n");
+		return;
+	}
+
+	if (mmc_read(ptn, buffer, size)) {
+		dprintf(CRITICAL, "Error: cannot read data\n");
+		free(buffer);
+		return;
+	}
+
+	clock_ce_enable(SSD_CE_INSTANCE);
+	scm_protect_keystore(buffer, size);
+	clock_ce_disable(SSD_CE_INSTANCE);
+	free(buffer);
+}
+
+/* Do any target specific intialization needed before entering fastboot mode */
+void target_fastboot_init(void)
+{
+	if (target_is_ssd_enabled()) {
+		clock_ce_enable(SSD_CE_INSTANCE);
+		target_load_ssd_keystore();
+	}
+
+}
+
 unsigned board_machtype(void)
 {
 	return LINUX_MACHTYPE_UNKNOWN;