Project

General

Profile

Testing ECC bitflip correction

The ECC algorithm for the 256MB nand part is BCH8, which means it can repair 8 bitflips per page. The 512MB and 1GB nand parts use BCH16, and so can repair 16 bitflips per page.
https://processors.wiki.ti.com/index.php/Raw_NAND_ECC#What_are_the_various_algorithms_and_the_differences_used_to_implement_ECC.3F

Manually creating bitflips in U-boot

Note: This requires a U-boot version with nand read.raw/write.raw, u-boot 2018 works

Reference: https://stackoverflow.com/a/44245633/780194

Below shows an example for the 512MB nand, but should work for other nand sizes if we leave page_addr at 0:

=> setenv ram_addr1 $loadaddr
=> setenv page_addr 0
=> setenv page_size 1000

# Make sure there is actually something in nand
=> nand erase.chip && mw.b $loadaddr ff 40000 &&  load mmc 0 $loadaddr MLO &&  nand write.i $loadaddr $page_addr $filesize

# Read one raw page
=> nand read.raw ${ram_addr1} ${page_addr} 1

# Clear x number of bits
=> mm $ram_addr1
83000000: 00000040 ?
...
83000018: 4e495454 ?
8300001c: 00005347 ?
83000020: ffffffff ? efffffff
83000024: ffffffff ? => <INTERRUPT>

# Write back page
=> nand write.raw ${ram_addr1} ${page_addr} 1

# Read the page
=> nand read ${ram_addr1} ${page_addr} ${page_size}

NAND read: device 0 offset 0x0, size 0x40000
 262144 bytes read: OK

# Verify flipped bit was corrected
=> md.l $ram_addr1 40
83000000: 00000040 0000000c 00000000 00000000    @...............
83000010: 00000000 45534843 4e495454 00005347    ....CHSETTINGS..
83000020: ffffffff ffffffff ffffffff ffffffff    ................
83000030: ffffffff ffffffff ffffffff ffffffff    ................

Make sure you try again with too many bitflips to make sure it fails

...
=> mm $ram_addr1
...
83000020: cccccccc ? 8ccccccc
83000024: ffffffff ? => <INTERRUPT>
=> nand write.raw ${ram_addr1} ${page_addr} 1

NAND write:  4320 bytes written: OK
=> nand read ${ram_addr1} ${page_addr} ${page_size}

NAND read: device 0 offset 0x0, size 0x40000
elm_config: 2
omap-elm: uncorrectable ECC errors
NAND read from offset 0 failed -74
 0 bytes read: ERROR

Manually creating bitflips in Linux

Below shows an example for the 512MB nand, but should work for other nand sizes:

# Ensure nand page is programmed with something
root@mitysom-335x:~# flash_erase /dev/mtd1 0 0
Erasing 256 Kibyte @ 0 -- 100 % complete
root@mitysom-335x:~# nandwrite -p /dev/mtd1 /run/media/mmcblk0p1/MLO
Writing data to block 0 at offset 0x0

# Test there are no bitflips to start
root@mitysom-335x:~# nanddump /dev/mtd1 -l 4096 > /dev/null
ECC failed: 0
ECC corrected: 0
Number of bad blocks: 0
Number of bbt blocks: 0
Block size 262144, page size 4096, OOB size 224
Dumping data starting at 0x00000000 and ending at 0x00001000...

# Dump raw nand page, length may change depending on page size of nand
root@mitysom-335x:~# nanddump --oob /dev/mtd0 -l 4096 -f nandpage.raw
ECC failed: 0
ECC corrected: 0
Number of bad blocks: 1
Number of bbt blocks: 0
Block size 262144, page size 4096, OOB size 224
Dumping data starting at 0x00000000 and ending at 0x00001000...

# Convert to hex
root@mitysom-335x:~# xxd nandpage.raw > nandpage.xxd

# Clear one or more bits in the hex output
# Note we are not doing a nand erase so it's not possible to change a bit from a zero to a one, so make sure to only clear bits
root@mitysom-335x:~# vi nandpage.xxd

# Convert back to binary
root@mitysom-335x:~# xxd -r nandpage.xxd nandpage.flipped

# Write back to nand
root@mitysom-335x:~# nandwrite --oob -noecc /dev/mtd1 nandpage.flipped
Writing data to block 0 at offset 0x0

root@mitysom-335x:~# nanddump /dev/mtd1 -l 4096 > /dev/null
ECC failed: 1
ECC corrected: 0
Number of bad blocks: 0
Number of bbt blocks: 0
Block size 262144, page size 4096, OOB size 224
Dumping data starting at 0x00000000 and ending at 0x00001000...
ECC: 1 corrected bitflip(s) at offset 0x00000000

Go to top
Add picture from clipboard (Maximum size: 1 GB)