xref: /rk3399_rockchip-uboot/tools/env/fw_env_main.c (revision bc11756daff89a3de09ca80adac962b88cf06e6e)
16aff3115Swdenk /*
2*bc11756dSGrant Erickson  * (C) Copyright 2000-2008
36aff3115Swdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
46aff3115Swdenk  *
56aff3115Swdenk  * See file CREDITS for list of people who contributed to this
66aff3115Swdenk  * project.
76aff3115Swdenk  *
86aff3115Swdenk  * This program is free software; you can redistribute it and/or
96aff3115Swdenk  * modify it under the terms of the GNU General Public License as
106aff3115Swdenk  * published by the Free Software Foundation; either version 2 of
116aff3115Swdenk  * the License, or (at your option) any later version.
126aff3115Swdenk  *
136aff3115Swdenk  * This program is distributed in the hope that it will be useful,
146aff3115Swdenk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
156aff3115Swdenk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
166aff3115Swdenk  * GNU General Public License for more details.
176aff3115Swdenk  *
186aff3115Swdenk  * You should have received a copy of the GNU General Public License
196aff3115Swdenk  * along with this program; if not, write to the Free Software
206aff3115Swdenk  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
216aff3115Swdenk  * MA 02111-1307 USA
226aff3115Swdenk  */
236aff3115Swdenk 
246aff3115Swdenk /*
253bac3513Swdenk  * Command line user interface to firmware (=U-Boot) environment.
266aff3115Swdenk  *
276aff3115Swdenk  * Implements:
28*bc11756dSGrant Erickson  *	fw_printenv [[ -n name ] | [ name ... ]]
29*bc11756dSGrant Erickson  *              - prints the value of a single environment variable
30*bc11756dSGrant Erickson  *                "name", the ``name=value'' pairs of one or more
31*bc11756dSGrant Erickson  *                environment variables "name", or the whole
32*bc11756dSGrant Erickson  *                environment if no names are specified.
336aff3115Swdenk  *	fw_setenv name [ value ... ]
346aff3115Swdenk  *		- If a name without any values is given, the variable
356aff3115Swdenk  *		  with this name is deleted from the environment;
366aff3115Swdenk  *		  otherwise, all "value" arguments are concatenated,
37*bc11756dSGrant Erickson  *		  separated by single blank characters, and the
386aff3115Swdenk  *		  resulting string is assigned to the environment
396aff3115Swdenk  *		  variable "name"
406aff3115Swdenk  */
416aff3115Swdenk 
426aff3115Swdenk #include <stdio.h>
436aff3115Swdenk #include <string.h>
446aff3115Swdenk #include <stdlib.h>
456aff3115Swdenk #include "fw_env.h"
466aff3115Swdenk 
476aff3115Swdenk #define	CMD_PRINTENV	"fw_printenv"
486aff3115Swdenk #define CMD_SETENV	"fw_setenv"
496aff3115Swdenk 
506aff3115Swdenk int
516aff3115Swdenk main(int argc, char *argv[])
526aff3115Swdenk {
536aff3115Swdenk 	char *p;
546aff3115Swdenk 	char *cmdname = *argv;
556aff3115Swdenk 
566aff3115Swdenk 	if ((p = strrchr (cmdname, '/')) != NULL) {
576aff3115Swdenk 		cmdname = p + 1;
586aff3115Swdenk 	}
596aff3115Swdenk 
606aff3115Swdenk 	if (strcmp(cmdname, CMD_PRINTENV) == 0) {
616aff3115Swdenk 
62*bc11756dSGrant Erickson 		if (fw_printenv (argc, argv) != 0)
63*bc11756dSGrant Erickson 			return (EXIT_FAILURE);
646aff3115Swdenk 
656aff3115Swdenk 		return (EXIT_SUCCESS);
666aff3115Swdenk 
676aff3115Swdenk 	} else if (strcmp(cmdname, CMD_SETENV) == 0) {
686aff3115Swdenk 
696aff3115Swdenk 		if (fw_setenv (argc, argv) != 0)
706aff3115Swdenk 			return (EXIT_FAILURE);
716aff3115Swdenk 
726aff3115Swdenk 		return (EXIT_SUCCESS);
73*bc11756dSGrant Erickson 
746aff3115Swdenk 	}
756aff3115Swdenk 
766aff3115Swdenk 	fprintf (stderr,
776aff3115Swdenk 		"Identity crisis - may be called as `" CMD_PRINTENV
786aff3115Swdenk 		"' or as `" CMD_SETENV "' but not as `%s'\n",
796aff3115Swdenk 		cmdname);
806aff3115Swdenk 	return (EXIT_FAILURE);
816aff3115Swdenk }
82