xref: /OK3568_Linux_fs/external/security/rk_tee_user/v1/host/rk_test/main.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2021 Rockchip Electronics Co. Ltd.
4  */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <strings.h>
8 #include <rktest.h>
9 
10 /*
11  * You can enable or disable the OTP test functions here.
12  * BE CAUTION:
13  * OTP means One Time Programmable Memory.
14  * You can read OTP memory many times, but you can only write it once.
15  * The "otp_write" program will try to write one byte to OTP memory (offset 0).
16  */
17 #ifndef OTP_TEST
18 #define OTP_TEST DISABLE
19 #endif
20 
21 
22 static const struct{
23 	const char *word;
24 	enum_func main_cmd;
25 } keyword[] = {
26 	{"transfer_data",		TRANSFER_DATA},
27 	{"storage",			STORAGE},
28 	{"storage_speed",		STORAGE_SPEED},
29 	{"property",			PROPERTY},
30 	{"crypto_sha",			CRYPTO_SHA},
31 	{"crypto_aes",			CRYPTO_AES},
32 	{"crypto_rsa",			CRYPTO_RSA},
33 #if (OTP_TEST == ENABLE)
34 	{"otp_read",			OTP_READ},
35 	{"otp_write",			OTP_WRITE},
36 	{"otp_size",			OTP_SIZE},
37 #endif
38 	{"trng",			TRNG_READ},
39 	{NULL,				TEST_NULL},
40 };
41 
42 
printf_main_cmd(void)43 static void printf_main_cmd(void)
44 {
45 	printf("Please entry one correct parameter when excuting the app!\n");
46 	printf("The correct parameters list:\n");
47 	for (int i = 0; keyword[i].word; i++)
48 		printf("	%s\n", keyword[i].word);
49 }
50 
config_main_cmd(const char * cp)51 static enum_func config_main_cmd(const char *cp)
52 {
53 	for (int i = 0; keyword[i].word; i++)
54 		if (strcasecmp(cp, keyword[i].word) == 0)
55 			return keyword[i].main_cmd;
56 
57 	printf_main_cmd();
58 	return TEST_NULL;
59 }
60 
main(int argc,char * argv[])61 int main(int argc, char *argv[])
62 {
63 	uint32_t invokeCommand = TEST_NULL;
64 
65 	if (argc != 2) {
66 		printf_main_cmd();
67 		return 0;
68 	}
69 
70 	invokeCommand = config_main_cmd(argv[1]);
71 	return rk_test(invokeCommand);
72 }
73 
74