All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default()
@ 2018-06-24 16:16 Yaniv Levinsky
  2018-06-24 16:16 ` [U-Boot] [PATCH 1/4] cmd: nvedit: rename flags in do_env_default Yaniv Levinsky
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Yaniv Levinsky @ 2018-06-24 16:16 UTC (permalink / raw)
  To: u-boot

The function do_env_default() doesn't propagate flags to himport_r(). It causes
the "-f" option to have no effect on the execution of "env default" commands.

Fix the call paths from do_env_default() to himport_r() to pass flags correctly.

Yaniv Levinsky (4):
  cmd: nvedit: rename flags in do_env_default
  cmd: nvedit: propagate envflag to set_default_vars
  cmd: nvedit: set H_INTERACTIVE in do_env_default
  env: common: accept flags on reset to default env

 arch/arm/mach-imx/mx6/opos6ul.c |  2 +-
 cmd/nvedit.c                    | 11 ++++++-----
 common/board_r.c                |  2 +-
 common/spl/spl_dfu.c            |  2 +-
 env/common.c                    | 27 ++++++++++++---------------
 env/ext4.c                      |  2 +-
 env/fat.c                       |  2 +-
 env/mmc.c                       | 12 ++++++------
 env/nand.c                      |  6 +++---
 env/sata.c                      |  2 +-
 env/sf.c                        | 10 +++++-----
 env/ubi.c                       |  6 +++---
 include/environment.h           |  4 ++--
 13 files changed, 43 insertions(+), 45 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH 1/4] cmd: nvedit: rename flags in do_env_default
  2018-06-24 16:16 [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
@ 2018-06-24 16:16 ` Yaniv Levinsky
  2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
  2018-06-24 16:16 ` [U-Boot] [PATCH 2/4] cmd: nvedit: propagate envflag to set_default_vars Yaniv Levinsky
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Yaniv Levinsky @ 2018-06-24 16:16 UTC (permalink / raw)
  To: u-boot

The naming convention for flags in nvedit.c is:
* The hashtable flag (defined in search.h) is named "env_flag"
* The command flag argument (defined in command.h) is named "flag"

This convention is kept in functions like do_env_print(), do_env_set()
and do_env_delete(), but not in do_env_default().

Rename the hashtable flag in do_env_default() from "flag" to "env_flag".
Rename the command flag in do_env_default() from "__flag" to "flag".

No functional change.

Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il>
Reviewed-by: Igor Grinberg <grinberg@compulab.co.il>
---
 cmd/nvedit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index ddc888a4fd..d456d2fc9b 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -777,10 +777,10 @@ int envmatch(uchar *s1, int i2)
 }
 
 #ifndef CONFIG_SPL_BUILD
-static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
+static int do_env_default(cmd_tbl_t *cmdtp, int flag,
 			  int argc, char * const argv[])
 {
-	int all = 0, flag = 0;
+	int all = 0, env_flag = 0;
 
 	debug("Initial value for argc=%d\n", argc);
 	while (--argc > 0 && **++argv == '-') {
@@ -792,7 +792,7 @@ static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
 				all = 1;
 				break;
 			case 'f':		/* force */
-				flag |= H_FORCE;
+				env_flag |= H_FORCE;
 				break;
 			default:
 				return cmd_usage(cmdtp);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH 2/4] cmd: nvedit: propagate envflag to set_default_vars
  2018-06-24 16:16 [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
  2018-06-24 16:16 ` [U-Boot] [PATCH 1/4] cmd: nvedit: rename flags in do_env_default Yaniv Levinsky
@ 2018-06-24 16:16 ` Yaniv Levinsky
  2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
  2018-06-24 16:16 ` [U-Boot] [PATCH 3/4] cmd: nvedit: set H_INTERACTIVE in do_env_default Yaniv Levinsky
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Yaniv Levinsky @ 2018-06-24 16:16 UTC (permalink / raw)
  To: u-boot

The env_flag in do_env_default() doesn't get propagated and therefore
gets ignored by himport_r(). This breaks to ability to "forcibly" reset
variables to their default values using the environment command.

Scenario example of the problem:
	# setenv kernel uImage
	# setenv .flags kernel:so
	# env default -f kernel
	## Error: Can't overwrite "kernel"
	himport_r: can't insert "kernel=zImage" into hash table

Change the call path so it will pass the flag correctly.

Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il>
Acked-by: Igor Grinberg <grinberg@compulab.co.il>
---
 cmd/nvedit.c          | 2 +-
 env/common.c          | 5 +++--
 include/environment.h | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index d456d2fc9b..1955dee0d0 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -807,7 +807,7 @@ static int do_env_default(cmd_tbl_t *cmdtp, int flag,
 	}
 	if (!all && (argc > 0)) {
 		/* Reset individual variables */
-		set_default_vars(argc, argv);
+		set_default_vars(argc, argv, env_flag);
 		return 0;
 	}
 
diff --git a/env/common.c b/env/common.c
index dc8a14f519..6cf5eddaf6 100644
--- a/env/common.c
+++ b/env/common.c
@@ -91,15 +91,16 @@ void set_default_env(const char *s)
 
 
 /* [re]set individual variables to their value in the default environment */
-int set_default_vars(int nvars, char * const vars[])
+int set_default_vars(int nvars, char * const vars[], int flags)
 {
 	/*
 	 * Special use-case: import from default environment
 	 * (and use \0 as a separator)
 	 */
+	flags |= H_NOCLEAR | H_INTERACTIVE;
 	return himport_r(&env_htab, (const char *)default_environment,
 				sizeof(default_environment), '\0',
-				H_NOCLEAR | H_INTERACTIVE, 0, nvars, vars);
+				flags, 0, nvars, vars);
 }
 
 /*
diff --git a/include/environment.h b/include/environment.h
index 70b7eda428..2fe1f3eb48 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -275,7 +275,7 @@ char *env_get_default(const char *name);
 void set_default_env(const char *s);
 
 /* [re]set individual variables to their value in the default environment */
-int set_default_vars(int nvars, char * const vars[]);
+int set_default_vars(int nvars, char * const vars[], int flags);
 
 /* Import from binary representation into hash table */
 int env_import(const char *buf, int check);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH 3/4] cmd: nvedit: set H_INTERACTIVE in do_env_default
  2018-06-24 16:16 [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
  2018-06-24 16:16 ` [U-Boot] [PATCH 1/4] cmd: nvedit: rename flags in do_env_default Yaniv Levinsky
  2018-06-24 16:16 ` [U-Boot] [PATCH 2/4] cmd: nvedit: propagate envflag to set_default_vars Yaniv Levinsky
@ 2018-06-24 16:16 ` Yaniv Levinsky
  2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
  2018-06-24 16:16 ` [U-Boot] [PATCH 4/4] env: common: accept flags on reset to default env Yaniv Levinsky
  2018-07-11 15:21 ` [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
  4 siblings, 1 reply; 10+ messages in thread
From: Yaniv Levinsky @ 2018-06-24 16:16 UTC (permalink / raw)
  To: u-boot

The function set_default_vars() in common.c adds H_INTERACTIVE to the
h_import() flag, but the function has no way of telling if the command
actually was user directed like this flag suggest. The flag should be
set by the calling function do_env_default() in nvedit.c instead, where
the command is certainty user directed.

Move the H_INTERACTIVE flag from set_default_vars() to do_env_default().

Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il>
Acked-by: Igor Grinberg <grinberg@compulab.co.il>
---
 cmd/nvedit.c | 2 +-
 env/common.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 1955dee0d0..8b73c606ca 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -780,7 +780,7 @@ int envmatch(uchar *s1, int i2)
 static int do_env_default(cmd_tbl_t *cmdtp, int flag,
 			  int argc, char * const argv[])
 {
-	int all = 0, env_flag = 0;
+	int all = 0, env_flag = H_INTERACTIVE;
 
 	debug("Initial value for argc=%d\n", argc);
 	while (--argc > 0 && **++argv == '-') {
diff --git a/env/common.c b/env/common.c
index 6cf5eddaf6..05183a4af0 100644
--- a/env/common.c
+++ b/env/common.c
@@ -97,7 +97,7 @@ int set_default_vars(int nvars, char * const vars[], int flags)
 	 * Special use-case: import from default environment
 	 * (and use \0 as a separator)
 	 */
-	flags |= H_NOCLEAR | H_INTERACTIVE;
+	flags |= H_NOCLEAR;
 	return himport_r(&env_htab, (const char *)default_environment,
 				sizeof(default_environment), '\0',
 				flags, 0, nvars, vars);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH 4/4] env: common: accept flags on reset to default env
  2018-06-24 16:16 [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
                   ` (2 preceding siblings ...)
  2018-06-24 16:16 ` [U-Boot] [PATCH 3/4] cmd: nvedit: set H_INTERACTIVE in do_env_default Yaniv Levinsky
@ 2018-06-24 16:16 ` Yaniv Levinsky
  2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
  2018-07-11 15:21 ` [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
  4 siblings, 1 reply; 10+ messages in thread
From: Yaniv Levinsky @ 2018-06-24 16:16 UTC (permalink / raw)
  To: u-boot

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>
---
 arch/arm/mach-imx/mx6/opos6ul.c |  2 +-
 cmd/nvedit.c                    |  3 ++-
 common/board_r.c                |  2 +-
 common/spl/spl_dfu.c            |  2 +-
 env/common.c                    | 22 +++++++++-------------
 env/ext4.c                      |  2 +-
 env/fat.c                       |  2 +-
 env/mmc.c                       | 12 ++++++------
 env/nand.c                      |  6 +++---
 env/sata.c                      |  2 +-
 env/sf.c                        | 10 +++++-----
 env/ubi.c                       |  6 +++---
 include/environment.h           |  2 +-
 13 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/arch/arm/mach-imx/mx6/opos6ul.c b/arch/arm/mach-imx/mx6/opos6ul.c
index af3384d10e..94a3d71201 100644
--- a/arch/arm/mach-imx/mx6/opos6ul.c
+++ b/arch/arm/mach-imx/mx6/opos6ul.c
@@ -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", "");
 	}
 
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 8b73c606ca..796867c62c 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -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)) {
diff --git a/common/board_r.c b/common/board_r.c
index 6b297068bd..8495777953 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -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
diff --git a/common/spl/spl_dfu.c b/common/spl/spl_dfu.c
index b8e3a6c89e..01178f611f 100644
--- a/common/spl/spl_dfu.c
+++ b/common/spl/spl_dfu.c
@@ -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");
diff --git a/env/common.c b/env/common.c
index 05183a4af0..1430100c85 100644
--- a/env/common.c
+++ b/env/common.c
@@ -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();
diff --git a/env/ext4.c b/env/ext4.c
index 7626784ca6..09c5e4a491 100644
--- a/env/ext4.c
+++ b/env/ext4.c
@@ -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;
 }
diff --git a/env/fat.c b/env/fat.c
index 5e5b1efe89..7f74c64dfe 100644
--- 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;
 }
diff --git a/env/mmc.c b/env/mmc.c
index 5e3da6dca7..c3cf35d01b 100644
--- 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;
 }
diff --git a/env/nand.c b/env/nand.c
index aecf445c21..3698e68957 100644
--- a/env/nand.c
+++ b/env/nand.c
@@ -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;
 	}
 
diff --git a/env/sata.c b/env/sata.c
index e5715e6d51..59aedf4d76 100644
--- a/env/sata.c
+++ b/env/sata.c
@@ -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;
 	}
 
diff --git a/env/sf.c b/env/sf.c
index 7f7f731992..494510533a 100644
--- 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;
 	}
 
diff --git a/env/ubi.c b/env/ubi.c
index d28247b34d..eb2346f3a1 100644
--- 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;
 	}
 
diff --git a/include/environment.h b/include/environment.h
index 2fe1f3eb48..5e90f157e8 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -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);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default()
  2018-06-24 16:16 [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
                   ` (3 preceding siblings ...)
  2018-06-24 16:16 ` [U-Boot] [PATCH 4/4] env: common: accept flags on reset to default env Yaniv Levinsky
@ 2018-07-11 15:21 ` Yaniv Levinsky
  4 siblings, 0 replies; 10+ messages in thread
From: Yaniv Levinsky @ 2018-07-11 15:21 UTC (permalink / raw)
  To: u-boot

Gentle ping.

On 06/24/2018 07:16 PM, Yaniv Levinsky wrote:
> The function do_env_default() doesn't propagate flags to himport_r(). It causes
> the "-f" option to have no effect on the execution of "env default" commands.
> 
> Fix the call paths from do_env_default() to himport_r() to pass flags correctly.
> 
> Yaniv Levinsky (4):
>   cmd: nvedit: rename flags in do_env_default
>   cmd: nvedit: propagate envflag to set_default_vars
>   cmd: nvedit: set H_INTERACTIVE in do_env_default
>   env: common: accept flags on reset to default env
> 
>  arch/arm/mach-imx/mx6/opos6ul.c |  2 +-
>  cmd/nvedit.c                    | 11 ++++++-----
>  common/board_r.c                |  2 +-
>  common/spl/spl_dfu.c            |  2 +-
>  env/common.c                    | 27 ++++++++++++---------------
>  env/ext4.c                      |  2 +-
>  env/fat.c                       |  2 +-
>  env/mmc.c                       | 12 ++++++------
>  env/nand.c                      |  6 +++---
>  env/sata.c                      |  2 +-
>  env/sf.c                        | 10 +++++-----
>  env/ubi.c                       |  6 +++---
>  include/environment.h           |  4 ++--
>  13 files changed, 43 insertions(+), 45 deletions(-)
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [U-Boot, 1/4] cmd: nvedit: rename flags in do_env_default
  2018-06-24 16:16 ` [U-Boot] [PATCH 1/4] cmd: nvedit: rename flags in do_env_default Yaniv Levinsky
@ 2018-07-20 12:35   ` Tom Rini
  0 siblings, 0 replies; 10+ messages in thread
From: Tom Rini @ 2018-07-20 12:35 UTC (permalink / raw)
  To: u-boot

On Sun, Jun 24, 2018 at 07:16:54PM +0300, Yaniv Levinsky wrote:

> The naming convention for flags in nvedit.c is:
> * The hashtable flag (defined in search.h) is named "env_flag"
> * The command flag argument (defined in command.h) is named "flag"
> 
> This convention is kept in functions like do_env_print(), do_env_set()
> and do_env_delete(), but not in do_env_default().
> 
> Rename the hashtable flag in do_env_default() from "flag" to "env_flag".
> Rename the command flag in do_env_default() from "__flag" to "flag".
> 
> No functional change.
> 
> Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il>
> Reviewed-by: Igor Grinberg <grinberg@compulab.co.il>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180720/1ac43d72/attachment.sig>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [U-Boot, 2/4] cmd: nvedit: propagate envflag to set_default_vars
  2018-06-24 16:16 ` [U-Boot] [PATCH 2/4] cmd: nvedit: propagate envflag to set_default_vars Yaniv Levinsky
@ 2018-07-20 12:35   ` Tom Rini
  0 siblings, 0 replies; 10+ messages in thread
From: Tom Rini @ 2018-07-20 12:35 UTC (permalink / raw)
  To: u-boot

On Sun, Jun 24, 2018 at 07:16:55PM +0300, Yaniv Levinsky wrote:

> The env_flag in do_env_default() doesn't get propagated and therefore
> gets ignored by himport_r(). This breaks to ability to "forcibly" reset
> variables to their default values using the environment command.
> 
> Scenario example of the problem:
> 	# setenv kernel uImage
> 	# setenv .flags kernel:so
> 	# env default -f kernel
> 	## Error: Can't overwrite "kernel"
> 	himport_r: can't insert "kernel=zImage" into hash table
> 
> Change the call path so it will pass the flag correctly.
> 
> Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il>
> Acked-by: Igor Grinberg <grinberg@compulab.co.il>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180720/ead74cd0/attachment.sig>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [U-Boot, 3/4] cmd: nvedit: set H_INTERACTIVE in do_env_default
  2018-06-24 16:16 ` [U-Boot] [PATCH 3/4] cmd: nvedit: set H_INTERACTIVE in do_env_default Yaniv Levinsky
@ 2018-07-20 12:35   ` Tom Rini
  0 siblings, 0 replies; 10+ messages in thread
From: Tom Rini @ 2018-07-20 12:35 UTC (permalink / raw)
  To: u-boot

On Sun, Jun 24, 2018 at 07:16:56PM +0300, Yaniv Levinsky wrote:

> The function set_default_vars() in common.c adds H_INTERACTIVE to the
> h_import() flag, but the function has no way of telling if the command
> actually was user directed like this flag suggest. The flag should be
> set by the calling function do_env_default() in nvedit.c instead, where
> the command is certainty user directed.
> 
> Move the H_INTERACTIVE flag from set_default_vars() to do_env_default().
> 
> Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il>
> Acked-by: Igor Grinberg <grinberg@compulab.co.il>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180720/8430b79a/attachment.sig>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [U-Boot, 4/4] env: common: accept flags on reset to default env
  2018-06-24 16:16 ` [U-Boot] [PATCH 4/4] env: common: accept flags on reset to default env Yaniv Levinsky
@ 2018-07-20 12:35   ` Tom Rini
  0 siblings, 0 replies; 10+ messages in thread
From: Tom Rini @ 2018-07-20 12:35 UTC (permalink / raw)
  To: u-boot

On Sun, Jun 24, 2018 at 07:16:57PM +0300, Yaniv Levinsky wrote:

> 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>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180720/dac54b57/attachment.sig>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-07-20 12:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-24 16:16 [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky
2018-06-24 16:16 ` [U-Boot] [PATCH 1/4] cmd: nvedit: rename flags in do_env_default Yaniv Levinsky
2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
2018-06-24 16:16 ` [U-Boot] [PATCH 2/4] cmd: nvedit: propagate envflag to set_default_vars Yaniv Levinsky
2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
2018-06-24 16:16 ` [U-Boot] [PATCH 3/4] cmd: nvedit: set H_INTERACTIVE in do_env_default Yaniv Levinsky
2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
2018-06-24 16:16 ` [U-Boot] [PATCH 4/4] env: common: accept flags on reset to default env Yaniv Levinsky
2018-07-20 12:35   ` [U-Boot] [U-Boot, " Tom Rini
2018-07-11 15:21 ` [U-Boot] [PATCH 0/4] fix propagation of flags from do_env_default() Yaniv Levinsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.