allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / cfe / cfe / ui / ui_misccmds.c
blobce4f19bbee349b43d83e49ab7f88053c7e2bbda0
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Miscellaneous commands File: ui_misccmds.c
5 *
6 * Some small but useful commands
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_string.h"
50 #include "lib_queue.h"
51 #include "lib_malloc.h"
52 #include "lib_printf.h"
54 #include "cfe_iocb.h"
55 #include "cfe_device.h"
56 #include "cfe_console.h"
57 #include "cfe_error.h"
58 #include "cfe_ioctl.h"
59 #include "cfe_devfuncs.h"
60 #include "ui_command.h"
61 #include "cfe.h"
64 static int ui_cmd_loop(ui_cmdline_t *cmd,int argc,char *argv[]);
65 #ifdef _FUNCSIM_
66 static int ui_cmd_exit(ui_cmdline_t *cmd,int argc,char *argv[]);
67 #endif
68 static int ui_cmd_console(ui_cmdline_t *cmd,int argc,char *argv[]);
70 int ui_init_misccmds(void);
72 int ui_init_misccmds(void)
75 cmd_addcmd("loop",
76 ui_cmd_loop,
77 NULL,
78 "Loop a command",
79 "loop \"command\" [-count=*]\n"
80 "The 'loop' command causes the specified command or list of commands\n"
81 "to be repeated 'count' times or forever, or until a character is typed",
82 "-count=*;Specifies number of iterations|"
83 "-forever;Loops forever");
85 #ifdef _FUNCSIM_
86 cmd_addcmd("exit",
87 ui_cmd_exit,
88 NULL,
89 "exit from the functional simulator",
90 "exit [n]\n\n"
91 "This command is useful only when running under the functional\n"
92 "simulator. It causes the simulator to exit and return to the\n"
93 "operating system. If specified, 'n' will be placed in $4 as a\n"
94 "return code.",
95 "");
96 #endif
98 cmd_addcmd("set console",
99 ui_cmd_console,
100 NULL,
101 "Change the active console device",
102 "set console device-name\n\n"
103 "Changes the console device to the specified device name. The console\n"
104 "must be a serial-style device. Be careful not to change the console\n"
105 "to a device that is not connected!",
106 "");
108 return 0;
111 static int ui_cmd_loop(ui_cmdline_t *cmd,int argc,char *argv[])
113 int count = 10;
114 char *x;
115 int res;
116 int forever;
118 if (cmd_sw_value(cmd,"-count",&x)) count = atoi(x);
120 forever = cmd_sw_isset(cmd,"-forever");
122 x = cmd_getarg(cmd,0);
123 if (!x) return ui_showusage(cmd);
125 res = 0;
126 while (count || forever) {
127 if (console_status()) break;
128 res = ui_docommands(x);
129 if (res != 0) break;
130 count--;
133 return res;
137 #ifdef _FUNCSIM_
138 static int ui_cmd_exit(ui_cmdline_t *cmd,int argc,char *argv[])
140 int val = 0;
141 char *x;
143 x = cmd_getarg(cmd,0);
144 if (x) val = atoi(x);
146 __asm __volatile ("move $4,%0 ; li $2,1 ; syscall 0xca" : "=r"(val));
148 return -1;
150 #endif
153 static int ui_cmd_console(ui_cmdline_t *cmd,int argc,char *argv[])
155 int res;
156 char *dev;
158 dev = cmd_getarg(cmd,0);
159 if (!dev) return -1;
161 res = cfe_getdevinfo(dev);
162 if (res < 0) {
163 xprintf("Device '%s' is not valid\n",dev);
164 return CFE_ERR_DEVNOTFOUND;
167 if ((res & CFE_DEV_MASK) != CFE_DEV_SERIAL) {
168 xprintf("Device '%s' is not the appropriate type to be a console\n",
169 dev);
170 return CFE_ERR_WRONGDEVTYPE;
173 cfe_set_console(dev);
175 return 0;