env: common: accept flags on reset to default env

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>
diff --git a/env/common.c b/env/common.c
index 05183a4..1430100 100644
--- a/env/common.c
+++ b/env/common.c
@@ -58,22 +58,18 @@
 	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 @@
 		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 @@
 
 	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 @@
 	}
 
 	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 @@
 			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 @@
 	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();