Patchwork mtd-utils: handle non-power-of-2 erase size (E.G. for dataflash)

login
register
mail settings
Submitter Peter Korsgaard
Date Feb. 17, 2009, 2:03 p.m.
Message ID <1234879420-29736-1-git-send-email-jacmet@sunsite.dk>
Download mbox | patch
Permalink /patch/23256/
State New
Headers show

Comments

Peter Korsgaard - Feb. 17, 2009, 2:03 p.m.
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
---
 flashcp.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
Artem Bityutskiy - Feb. 17, 2009, 3:18 p.m.
On Tue, 2009-02-17 at 15:03 +0100, Peter Korsgaard wrote:
> Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>

Pushed, thanks.

Patch

diff --git a/flashcp.c b/flashcp.c
index 7f7764a..8775022 100644
--- a/flashcp.c
+++ b/flashcp.c
@@ -255,8 +255,9 @@  int main (int argc,char *argv[])
 #warning "Check for smaller erase regions"
 
 	erase.start = 0;
-	erase.length = filestat.st_size & ~(mtd.erasesize - 1);
-	if (filestat.st_size % mtd.erasesize) erase.length += mtd.erasesize;
+	erase.length = (filestat.st_size + mtd.erasesize - 1) / mtd.erasesize;
+	erase.length *= mtd.erasesize;
+
 	if (flags & FLAG_VERBOSE)
 	{
 		/* if the user wants verbose output, erase 1 block at a time and show him/her what's going on */