tools: env: update usage strings

Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
This commit is contained in:
Andreas Fenkart
2015-12-09 13:13:27 +01:00
committed by Tom Rini
parent af93e3d8ab
commit b92ae3af6e

View File

@ -36,12 +36,16 @@
#include <unistd.h> #include <unistd.h>
#include "fw_env.h" #include "fw_env.h"
#define CMD_PRINTENV "fw_printenv" #define CMD_PRINTENV "fw_printenv"
#define CMD_SETENV "fw_setenv" #define CMD_SETENV "fw_setenv"
static int do_printenv;
static struct option long_options[] = { static struct option long_options[] = {
{"script", required_argument, NULL, 's'}, {"aes", required_argument, NULL, 'a'},
{"config", required_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"script", required_argument, NULL, 's'},
{"noheader", required_argument, NULL, 'n'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
@ -49,36 +53,58 @@ struct common_args common_args;
struct printenv_args printenv_args; struct printenv_args printenv_args;
struct setenv_args setenv_args; struct setenv_args setenv_args;
void usage(void) void usage_printenv(void)
{ {
fprintf(stderr, "fw_printenv/fw_setenv, " fprintf(stderr,
"a command line interface to U-Boot environment\n\n" "Usage: fw_printenv [OPTIONS]... [VARIABLE]...\n"
#ifndef CONFIG_FILE "Print variables from U-Boot environment\n"
"usage:\tfw_printenv [-a key] [-n] [variable name]\n" "\n"
"\tfw_setenv [-a key] [variable name] [variable value]\n" " -h, --help print this help.\n"
#else #ifdef CONFIG_ENV_AES
"usage:\tfw_printenv [-c /my/fw_env.config] [-a key] [-n] [variable name]\n" " -a, --aes aes key to access environment\n"
"\tfw_setenv [-c /my/fw_env.config] [-a key] [variable name] [variable value]\n"
#endif #endif
"\tfw_setenv -s [ file ]\n" #ifdef CONFIG_FILE
"\tfw_setenv -s - < [ file ]\n\n" " -c, --config configuration file, default:" CONFIG_FILE "\n"
"The file passed as argument contains only pairs " #endif
"name / value\n" " -n, --noheader do not repeat variable name in output\n"
"Example:\n" "\n");
"# Any line starting with # is treated as comment\n" }
void usage_setenv(void)
{
fprintf(stderr,
"Usage: fw_setenv [OPTIONS]... [VARIABLE]...\n"
"Modify variables in U-Boot environment\n"
"\n" "\n"
"\t netdev eth0\n" " -h, --help print this help.\n"
"\t kernel_addr 400000\n" #ifdef CONFIG_ENV_AES
"\t var1\n" " -a, --aes aes key to access environment\n"
"\t var2 The quick brown fox jumps over the " #endif
"lazy dog\n" #ifdef CONFIG_FILE
" -c, --config configuration file, default:" CONFIG_FILE "\n"
#endif
" -s, --script batch mode to minimize writes\n"
"\n" "\n"
"A variable without value will be dropped. It is possible\n" "Examples:\n"
"to put any number of spaces between the fields, but any\n" " fw_setenv foo bar set variable foo equal bar\n"
"space inside the value is treated as part of the value " " fw_setenv foo clear variable foo\n"
"itself.\n\n" " fw_setenv --script file run batch script\n"
); "\n"
"Script Syntax:\n"
" key [space] value\n"
" lines starting with '#' are treated as commment\n"
"\n"
" A variable without value will be deleted. Any number of spaces are\n"
" allowed between key and value. Space inside of the value is treated\n"
" as part of the value itself.\n"
"\n"
"Script Example:\n"
" netdev eth0\n"
" kernel_addr 400000\n"
" foo empty empty empty empty empty empty\n"
" bar\n"
"\n");
} }
static void parse_common_args(int argc, char *argv[]) static void parse_common_args(int argc, char *argv[])
@ -105,7 +131,7 @@ static void parse_common_args(int argc, char *argv[])
break; break;
#endif #endif
case 'h': case 'h':
usage(); do_printenv ? usage_printenv() : usage_setenv();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
default: default:
@ -137,7 +163,7 @@ int parse_printenv_args(int argc, char *argv[])
/* ignore common options */ /* ignore common options */
break; break;
default: /* '?' */ default: /* '?' */
usage(); usage_printenv();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
break; break;
} }
@ -163,7 +189,7 @@ int parse_setenv_args(int argc, char *argv[])
/* ignore common options */ /* ignore common options */
break; break;
default: /* '?' */ default: /* '?' */
usage(); usage_setenv();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
break; break;
} }
@ -173,27 +199,34 @@ int parse_setenv_args(int argc, char *argv[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *cmdname = *argv;
const char *lockname = "/var/lock/" CMD_PRINTENV ".lock"; const char *lockname = "/var/lock/" CMD_PRINTENV ".lock";
int lockfd = -1; int lockfd = -1;
int retval = EXIT_SUCCESS; int retval = EXIT_SUCCESS;
char *_cmdname;
if (strrchr(cmdname, '/') != NULL) _cmdname = *argv;
cmdname = strrchr(cmdname, '/') + 1; if (strrchr(_cmdname, '/') != NULL)
_cmdname = strrchr(_cmdname, '/') + 1;
if (strcmp(cmdname, CMD_PRINTENV) == 0) { if (strcmp(_cmdname, CMD_PRINTENV) == 0) {
if (parse_printenv_args(argc, argv)) do_printenv = 1;
exit(EXIT_FAILURE); } else if (strcmp(_cmdname, CMD_SETENV) == 0) {
} else if (strcmp(cmdname, CMD_SETENV) == 0) { do_printenv = 0;
if (parse_setenv_args(argc, argv))
exit(EXIT_FAILURE);
} else { } else {
fprintf(stderr, fprintf(stderr,
"Identity crisis - may be called as `%s' or as `%s' but not as `%s'\n", "Identity crisis - may be called as `%s' or as `%s' but not as `%s'\n",
CMD_PRINTENV, CMD_SETENV, cmdname); CMD_PRINTENV, CMD_SETENV, _cmdname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (do_printenv) {
if (parse_printenv_args(argc, argv))
exit(EXIT_FAILURE);
} else {
if (parse_setenv_args(argc, argv))
exit(EXIT_FAILURE);
}
/* shift parsed flags, jump to non-option arguments */ /* shift parsed flags, jump to non-option arguments */
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -210,10 +243,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (strcmp(cmdname, CMD_PRINTENV) == 0) { if (do_printenv) {
if (fw_printenv(argc, argv) != 0) if (fw_printenv(argc, argv) != 0)
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
} else if (strcmp(cmdname, CMD_SETENV) == 0) { } else {
if (!setenv_args.script_file) { if (!setenv_args.script_file) {
if (fw_setenv(argc, argv) != 0) if (fw_setenv(argc, argv) != 0)
retval = EXIT_FAILURE; retval = EXIT_FAILURE;