1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  RESET command				File: ui_reset.c
5    *
6    *  Commands to reset the CPU
7    *
8    *********************************************************************
9    *
10    *  Copyright 2000,2001,2002,2003
11    *  Broadcom Corporation. All rights reserved.
12    *
13    *  This software is furnished under license and may be used and
14    *  copied only in accordance with the following terms and
15    *  conditions.  Subject to these conditions, you may download,
16    *  copy, install, use, modify and distribute modified or unmodified
17    *  copies of this software in source and/or binary form.  No title
18    *  or ownership is transferred hereby.
19    *
20    *  1) Any source code used, modified or distributed must reproduce
21    *     and retain this copyright notice and list of conditions
22    *     as they appear in the source file.
23    *
24    *  2) No right is granted to use any trade name, trademark, or
25    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
26    *     name may not be used to endorse or promote products derived
27    *     from this software without the prior written permission of
28    *     Broadcom Corporation.
29    *
30    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
31    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
32    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
33    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
34    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
35    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
36    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
40    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
41    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
42    *     THE POSSIBILITY OF SUCH DAMAGE.
43    ********************************************************************* */
44
45
46#include "cfe.h"
47#include "lib_physio.h"
48
49#include "ui_command.h"
50
51/*  *********************************************************************
52    *  Configuration
53    ********************************************************************* */
54
55/*  *********************************************************************
56    *  prototypes
57    ********************************************************************* */
58
59int ui_init_resetcmds(void);
60static int ui_cmd_reset(ui_cmdline_t *cmd,int argc,char *argv[]);
61
62
63/*  *********************************************************************
64    *  Data
65    ********************************************************************* */
66
67
68/*  *********************************************************************
69    *  ui_init_resetcmds()
70    *
71    *  Add RESET-specific commands to the command table
72    *
73    *  Input parameters:
74    *  	   nothing
75    *
76    *  Return value:
77    *  	   0
78    ********************************************************************* */
79
80
81int ui_init_resetcmds(void)
82{
83    cmd_addcmd("reset",
84	       ui_cmd_reset,
85	       NULL,
86	       "Reset the system.",
87	       "reset [-yes] -cpu|-sysreset",
88	       "-yes;Don't ask for confirmation|"
89	       "-cpu;Reset the CPU|"
90	       "-sysreset;Full system reset");
91
92
93
94    return 0;
95}
96
97
98
99
100
101/*  *********************************************************************
102    *  ui_cmd_reset(cmd,argc,argv)
103    *
104    *  RESET command.
105    *
106    *  Input parameters:
107    *  	   cmd - command structure
108    *  	   argc,argv - parameters
109    *
110    *  Return value:
111    *  	   -1 if error occured.  Does not return otherwise
112    ********************************************************************* */
113
114static int ui_cmd_reset(ui_cmdline_t *cmd,int argc,char *argv[])
115{
116    uint8_t data = 0;
117    int confirm = 1;
118    char str[50];
119
120    if (cmd_sw_isset(cmd,"-yes")) confirm = 0;
121
122    if (cmd_sw_isset(cmd,"-sysreset")) data |= 0xFF;
123
124    if (cmd_sw_isset(cmd,"-cpu")) data |= 0xFF;
125
126    if (data == 0) {		/* no changes to reset pins were specified */
127	return ui_showusage(cmd);
128	}
129
130    if (confirm) {
131	console_readline("Are you sure you want to reset? ",str,sizeof(str));
132	if ((str[0] != 'Y') && (str[0] != 'y')) return -1;
133	}
134
135#ifdef A_BMW_PLD
136    phys_write8(A_BMW_PLD,data);
137    phys_write8(A_BMW_PLD,0);
138    for (;;);
139#else
140    printf("PLD on this board does not support self-reset\n");
141#endif
142
143    /* should not return */
144
145    return -1;
146}
147
148
149