flashcp

Jörn Engel joern at logfs.org
Thu Jul 19 15:56:38 EDT 2007


On Thu, 19 July 2007 20:46:46 +0200, Tobias Simon wrote:
> 
> I am new in this list.
> Today I found a bug in the flashcp program of the mtd-utils:
> 
> In Line 260 of flashcp.c, the following operation is performed:
> 
> erase.length = filestat.st_size & ~(mtd.erasesize - 1);
> 
> I think that is not correct, because if mtd.erasesize is not a power of 2, 
> using a bitmask is wrong. ARM dataflash, for instance has a erasesize of 
> 1056. My suggestion is the following code replacement, which uses modular 
> arithmetics:
> 
> if (filestat.st_size <= mtd.erasesize)
> {
>    erase.length = mtd.erasesize;
> }
> else
> {
>    erase.length = filestat.st_size + mtd.erasesize - (filestat.st_size % 
> mtd.erasesize);
> }
> 
> What's your opinion?

Many-fold.

1. You're off-by-one when (filestat.st_size % mtd.erasesize) yields
zero.

2. In principle the "patch" looks fine.  Except that it should be a
patch and probably follow kernel coding style or something similar.

3. I keep wondering whether the oddball erasesize of dataflash makes
sense.  Why did they pick 1056, the exact size of two 512 Byte nand
pages with the standard 16 Bytes of OOB each?  Could they need ECC as
well and should the "spare" 32 bytes be used for that instead?

Jörn

-- 
Fools ignore complexity.  Pragmatists suffer it.
Some can avoid it.  Geniuses remove it.
-- Perlis's Programming Proverb #58, SIGPLAN Notices, Sept.  1982



More information about the linux-mtd mailing list