[U-Boot] [PATCH] tools/env: check that redundant environments have equal size

Andreas Fenkart andreas.fenkart at digitalstrom.com
Thu May 19 12:43:51 CEST 2016


For double buffering to work, the target buffer must always be big
enough to hold all data. This can only be ensured if buffers are of
equal size, otherwise one must be smaller and we risk data loss
when copying from the bigger to the smaller.

Signed-off-by: Andreas Fenkart <andreas.fenkart at digitalstrom.com>
---
 tools/env/fw_env.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 06cf63d..60a7394 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1373,12 +1373,21 @@ static int parse_config ()
 		return -1;
 	}
 
-	if (HaveRedundEnv && stat (DEVNAME (1), &st)) {
-		fprintf (stderr,
-			"Cannot access MTD device %s: %s\n",
-			DEVNAME (1), strerror (errno));
-		return -1;
+	if (HaveRedundEnv) {
+		if (stat(DEVNAME(1), &st)) {
+			fprintf(stderr,
+				"Cannot access MTD device %s: %s\n",
+				DEVNAME(1), strerror(errno));
+			return -1;
+		}
+
+		if (ENVSIZE(0) != ENVSIZE(1)) {
+			fprintf(stderr,
+				"Redundant environments are not of equal size");
+			return -1;
+		}
 	}
+
 	return 0;
 }
 
-- 
2.8.1



More information about the U-Boot mailing list