summaryrefslogtreecommitdiff
path: root/ubi-utils/src/nandcorr.c
diff options
context:
space:
mode:
authorFrank Haverkamp <haver@vnet.ibm.com>2007-11-24 11:04:51 +0100
committerFrank Haverkamp <haver@vnet.ibm.com>2007-11-24 11:04:51 +0100
commitec50ff6d648dee1f3024e1cbd23f1d1cec4944dc (patch)
treef1a9fcefd8a87025b781c835d7de09f88b6dc28d /ubi-utils/src/nandcorr.c
parent636524b9c8fa81d0c07f1f0bbf3ac9e5f6287247 (diff)
ubi-utils: nand2bin had ECC calculation problems
Fixed a problem when ECC was checked. The correction was not properly done by subpage. Added more output for the moment to be able to figure out more potential problems. Added testcase: bin2nand2bin.sh and biterror inject program inject_biterror.pl Interface o ECC correction disabled by default. Switch to turn it explicitly on. The user must specify what he wants to be done. Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
Diffstat (limited to 'ubi-utils/src/nandcorr.c')
-rw-r--r--ubi-utils/src/nandcorr.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/ubi-utils/src/nandcorr.c b/ubi-utils/src/nandcorr.c
index 7f1a547..caa07e2 100644
--- a/ubi-utils/src/nandcorr.c
+++ b/ubi-utils/src/nandcorr.c
@@ -36,8 +36,15 @@ static int countbits(uint32_t byte)
return res;
}
-int nand_correct_data(uint8_t *dat, const uint8_t *fail_ecc)
-
+/**
+ * @dat: data which should be corrected
+ * @read_ecc: ecc information read from flash
+ * @calc_ecc: calculated ecc information from the data
+ * @return: number of corrected bytes
+ * or -1 when no correction is possible
+ */
+int nand_correct_data(uint8_t *dat, const uint8_t *read_ecc,
+ const uint8_t *calc_ecc)
{
uint8_t s0, s1, s2;
@@ -47,9 +54,12 @@ int nand_correct_data(uint8_t *dat, const uint8_t *fail_ecc)
* Be careful, the index magic is due to a pointer to a
* uint32_t.
*/
- s0 = fail_ecc[1];
- s1 = fail_ecc[2];
- s2 = fail_ecc[3];
+ s0 = calc_ecc[0] ^ read_ecc[0];
+ s1 = calc_ecc[1] ^ read_ecc[1];
+ s2 = calc_ecc[2] ^ read_ecc[2];
+
+ if ((s0 | s1 | s2) == 0)
+ return 0;
/* Check for a single bit error */
if( ((s0 ^ (s0 >> 1)) & 0x55) == 0x55 &&