[U-Boot] [RFC, PATCH v4 11/16] env: save a context immediately if 'autosave' variable is changed

AKASHI Takahiro takahiro.akashi at linaro.org
Wed Jul 17 08:25:20 UTC 2019


By definition, when any variable with VARSTORAGE_NON_VOLATILE_AUTOSAVE
is modified with env_save_ext(), the associated context should be written
back to storage immediately.

Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
 cmd/nvedit.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index cc80ba712767..9896a4141a2a 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -271,8 +271,27 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag,
 
 	/* Delete only ? */
 	if (argc < 3 || argv[2] == NULL) {
-		int rc = hdelete_r(name, &env_htab, env_flag);
-		return !rc;
+		uint32_t flags;
+
+		int rc = hdelete_ext(name, &env_htab, ctx, &flags, env_flag);
+		if (!rc) {
+			debug("Failed to delete from hash table\n");
+			return 1;
+		}
+
+		if (env_flags_parse_varstorage_from_binflags(flags)
+				== env_flags_varstorage_non_volatile_autosave) {
+			int ret;
+
+			ret = env_save_ext(ctx);
+			if (ret) {
+				printf("## Error saving variables, ret = %d\n",
+				       ret);
+				return 1;
+			}
+		}
+
+		return 0;
 	}
 
 	/*
@@ -307,6 +326,17 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag,
 		return 1;
 	}
 
+	if (env_flags_parse_varstorage_from_binflags(ep->flags)
+			== env_flags_varstorage_non_volatile_autosave) {
+		int ret;
+
+		ret = env_save_ext(ep->context);
+		if (ret) {
+			printf("## Error saving variables, ret = %d\n", ret);
+			return 1;
+		}
+	}
+
 	return 0;
 }
 
-- 
2.21.0



More information about the U-Boot mailing list