public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] tools/env: fix environment alignment tests for block devices
@ 2016-11-18 10:38 Max Krummenacher
  2016-11-18 13:26 ` Andreas Fenkart
  0 siblings, 1 reply; 3+ messages in thread
From: Max Krummenacher @ 2016-11-18 10:38 UTC (permalink / raw)
  To: u-boot

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@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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-19 12:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-18 10:38 [U-Boot] [PATCH] tools/env: fix environment alignment tests for block devices Max Krummenacher
2016-11-18 13:26 ` Andreas Fenkart
2016-11-19 12:52   ` Max Krummenacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox