
Dear Ivan Nardi,
In message AANLkTikV1wyzcjLr2lIr4cPAvf_vw-pnmO361mWk2_lL@mail.gmail.com you wrote:
I'am having a look at the ecc algorithms in nand code and I observe (both in kernel and in u-boot) that when ecc corrects some data, corrected data are given to the user, but the data storage in the nand do not change. In other words, I expected the flash would be written with the new (corrected) data.
Where exactly have you been looking? At plain simple NAND flash drivers? These provide only the lowest software layer to access NAND storage. Recovery from error situations like these requires a little more intelligence and is typically implemented in higer software layers.
Why data corrected by ecc are not rewrite to the flash?
I think that it should be easy achieve this goal. In the read function, if ecc corrects some data on a page, I read the entire block, erase it and write back (correct) data to the flash.
Such a simple approach would be way too dangerous. ECC errors are an indication that this sector has problems. But you can still read the data. What would you do if the write-back of the data fails? Now you still have the data, but where to store these if the original block cannot be written any more?
Nobody is interested in this feature? Or is it more difficult than I think?
It is more difficult than you think, but there is definitely interest in such things, and actually the problem has been solved a long time ago. The name of the solution is UBI. U-Boot supports UBI, so you just have to enable it in your board configuration.
Note that for reliable booting from NAND you want to read the U-Boot image from a (static) UBI volume, which is kind of challenging for the 1st stage NAND boot loader that usually must fit in very small memory such as 4 KiB or so.
Best regards,
Wolfgang Denk