blob: 1c22e7143d6e84959a7dc42786ad722ebbdfa7b0 [file] [log] [blame]
wdenk6aff3112002-12-17 01:51:00 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * Command line user interface to firmware (=PPCBoot) environment.
26 *
27 * Implements:
28 * fw_printenv [ name ... ]
29 * - prints the values of the environment variables
30 * "name", or the whole environment if no names are
31 * specified
32 * fw_setenv name [ value ... ]
33 * - If a name without any values is given, the variable
34 * with this name is deleted from the environment;
35 * otherwise, all "value" arguments are concatenated,
36 * separated by sinlge blank characters, and the
37 * resulting string is assigned to the environment
38 * variable "name"
39 */
40
41#include <stdio.h>
42#include <string.h>
43#include <stdlib.h>
44#include "fw_env.h"
45
46#define CMD_PRINTENV "fw_printenv"
47#define CMD_SETENV "fw_setenv"
48
49int
50main(int argc, char *argv[])
51{
52 char *p;
53 char *cmdname = *argv;
54
55 if ((p = strrchr (cmdname, '/')) != NULL) {
56 cmdname = p + 1;
57 }
58
59 if (strcmp(cmdname, CMD_PRINTENV) == 0) {
60
61 fw_printenv (argc, argv);
62
63 return (EXIT_SUCCESS);
64
65 } else if (strcmp(cmdname, CMD_SETENV) == 0) {
66
67 if (fw_setenv (argc, argv) != 0)
68 return (EXIT_FAILURE);
69
70 return (EXIT_SUCCESS);
71 }
72
73 fprintf (stderr,
74 "Identity crisis - may be called as `" CMD_PRINTENV
75 "' or as `" CMD_SETENV "' but not as `%s'\n",
76 cmdname);
77 return (EXIT_FAILURE);
78}