1 //#include <nuttx/config.h>
2 #include <stdio.h>
3 //#include "MsTypes.h"
4 //#include "stdlib.h"
5 #include "utopia.h" // for utopia open/ioctl/close
6 #include "utopia_driver_id.h" // for module id
7 #include "MsOS.h" // for MsOS_ObtainMutex test
8 //#include "drvMMIO.h"
9 //#include <string.h>
10 //#include <unistd.h>
11 //#include "drvMIU.h"
12
13 #include "drvSYS.h"
14 #include "drvSYS_priv.h"
15
16 static const char optee_test[] = "opteearmtz00";
17 char *_device = (char *)optee_test;
18
19
20 TEEC_Context mstar_teec_ctx;
21 /* This UUID is generated with the ITU-T UUID generator at
22 http://www.itu.int/ITU-T/asn1/uuid.html
23 7cac5480-a1fb-11e5-acb4-0002a5d5c51b */
24 #define MSTAR_INTERNAL_TEST_UUID {0x7cac5480, 0xa1fb, 0x11e5, \
25 {0xac, 0xb4, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b} }
26 #define SYS_TEEC_OPERATION_INITIALIZER { 0, 0, { { { 0 } } } }
27 #define CMD_TRACE 0
28 #define CMD_PARAMS 1
29 #define CMD_SELF_TESTS 2
30 #define CMD_PRINT 3
31 #define CMD_MULTIPLY_VALUE 4
32 #define CMD_MEMORY_WRITE 5
33 #define CMD_MEMORY_READ 6
34
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37 unsigned int ret, ret_orig= 0;
38 TEEC_Session session = { 0 };
39 TEEC_UUID uuid = MSTAR_INTERNAL_TEST_UUID;
40 TEEC_Operation op = SYS_TEEC_OPERATION_INITIALIZER;
41 int cmd = 0;
42 uint8_t buf[32];
43
44 if (argc < 2) {
45 printf("./verify 0 or ./verify [0..5]\n");
46 goto end_test;
47 }
48
49 cmd = atoi(argv[1]);
50 printf("cmd:%d\n",cmd);
51
52
53 switch (cmd)
54 {
55 case CMD_TRACE:
56 case CMD_PARAMS:
57 case CMD_SELF_TESTS:
58 case CMD_PRINT:
59 if (ret = MDrv_SYS_TEEC_InitializeContext(_device, &mstar_teec_ctx)) {
60 printf("%s %d: Init Context failed\n",__func__,__LINE__);
61 goto end_test;
62 }
63
64 if (ret = MDrv_SYS_TEEC_Open(&mstar_teec_ctx, &session, &uuid, TEEC_LOGIN_PUBLIC, NULL, &op, &ret_orig)) {
65 printf("%s %d: TEEC Open session failed\n",__func__,__LINE__);
66 goto end_test;
67 }
68 if (ret = MDrv_SYS_TEEC_InvokeCmd(&session, cmd, &op, &ret_orig)) {
69 printf("%s %d: TEEC Invoke command failed\n",__func__,__LINE__);
70 goto end_test1;
71 }
72 break;
73 case CMD_MULTIPLY_VALUE:
74 if (argc < 4) {
75 printf("./verify 4 num1 num2\n");
76 printf("num1 is a numeric\n");
77 printf("num2 is a numeric\n");
78 goto end_test;
79 }
80 if (ret = MDrv_SYS_TEEC_InitializeContext(_device, &mstar_teec_ctx)) {
81 printf("%s %d: Init Context failed\n",__func__,__LINE__);
82 goto end_test;
83 }
84
85 if (ret = MDrv_SYS_TEEC_Open(&mstar_teec_ctx, &session, &uuid, TEEC_LOGIN_PUBLIC, NULL, &op, &ret_orig)) {
86 printf("%s %d: TEEC Open session failed\n",__func__,__LINE__);
87 goto end_test;
88 }
89
90 op.params[0].value.a = atoi(argv[2]);
91 op.params[0].value.b = atoi(argv[3]);
92 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_OUTPUT,
93 TEEC_NONE, TEEC_NONE);
94
95 if (ret = MDrv_SYS_TEEC_InvokeCmd(&session, CMD_MULTIPLY_VALUE, &op, &ret_orig)) {
96 printf("%s %d: TEEC Invoke command failed\n",__func__,__LINE__);
97 goto end_test1;
98 }
99 printf("%d * %d = %d\n",op.params[0].value.a, op.params[0].value.b, op.params[1].value.a);
100 break;
101 case CMD_MEMORY_WRITE:
102 case CMD_MEMORY_READ:
103 {
104 static uint8_t test_input[3] = {0x5A, 0xA5, 0x5A};
105 static uint8_t test_out[3] = {0xBB, 0xCC, 0xDD};
106 printf("test_input:%x, %x, %x, test_out:%x, %x, %x\n",test_input[0], test_input[1], test_input[2], test_out[0], test_out[1], test_out[2]);
107 if (ret = MDrv_SYS_TEEC_InitializeContext(_device, &mstar_teec_ctx)) {
108 printf("%s %d: Init Context failed\n",__func__,__LINE__);
109 goto end_test;
110 }
111
112 if (ret = MDrv_SYS_TEEC_Open(&mstar_teec_ctx, &session, &uuid, TEEC_LOGIN_PUBLIC, NULL, &op, &ret_orig)) {
113 printf("%s %d: TEEC Open session failed\n",__func__,__LINE__);
114 goto end_test;
115 }
116 op.params[0].tmpref.buffer = test_input;
117 op.params[0].tmpref.size = sizeof(test_input);
118 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
119 TEEC_NONE, TEEC_NONE);
120 if (ret = MDrv_SYS_TEEC_InvokeCmd(&session, CMD_MEMORY_WRITE, &op, &ret_orig)) {
121 printf("%s %d: TEEC Invoke command failed\n",__func__,__LINE__);
122 goto end_test1;
123 }
124
125 op.params[0].tmpref.buffer = test_out;
126 op.params[0].tmpref.size = sizeof(test_out);
127 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE,
128 TEEC_NONE, TEEC_NONE);
129 if (ret = MDrv_SYS_TEEC_InvokeCmd(&session, CMD_MEMORY_READ, &op, &ret_orig)) {
130 printf("%s %d: TEEC Invoke command failed\n",__func__,__LINE__);
131 goto end_test1;
132 }
133 printf("test_input:%x, %x, %x, test_out:%x, %x, %x\n",test_input[0], test_input[1], test_input[2], test_out[0], test_out[1], test_out[2]);
134 }
135 break;
136 }
137
138 end_test1:
139 MDrv_SYS_TEEC_Close(&session);
140 end_test:
141 printf("%s %d:ret:%u\n",__func__,__LINE__,ret);
142 return 0;
143 }
144