Merge https://gitlab.denx.de/u-boot/custodians/u-boot-sh
[platform/kernel/u-boot.git] / cmd / nvedit.c
index 08d49df..acd9f82 100644 (file)
@@ -1224,12 +1224,18 @@ static int print_env_info(void)
  * env info - display environment information
  * env info [-d] - evaluate whether default environment is used
  * env info [-p] - evaluate whether environment can be persisted
+ *      Add [-q] - quiet mode, use only for command result, for test by example:
+ *                 test env info -p -d -q
  */
 static int do_env_info(struct cmd_tbl *cmdtp, int flag,
                       int argc, char *const argv[])
 {
        int eval_flags = 0;
        int eval_results = 0;
+       bool quiet = false;
+#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
+       enum env_location loc;
+#endif
 
        /* display environment information */
        if (argc <= 1)
@@ -1247,6 +1253,9 @@ static int do_env_info(struct cmd_tbl *cmdtp, int flag,
                        case 'p':
                                eval_flags |= ENV_INFO_IS_PERSISTED;
                                break;
+                       case 'q':
+                               quiet = true;
+                               break;
                        default:
                                return CMD_RET_USAGE;
                        }
@@ -1256,20 +1265,30 @@ static int do_env_info(struct cmd_tbl *cmdtp, int flag,
        /* evaluate whether default environment is used */
        if (eval_flags & ENV_INFO_IS_DEFAULT) {
                if (gd->flags & GD_FLG_ENV_DEFAULT) {
-                       printf("Default environment is used\n");
+                       if (!quiet)
+                               printf("Default environment is used\n");
                        eval_results |= ENV_INFO_IS_DEFAULT;
                } else {
-                       printf("Environment was loaded from persistent storage\n");
+                       if (!quiet)
+                               printf("Environment was loaded from persistent storage\n");
                }
        }
 
        /* evaluate whether environment can be persisted */
        if (eval_flags & ENV_INFO_IS_PERSISTED) {
-#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
-               printf("Environment can be persisted\n");
-               eval_results |= ENV_INFO_IS_PERSISTED;
+#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
+               loc = env_get_location(ENVOP_SAVE, gd->env_load_prio);
+               if (ENVL_NOWHERE != loc && ENVL_UNKNOWN != loc) {
+                       if (!quiet)
+                               printf("Environment can be persisted\n");
+                       eval_results |= ENV_INFO_IS_PERSISTED;
+               } else {
+                       if (!quiet)
+                               printf("Environment cannot be persisted\n");
+               }
 #else
-               printf("Environment cannot be persisted\n");
+               if (!quiet)
+                       printf("Environment cannot be persisted\n");
 #endif
        }
 
@@ -1326,7 +1345,7 @@ static struct cmd_tbl cmd_env_sub[] = {
        U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
 #endif
 #if defined(CONFIG_CMD_NVEDIT_INFO)
-       U_BOOT_CMD_MKENT(info, 2, 0, do_env_info, "", ""),
+       U_BOOT_CMD_MKENT(info, 3, 0, do_env_info, "", ""),
 #endif
        U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
 #if defined(CONFIG_CMD_RUN)
@@ -1405,12 +1424,14 @@ static char env_help_text[] =
 #endif
 #if defined(CONFIG_CMD_NVEDIT_INFO)
        "env info - display environment information\n"
-       "env info [-d] - whether default environment is used\n"
-       "env info [-p] - whether environment can be persisted\n"
+       "env info [-d] [-p] [-q] - evaluate environment information\n"
+       "      \"-d\": default environment is used\n"
+       "      \"-p\": environment can be persisted\n"
+       "      \"-q\": quiet output\n"
 #endif
        "env print [-a | name ...] - print environment\n"
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-       "env print -e [-guid guid|-all][-n] [name ...] - print UEFI environment\n"
+       "env print -e [-guid guid[-n] [name ...] - print UEFI environment\n"
 #endif
 #if defined(CONFIG_CMD_RUN)
        "env run var [...] - run commands in an environment variable\n"
@@ -1452,8 +1473,9 @@ U_BOOT_CMD_COMPLETE(
        "print environment variables",
        "[-a]\n    - print [all] values of all environment variables\n"
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-       "printenv -e [-guid guid|-all][-n] [name ...]\n"
+       "printenv -e [-guid guid][-n] [name ...]\n"
        "    - print UEFI variable 'name' or all the variables\n"
+       "      \"-guid\": GUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n"
        "      \"-n\": suppress dumping variable's value\n"
 #endif
        "printenv name ...\n"
@@ -1487,7 +1509,7 @@ U_BOOT_CMD_COMPLETE(
        "-e [-guid guid][-nv][-bs][-rt][-at][-a][-v]\n"
        "        [-i addr,size name], or [name [value ...]]\n"
        "    - set UEFI variable 'name' to 'value' ...'\n"
-       "      \"-guid\": set vendor guid\n"
+       "      \"-guid\": GUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n"
        "      \"-nv\": set non-volatile attribute\n"
        "      \"-bs\": set boot-service attribute\n"
        "      \"-rt\": set runtime attribute\n"