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>
48 void k3conf_print_version(FILE *stream)
49 {
50 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
51 struct ti_sci_version_info ver = soc_info.sci_info.version;
52 uint32_t row = 0;
54 if (stream == NULL) {
55 fprintf(stderr, "%s(): stream == NULL!!!\n", __func__);
56 return;
57 }
59 autoadjust_table_init(table);
60 strncpy(table[row][0], "VERSION INFO", TABLE_MAX_ELT_LEN);
61 row++;
62 strncpy(table[row][0], "K3CONF", TABLE_MAX_ELT_LEN);
63 snprintf(table[row][1], TABLE_MAX_ELT_LEN, "(version %s built %s)", k3conf_version, builddate);
64 row++;
65 strncpy(table[row][0], "SoC", TABLE_MAX_ELT_LEN);
66 strncpy(table[row][1], soc_info.soc_full_name, TABLE_MAX_ELT_LEN);
67 row++;
69 if (soc_info.ti_sci_enabled) {
70 strncpy(table[row][0], "SYSFW", TABLE_MAX_ELT_LEN);
71 snprintf(table[row][1], TABLE_MAX_ELT_LEN,
72 "ABI: %d.%d (firmware version 0x%04x '%.*s)')",
73 ver.abi_major, ver.abi_minor, ver.firmware_version,
74 (int)sizeof(ver.firmware_description),
75 ver.firmware_description);
76 row++;
77 }
79 autoadjust_table_generic_fprint(stream, table, row, 2, TABLE_HAS_TITLE);
81 return;
82 }
84 int main(int argc, char *argv[])
85 {
86 int ret = 0;
88 /* Scan user arguments for options */
89 argc--;
90 argv++;
92 if (argc == 0) {
93 help(HELP_USAGE);
94 ret = -1;
95 goto main_exit;
96 }
98 if (soc_init())
99 goto main_exit;
101 if (!strcmp(argv[0], "--help")) {
102 k3conf_print_version(stdout);
103 help(HELP_ALL);
104 goto main_exit;
105 } else if (!strcmp(argv[0], "--version")) {
106 k3conf_print_version(stdout);
107 goto main_exit;
108 } else {
109 fprintf(stderr, "Invalid argument %s", argv[0]);
110 help(HELP_USAGE);
111 ret = -1;
112 goto main_exit;
113 }
115 main_exit:
116 return ret;
117 }