Last active
August 27, 2019 22:12
-
-
Save pamolloy/9b21987c4c6033ece4ee23c4c50167cb to your computer and use it in GitHub Desktop.
U-Boot patch to exit userspace tools when an invalid CRC is found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 6482180e602c4853e43d5c5a40b3349b63aba276 Mon Sep 17 00:00:00 2001 | |
From: Philip Molloy <philip-molloy@idexx.com> | |
Date: Tue, 2 Apr 2019 17:02:48 -0400 | |
Subject: [PATCH 1/1] env: Exit tools when invalid CRC found | |
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@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment