Keymaster: Support for 64bit userspace and 32bit TZ

HW keymaster is not supported for 64bit userspace. This patch
updates variable types to support the architecture.
It also makes change in Android.mk file to support all qcom
platforms.

Change-Id: I25633d707b425388bcc116196c0e0022c5c4f9a5

keymaster: Fix build for devices that don't define BOARD_USES_QCOM_HARDWARE

Change-Id: Ia80c28920ac8d8fd0ce3ac703977dc8a5a0651ce

keymaster: Allow 8952 to build

Change-Id: I9c2d5a0e4fc584f7909e0733827d5499191d82a3

keymaster: add msm8909 into support list

Issue-Id: FEIJ-8

Issue: FP2P-383
Change-Id: I1252ec5f1171ca94635e6f58d835a588948be771
(cherry picked from commit 849014b6cdb7e0b8a89abb1634dd74c6e479a2f0)
diff --git a/keymaster_qcom.cpp b/keymaster_qcom.cpp
index e779cbc..4219317 100644
--- a/keymaster_qcom.cpp
+++ b/keymaster_qcom.cpp
@@ -51,6 +51,9 @@
 //#define LOG_NDEBUG 0
 
 #define LOG_TAG "QCOMKeyMaster"
+#define UNUSED(x) (void)(x)
+#define KM_SB_LENGTH (4096 * 2)
+
 #include <cutils/log.h>
 struct qcom_km_ion_info_t {
     int32_t ion_fd;
@@ -63,8 +66,8 @@
 struct qcom_keymaster_handle {
     struct QSEECom_handle *qseecom;
     void *libhandle;
-    int (*QSEECom_start_app)(struct QSEECom_handle ** handle, char* path,
-                          char* appname, uint32_t size);
+    int (*QSEECom_start_app)(struct QSEECom_handle ** handle, const char* path,
+                          const char* appname, uint32_t size);
     int (*QSEECom_shutdown_app)(struct QSEECom_handle **handle);
     int (*QSEECom_send_cmd)(struct QSEECom_handle* handle, void *cbuf,
                           uint32_t clen, void *rbuf, uint32_t rlen);
@@ -105,6 +108,7 @@
 
     struct qcom_km_key_blob * keyblob_ptr = (struct qcom_km_key_blob *)keyBlob;
 
+    UNUSED(dev);
     if (x509_data == NULL || x509_data_length == NULL) {
         ALOGE("Output public key buffer == NULL");
         return -1;
@@ -236,7 +240,7 @@
        goto alloc_fail;
     }
 
-    if (ion_alloc_data.handle != NULL) {
+    if (ion_alloc_data.handle) {
        ifd_data.handle = ion_alloc_data.handle;
     } else {
        ret = -1;
@@ -403,7 +407,7 @@
     int ret = 0;
 
     ihandle.ion_fd = 0;
-    ihandle.ion_alloc_handle.handle = NULL;
+    ihandle.ion_alloc_handle.handle = 0;
     if (qcom_km_ION_memalloc(&ihandle, QSEECOM_ALIGN(key_length)) < 0) {
         ALOGE("ION allocation  failed");
         return -1;
@@ -425,7 +429,7 @@
     resp = (keymaster_import_keypair_resp_t *)(handle->ion_sbuffer +
                                         QSEECOM_ALIGN(sizeof(keymaster_import_keypair_cmd_t)));
     send_cmd->cmd_id = KEYMASTER_IMPORT_KEYPAIR;
-    send_cmd->pkcs8_key = (uint32_t)ihandle.ion_sbuffer;
+    send_cmd->pkcs8_key = (uint32_t)(uintptr_t)ihandle.ion_sbuffer;
 
     memcpy((unsigned char *)ihandle.ion_sbuffer, key, key_length);
 
@@ -506,7 +510,7 @@
 
     handle = (struct QSEECom_handle *)(km_handle->qseecom);
     ihandle.ion_fd = 0;
-    ihandle.ion_alloc_handle.handle = NULL;
+    ihandle.ion_alloc_handle.handle = 0;
     if (qcom_km_ION_memalloc(&ihandle, dataLength) < 0) {
         ALOGE("ION allocation  failed");
         return -1;
@@ -527,7 +531,7 @@
     memcpy((unsigned char *)(&send_cmd->key_blob), keyBlob, keyBlobLength);
     memcpy((unsigned char *)ihandle.ion_sbuffer, data, dataLength);
 
-    send_cmd->data = (uint32_t)ihandle.ion_sbuffer;
+    send_cmd->data = (uint32_t)(uintptr_t)ihandle.ion_sbuffer;
     send_cmd->dlen = dataLength;
     resp->sig_len = KM_KEY_SIZE_MAX;
     resp->status = KEYMASTER_FAILURE;
@@ -606,7 +610,7 @@
 
     handle = (struct QSEECom_handle *)(km_handle->qseecom);
     ihandle.ion_fd = 0;
-    ihandle.ion_alloc_handle.handle = NULL;
+    ihandle.ion_alloc_handle.handle = 0;
     if (qcom_km_ION_memalloc(&ihandle, signedDataLength + signatureLength) <0) {
         ALOGE("ION allocation  failed");
         return -1;
@@ -626,7 +630,7 @@
     send_cmd->sign_param.padding_type = sign_params->padding_type;
     memcpy((unsigned char *)(&send_cmd->key_blob), keyBlob, keyBlobLength);
 
-    send_cmd->signed_data = (uint32_t)ihandle.ion_sbuffer;
+    send_cmd->signed_data = (uint32_t)(uintptr_t)ihandle.ion_sbuffer;
     send_cmd->signed_dlen = signedDataLength;
     memcpy((unsigned char *)ihandle.ion_sbuffer, signedData, signedDataLength);
 
@@ -757,7 +761,10 @@
     }
     dev->context = (void *)km_handle;
     ret = (*km_handle->QSEECom_start_app)((struct QSEECom_handle **)&km_handle->qseecom,
-                         "/vendor/firmware/keymaster", "keymaster", 4096*2);
+                        "/vendor/firmware/keymaster", "keymaster", KM_SB_LENGTH);
+    if(ret)
+        ret = (*km_handle->QSEECom_start_app)((struct QSEECom_handle **)&km_handle->qseecom,
+                        "/firmware/image", "keymaste", KM_SB_LENGTH);
     if (ret) {
         ALOGE("Loading keymaster app failed");
         free(km_handle);