[U-Boot] [PATCH] env: common: load read-only variables after reset

Yaniv Levinsky yaniv.levinsky at compulab.co.il
Fri Jul 27 15:34:44 UTC 2018


U-Boot fails to load read-only variables from storage after a reset. It
happens because the environment hash table prevents creating read-only
variables unless the H_FORCE flag is passed.

In the following example, the variable "test" is set to read-only in the
board header file (#define CONFIG_ENV_FLAGS_LIST_DEFAULT "test:sr"):

	U-Boot> printenv .flags
	.flags=test:sr
	U-Boot> setenv -f test 1
	U-Boot> printenv test
	test=1
	U-Boot> savee
	Saving Environment to SPI Flash
	...
	OK
	U-Boot> reset
	...
	Loading Environment from SPI Flash...
	## Error: Can't create "test"
	himport_r: can't insert "test=1" into hash table
	...
	U-Boot> printenv test
	## Error: "test" not defined

Pass the H_FORCE flag when importing the environment from storage.

Signed-off-by: Yaniv Levinsky <yaniv.levinsky at compulab.co.il>
---
 env/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/env/common.c b/env/common.c
index 3317cef355..de8dd47e9b 100644
--- a/env/common.c
+++ b/env/common.c
@@ -119,7 +119,7 @@ int env_import(const char *buf, int check)
 		}
 	}
 
-	if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, 0,
+	if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', H_FORCE, 0,
 			0, NULL)) {
 		gd->flags |= GD_FLG_ENV_READY;
 		return 0;
-- 
2.18.0



More information about the U-Boot mailing list