2013-08-29 23:06:29 +00:00
|
|
|
From: Oliver Metz <oliver@freetz.org>
|
|
|
|
Subject: [PATCH v2 2/2] fw_env: fix writing environment for mtd devices
|
2013-07-02 23:08:17 +00:00
|
|
|
|
|
|
|
Signed-off-by: Oliver Metz <oliver@freetz.org>
|
2013-08-29 23:06:29 +00:00
|
|
|
Tested-by: Luka Perkov <luka@openwrt.org>
|
2013-07-02 23:08:17 +00:00
|
|
|
---
|
2013-08-29 23:06:29 +00:00
|
|
|
|
|
|
|
v1 -> v2:
|
|
|
|
* fix checkpatch.pl warnings
|
|
|
|
|
|
|
|
http://lists.denx.de/pipermail/u-boot/2013-August/161695.html
|
|
|
|
http://patchwork.ozlabs.org/patch/270994/
|
|
|
|
|
|
|
|
tools/env/fw_env.c | 70 ++++++++++++++++++++++++++++++++----------------------
|
|
|
|
1 file changed, 42 insertions(+), 28 deletions(-)
|
2013-07-02 23:08:17 +00:00
|
|
|
|
|
|
|
--- a/tools/env/fw_env.c
|
|
|
|
+++ b/tools/env/fw_env.c
|
|
|
|
@@ -743,27 +743,39 @@ static int flash_write_buf (int dev, int
|
|
|
|
MEMGETBADBLOCK needs 64 bits */
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
- blocklen = DEVESIZE (dev);
|
|
|
|
+ /*
|
|
|
|
+ * For mtd devices only offset and size of the environment do matter
|
|
|
|
+ */
|
|
|
|
+ if (mtd_type == MTD_ABSENT) {
|
|
|
|
+ blocklen = count;
|
|
|
|
+ top_of_range = offset + count;
|
|
|
|
+ erase_len = blocklen;
|
|
|
|
+ blockstart = offset;
|
|
|
|
+ block_seek = 0;
|
|
|
|
+ write_total = blocklen;
|
|
|
|
+ } else {
|
2013-08-29 23:06:29 +00:00
|
|
|
+ blocklen = DEVESIZE(dev);
|
2013-07-02 23:08:17 +00:00
|
|
|
|
|
|
|
- top_of_range = ((DEVOFFSET(dev) / blocklen) +
|
|
|
|
- ENVSECTORS (dev)) * blocklen;
|
|
|
|
+ top_of_range = ((DEVOFFSET(dev) / blocklen) +
|
2013-08-29 23:06:29 +00:00
|
|
|
+ ENVSECTORS(dev)) * blocklen;
|
2013-07-02 23:08:17 +00:00
|
|
|
|
|
|
|
- erase_offset = (offset / blocklen) * blocklen;
|
|
|
|
+ erase_offset = (offset / blocklen) * blocklen;
|
|
|
|
|
|
|
|
- /* Maximum area we may use */
|
|
|
|
- erase_len = top_of_range - erase_offset;
|
|
|
|
+ /* Maximum area we may use */
|
|
|
|
+ erase_len = top_of_range - erase_offset;
|
|
|
|
|
|
|
|
- blockstart = erase_offset;
|
|
|
|
- /* Offset inside a block */
|
|
|
|
- block_seek = offset - erase_offset;
|
|
|
|
+ blockstart = erase_offset;
|
|
|
|
+ /* Offset inside a block */
|
|
|
|
+ block_seek = offset - erase_offset;
|
|
|
|
|
|
|
|
- /*
|
|
|
|
- * Data size we actually have to write: from the start of the block
|
|
|
|
- * to the start of the data, then count bytes of data, and to the
|
|
|
|
- * end of the block
|
|
|
|
- */
|
|
|
|
- write_total = ((block_seek + count + blocklen - 1) /
|
|
|
|
- blocklen) * blocklen;
|
|
|
|
+ /*
|
|
|
|
+ * Data size we actually write: from the start of the block
|
2013-08-29 23:06:29 +00:00
|
|
|
+ * to the start of the data, then count bytes of data, and
|
|
|
|
+ * to the end of the block
|
2013-07-02 23:08:17 +00:00
|
|
|
+ */
|
|
|
|
+ write_total = ((block_seek + count + blocklen - 1) /
|
|
|
|
+ blocklen) * blocklen;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support data anywhere within erase sectors: read out the complete
|
|
|
|
@@ -834,17 +846,18 @@ static int flash_write_buf (int dev, int
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- erase.start = blockstart;
|
|
|
|
- ioctl (fd, MEMUNLOCK, &erase);
|
|
|
|
- /* These do not need an explicit erase cycle */
|
|
|
|
- if (mtd_type != MTD_ABSENT &&
|
|
|
|
- mtd_type != MTD_DATAFLASH)
|
|
|
|
- if (ioctl (fd, MEMERASE, &erase) != 0) {
|
|
|
|
- fprintf (stderr, "MTD erase error on %s: %s\n",
|
|
|
|
- DEVNAME (dev),
|
|
|
|
- strerror (errno));
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
+ if (mtd_type != MTD_ABSENT) {
|
|
|
|
+ erase.start = blockstart;
|
2013-08-29 23:06:29 +00:00
|
|
|
+ ioctl(fd, MEMUNLOCK, &erase);
|
2013-07-02 23:08:17 +00:00
|
|
|
+ /* These do not need an explicit erase cycle */
|
|
|
|
+ if (mtd_type != MTD_DATAFLASH)
|
2013-08-29 23:06:29 +00:00
|
|
|
+ if (ioctl(fd, MEMERASE, &erase) != 0) {
|
|
|
|
+ fprintf(stderr,
|
|
|
|
+ "MTD erase error on %s: %s\n",
|
|
|
|
+ DEVNAME(dev), strerror(errno));
|
2013-07-02 23:08:17 +00:00
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (lseek (fd, blockstart, SEEK_SET) == -1) {
|
|
|
|
fprintf (stderr,
|
2013-08-29 23:06:29 +00:00
|
|
|
@@ -863,7 +876,8 @@ static int flash_write_buf (int dev, int
|
2013-07-02 23:08:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-08-29 23:06:29 +00:00
|
|
|
|
2013-07-02 23:08:17 +00:00
|
|
|
- ioctl (fd, MEMLOCK, &erase);
|
|
|
|
+ if (mtd_type != MTD_ABSENT)
|
2013-08-29 23:06:29 +00:00
|
|
|
+ ioctl(fd, MEMLOCK, &erase);
|
2013-07-02 23:08:17 +00:00
|
|
|
|
|
|
|
processed += blocklen;
|
|
|
|
block_seek = 0;
|