aarch32: optee: define the OP-TEE secure payload

AArch32 only platforms can boot the OP-TEE secure firmware as
a BL32 secure payload. Such configuration can be defined through
AARCH32_SP=optee.

The source files can rely on AARCH32_SP_OPTEE to condition
OP-TEE boot specific instruction sequences.

OP-TEE does not expect ARM Trusted Firmware formatted structure
as boot argument. Load sequence is expected to have already loaded
to OP-TEE boot arguments into the bl32 entrypoint info structure.

Last, AArch32 platform can only boot AArch32 OP-TEE images.

Change-Id: Ic28eec5004315fc9111051add6bb1a1d607fc815
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
diff --git a/lib/optee/optee_utils.c b/lib/optee/optee_utils.c
index deb948c..87e52bd 100644
--- a/lib/optee/optee_utils.c
+++ b/lib/optee/optee_utils.c
@@ -158,9 +158,12 @@
 	 *	and BL32_EXTRA2_IMAGE_ID to load pager and paged bin.
 	 */
 	if (!tee_validate_header(optee_header)) {
-		INFO("Invalid OPTEE header, legacy mode.\n");
-		/* Set legacy OPTEE runtime arch - aarch64 */
+		INFO("Invalid OPTEE header, set legacy mode.\n");
+#ifdef AARCH64
 		header_ep->args.arg0 = MODE_RW_64;
+#else
+		header_ep->args.arg0 = MODE_RW_32;
+#endif
 		return 0;
 	}
 
@@ -208,10 +211,16 @@
 	header_ep->args.arg2 = paged_image_info->image_size;
 
 	/* Set OPTEE runtime arch - aarch32/aarch64 */
-	if (optee_header->arch == 0)
+	if (optee_header->arch == 0) {
 		header_ep->args.arg0 = MODE_RW_32;
-	else
+	} else {
+#ifdef AARCH64
 		header_ep->args.arg0 = MODE_RW_64;
+#else
+		ERROR("Cannot boot an AArch64 OP-TEE\n");
+		return -1;
+#endif
+	}
 
 	return 0;
 }