1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * carmel-specific commands File: ui_carmel.c
6 * A temporary sandbox for misc test routines and commands.
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
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 "lib_physio.h"
56 #include "cfe_timer.h"
58 #include "cfe_error.h"
59 #include "cfe_console.h"
61 #include "ui_command.h"
64 #include "bsp_config.h"
67 #include "sb1250_regs.h"
68 #include "sb1250_scd.h"
73 #include "carmel_env.h"
75 /* *********************************************************************
77 ********************************************************************* */
79 /* *********************************************************************
81 ********************************************************************* */
83 int ui_init_carmelcmds(void);
85 static int ui_cmd_mreset(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
86 static int ui_cmd_msetup(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
87 static int ui_cmd_msetenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
88 static int ui_cmd_mprintenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
89 static int ui_cmd_munsetenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
91 /* *********************************************************************
93 ********************************************************************* */
96 /* *********************************************************************
97 * ui_init_carmelcmds()
99 * Add carmel-specific commands to the command table
106 ********************************************************************* */
109 int ui_init_carmelcmds(void)
111 cmd_addcmd("monterey reset",
114 "Reset the Monterey Subsystem",
115 "monterey reset [0|1]\n\n"
116 "This command resets the board that the Carmel is attached to. For\n"
117 "example, if Carmel is attached to a Monterey board, the Monterey\n"
118 "FPGA is reset. You can specify an absolute value for the reset pin\n"
119 "or type 'monterey reset' without a parameter to pulse the reset line.",
122 cmd_addcmd("monterey setenv",
125 "Set a Monterey environment variable.",
126 "monterey setenv [-p] varname value\n\n"
127 "This command sets an environment variable. By default, an environment variable\n"
128 "is stored only in memory and will not be retained across system restart.",
129 "-p;Store environment variable permanently in the NVRAM device, if present");
131 cmd_addcmd("monterey printenv",
134 "Display the Monterey environment variables",
135 "monterey printenv\n\n"
136 "This command prints a table of the Monterey environment variables and their\n"
140 cmd_addcmd("monterey unsetenv",
143 "Delete a Monterey environment variable.",
144 "monterey unsetenv varname\n\n"
145 "This command deletes a Monterey environment variable from memory and also \n"
146 "removes it from the NVRAM device (if present).",
149 cmd_addcmd("monterey setup",
152 "Interactive setup for Monterey variables.",
154 "This command prompts for the important Monterey environment variables and\n"
155 "stores them in the ID EEPROM\n",
164 static int ui_cmd_mreset(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
169 if ((x
= cmd_getarg(cmd
,0))) {
172 SBWRITECSR(A_GPIO_PIN_SET
,M_GPIO_MONTEREY_RESET
);
175 SBWRITECSR(A_GPIO_PIN_CLR
,M_GPIO_MONTEREY_RESET
);
177 printf("Monterey reset pin set to %d\n",val
? 1 : 0);
180 SBWRITECSR(A_GPIO_PIN_CLR
,M_GPIO_MONTEREY_RESET
);
182 SBWRITECSR(A_GPIO_PIN_SET
,M_GPIO_MONTEREY_RESET
);
183 printf("Monterey has been reset.\n");
194 static int ui_cmd_mprintenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
201 xprintf("Variable Name Value\n");
202 xprintf("-------------------- --------------------------------------------------\n");
206 varlen
= sizeof(varname
);
207 vallen
= sizeof(value
);
208 if (carmel_enumenv(idx
,varname
,&varlen
,value
,&vallen
) < 0) break;
209 xprintf("%20s %s\n",varname
,value
);
217 static int ui_cmd_msetenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
221 int roflag
= ENV_FLG_NORMAL
;
224 varname
= cmd_getarg(cmd
,0);
227 return ui_showusage(cmd
);
230 value
= cmd_getarg(cmd
,1);
232 return ui_showusage(cmd
);
235 if (!cmd_sw_isset(cmd
,"-p")) {
236 roflag
= ENV_FLG_BUILTIN
; /* just in memory, not NVRAM */
239 if ((res
= carmel_setenv(varname
,value
,roflag
)) == 0) {
240 if (roflag
!= ENV_FLG_BUILTIN
) carmel_saveenv();
243 return ui_showerror(res
,"Could not set Monterey environment variable '%s'",
251 static int ui_cmd_munsetenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
257 varname
= cmd_getarg(cmd
,0);
260 return ui_showusage(cmd
);
263 type
= carmel_envtype(varname
);
265 if ((res
= carmel_delenv(varname
)) == 0) {
266 if ((type
>= 0) && (type
!= ENV_FLG_BUILTIN
)) carmel_saveenv();
269 return ui_showerror(res
,"Could not delete Monterey environment variable '%s'",
277 #define MSETUP_UCASE 1
278 #define MSETUP_YESNO 2
280 static int msetup_getone(char *prompt
,char *envvar
,char *defval
,int flg
)
286 curval
= carmel_getenv(envvar
);
287 if (!curval
) curval
= defval
;
289 sprintf(pbuf
,"%s [%s]: ",prompt
,curval
);
292 console_readline(pbuf
,buffer
,sizeof(buffer
));
293 if (buffer
[0] == 0) break; /* default */
294 if (flg
& (MSETUP_UCASE
|MSETUP_YESNO
)) strupr(buffer
);
295 if (flg
& MSETUP_YESNO
) {
296 if (strcmp(buffer
,"YES") == 0) break;
297 if (strcmp(buffer
,"NO") == 0) break;
298 printf("You must enter 'YES' or 'NO'.\n");
305 if (buffer
[0] == 0) {
306 carmel_setenv(envvar
,defval
,0);
309 carmel_setenv(envvar
,buffer
,0);
316 static int ui_cmd_msetup(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
319 msetup_getone("Board type (MONTEREY,LITTLESUR,BIGSUR)","M_BOARDTYPE","MONTEREY",MSETUP_UCASE
);
320 msetup_getone("FPGA Autoload (YES,NO)","M_FPGALOAD","YES",MSETUP_YESNO
);
321 msetup_getone("FPGA GPIO bits convoluted (YES,NO)","M_FPGACONVOLUTED","NO",