1 /*
2 * K3CONF main entry file
3 *
4 * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
5 * Lokesh Vutla <lokeshvutla@ti.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
17 * distribution.
18 *
19 * Neither the name of Texas Instruments Incorporated nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
36 #include <ctype.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <sec_proxy.h>
41 #include <tisci.h>
42 #include <version.h>
43 #include <socinfo.h>
44 #include <help.h>
45 #include <string.h>
46 #include <autoadjust_table.h>
47 #include <k3conf.h>
49 #ifdef DEBUG
50 #define dprintf(format, ...) printf(format, ## __VA_ARGS__)
51 #else
52 #define dprintf(format, ...)
53 #endif
55 void k3conf_print_version(FILE *stream)
56 {
57 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
58 struct ti_sci_version_info ver = soc_info.sci_info.version;
59 uint32_t row = 0;
61 if (stream == NULL) {
62 fprintf(stderr, "%s(): stream == NULL!!!\n", __func__);
63 return;
64 }
66 autoadjust_table_init(table);
67 strncpy(table[row][0], "VERSION INFO", TABLE_MAX_ELT_LEN);
68 row++;
69 strncpy(table[row][0], "K3CONF", TABLE_MAX_ELT_LEN);
70 snprintf(table[row][1], TABLE_MAX_ELT_LEN, "(version %s built %s)", k3conf_version, builddate);
71 row++;
72 strncpy(table[row][0], "SoC", TABLE_MAX_ELT_LEN);
73 strncpy(table[row][1], soc_info.soc_full_name, TABLE_MAX_ELT_LEN);
74 row++;
76 if (soc_info.ti_sci_enabled) {
77 strncpy(table[row][0], "SYSFW", TABLE_MAX_ELT_LEN);
78 snprintf(table[row][1], TABLE_MAX_ELT_LEN,
79 "ABI: %d.%d (firmware version 0x%04x '%.*s)')",
80 ver.abi_major, ver.abi_minor, ver.firmware_version,
81 (int)sizeof(ver.firmware_description),
82 ver.firmware_description);
83 row++;
84 }
86 autoadjust_table_generic_fprint(stream, table, row, 2, TABLE_HAS_TITLE);
88 return;
89 }
91 int main(int argc, char *argv[])
92 {
93 uint32_t host_id;
94 int ret = 0;
96 /* Scan user arguments for options */
97 argc--;
98 argv++;
100 if (argc == 0) {
101 help(HELP_USAGE);
102 ret = -1;
103 goto main_exit;
104 }
106 host_id = INVALID_HOST_ID;
107 if (!strcmp(argv[0], "--host")) {
108 argc--; argv++;
109 ret = sscanf(argv[0], "%u", &host_id);
110 if (ret != 1) {
111 fprintf(stderr, "Invalid host id %s\n", argv[0]);
112 return -1;
113 }
114 dprintf("%s: host_id from user = %d\n", __func__,
115 soc_info.host_id);
116 argc--; argv++;
117 }
119 if (soc_init(host_id))
120 goto main_exit;
122 if (!strcmp(argv[0], "--help")) {
123 k3conf_print_version(stdout);
124 help(HELP_ALL);
125 goto main_exit;
126 } else if (!strcmp(argv[0], "--version")) {
127 k3conf_print_version(stdout);
128 goto main_exit;
129 } else if (!strcmp(argv[0], "--cpuinfo")) {
130 k3conf_print_version(stdout);
131 dump_cpu_info();
132 goto main_exit;
133 } else if (!strcmp(argv[0], "show")) {
134 argc--;
135 argv++;
136 k3conf_print_version(stdout);
137 return process_show_command(argc, argv);
138 } else if (!strcmp(argv[0], "dump")) {
139 argc--;
140 argv++;
141 k3conf_print_version(stdout);
142 return process_dump_command(argc, argv);
143 } else if (!strcmp(argv[0], "enable")) {
144 argc--;
145 argv++;
146 k3conf_print_version(stdout);
147 return process_enable_command(argc, argv);
148 } else if (!strcmp(argv[0], "disable")) {
149 argc--;
150 argv++;
151 k3conf_print_version(stdout);
152 return process_disable_command(argc, argv);
153 } else if (!strcmp(argv[0], "set")) {
154 argc--;
155 argv++;
156 k3conf_print_version(stdout);
157 return process_set_command(argc, argv);
158 } else if (!strcmp(argv[0], "read")) {
159 argc--;
160 argv++;
161 k3conf_print_version(stdout);
162 return process_read_command(argc, argv);
163 } else if (!strcmp(argv[0], "write")) {
164 argc--;
165 argv++;
166 k3conf_print_version(stdout);
167 return process_write_command(argc, argv);
168 } else {
169 fprintf(stderr, "Invalid argument %s", argv[0]);
170 help(HELP_USAGE);
171 ret = -1;
172 goto main_exit;
173 }
175 main_exit:
176 return ret;
177 }