]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_nvedit.c
ppc: Move mirror_hack to arch_global_data
[u-boot] / common / cmd_nvedit.c
index 468b89cc9c93558d7ec58a0cb02214c7b2a79d8b..7633f0c44a7e3ecb4c8828fbb62af4ede1d9fa21 100644 (file)
@@ -200,7 +200,24 @@ static int _do_env_set(int flag, int argc, char * const argv[])
        int   i, len;
        char  *name, *value, *s;
        ENTRY e, *ep;
+       int env_flag = H_INTERACTIVE;
 
+       debug("Initial value for argc=%d\n", argc);
+       while (argc > 1 && **(argv + 1) == '-') {
+               char *arg = *++argv;
+
+               --argc;
+               while (*++arg) {
+                       switch (*arg) {
+                       case 'f':               /* force */
+                               env_flag |= H_FORCE;
+                               break;
+                       default:
+                               return CMD_RET_USAGE;
+                       }
+               }
+       }
+       debug("Final value for argc=%d\n", argc);
        name = argv[1];
        value = argv[2];
 
@@ -214,7 +231,7 @@ static int _do_env_set(int flag, int argc, char * const argv[])
 
        /* Delete only ? */
        if (argc < 3 || argv[2] == NULL) {
-               int rc = hdelete_r(name, &env_htab, H_INTERACTIVE);
+               int rc = hdelete_r(name, &env_htab, env_flag);
                return !rc;
        }
 
@@ -241,7 +258,7 @@ static int _do_env_set(int flag, int argc, char * const argv[])
 
        e.key   = name;
        e.data  = value;
-       hsearch_r(e, ENTER, &ep, &env_htab, H_INTERACTIVE);
+       hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
        free(value);
        if (!ep) {
                printf("## Error inserting \"%s\" variable, errno=%d\n",
@@ -447,8 +464,11 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 static int print_static_flags(const char *var_name, const char *flags)
 {
        enum env_flags_vartype type = env_flags_parse_vartype(flags);
+       enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
 
-       printf("\t%-20s %-20s\n", var_name, env_flags_get_vartype_name(type));
+       printf("\t%-20s %-20s %-20s\n", var_name,
+               env_flags_get_vartype_name(type),
+               env_flags_get_varaccess_name(access));
 
        return 0;
 }
@@ -456,13 +476,17 @@ static int print_static_flags(const char *var_name, const char *flags)
 static int print_active_flags(ENTRY *entry)
 {
        enum env_flags_vartype type;
+       enum env_flags_varaccess access;
 
        if (entry->flags == 0)
                return 0;
 
        type = (enum env_flags_vartype)
                (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
-       printf("\t%-20s %-20s\n", entry->key, env_flags_get_vartype_name(type));
+       access = env_flags_parse_varaccess_from_binflags(entry->flags);
+       printf("\t%-20s %-20s %-20s\n", entry->key,
+               env_flags_get_vartype_name(type),
+               env_flags_get_varaccess_name(access));
 
        return 0;
 }
@@ -480,17 +504,29 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        env_flags_print_vartypes();
        puts("\n");
 
+       /* Print the available variable access types */
+       printf("Available variable access flags (position %d):\n",
+               ENV_FLAGS_VARACCESS_LOC);
+       puts("\tFlag\tVariable Access Name\n");
+       puts("\t----\t--------------------\n");
+       env_flags_print_varaccess();
+       puts("\n");
+
        /* Print the static flags that may exist */
        puts("Static flags:\n");
-       printf("\t%-20s %-20s\n", "Variable Name", "Variable Type");
-       printf("\t%-20s %-20s\n", "-------------", "-------------");
+       printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
+               "Variable Access");
+       printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
+               "---------------");
        env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
        puts("\n");
 
        /* walk through each variable and print the flags if non-default */
        puts("Active flags:\n");
-       printf("\t%-20s %-20s\n", "Variable Name", "Variable Type");
-       printf("\t%-20s %-20s\n", "-------------", "-------------");
+       printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
+               "Variable Access");
+       printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
+               "---------------");
        hwalk_r(&env_htab, print_active_flags);
        return 0;
 }
@@ -689,8 +725,36 @@ static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
                         int argc, char * const argv[])
 {
-       printf("Not implemented yet\n");
-       return 0;
+       int env_flag = H_INTERACTIVE;
+       int ret = 0;
+
+       debug("Initial value for argc=%d\n", argc);
+       while (argc > 1 && **(argv + 1) == '-') {
+               char *arg = *++argv;
+
+               --argc;
+               while (*++arg) {
+                       switch (*arg) {
+                       case 'f':               /* force */
+                               env_flag |= H_FORCE;
+                               break;
+                       default:
+                               return CMD_RET_USAGE;
+                       }
+               }
+       }
+       debug("Final value for argc=%d\n", argc);
+
+       env_id++;
+
+       while (--argc > 0) {
+               char *name = *++argv;
+
+               if (!hdelete_r(name, &env_htab, env_flag))
+                       ret = 1;
+       }
+
+       return ret;
 }
 
 #ifdef CONFIG_CMD_EXPORTENV
@@ -959,7 +1023,7 @@ static cmd_tbl_t cmd_env_sub[] = {
        U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
 #endif
        U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
-       U_BOOT_CMD_MKENT(delete, 2, 0, do_env_delete, "", ""),
+       U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
 #if defined(CONFIG_CMD_EDITENV)
        U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
 #endif
@@ -1024,6 +1088,7 @@ static char env_help_text[] =
 #endif
        "default [-f] -a - [forcibly] reset default environment\n"
        "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
+       "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
 #if defined(CONFIG_CMD_EDITENV)
        "env edit name - edit environment variable\n"
 #endif
@@ -1090,10 +1155,10 @@ U_BOOT_CMD_COMPLETE(
 U_BOOT_CMD_COMPLETE(
        setenv, CONFIG_SYS_MAXARGS, 0,  do_env_set,
        "set environment variables",
-       "name value ...\n"
-       "    - set environment variable 'name' to 'value ...'\n"
-       "setenv name\n"
-       "    - delete environment variable 'name'",
+       "[-f] name value ...\n"
+       "    - [forcibly] set environment variable 'name' to 'value ...'\n"
+       "setenv [-f] name\n"
+       "    - [forcibly] delete environment variable 'name'",
        var_complete
 );