blob: 7f631c4494b67839fcf13bc182d2545e3a737b1e [file] [log] [blame]
wdenk6aff3112002-12-17 01:51:00 +00001/*
Grant Ericksonbc117562008-05-06 20:16:15 -07002 * (C) Copyright 2000-2008
wdenk6aff3112002-12-17 01:51:00 +00003 * 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/*
wdenk3bac3512003-03-12 10:41:04 +000025 * Command line user interface to firmware (=U-Boot) environment.
wdenk6aff3112002-12-17 01:51:00 +000026 *
27 * Implements:
Grant Ericksonbc117562008-05-06 20:16:15 -070028 * fw_printenv [[ -n name ] | [ name ... ]]
29 * - prints the value of a single environment variable
30 * "name", the ``name=value'' pairs of one or more
31 * environment variables "name", or the whole
32 * environment if no names are specified.
wdenk6aff3112002-12-17 01:51:00 +000033 * fw_setenv name [ value ... ]
34 * - If a name without any values is given, the variable
35 * with this name is deleted from the environment;
36 * otherwise, all "value" arguments are concatenated,
Grant Ericksonbc117562008-05-06 20:16:15 -070037 * separated by single blank characters, and the
wdenk6aff3112002-12-17 01:51:00 +000038 * resulting string is assigned to the environment
39 * variable "name"
40 */
41
42#include <stdio.h>
43#include <string.h>
44#include <stdlib.h>
45#include "fw_env.h"
46
47#define CMD_PRINTENV "fw_printenv"
48#define CMD_SETENV "fw_setenv"
49
50int
51main(int argc, char *argv[])
52{
53 char *p;
54 char *cmdname = *argv;
55
56 if ((p = strrchr (cmdname, '/')) != NULL) {
57 cmdname = p + 1;
58 }
59
60 if (strcmp(cmdname, CMD_PRINTENV) == 0) {
61
Grant Ericksonbc117562008-05-06 20:16:15 -070062 if (fw_printenv (argc, argv) != 0)
63 return (EXIT_FAILURE);
wdenk6aff3112002-12-17 01:51:00 +000064
Grant Ericksonbc117562008-05-06 20:16:15 -070065 return (EXIT_SUCCESS);
wdenk6aff3112002-12-17 01:51:00 +000066
67 } else if (strcmp(cmdname, CMD_SETENV) == 0) {
68
Grant Ericksonbc117562008-05-06 20:16:15 -070069 if (fw_setenv (argc, argv) != 0)
70 return (EXIT_FAILURE);
wdenk6aff3112002-12-17 01:51:00 +000071
Grant Ericksonbc117562008-05-06 20:16:15 -070072 return (EXIT_SUCCESS);
73
wdenk6aff3112002-12-17 01:51:00 +000074 }
75
76 fprintf (stderr,
77 "Identity crisis - may be called as `" CMD_PRINTENV
78 "' or as `" CMD_SETENV "' but not as `%s'\n",
79 cmdname);
80 return (EXIT_FAILURE);
81}