Add NXP's i.MX8 SoCs build info SIP(silicon provider) service support

This patch adds NXP i.MX8QM/i.MX8QXP's build info SIP support to
easy debug. With this function enabled, each SW components' commit
hash will be showed in debug console when booting up.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
diff --git a/plat/imx/common/imx8_sip_svc.c b/plat/imx/common/imx8_sip_svc.c
index 874a060..6dd59a1 100644
--- a/plat/imx/common/imx8_sip_svc.c
+++ b/plat/imx/common/imx8_sip_svc.c
@@ -41,6 +41,9 @@
 	case  IMX_SIP_SRTC:
 		return imx_srtc_handler(smc_fid, handle, x1, x2, x3, x4);
 #endif
+	case  IMX_SIP_BUILDINFO:
+		SMC_RET1(handle, imx_buildinfo_handler(smc_fid, x1, x2, x3, x4));
+		break;
 	default:
 		WARN("Unimplemented SIP Service Call: 0x%x \n", smc_fid);
 		SMC_RET1(handle, SMC_UNK);
diff --git a/plat/imx/common/include/imx_sip.h b/plat/imx/common/include/imx_sip.h
index d211fcb..4e1c8e9 100644
--- a/plat/imx/common/include/imx_sip.h
+++ b/plat/imx/common/include/imx_sip.h
@@ -20,11 +20,17 @@
 #define IMX_SIP_SRTC_GET_WDOG_STAT	0x06
 #define IMX_SIP_SRTC_SET_PRETIME_WDOG	0x07
 
+#define IMX_SIP_BUILDINFO			0xC2000003
+#define IMX_SIP_BUILDINFO_GET_COMMITHASH	0x00
+
 #if defined(PLAT_IMX8QM) || defined(PLAT_IMX8QX)
 int imx_cpufreq_handler(uint32_t smc_fid, u_register_t x1,
 			u_register_t x2, u_register_t x3);
 int imx_srtc_handler(uint32_t smc_fid, void *handle, u_register_t x1,
 	u_register_t x2, u_register_t x3, u_register_t x4);
 #endif
+uint64_t imx_buildinfo_handler(uint32_t smc_fid, u_register_t x1,
+				u_register_t x2, u_register_t x3,
+				u_register_t x4);
 
 #endif
diff --git a/plat/imx/common/misc.c b/plat/imx/common/misc.c
new file mode 100644
index 0000000..1c3afaa
--- /dev/null
+++ b/plat/imx/common/misc.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017 NXP
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <debug.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <std_svc.h>
+#include <stdbool.h>
+#include <string.h>
+#include <uuid.h>
+#include <bl_common.h>
+#include <platform_def.h>
+#include <sci/sci.h>
+#include <runtime_svc.h>
+#include <imx_sip.h>
+
+static uint64_t imx_get_commit_hash(u_register_t x2,
+		    u_register_t x3,
+		    u_register_t x4)
+{
+	/* Parse the version_string */
+	char* parse = (char*)version_string;
+	uint64_t hash = 0;
+
+	do {
+		parse = strchr(parse, '-');
+		if (parse) {
+			parse += 1;
+			if (*(parse) == 'g') {
+				/* Default is 7 hexadecimal digits */
+				memcpy((void *)&hash, (void *)(parse + 1), 7);
+				break;
+			}
+		}
+
+	} while (parse != NULL);
+
+	return hash;
+}
+
+uint64_t imx_buildinfo_handler(uint32_t smc_fid,
+		    u_register_t x1,
+		    u_register_t x2,
+		    u_register_t x3,
+		    u_register_t x4)
+{
+	uint64_t ret;
+
+	switch(x1) {
+	case IMX_SIP_BUILDINFO_GET_COMMITHASH:
+		ret = imx_get_commit_hash(x2, x3, x4);
+		break;
+	default:
+		return SMC_UNK;
+	}
+
+	return ret;
+}
diff --git a/plat/imx/imx8qm/platform.mk b/plat/imx/imx8qm/platform.mk
index ec3a403..564f258 100644
--- a/plat/imx/imx8qm/platform.mk
+++ b/plat/imx/imx8qm/platform.mk
@@ -24,6 +24,7 @@
 				plat/imx/common/imx8_psci.c		\
 				plat/imx/common/cpufreq.c		\
 				plat/imx/common/srtc.c			\
+				plat/imx/common/misc.c			\
 				plat/imx/common/imx8_sip_svc.c		\
 				lib/xlat_tables/aarch64/xlat_tables.c		\
 				lib/xlat_tables/xlat_tables_common.c		\
diff --git a/plat/imx/imx8qx/platform.mk b/plat/imx/imx8qx/platform.mk
index baff1ae..d9f0c51 100644
--- a/plat/imx/imx8qx/platform.mk
+++ b/plat/imx/imx8qx/platform.mk
@@ -23,6 +23,7 @@
 				plat/imx/common/imx8_psci.c		\
 				plat/imx/common/cpufreq.c		\
 				plat/imx/common/srtc.c			\
+				plat/imx/common/misc.c			\
 				plat/imx/common/imx8_sip_svc.c		\
 				plat/common/plat_psci_common.c		\
 				lib/xlat_tables/xlat_tables_common.c	\