MTD: Add __nand_calculate_ecc() to NAND ECC functions
Subsystems (2)
PATCH 1/2 MTD: Add __nand_calculate_ecc() to NAND ECC functions
Add __nand_calculate_ecc() which does not take struct mtd_info. The built-in 256/512 software ECC calculation and correction tester will use it.
--- drivers/mtd/nand/nand_ecc.c | 25 ++++++++++++++++++++----- include/linux/mtd/nand_ecc.h | 10 ++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-)
drivers/mtd/nand/nand_ecc.c +20 -5
@@ -150,20 +150,19 @@ static const char addressbits[256] = { };/** -* nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte +* __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte * block -* @mtd: MTD block structure * @buf: input buffer with raw data +* @eccsize: data bytes per ecc step (256 or 512) * @code: output buffer with ECC */ -int nand_calculate_ecc (struct mtd_info *mtd,const unsigned char *buf, +void __nand_calculate_ecc (const unsigned char *buf,unsigned int eccsize,unsigned char *code) {int i;const uint32_t *bp = (uint32_t *)buf;/* 256 or 512 bytes/ecc */ -const uint32_t eccsize_mult = - (((struct nand_chip *)mtd->priv)->ecc.size) >>8 ; +const uint32_t eccsize_mult = eccsize >>8 ;uint32_t cur;/* current value in buffer */ /* rp0..rp15..rp17 are the various accumulated parities (per byte) */ uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7;
@@ -412,6 +411,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf, (invparity[par &0x55 ] <<2 ) | (invparity[rp17] <<1 ) | (invparity[rp16] <<0 ); +} +EXPORT_SYMBOL (__nand_calculate_ecc); + +/** +* nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte +* block +* @mtd: MTD block structure +* @buf: input buffer with raw data +* @code: output buffer with ECC +*/ +int nand_calculate_ecc (struct mtd_info *mtd,const unsigned char *buf, +unsigned char *code) +{ +__nand_calculate_ecc (buf, + ((struct nand_chip *)mtd->priv)->ecc.size, code); +return 0 ; }EXPORT_SYMBOL (nand_calculate_ecc);
include/linux/mtd/nand_ecc.h +8 -2
@@ -16,7 +16,13 @@struct mtd_info ;/* -* Calculate 3 byte ECC code for 256 byte block +* Calculate 3 byte ECC code for eccsize byte block +*/ +void __nand_calculate_ecc (const u_char *dat,unsigned int eccsize, +u_char *ecc_code); + +/* +* Calculate 3 byte ECC code for 256/512 byte block */ int nand_calculate_ecc (struct mtd_info *mtd,const u_char *dat,u_char *ecc_code);
@@ -27,7 +33,7 @@ int __nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc, unsigned int eccsize);/* -* Detect and correct a 1 bit error for 256 byte block +* Detect and correct a 1 bit error for 256/512 byte block */ int nand_correct_data (struct mtd_info *mtd,u_char *dat,u_char *read_ecc,u_char *calc_ecc);
Signature · 1 line
1.5.4.3
PATCH 2/2 MTD: Add nand_ecc test module
This module tests NAND ECC functions.
The test is simple.
1. Create a 256 or 512 bytes block of data filled with random bytes (data)
2. Duplicate the data block and inject single bit error (error_data)
3. Try to correct error_data
4. Compare data and error_data
--- drivers/mtd/tests/Makefile | 1 + drivers/mtd/tests/mtd_nandecctest.c | 87 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/tests/mtd_nandecctest.c
drivers/mtd/tests/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_speedtest.o obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o +obj-$(CONFIG_MTD_TESTS) += mtd_nandecctest.o
drivers/mtd/tests/mtd_nandecctest.c new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
1.5.4.3
Please add my ack:
-vimal
Quoted 98 lines · Akinobu Mita
Add
__nand_calculate_ecc()which does not take structmtd_info. The built-in 256/512 software ECC calculation and correction tester will use it.Signed-off-by Akinobu Mita <[email protected]>Cc David Woodhouse <[email protected]>Cc Artem Bityutskiy <[email protected]>Cc vimal singh <[email protected]>---
drivers/mtd/nand/nand_ecc.c | 25 ++++++++++++++++++++-----include/linux/mtd/nand_ecc.h| 10 ++++++++--2 files changed, 28 insertions(+), 7 deletions(-)drivers/mtd/nand/nand_ecc.c +4
-5@@ -150,20 +150,19 @@ static const char addressbits[256] = { }; /** -* nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte +* __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte * block -* @mtd: MTD block structure * @buf: input buffer with raw data +* @eccsize: data bytes per ecc step (256 or 512) * @code: output buffer with ECC */ -int nand_calculate_ecc (struct mtd_info *mtd,const unsigned char *buf, +void __nand_calculate_ecc (const unsigned char *buf,unsigned int eccsize, unsigned char *code) { int i; const uint32_t *bp = (uint32_t *)buf; /* 256 or 512 bytes/ecc */ - const uint32_t eccsize_mult = - (((struct nand_chip *)mtd->priv)->ecc.size) >> 8; + const uint32_t eccsize_mult = eccsize >> 8;uint32_t cur; /* current value in buffer */
/* rp0..rp15..rp17 are the various accumulated parities (per byte) */uint32_trp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7;drivers/mtd/nand/nand_ecc.c +0
-0@@ -412,6 +411,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,(invparity[par &
0x55] << 2) |
(invparity[rp17] << 1) |
(invparity[rp16] << 0);drivers/mtd/nand/nand_ecc.c +16
-0+} +EXPORT_SYMBOL (__nand_calculate_ecc); + +/** +* nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte +* block +* @mtd: MTD block structure +* @buf: input buffer with raw data +* @code: output buffer with ECC +*/ +int nand_calculate_ecc (struct mtd_info *mtd,const unsigned char *buf, + unsigned char *code) +{ + __nand_calculate_ecc(buf, + ((struct nand_chip *)mtd->priv)->ecc.size, code); +return 0;
}
EXPORT_SYMBOL(nand_calculate_ecc);include/linux/mtd/nand_ecc.h +8
-3@@ -16,7 +16,13 @@ struct mtd_info; /* - * Calculate 3 byte ECC code for 256 byte block +* Calculate 3 byte ECC code for eccsize byte block +*/ +void __nand_calculate_ecc (const u_char *dat,unsigned int eccsize, + u_char *ecc_code); + +/* +* Calculate 3 byte ECC code for 256/512 byte block */ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);@@ -27,7 +33,7 @@ int __nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc, unsigned int eccsize); /* - * Detect and correct a 1 bit error for 256 byte block + * Detect and correct a 1 bit error for 256/512 byte block */ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc); --1.5.4.3
Quoted 3 lines · Vimal Singh
Please add my ack:
Acked-by Vimal Singh <[email protected]>
Yes, applied to my l2 tree and added your ack.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)