Good news!
The file
nand_ecc_rs.c indeed contains the algorithm used to compute the 4-bit ECC in /dev/mtd0. Using that, I have written a program that takes the output of
nanddump -n -s 0xa0000 -l 0x20000 /dev/mtd0 and successfully performs error correction, checksum validation and conversion to a newline-separated text file.
In the process of getting this done, however, I noticed that Marvell has been less than careful about licensing: the header in
nand_ecc_rs.c first claims that the file "contains an ECC algorithm from Toshiba that detects and corrects 1 bit errors in a 256 byte block of data," then goes on to say that the file is released under GPLv2 or later. However, the first claim is patently wrong: this is certainly not 1-bit ECC, it appears to me that the comment is there simply because it was in
nand_ecc.c and someone forgot to change it. The same applies to the comments at the top of the encode/decode functions: they are identical to their counterparts in
nand_ecc.c, and completely fail to properly describe the functions they supposedly document.
It seems to me to have been (very lightly) adapted from code available at The ECC Page (
http://www.eccpage.com/), as an illustration of a Reed-Solomon codec (
http://www.eccpage.com/rs.c). The program is distributed with the following notice:
Notice
--------
This program may be freely modified and/or given to whoever wants it.
A condition of such distribution is that the author's contribution be
acknowledged by his name being left in the comments heading the program,
however no responsibility is accepted for any financial or other loss which
may result from some unforseen errors or malfunctioning of the program
during use.
Simon Rockliff, 26th June 1991
So, as far as I can tell, Marvell is distributing this code in violation of the author's terms :-(
So, I'm off to write the textfile-to-checsummed-environment code! Stay tuned...