[U-Boot] [PATCH] tools/env: fix environment alignment tests for block devices

Max Krummenacher max.oss.09 at gmail.com
Fri Nov 18 11:38:43 CET 2016


commit 183923d3e412500bdc597d1745e2fb6f7f679ec7 enforces that the
environment must start at an erase block boundary.

For block devices the sample fw_env.config does not mandate a erase block size
for block devices. A missing setting defaults to the full env size.

Depending on the environment location the alignment check now errors out for
perfectly legal settings.

Fix this by defaulting to the standard blocksize of 0x200 for environments
stored in a block device.
That keeps the fw_env.config files for block devices working even with that
new check.

Signed-off-by: Max Krummenacher <max.krummenacher at toradex.com>
---

 tools/env/fw_env.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 3dc0d53..f2126f8 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1335,10 +1335,25 @@ static int check_device_config(int dev)
 			goto err;
 		}
 		DEVTYPE(dev) = mtdinfo.type;
+		if (DEVESIZE(dev) == -1) {
+			/* Assume the erase size is the same as the env-size */
+			DEVESIZE(dev) = ENVSIZE(dev);
+			/* Assume enough env sectors to cover the environment */
+			ENVSECTORS(dev) = (ENVSIZE(dev) + DEVESIZE(dev) - 1) /
+					   DEVESIZE(dev);
+		}
 	} else {
 		uint64_t size;
 		DEVTYPE(dev) = MTD_ABSENT;
 
+		if (DEVESIZE(dev) == -1) {
+			/* Assume the erase size to be 512 bytes */
+			DEVESIZE(dev) = 0x200;
+			/* Assume enough env sectors to cover the environment */
+			ENVSECTORS(dev) = (ENVSIZE(dev) + DEVESIZE(dev) - 1) /
+					   DEVESIZE(dev);
+		}
+
 		/*
 		 * Check for negative offsets, treat it as backwards offset
 		 * from the end of the block device
@@ -1467,10 +1482,9 @@ static int get_config (char *fname)
 		DEVNAME(i) = devname;
 
 		if (rc < 4)
-			/* Assume the erase size is the same as the env-size */
-			DEVESIZE(i) = ENVSIZE(i);
-
-		if (rc < 5)
+			/* Fixup later depending on DEVTYPE */
+			DEVESIZE(i) = -1;
+		else if (rc < 5)
 			/* Assume enough env sectors to cover the environment */
 			ENVSECTORS (i) = (ENVSIZE(i) + DEVESIZE(i) - 1) / DEVESIZE(i);
 
-- 
2.5.5



More information about the U-Boot mailing list