env: common: accept flags on reset to default env
authorYaniv Levinsky <yaniv.levinsky@compulab.co.il>
Sun, 24 Jun 2018 16:16:57 +0000 (19:16 +0300)
committerTom Rini <trini@konsulko.com>
Thu, 19 Jul 2018 20:17:58 +0000 (16:17 -0400)
The function set_default_env() sets the hashtable flags for import_r().
Formally set_default_env() doesn't accept flags from its callers. In
practice the caller can (un)set the H_INTERACTIVE flag, but it has to be
done using the first character of the function's string argument. Other
flags like H_FORCE can't be set by the caller.

Change the function to accept flags argument. The benefits are:
1. The caller will have to explicitly set the H_INTERACTIVE flag,
   instead of un-setting it using a special char in a string.
2. Add the ability to propagate flags from the caller to himport(),
   especially the H_FORCE flag from do_env_default() in nvedit.c that
   currently gets ignored for "env default -a -f" commands.
3. Flags and messages will not be coupled together. A caller will be
   able to set flags without passing a string and vice versa.

Please note:
The propagation of H_FORCE from do_env_default() does not introduce any
functional changes, because currently himport_r() is set to destroy the
old environment regardless if H_FORCE flag is set or not. More changes
are needed to utilize the propagation of H_FORCE.

Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il>
Acked-by: Igor Grinberg <grinberg@compulab.co.il>
13 files changed:
arch/arm/mach-imx/mx6/opos6ul.c
cmd/nvedit.c
common/board_r.c
common/spl/spl_dfu.c
env/common.c
env/ext4.c
env/fat.c
env/mmc.c
env/nand.c
env/sata.c
env/sf.c
env/ubi.c
include/environment.h

index af3384d..94a3d71 100644 (file)
@@ -127,7 +127,7 @@ int board_late_init(void)
 
        /* In bootstrap don't use the env vars */
        if (((reg & 0x3000000) >> 24) == 0x1) {
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
                env_set("preboot", "");
        }
 
index 8b73c60..796867c 100644 (file)
@@ -802,7 +802,8 @@ static int do_env_default(cmd_tbl_t *cmdtp, int flag,
        debug("Final value for argc=%d\n", argc);
        if (all && (argc == 0)) {
                /* Reset the whole environment */
-               set_default_env("## Resetting to default environment\n");
+               set_default_env("## Resetting to default environment\n",
+                               env_flag);
                return 0;
        }
        if (!all && (argc > 0)) {
index e9f827a..64f2574 100644 (file)
@@ -454,7 +454,7 @@ static int initr_env(void)
        if (should_load_env())
                env_relocate();
        else
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
 #ifdef CONFIG_OF_CONTROL
        env_set_addr("fdtcontroladdr", gd->fdt_blob);
 #endif
index b8e3a6c..01178f6 100644 (file)
@@ -38,7 +38,7 @@ int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr)
        int ret;
 
        /* set default environment */
-       set_default_env(0);
+       set_default_env(NULL, 0);
        str_env = env_get(dfu_alt_info);
        if (!str_env) {
                pr_err("\"dfu_alt_info\" env variable not defined!\n");
index 05183a4..1430100 100644 (file)
@@ -58,22 +58,18 @@ char *env_get_default(const char *name)
        return ret_val;
 }
 
-void set_default_env(const char *s)
+void set_default_env(const char *s, int flags)
 {
-       int flags = 0;
-
        if (sizeof(default_environment) > ENV_SIZE) {
                puts("*** Error - default environment is too large\n\n");
                return;
        }
 
        if (s) {
-               if (*s == '!') {
+               if ((flags & H_INTERACTIVE) == 0) {
                        printf("*** Warning - %s, "
-                               "using default environment\n\n",
-                               s + 1);
+                               "using default environment\n\n", s);
                } else {
-                       flags = H_INTERACTIVE;
                        puts(s);
                }
        } else {
@@ -117,7 +113,7 @@ int env_import(const char *buf, int check)
                memcpy(&crc, &ep->crc, sizeof(crc));
 
                if (crc32(0, ep->data, ENV_SIZE) != crc) {
-                       set_default_env("!bad CRC");
+                       set_default_env("bad CRC", 0);
                        return -EIO;
                }
        }
@@ -130,7 +126,7 @@ int env_import(const char *buf, int check)
 
        pr_err("Cannot import environment: errno = %d\n", errno);
 
-       set_default_env("!import failed");
+       set_default_env("import failed", 0);
 
        return -EIO;
 }
@@ -155,7 +151,7 @@ int env_import_redund(const char *buf1, int buf1_read_fail,
        }
 
        if (buf1_read_fail && buf2_read_fail) {
-               set_default_env("!bad env area");
+               set_default_env("bad env area", 0);
                return -EIO;
        } else if (!buf1_read_fail && buf2_read_fail) {
                gd->env_valid = ENV_VALID;
@@ -171,7 +167,7 @@ int env_import_redund(const char *buf1, int buf1_read_fail,
                        tmp_env2->crc;
 
        if (!crc1_ok && !crc2_ok) {
-               set_default_env("!bad CRC");
+               set_default_env("bad CRC", 0);
                return -EIO;
        } else if (crc1_ok && !crc2_ok) {
                gd->env_valid = ENV_VALID;
@@ -233,10 +229,10 @@ void env_relocate(void)
        if (gd->env_valid == ENV_INVALID) {
 #if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)
                /* Environment not changable */
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
 #else
                bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM);
-               set_default_env("!bad CRC");
+               set_default_env("bad CRC", 0);
 #endif
        } else {
                env_load();
index 7626784..09c5e4a 100644 (file)
@@ -119,7 +119,7 @@ static int env_ext4_load(void)
        return env_import(buf, 1);
 
 err_env_relocate:
-       set_default_env(NULL);
+       set_default_env(NULL, 0);
 
        return -EIO;
 }
index 5e5b1ef..7f74c64 100644 (file)
--- a/env/fat.c
+++ b/env/fat.c
@@ -122,7 +122,7 @@ static int env_fat_load(void)
        return env_import(buf, 1);
 
 err_env_relocate:
-       set_default_env(NULL);
+       set_default_env(NULL, 0);
 
        return -EIO;
 }
index 5e3da6d..c3cf35d 100644 (file)
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -155,19 +155,19 @@ static inline int mmc_set_env_part(struct mmc *mmc) {return 0; };
 static const char *init_mmc_for_env(struct mmc *mmc)
 {
        if (!mmc)
-               return "!No MMC card found";
+               return "No MMC card found";
 
 #if CONFIG_IS_ENABLED(BLK)
        struct udevice *dev;
 
        if (blk_get_from_parent(mmc->dev, &dev))
-               return "!No block device";
+               return "No block device";
 #else
        if (mmc_init(mmc))
-               return "!MMC init failed";
+               return "MMC init failed";
 #endif
        if (mmc_set_env_part(mmc))
-               return "!MMC partition switch failed";
+               return "MMC partition switch failed";
 
        return NULL;
 }
@@ -298,7 +298,7 @@ fini:
        fini_mmc_for_env(mmc);
 err:
        if (ret)
-               set_default_env(errmsg);
+               set_default_env(errmsg, 0);
 
 #endif
        return ret;
@@ -339,7 +339,7 @@ fini:
        fini_mmc_for_env(mmc);
 err:
        if (ret)
-               set_default_env(errmsg);
+               set_default_env(errmsg, 0);
 #endif
        return ret;
 }
index aecf445..3698e68 100644 (file)
@@ -327,7 +327,7 @@ static int env_nand_load(void)
        tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE);
        if (tmp_env1 == NULL || tmp_env2 == NULL) {
                puts("Can't allocate buffers for environment\n");
-               set_default_env("!malloc() failed");
+               set_default_env("malloc() failed", 0);
                ret = -EIO;
                goto done;
        }
@@ -366,14 +366,14 @@ static int env_nand_load(void)
        if (mtd && !get_nand_env_oob(mtd, &nand_env_oob_offset)) {
                printf("Found Environment offset in OOB..\n");
        } else {
-               set_default_env("!no env offset in OOB");
+               set_default_env("no env offset in OOB", 0);
                return;
        }
 #endif
 
        ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
        if (ret) {
-               set_default_env("!readenv() failed");
+               set_default_env("readenv() failed", 0);
                return -EIO;
        }
 
index e5715e6..59aedf4 100644 (file)
@@ -106,7 +106,7 @@ static void env_sata_load(void)
        }
 
        if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) {
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
                return -EIO;
        }
 
index 7f7f731..4945105 100644 (file)
--- a/env/sf.c
+++ b/env/sf.c
@@ -60,7 +60,7 @@ static int setup_flash_device(void)
        ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
                                     0, 0, &new);
        if (ret) {
-               set_default_env("!spi_flash_probe_bus_cs() failed");
+               set_default_env("spi_flash_probe_bus_cs() failed", 0);
                return ret;
        }
 
@@ -72,7 +72,7 @@ static int setup_flash_device(void)
                        CONFIG_ENV_SPI_CS,
                        CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
                if (!env_flash) {
-                       set_default_env("!spi_flash_probe() failed");
+                       set_default_env("spi_flash_probe() failed", 0);
                        return -EIO;
                }
        }
@@ -173,7 +173,7 @@ static int env_sf_load(void)
        tmp_env2 = (env_t *)memalign(ARCH_DMA_MINALIGN,
                        CONFIG_ENV_SIZE);
        if (!tmp_env1 || !tmp_env2) {
-               set_default_env("!malloc() failed");
+               set_default_env("malloc() failed", 0);
                ret = -EIO;
                goto out;
        }
@@ -268,7 +268,7 @@ static int env_sf_load(void)
 
        buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
        if (!buf) {
-               set_default_env("!malloc() failed");
+               set_default_env("malloc() failed", 0);
                return -EIO;
        }
 
@@ -279,7 +279,7 @@ static int env_sf_load(void)
        ret = spi_flash_read(env_flash,
                CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf);
        if (ret) {
-               set_default_env("!spi_flash_read() failed");
+               set_default_env("spi_flash_read() failed", 0);
                goto err_read;
        }
 
index d28247b..eb2346f 100644 (file)
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -114,7 +114,7 @@ static int env_ubi_load(void)
        if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) {
                printf("\n** Cannot find mtd partition \"%s\"\n",
                       CONFIG_ENV_UBI_PART);
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
                return -EIO;
        }
 
@@ -151,14 +151,14 @@ static int env_ubi_load(void)
        if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) {
                printf("\n** Cannot find mtd partition \"%s\"\n",
                       CONFIG_ENV_UBI_PART);
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
                return -EIO;
        }
 
        if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
                printf("\n** Unable to read env from %s:%s **\n",
                       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
-               set_default_env(NULL);
+               set_default_env(NULL, 0);
                return -EIO;
        }
 
index 2fe1f3e..5e90f15 100644 (file)
@@ -272,7 +272,7 @@ void env_crc_update(void);
 char *env_get_default(const char *name);
 
 /* [re]set to the default environment */
-void set_default_env(const char *s);
+void set_default_env(const char *s, int flags);
 
 /* [re]set individual variables to their value in the default environment */
 int set_default_vars(int nvars, char * const vars[], int flags);