1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Environment commands File: ui_envcmds.c
6 * User interface for environment variables
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"
55 #include "cfe_device.h"
56 #include "cfe_console.h"
58 #include "ui_command.h"
62 int ui_init_envcmds(void);
63 static int ui_cmd_setenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
64 static int ui_cmd_printenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
65 static int ui_cmd_unsetenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
69 static int ui_cmd_printenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
76 xprintf("Variable Name Value\n");
77 xprintf("-------------------- --------------------------------------------------\n");
81 varlen
= sizeof(varname
);
82 vallen
= sizeof(value
);
83 if (env_enum(idx
,varname
,&varlen
,value
,&vallen
) < 0) break;
84 xprintf("%20s %s\n",varname
,value
);
92 static int ui_cmd_setenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
96 int roflag
= ENV_FLG_NORMAL
;
99 varname
= cmd_getarg(cmd
,0);
102 return ui_showusage(cmd
);
105 value
= cmd_getarg(cmd
,1);
107 return ui_showusage(cmd
);
110 if (!cmd_sw_isset(cmd
,"-p")) {
111 roflag
= ENV_FLG_BUILTIN
; /* just in memory, not NVRAM */
114 if (cmd_sw_isset(cmd
,"-ro")) {
115 roflag
= ENV_FLG_READONLY
;
118 if ((res
= env_setenv(varname
,value
,roflag
)) == 0) {
119 if (roflag
!= ENV_FLG_BUILTIN
) env_save();
122 return ui_showerror(res
,"Could not set environment variable '%s'",
130 static int ui_cmd_unsetenv(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
136 varname
= cmd_getarg(cmd
,0);
139 return ui_showusage(cmd
);
142 type
= env_envtype(varname
);
144 if ((res
= env_delenv(varname
)) == 0) {
145 if ((type
>= 0) && (type
!= ENV_FLG_BUILTIN
)) env_save();
148 return ui_showerror(res
,"Could not delete environment variable '%s'",
157 int ui_init_envcmds(void)
163 "Set an environment variable.",
164 "setenv [-ro] [-p] varname value\n\n"
165 "This command sets an environment variable. By default, an environment variable\n"
166 "is stored only in memory and will not be retained across system restart.",
167 "-p;Store environment variable permanently in the NVRAM device, if present|"
168 "-ro;Causes variable to be read-only\n"
169 "(cannot be changed in the future, implies -p)");
171 cmd_addcmd("printenv",
174 "Display the environment variables",
176 "This command prints a table of the environment variables and their\n"
180 cmd_addcmd("unsetenv",
183 "Delete an environment variable.",
184 "unsetenv varname\n\n"
185 "This command deletes an environment variable from memory and also \n"
186 "removes it from the NVRAM device (if present).",