898c1c41cb021fd4d2fd131a251353f3d5d667db
1 /*
2 * K3CONF main entry file
3 *
4 * Copyright (C) 2019 Texas Instruments Incorporated - http://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 void k3conf_print_version(FILE *stream)
50 {
51 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
52 struct ti_sci_version_info ver = soc_info.sci_info.version;
53 uint32_t row = 0;
55 if (stream == NULL) {
56 fprintf(stderr, "%s(): stream == NULL!!!\n", __func__);
57 return;
58 }
60 autoadjust_table_init(table);
61 strncpy(table[row][0], "VERSION INFO", TABLE_MAX_ELT_LEN);
62 row++;
63 strncpy(table[row][0], "K3CONF", TABLE_MAX_ELT_LEN);
64 snprintf(table[row][1], TABLE_MAX_ELT_LEN, "(version %s built %s)", k3conf_version, builddate);
65 row++;
66 strncpy(table[row][0], "SoC", TABLE_MAX_ELT_LEN);
67 strncpy(table[row][1], soc_info.soc_full_name, TABLE_MAX_ELT_LEN);
68 row++;
70 if (soc_info.ti_sci_enabled) {
71 strncpy(table[row][0], "SYSFW", TABLE_MAX_ELT_LEN);
72 snprintf(table[row][1], TABLE_MAX_ELT_LEN,
73 "ABI: %d.%d (firmware version 0x%04x '%.*s)')",
74 ver.abi_major, ver.abi_minor, ver.firmware_version,
75 (int)sizeof(ver.firmware_description),
76 ver.firmware_description);
77 row++;
78 }
80 autoadjust_table_generic_fprint(stream, table, row, 2, TABLE_HAS_TITLE);
82 return;
83 }
85 int main(int argc, char *argv[])
86 {
87 int ret = 0;
89 /* Scan user arguments for options */
90 argc--;
91 argv++;
93 if (argc == 0) {
94 help(HELP_USAGE);
95 ret = -1;
96 goto main_exit;
97 }
99 if (soc_init())
100 goto main_exit;
102 if (!strcmp(argv[0], "--help")) {
103 k3conf_print_version(stdout);
104 help(HELP_ALL);
105 goto main_exit;
106 } else if (!strcmp(argv[0], "--version")) {
107 k3conf_print_version(stdout);
108 goto main_exit;
109 } else if (!strcmp(argv[0], "--cpuinfo")) {
110 k3conf_print_version(stdout);
111 dump_cpu_info();
112 goto main_exit;
113 } else if (!strcmp(argv[0], "show")) {
114 argc--;
115 argv++;
116 k3conf_print_version(stdout);
117 return process_show_command(argc, argv);
118 } else if (!strcmp(argv[0], "dump")) {
119 argc--;
120 argv++;
121 k3conf_print_version(stdout);
122 return process_dump_command(argc, argv);
123 } else if (!strcmp(argv[0], "enable")) {
124 argc--;
125 argv++;
126 k3conf_print_version(stdout);
127 return process_enable_command(argc, argv);
128 } else if (!strcmp(argv[0], "disable")) {
129 argc--;
130 argv++;
131 k3conf_print_version(stdout);
132 return process_disable_command(argc, argv);
133 } else if (!strcmp(argv[0], "set")) {
134 argc--;
135 argv++;
136 k3conf_print_version(stdout);
137 return process_set_command(argc, argv);
138 } else {
139 fprintf(stderr, "Invalid argument %s", argv[0]);
140 help(HELP_USAGE);
141 ret = -1;
142 goto main_exit;
143 }
145 main_exit:
146 return ret;
147 }