diff mbox

[U-Boot,v2,4/5] tools/env: compute size of usable area only once

Message ID 1461098623-5297-5-git-send-email-andreas.fenkart@digitalstrom.com
State Accepted
Commit f71cee4bfc9a8f9be40a49ec2da84f4344e398fc
Delegated to: Tom Rini
Headers show

Commit Message

Andreas Fenkart April 19, 2016, 8:43 p.m. UTC
for double buffering to work, redundant buffers must have equal size

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

Comments

Tom Rini May 30, 2016, 5:55 p.m. UTC | #1
On Tue, Apr 19, 2016 at 10:43:42PM +0200, Andreas Fenkart wrote:

> for double buffering to work, redundant buffers must have equal size
> 
> Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 1420855..15df5ad 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -75,7 +75,8 @@  static int dev_current;
 
 #define CUR_ENVSIZE ENVSIZE(dev_current)
 
-#define ENV_SIZE      getenvsize()
+static unsigned long usable_envsize;
+#define ENV_SIZE      usable_envsize
 
 struct env_image_single {
 	uint32_t	crc;	/* CRC32 over data bytes    */
@@ -124,18 +125,6 @@  static int parse_config (void);
 #if defined(CONFIG_FILE)
 static int get_config (char *);
 #endif
-static inline ulong getenvsize (void)
-{
-	ulong rc = CUR_ENVSIZE - sizeof(uint32_t);
-
-	if (HaveRedundEnv)
-		rc -= sizeof (char);
-
-	if (common_args.aes_flag)
-		rc &= ~(AES_KEY_LENGTH - 1);
-
-	return rc;
-}
 
 static char *skip_chars(char *s)
 {
@@ -953,7 +942,7 @@  static int flash_flag_obsolete (int dev, int fd, off_t offset)
 static int env_aes_cbc_crypt(char *payload, const int enc, uint8_t *key)
 {
 	uint8_t *data = (uint8_t *)payload;
-	const int len = getenvsize();
+	const int len = usable_envsize;
 	uint8_t key_exp[AES_EXPAND_KEY_LENGTH];
 	uint32_t aes_blocks;
 
@@ -1379,6 +1368,21 @@  static int parse_config ()
 			DEVNAME (1), strerror (errno));
 		return -1;
 	}
+
+	if (HaveRedundEnv && ENVSIZE(0) != ENVSIZE(1)) {
+		ENVSIZE(0) = ENVSIZE(1) = min(ENVSIZE(0), ENVSIZE(1));
+		fprintf(stderr,
+			"Redundant environments have inequal size, set to 0x%08lx\n",
+			ENVSIZE(1));
+	}
+
+	usable_envsize = CUR_ENVSIZE - sizeof(uint32_t);
+	if (HaveRedundEnv)
+		usable_envsize -= sizeof(char);
+
+	if (common_args.aes_flag)
+		usable_envsize &= ~(AES_KEY_LENGTH - 1);
+
 	return 0;
 }