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>
47 void k3conf_print_version(FILE *stream)
48 {
49 struct ti_sci_version_info ver = soc_info.sci_info.version;
51 if (stream == NULL) {
52 fprintf(stderr, "%s(): stream == NULL!!!\n", __func__);
53 return;
54 }
56 fprintf(stream, "K3CONF (version %s built %s)\n", k3conf_version,
57 builddate);
58 fprintf(stream, "SoC %s\n", soc_info.soc_full_name);
60 if (!soc_info.ti_sci_enabled)
61 return;
63 fprintf(stream, "SYSFW ABI: %d.%d (firmware version 0x%04x '%.*s)')\n",
64 ver.abi_major, ver.abi_minor, ver.firmware_version,
65 (int)sizeof(ver.firmware_description),
66 ver.firmware_description);
67 }
69 int main(int argc, char *argv[])
70 {
71 int ret = 0;
73 /* Scan user arguments for options */
74 argc--;
75 argv++;
77 if (argc == 0) {
78 help(HELP_USAGE);
79 ret = -1;
80 goto main_exit;
81 }
83 if (soc_init())
84 goto main_exit;
86 if (!strcmp(argv[0], "--help")) {
87 k3conf_print_version(stdout);
88 help(HELP_ALL);
89 goto main_exit;
90 } else if (!strcmp(argv[0], "--version")) {
91 k3conf_print_version(stdout);
92 goto main_exit;
93 } else {
94 fprintf(stderr, "Invalid argument %s", argv[0]);
95 help(HELP_USAGE);
96 ret = -1;
97 goto main_exit;
98 }
100 main_exit:
101 return ret;
102 }