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 {"secstor_ta", SECSTOR_TA},
34 #if (OTP_TEST == ENABLE)
35 {"otp_read", OTP_READ},
36 {"otp_write", OTP_WRITE},
37 {"otp_size", OTP_SIZE},
38 {"otp_ns_read", OTP_NS_READ},
39 {"otp_ns_write", OTP_NS_WRITE},
40 #endif
41 {"trng", TRNG_READ},
42 {"socket", SOCKET},
43 {"crypto_hw", CRYPTO_HW},
44 {"derive_key", DERIVE_KEY},
45 {NULL, TEST_NULL},
46 };
47
48
printf_main_cmd(void)49 static void printf_main_cmd(void)
50 {
51 printf("Please entry one correct parameter when excuting the app!\n");
52 printf("The correct parameters list:\n");
53 for (int i = 0; keyword[i].word; i++)
54 printf(" %s\n", keyword[i].word);
55 }
56
config_main_cmd(const char * cp)57 static enum_func config_main_cmd(const char *cp)
58 {
59 for (int i = 0; keyword[i].word; i++)
60 if (strcasecmp(cp, keyword[i].word) == 0)
61 return keyword[i].main_cmd;
62
63 printf_main_cmd();
64 return TEST_NULL;
65 }
66
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69 uint32_t invokeCommand = TEST_NULL;
70
71 if (argc != 2) {
72 printf_main_cmd();
73 return 0;
74 }
75
76 invokeCommand = config_main_cmd(argv[1]);
77 return rk_test(invokeCommand);
78 }
79
80