Various minor changes on optee examples

Prefix test applications for the examples with 'optee_example_'.
Gitignore the generate test applications.
Few extra minor changes as make verbosity and source coding style.
STR_TRACE_USER_TA is deprecated.
Update README.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
diff --git a/.gitignore b/.gitignore
index 6b4c411..560f78b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@
 *.ta
 cscope.*
 out/
+hello_world/host/optee_example_hello_world
+random/host/optee_example_random
diff --git a/Makefile b/Makefile
index 4d29a41..9fb6b46 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,9 @@
-export V?=0
+export V ?= 0
 
 OUTPUT_DIR := $(CURDIR)/out
-EXAMPLE_LIST := hello_world random
+
+EXAMPLE_LIST := hello_world
+EXAMPLE_LIST += random
 
 .PHONY: all
 all: examples prepare-for-rootfs
@@ -10,27 +12,28 @@
 clean: examples-clean prepare-for-rootfs-clean
 
 examples:
-	for example in $(EXAMPLE_LIST); do \
+	@for example in $(EXAMPLE_LIST); do \
 		$(MAKE) -C $$example CROSS_COMPILE="$(HOST_CROSS_COMPILE)"; \
 	done
 
 examples-clean:
-	for example in $(EXAMPLE_LIST); do \
+	@for example in $(EXAMPLE_LIST); do \
 		$(MAKE) -C $$example clean; \
 	done
 
 prepare-for-rootfs: examples
-	echo "Copying example CA and TA binaries to $(OUTPUT_DIR)..."
+	@echo "Copying example CA and TA binaries to $(OUTPUT_DIR)..."
 	@mkdir -p $(OUTPUT_DIR)
 	@mkdir -p $(OUTPUT_DIR)/ta
 	@mkdir -p $(OUTPUT_DIR)/ca
 	@for example in $(EXAMPLE_LIST); do \
-		if [ -e $$example/host/optee_$$example ]; then \
-			cp -p $$example/host/optee_$$example $(OUTPUT_DIR)/ca/; \
+		if [ -e $$example/host/optee_example_$$example ]; then \
+			cp -p $$example/host/optee_example_$$example $(OUTPUT_DIR)/ca/; \
 		fi; \
 		cp -pr $$example/ta/*.ta $(OUTPUT_DIR)/ta/; \
 	done
 
 prepare-for-rootfs-clean:
-	rm -rf $(OUTPUT_DIR)/ta/*
-	rm -rf $(OUTPUT_DIR)/ca/*
+	@rm -rf $(OUTPUT_DIR)/ta
+	@rm -rf $(OUTPUT_DIR)/ca
+	@rmdir --ignore-fail-on-non-empty $(OUTPUT_DIR) || test ! -e $(OUTPUT_DIR)
diff --git a/README.md b/README.md
index 15b29b5..7d83de1 100644
--- a/README.md
+++ b/README.md
@@ -8,8 +8,19 @@
 This document describes the sample applications that are included in the OP-TEE,
 that aim to showcase specific functionality and use case.
 
+For sake of simplicity, all OP-TEE example test application are prefixed with
+`optee_example_`.
+
 ---
 ## 2. List of sample applications
-* **hello_world**: use Trusted Application for incrementing an integer value
-* **random**: generate random UUID using capabilities of TEE API
-(`TEE_GenerateRandom()`)
+
+Directory **hello_world/**:
+* A very simple Trusted Application to answer a hello command and incrementing
+an integer value.
+* Test application: `optee_example_hello_world`
+* Trusted application UUID: 8aaaf200-2450-11e4-abe2-0002a5d5c51b
+
+Directory **random/**:
+* Generates a random UUID using capabilities of TEE API (`TEE_GenerateRandom()`).
+* Test application: `optee_example_random`
+* Trusted application UUID: b6c53aba-9669-4668-a7f2-205629d00f86
diff --git a/hello_world/Android.mk b/hello_world/Android.mk
index 5c019b3..ff7e7c1 100644
--- a/hello_world/Android.mk
+++ b/hello_world/Android.mk
@@ -13,7 +13,7 @@
 		$(OPTEE_CLIENT_EXPORT)/include \
 
 LOCAL_SHARED_LIBRARIES := libteec
-LOCAL_MODULE := tee_example_helloworld
+LOCAL_MODULE := optee_example_hello_world
 LOCAL_MODULE_TAGS := optional
 include $(BUILD_EXECUTABLE)
 
diff --git a/hello_world/host/Makefile b/hello_world/host/Makefile
index 17f14fe..a4099ef 100644
--- a/hello_world/host/Makefile
+++ b/hello_world/host/Makefile
@@ -12,7 +12,7 @@
 #Add/link other required libraries here
 LDADD += -lteec -L$(TEEC_EXPORT)/lib
 
-BINARY = optee_hello_world
+BINARY = optee_example_hello_world
 
 .PHONY: all
 all: $(BINARY)
diff --git a/hello_world/ta/hello_world_ta.c b/hello_world/ta/hello_world_ta.c
index 4aeacca..2423b30 100644
--- a/hello_world/ta/hello_world_ta.c
+++ b/hello_world/ta/hello_world_ta.c
@@ -25,12 +25,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#define STR_TRACE_USER_TA "HELLO_WORLD"
-
 #include <tee_internal_api.h>
 #include <tee_internal_api_extensions.h>
 
-#include "hello_world_ta.h"
+#include <hello_world_ta.h>
 
 /*
  * Called when the instance of the TA is created. This is the first call in
diff --git a/hello_world/ta/include/hello_world_ta.h b/hello_world/ta/include/hello_world_ta.h
index a25d0a4..8e40276 100644
--- a/hello_world/ta/include/hello_world_ta.h
+++ b/hello_world/ta/include/hello_world_ta.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Linaro Limited
+ * Copyright (c) 2016-2017, Linaro Limited
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,13 +27,17 @@
 #ifndef TA_HELLO_WORLD_H
 #define TA_HELLO_WORLD_H
 
-/* This UUID is generated with uuidgen
-   the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html */
-#define TA_HELLO_WORLD_UUID { 0x8aaaf200, 0x2450, 0x11e4, \
+
+/*
+ * This UUID is generated with uuidgen
+ * the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html
+ */
+#define TA_HELLO_WORLD_UUID \
+	{ 0x8aaaf200, 0x2450, 0x11e4, \
 		{ 0xab, 0xe2, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b} }
 
-/* The Trusted Application Function ID(s) implemented in this TA */
-#define TA_HELLO_WORLD_CMD_INC_VALUE	0
-#define TA_HELLO_WORLD_CMD_DEC_VALUE	1
+/* The function IDs implemented in this TA */
+#define TA_HELLO_WORLD_CMD_INC_VALUE		0
+#define TA_HELLO_WORLD_CMD_DEC_VALUE		1
 
 #endif /*TA_HELLO_WORLD_H*/
diff --git a/hello_world/ta/sub.mk b/hello_world/ta/sub.mk
index db2413c..957af07 100644
--- a/hello_world/ta/sub.mk
+++ b/hello_world/ta/sub.mk
@@ -1,5 +1,4 @@
 global-incdirs-y += include
-#global-incdirs-y += ../host/include
 srcs-y += hello_world_ta.c
 
 # To remove a certain compiler flag, add a line like this
diff --git a/hello_world/ta/user_ta_header_defines.h b/hello_world/ta/user_ta_header_defines.h
index 016c402..fdfa6c4 100644
--- a/hello_world/ta/user_ta_header_defines.h
+++ b/hello_world/ta/user_ta_header_defines.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Linaro Limited
+ * Copyright (c) 2016-2017, Linaro Limited
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,17 +32,27 @@
 #ifndef USER_TA_HEADER_DEFINES_H
 #define USER_TA_HEADER_DEFINES_H
 
-#include <hello_world_ta.h> /* To get the TA_HELLO_WORLD_UUID define */
+/* To get the TA UUID definition */
+#include <hello_world_ta.h>
 
-#define TA_UUID 				TA_HELLO_WORLD_UUID
+#define TA_UUID				TA_HELLO_WORLD_UUID
 
-#define TA_FLAGS				TA_FLAG_EXEC_DDR
+/*
+ * TA properties: multi-instance TA, no specific attribute
+ * TA_FLAG_EXEC_DDR is meaningless but mandated.
+ */
+#define TA_FLAGS			TA_FLAG_EXEC_DDR
+
+/* Provisioned stack size */
 #define TA_STACK_SIZE			(2 * 1024)
+
+/* Provisioned heap size for TEE_Malloc() and friends */
 #define TA_DATA_SIZE			(32 * 1024)
 
+/* Extra properties (give a version id and a string name) */
 #define TA_CURRENT_TA_EXT_PROPERTIES \
     { "gp.ta.description", USER_TA_PROP_TYPE_STRING, \
-        "Hello World TA" }, \
+        "Example of OP-TEE Hello World Trusted Application" }, \
     { "gp.ta.version", USER_TA_PROP_TYPE_U32, &(const uint32_t){ 0x0010 } }
 
-#endif /*USER_TA_HEADER_DEFINES_H*/
+#endif /* USER_TA_HEADER_DEFINES_H */
diff --git a/random/Android.mk b/random/Android.mk
index f17b621..5221265 100644
--- a/random/Android.mk
+++ b/random/Android.mk
@@ -10,10 +10,10 @@
 LOCAL_SRC_FILES += host/main.c
 
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/ta/include \
-		$(OPTEE_CLIENT_EXPORT)/include \
+		    $(OPTEE_CLIENT_EXPORT)/include
 
 LOCAL_SHARED_LIBRARIES := libteec
-LOCAL_MODULE := tee_example_random
+LOCAL_MODULE := optee_example_random
 LOCAL_MODULE_TAGS := optional
 include $(BUILD_EXECUTABLE)
 
diff --git a/random/Makefile b/random/Makefile
index ee4f5d8..3b9a8dc 100644
--- a/random/Makefile
+++ b/random/Makefile
@@ -1,4 +1,4 @@
-export V?=0
+export V ?= 0
 
 # If _HOST or _TA specific compilers are not specified, then use CROSS_COMPILE
 HOST_CROSS_COMPILE ?= $(CROSS_COMPILE)
diff --git a/random/host/Makefile b/random/host/Makefile
index fcd05f2..8d063ae 100644
--- a/random/host/Makefile
+++ b/random/host/Makefile
@@ -8,11 +8,11 @@
 
 OBJS = main.o
 
-CFLAGS += -Wall -I../ta/include -I$(TEEC_EXPORT)/include -I./include
-#Add/link other required libraries here
+CFLAGS += -Wall -I../ta/include -I./include
+CFLAGS += -I$(TEEC_EXPORT)/include
 LDADD += -lteec -L$(TEEC_EXPORT)/lib
 
-BINARY = optee_random
+BINARY = optee_example_random
 
 .PHONY: all
 all: $(BINARY)
diff --git a/random/host/main.c b/random/host/main.c
index 5ad9de0..de857b9 100644
--- a/random/host/main.c
+++ b/random/host/main.c
@@ -33,7 +33,7 @@
 #include <tee_client_api.h>
 
 /* To the the UUID (found the the TA's h-file(s)) */
-#include <random_example_ta.h>
+#include <random_ta.h>
 
 int main(int argc, char *argv[])
 {
@@ -41,7 +41,7 @@
 	TEEC_Context ctx;
 	TEEC_Session sess;
 	TEEC_Operation op = { 0 };
-	TEEC_UUID uuid = TA_RANDOM_EXAMPLE_UUID;
+	TEEC_UUID uuid = TA_RANDOM_UUID;
 	uint8_t random_uuid[16] = { 0 };
 	uint32_t err_origin;
 
@@ -75,8 +75,8 @@
 	 * Prepare the argument. Pass a value in the first parameter,
 	 * the remaining three parameters are unused.
 	 */
-	op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE,
-					 TEEC_NONE, TEEC_NONE);
+	op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT,
+					 TEEC_NONE, TEEC_NONE, TEEC_NONE);
 	op.params[0].tmpref.buffer = random_uuid;
 	op.params[0].tmpref.size = sizeof(random_uuid);
 
@@ -85,8 +85,8 @@
 	 * called.
 	 */
 	printf("Invoking TA to generate random UUID... \n");
-	res = TEEC_InvokeCommand(&sess, TA_EXAMPLE_RANDOM_GENERATE, &op,
-				 &err_origin);
+	res = TEEC_InvokeCommand(&sess, TA_RANDOM_CMD_GENERATE,
+				 &op, &err_origin);
 	if (res != TEEC_SUCCESS)
 		errx(1, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x",
 			res, err_origin);
diff --git a/random/ta/include/random_example_ta.h b/random/ta/include/random_ta.h
similarity index 79%
rename from random/ta/include/random_example_ta.h
rename to random/ta/include/random_ta.h
index d40bb63..30eeead 100644
--- a/random/ta/include/random_example_ta.h
+++ b/random/ta/include/random_ta.h
@@ -24,15 +24,19 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#ifndef TA_RANDOM_EXAMPLE_H
-#define TA_RANDOM_EXAMPLE_H
 
-/* This UUID is generated with uuidgen
-   the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html */
-#define TA_RANDOM_EXAMPLE_UUID { 0xb6c53aba, 0x9669, 0x4668, \
+#ifndef __RANDOM_TA_H__
+#define __RANDOM_TA_H__
+
+/*
+ * This UUID is generated with uuidgen
+ * the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html
+ */
+#define TA_RANDOM_UUID \
+	{ 0xb6c53aba, 0x9669, 0x4668, \
 		{ 0xa7, 0xf2, 0x20, 0x56, 0x29, 0xd0, 0x0f, 0x86} }
 
-/* The Trusted Application Function ID(s) implemented in this TA */
-#define TA_EXAMPLE_RANDOM_GENERATE	0
+/* The function ID implemented in this TA */
+#define TA_RANDOM_CMD_GENERATE		0
 
-#endif /* TA_RANDOM_EXAMPLE_H */
+#endif /* __RANDOM_TA_H__ */
diff --git a/random/ta/random_example_ta.c b/random/ta/random_example_ta.c
index 8f7506a..ef4696a 100644
--- a/random/ta/random_example_ta.c
+++ b/random/ta/random_example_ta.c
@@ -25,12 +25,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#define STR_TRACE_USER_TA "RANDOM_EXAMPLE_TA"
-
 #include <tee_internal_api.h>
 #include <tee_internal_api_extensions.h>
 
-#include "random_example_ta.h"
+#include <random_ta.h>
 
 TEE_Result TA_CreateEntryPoint(void)
 {
@@ -66,9 +64,11 @@
 static TEE_Result random_number_generate(uint32_t param_types,
 	TEE_Param params[4])
 {
-	uint32_t exp_param_types = TEE_PARAM_TYPES
-					(TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE,
-					 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE);
+	uint32_t exp_param_types =
+				TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_OUTPUT,
+						TEE_PARAM_TYPE_NONE,
+						TEE_PARAM_TYPE_NONE,
+						TEE_PARAM_TYPE_NONE);
 
 	DMSG("has been called");
 	if (param_types != exp_param_types)
@@ -95,7 +95,7 @@
 	(void)&sess_ctx;
 
 	switch (cmd_id) {
-	case TA_EXAMPLE_RANDOM_GENERATE:
+	case TA_RANDOM_CMD_GENERATE:
 		return random_number_generate(param_types, params);
 	default:
 		return TEE_ERROR_BAD_PARAMETERS;
diff --git a/random/ta/user_ta_header_defines.h b/random/ta/user_ta_header_defines.h
index 07ee1ce..37dacc1 100644
--- a/random/ta/user_ta_header_defines.h
+++ b/random/ta/user_ta_header_defines.h
@@ -32,17 +32,27 @@
 #ifndef USER_TA_HEADER_DEFINES_H
 #define USER_TA_HEADER_DEFINES_H
 
-#include <random_example_ta.h> /* To get the TA_RANDOM_EXAMPLE_UUID define */
+ /* To get the TA_RANDOM_EXAMPLE_UUID define */
+#include <random_ta.h>
 
-#define TA_UUID TA_RANDOM_EXAMPLE_UUID
+#define TA_UUID				TA_RANDOM_UUID
 
-#define TA_FLAGS                    TA_FLAG_EXEC_DDR
-#define TA_STACK_SIZE               (2 * 1024)
-#define TA_DATA_SIZE                (32 * 1024)
+/*
+ * TA properties: multi-instance TA, no specific attribute
+ * TA_FLAG_EXEC_DDR is meaningless but mandated.
+ */
+#define TA_FLAGS			TA_FLAG_EXEC_DDR
 
+/* Provisioned stack size */
+#define TA_STACK_SIZE			(2 * 1024)
+
+/* Provisioned heap size for TEE_Malloc() and friends */
+#define TA_DATA_SIZE			(32 * 1024)
+
+/* Extra properties (give a version id and a string name) */
 #define TA_CURRENT_TA_EXT_PROPERTIES \
     { "gp.ta.description", USER_TA_PROP_TYPE_STRING, \
-      "Fill buffer with output from TEE_GenerateRandom" }, \
+      "Example of a TA that returns the output from TEE_GenerateRandom" }, \
     { "gp.ta.version", USER_TA_PROP_TYPE_U32, &(const uint32_t){ 0x0010 } }
 
-#endif /*USER_TA_HEADER_DEFINES_H*/
+#endif /* USER_TA_HEADER_DEFINES_H */