U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] Suspected Spam: Do not open attachements![PATCH 4/6] tools/env: flash_write_buf: enforce offset to be start of environment
Date: Mon, 29 Aug 2016 23:17:00 +0200	[thread overview]
Message-ID: <1472505422-26122-5-git-send-email-andreas.fenkart@digitalstrom.com> (raw)
In-Reply-To: <1472505422-26122-1-git-send-email-andreas.fenkart@digitalstrom.com>

This allows to take advantage of the environment being block aligned.
This is not a new constraint. Writes always start at the begin of the
environment, since the header with CRC/length as there.
Every environment modification requires updating the header

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

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 0f0eaa4..3dc0d53 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -765,12 +765,12 @@ static int flash_read_buf (int dev, int fd, void *buf, size_t count,
 }
 
 /*
- * Write count bytes at offset, but stay within ENVSECTORS (dev) sectors of
+ * Write count bytes from begin of environment, but stay within
+ * ENVSECTORS(dev) sectors of
  * DEVOFFSET (dev). Similar to the read case above, on NOR and dataflash we
  * erase and write the whole data at once.
  */
-static int flash_write_buf (int dev, int fd, void *buf, size_t count,
-			    off_t offset)
+static int flash_write_buf(int dev, int fd, void *buf, size_t count)
 {
 	void *data;
 	struct erase_info_user erase;
@@ -796,20 +796,21 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count,
 	if (DEVTYPE(dev) == MTD_ABSENT) {
 		blocklen = count;
 		erase_len = blocklen;
-		blockstart = offset;
+		blockstart = DEVOFFSET(dev);
 		block_seek = 0;
 		write_total = blocklen;
 	} else {
 		blocklen = DEVESIZE(dev);
 
-		erase_offset = (offset / blocklen) * blocklen;
+		erase_offset = DEVOFFSET(dev);
 
 		/* Maximum area we may use */
 		erase_len = environment_end(dev) - erase_offset;
 
 		blockstart = erase_offset;
+
 		/* Offset inside a block */
-		block_seek = offset - erase_offset;
+		block_seek = DEVOFFSET(dev) - erase_offset;
 
 		/*
 		 * Data size we actually write: from the start of the block
@@ -1007,7 +1008,7 @@ static int flash_write (int fd_current, int fd_target, int dev_target)
 #endif
 
 	rc = flash_write_buf(dev_target, fd_target, environment.image,
-			     CUR_ENVSIZE, DEVOFFSET(dev_target));
+			     CUR_ENVSIZE);
 	if (rc < 0)
 		return rc;
 
-- 
2.8.1

  parent reply	other threads:[~2016-08-29 21:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-29 21:16 [U-Boot] [PATCH 0/6] tools/env: refactor flash read/write function Andreas Fenkart
2016-08-29 21:16 ` [U-Boot] [PATCH 1/6] tools/env: factor out environment_end function Andreas Fenkart
2016-10-08 17:04   ` [U-Boot] [U-Boot, " Tom Rini
2016-08-29 21:16 ` [U-Boot] [PATCH 2/6] tools/env: pass bad block offset by value Andreas Fenkart
2016-10-08 17:04   ` [U-Boot] [U-Boot, " Tom Rini
2016-08-29 21:16 ` [U-Boot] [PATCH 3/6] tools/env: lookup dev_type directly from flash_read_buf/flash_write_buf Andreas Fenkart
2016-10-08 17:04   ` [U-Boot] [U-Boot, " Tom Rini
2016-08-29 21:17 ` Andreas Fenkart [this message]
2016-10-08 17:04   ` [U-Boot] Suspected Spam: Do not open attachements![PATCH 4/6] tools/env: flash_write_buf: enforce offset to be start of environment Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472505422-26122-5-git-send-email-andreas.fenkart@digitalstrom.com \
    --to=andreas.fenkart@digitalstrom.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox