target: init: Change to get vb version on runtime.

Add function to get vb version used on runtime, based on
keymaster partition is present.

Change-Id: I9b26dc6912b2be1f344b1c2e024f442dfc80905f
diff --git a/include/target.h b/include/target.h
index a9a1eea..2963b2d 100644
--- a/include/target.h
+++ b/include/target.h
@@ -27,6 +27,14 @@
 #include <qmp_phy.h>
 
 #define TARGET_MAX_CMDLNBUF 64
+
+/* Enum for target VB version detection */
+enum
+{
+	VB_V1 = 1,
+	VB_V2 = 2,
+};
+
 /* Target helper functions exposed to USB driver */
 typedef struct {
 	void (*mux_config) ();
@@ -109,4 +117,5 @@
 bool target_battery_is_present();
 uint32_t target_get_pmic();
 int target_update_cmdline(char *cmdline);
+int target_get_vb_version();
 #endif
diff --git a/target/init.c b/target/init.c
index 06be1f0..6f57540 100644
--- a/target/init.c
+++ b/target/init.c
@@ -43,6 +43,11 @@
 #include <pm_fg_adc_usr.h>
 #endif
 
+#if VERIFIED_BOOT
+#include <partition_parser.h>
+#include <ab_partition_parser.h>
+#endif
+
 #define EXPAND(NAME) #NAME
 #define TARGET(NAME) EXPAND(NAME)
 
@@ -50,6 +55,9 @@
 #define PMIC_SLAVE_ID                   0x20000
 #define BAT_IF_BAT_PRES_STATUS		0x1208
 
+#if VERIFIED_BOOT
+static int vb_version = INVALID;
+#endif
 /*
  * default implementations of these routines, if the target code
  * chooses not to implement.
@@ -281,6 +289,24 @@
 	return ret;
 }
 
+#if VERIFIED_BOOT
+int target_get_vb_version()
+{
+	if (vb_version == INVALID)
+	{
+		/* check vb version on first time. */
+		/* Incase of keymaster present, its VB2.0 */
+		if (partition_get_index("keymaster") != INVALID_PTN)
+			vb_version = VB_V2;
+		else
+		/* Incase keymaster is not present,
+		we use keystore for verification. */
+			vb_version = VB_V1;
+	}
+	return vb_version;
+}
+#endif
+
 #if VERIFIED_BOOT_LE
 int verified_boot_le = 1;
 #else