[U-Boot] [PATCH 1/1] env: Exit tools when invalid CRC found

Molloy, Philip Philip-Molloy at idexx.com
Wed Apr 3 13:30:47 UTC 2019


fw_setenv and fw_printenv currently print a warning and use a default
environment compiled into the binary when an invalid CRC is found. This
modifies the default behavior to print an error and exit. This is
especially important when calling the tools from a script since the
script depends on the exit code of the tool to know something went
wrong.

If the default environment is desired it should be read explicitly by
the caller. A better model is to store a default environment as a
separate binary or text file rather than storing it in the executable.

Signed-off-by: Philip Molloy <philip-molloy at idexx.com>
---
 tools/env/fw_env.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index a5d75958e1..ef33e9e1be 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1438,9 +1438,8 @@ int fw_env_open(struct env_opts *opts)
 	if (!have_redund_env) {
 		if (!crc0_ok) {
 			fprintf(stderr,
-				"Warning: Bad CRC, using default
environment\n");
-			memcpy(environment.data, default_environment,
-			       sizeof(default_environment));
+				"Invalid CRC found in environment\n");
+			return -1;
 		}
 	} else {
 		flag0 = *environment.flags;
@@ -1500,10 +1499,8 @@ int fw_env_open(struct env_opts *opts)
 			dev_current = 1;
 		} else if (!crc0_ok && !crc1_ok) {
 			fprintf(stderr,
-				"Warning: Bad CRC, using default
environment\n");
-			memcpy(environment.data, default_environment,
-			       sizeof(default_environment));
-			dev_current = 0;
+				"Invalid CRC found in both redundant
environments\n");
+			return -1;
 		} else {
 			switch (environment.flag_scheme) {
 			case FLAG_BOOLEAN:
-- 
2.20.1


More information about the U-Boot mailing list