aes-perf, sha-perf: trace TEE error origin when applicable

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
diff --git a/host/xtest/sha_perf.c b/host/xtest/sha_perf.c
index bb40038..b6ba4df 100644
--- a/host/xtest/sha_perf.c
+++ b/host/xtest/sha_perf.c
@@ -54,16 +54,19 @@
 	.flags = TEEC_MEM_OUTPUT
 };
 
-static void errx(const char *msg, TEEC_Result res)
+static void errx(const char *msg, TEEC_Result res, uint32_t *orig)
 {
 	fprintf(stderr, "%s: 0x%08x", msg, res);
+	if (orig)
+		fprintf(stderr, " (orig=%d)", (int)*orig);
+	fprintf(stderr, "\n");
 	exit (1);
 }
 
-static void check_res(TEEC_Result res, const char *errmsg)
+static void check_res(TEEC_Result res, const char *errmsg, uint32_t *orig)
 {
 	if (res != TEEC_SUCCESS)
-		errx(errmsg, res);
+		errx(errmsg, res, orig);
 }
 
 static void open_ta(void)
@@ -73,11 +76,11 @@
 	uint32_t err_origin;
 
 	res = TEEC_InitializeContext(NULL, &ctx);
-	check_res(res,"TEEC_InitializeContext");
+	check_res(res,"TEEC_InitializeContext", NULL);
 
 	res = TEEC_OpenSession(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL,
 			       NULL, &err_origin);
-	check_res(res,"TEEC_OpenSession");
+	check_res(res,"TEEC_OpenSession", &err_origin);
 }
 
 /*
@@ -169,12 +172,12 @@
 	in_shm.buffer = NULL;
 	in_shm.size = sz + offset;
 	res = TEEC_AllocateSharedMemory(&ctx, &in_shm);
-	check_res(res, "TEEC_AllocateSharedMemory");
+	check_res(res, "TEEC_AllocateSharedMemory", NULL);
 
 	out_shm.buffer = NULL;
 	out_shm.size = hash_size(algo);
 	res = TEEC_AllocateSharedMemory(&ctx, &out_shm);
-	check_res(res, "TEEC_AllocateSharedMemory");
+	check_res(res, "TEEC_AllocateSharedMemory", NULL);
 }
 
 static void free_shm(void)
@@ -241,7 +244,7 @@
 	get_current_time(&t0);
 	res = TEEC_InvokeCommand(&sess, TA_SHA_PERF_CMD_PROCESS, op,
 				 &ret_origin);
-	check_res(res, "TEEC_InvokeCommand");
+	check_res(res, "TEEC_InvokeCommand", &ret_origin);
 	get_current_time(&t1);
 
 	return timespec_diff_ns(&t0, &t1);
@@ -259,7 +262,7 @@
 	op.params[0].value.a = algo;
 	res = TEEC_InvokeCommand(&sess, TA_SHA_PERF_CMD_PREPARE_OP, &op,
 				 &ret_origin);
-	check_res(res, "TEEC_InvokeCommand");
+	check_res(res, "TEEC_InvokeCommand", &ret_origin);
 }
 
 static void do_warmup(int warmup)