How to write to nand with an image containing oob data, including ECC?

Ricard Wanderlof ricard.wanderlof at axis.com
Tue Mar 29 11:30:21 EDT 2011


Hi,

In order to test an ECC algorithm (BCH in this case, as I recently posted 
about), i want to write an image to a nand flash which contains bit 
errors.

What I want to do, and I seem to remember doing this in the past, is to 
dump the whole image, change a single bit, and write it back, including 
the oob.

So what I'm doing is

$ nandwrite -o -n /dev/mtd3 /tmp/mtd3-badimage

where /tmp/mtd3-badimage contains an image including all oobs for all 
pages.

However, this fails saying

Writing data to block 0 at offset 0x0
libmtd: error!: cannot write 2048 bytes to mtd3 (eraseblock 0, offset 0)
         error 22 (Invalid argument)
nandwrite: error!: /dev/mtd3: MTD write failure
            error 22 (Invalid argument)
Data was only partially written due to error
: Invalid argument

Using just -o doesn't work because it seems nandwrite writes the oob, but 
then since it doesn't write the main page in raw mode, the ecc gets 
overwritten. Strangely enough, the ECC doesn't seem to match the data 
written, as I get uncorrectable errors when reading back (not just with 
BCH, but also with the standard mtd built-in algorithm). Perhaps the oob 
gets written twice, once with my data and once more with the calculated 
ecc?

Is this a known bug, or are the some other options I should be using?

nandwrite is the latest from the git repository.

The kernel version I'm using is 2.6.35 .

/Ricard
-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30



More information about the linux-mtd mailing list