Merge branch 'master' of git://www.denx.de/git/u-boot-cfi-flash
[platform/kernel/u-boot.git] / common / cmd_nvedit.c
index 9158b96..778dca5 100644 (file)
@@ -7,23 +7,7 @@
  *
  * Copyright 2011 Freescale Semiconductor, Inc.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+ 
  */
 
 /*
@@ -165,12 +149,13 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
                       int argc, char * const argv[])
 {
        char *res = NULL;
-       int len, grep_flags;
+       int len, grep_how, grep_what;
 
        if (argc < 2)
                return CMD_RET_USAGE;
 
-       grep_flags = H_MATCH_BOTH;
+       grep_how  = H_MATCH_SUBSTR;     /* default: substring search    */
+       grep_what = H_MATCH_BOTH;       /* default: grep names and values */
 
        while (argc > 1 && **(argv + 1) == '-') {
                char *arg = *++argv;
@@ -178,14 +163,19 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
                --argc;
                while (*++arg) {
                        switch (*arg) {
+#ifdef CONFIG_REGEX
+                       case 'e':               /* use regex matching */
+                               grep_how  = H_MATCH_REGEX;
+                               break;
+#endif
                        case 'n':               /* grep for name */
-                               grep_flags = H_MATCH_KEY;
+                               grep_what = H_MATCH_KEY;
                                break;
                        case 'v':               /* grep for value */
-                               grep_flags = H_MATCH_DATA;
+                               grep_what = H_MATCH_DATA;
                                break;
                        case 'b':               /* grep for both */
-                               grep_flags = H_MATCH_BOTH;
+                               grep_what = H_MATCH_BOTH;
                                break;
                        case '-':
                                goto DONE;
@@ -197,7 +187,7 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
 
 DONE:
        len = hexport_r(&env_htab, '\n',
-                       flag | grep_flags | H_MATCH_SUBSTR,
+                       flag | grep_what | grep_how,
                        &res, 0, argc, argv);
 
        if (len > 0) {
@@ -308,7 +298,7 @@ int setenv(const char *varname, const char *varvalue)
 /**
  * Set an environment variable to an integer value
  *
- * @param varname      Environmet variable to set
+ * @param varname      Environment variable to set
  * @param value                Value to set it to
  * @return 0 if ok, 1 on error
  */
@@ -323,7 +313,7 @@ int setenv_ulong(const char *varname, ulong value)
 /**
  * Set an environment variable to an value in hex
  *
- * @param varname      Environmet variable to set
+ * @param varname      Environment variable to set
  * @param value                Value to set it to
  * @return 0 if ok, 1 on error
  */
@@ -1153,8 +1143,12 @@ static char env_help_text[] =
        "env flags - print variables that have non-default flags\n"
 #endif
 #if defined(CONFIG_CMD_GREPENV)
+#ifdef CONFIG_REGEX
+       "env grep [-e] [-n | -v | -b] string [...] - search environment\n"
+#else
        "env grep [-n | -v | -b] string [...] - search environment\n"
 #endif
+#endif
 #if defined(CONFIG_CMD_IMPORTENV)
        "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
 #endif
@@ -1200,8 +1194,15 @@ U_BOOT_CMD_COMPLETE(
 U_BOOT_CMD_COMPLETE(
        grepenv, CONFIG_SYS_MAXARGS, 0,  do_env_grep,
        "search environment variables",
+#ifdef CONFIG_REGEX
+       "[-e] [-n | -v | -b] string ...\n"
+#else
        "[-n | -v | -b] string ...\n"
+#endif
        "    - list environment name=value pairs matching 'string'\n"
+#ifdef CONFIG_REGEX
+       "      \"-e\": enable regular expressions;\n"
+#endif
        "      \"-n\": search variable names; \"-v\": search values;\n"
        "      \"-b\": search both names and values (default)",
        var_complete