]> git.sur5r.net Git - u-boot/commitdiff
tools: env: update usage strings
authorAndreas Fenkart <andreas.fenkart@digitalstrom.com>
Wed, 9 Dec 2015 12:13:27 +0000 (13:13 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 8 Feb 2016 15:10:33 +0000 (10:10 -0500)
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
tools/env/fw_env_main.c

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