mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support
@ 2016-04-11  8:28 Teresa Remmet
  2016-04-11  8:28 ` [PATCH 2/2] mtd: nand: omap_gpmc: Fix bitflips in empty page Teresa Remmet
  2016-04-12  6:16 ` [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Teresa Remmet @ 2016-04-11  8:28 UTC (permalink / raw)
  To: barebox

This has no users and seems to be untested. Removed it.

Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
---
 arch/arm/mach-omap/include/mach/gpmc_nand.h |  1 -
 drivers/bus/omap-gpmc.c                     |  3 ---
 drivers/mtd/nand/nand_omap_gpmc.c           | 36 +----------------------------
 3 files changed, 1 insertion(+), 39 deletions(-)

diff --git a/arch/arm/mach-omap/include/mach/gpmc_nand.h b/arch/arm/mach-omap/include/mach/gpmc_nand.h
index 8839486..c9730a9 100644
--- a/arch/arm/mach-omap/include/mach/gpmc_nand.h
+++ b/arch/arm/mach-omap/include/mach/gpmc_nand.h
@@ -32,7 +32,6 @@
 enum gpmc_ecc_mode {
 	OMAP_ECC_SOFT,
 	OMAP_ECC_HAMMING_CODE_HW_ROMCODE,
-	OMAP_ECC_BCH4_CODE_HW,
 	OMAP_ECC_BCH8_CODE_HW,
 	OMAP_ECC_BCH8_CODE_HW_ROMCODE,
 };
diff --git a/drivers/bus/omap-gpmc.c b/drivers/bus/omap-gpmc.c
index 8ae909a..be9ef92 100644
--- a/drivers/bus/omap-gpmc.c
+++ b/drivers/bus/omap-gpmc.c
@@ -446,9 +446,6 @@ static struct dt_eccmode modes[] = {
 		.name = "hw-romcode",
 		.mode = OMAP_ECC_HAMMING_CODE_HW_ROMCODE,
 	}, {
-		.name = "bch4",
-		.mode = OMAP_ECC_BCH4_CODE_HW,
-	}, {
 		.name = "bch8",
 		.mode = OMAP_ECC_BCH8_CODE_HW_ROMCODE,
 	},
diff --git a/drivers/mtd/nand/nand_omap_gpmc.c b/drivers/mtd/nand/nand_omap_gpmc.c
index a920522..1d1de5b 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -86,7 +86,6 @@
 #define GPMC_ECC_SIZE_CONFIG_ECCSIZE1(x)	((x) << 22)
 
 #define BCH8_MAX_ERROR	8	/* upto 8 bit correctable */
-#define BCH4_MAX_ERROR	4	/* upto 4 bit correctable */
 
 int omap_gpmc_decode_bch(int select_4_8, unsigned char *ecc, unsigned int *err_loc);
 
@@ -239,9 +238,6 @@ static int __omap_calculate_ecc(struct mtd_info *mtd, const uint8_t *dat,
 	int ecc_size = 8;
 
 	switch (oinfo->ecc_mode) {
-	case OMAP_ECC_BCH4_CODE_HW:
-		ecc_size = 4;
-		/* fall through */
 	case OMAP_ECC_BCH8_CODE_HW:
 	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
 		for (i = 0; i < 4; i++) {
@@ -300,24 +296,17 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
 	struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
 	int i, j, eccflag, count, totalcount, actual_eccsize;
 	unsigned int err_loc[8];
-	int select_4_8;
 
 	int eccsteps = oinfo->nand.ecc.steps;
 	int eccsize = oinfo->nand.ecc.bytes;
 
 	switch (oinfo->ecc_mode) {
-	case OMAP_ECC_BCH4_CODE_HW:
-		actual_eccsize = eccsize;
-		select_4_8 = 0;
-		break;
 	case OMAP_ECC_BCH8_CODE_HW:
 		eccsize /= eccsteps;
 		actual_eccsize = eccsize;
-		select_4_8 = 1;
 		break;
 	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
 		actual_eccsize = eccsize - 1;
-		select_4_8 = 1;
 		break;
 	default:
 		dev_err(oinfo->pdev, "invalid driver configuration\n");
@@ -344,7 +333,7 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
 
 		count = 0;
 		if (eccflag == 1) {
-			count = omap_gpmc_decode_bch(select_4_8, calc_ecc, err_loc);
+			count = omap_gpmc_decode_bch(1, calc_ecc, err_loc);
 			if (count < 0)
 				return count;
 			else
@@ -435,7 +424,6 @@ static int omap_correct_data(struct mtd_info *mtd, uint8_t *dat,
 	switch (oinfo->ecc_mode) {
 	case OMAP_ECC_HAMMING_CODE_HW_ROMCODE:
 		return omap_correct_hamming(mtd, dat, read_ecc, calc_ecc);
-	case OMAP_ECC_BCH4_CODE_HW:
 	case OMAP_ECC_BCH8_CODE_HW:
 	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
 		/*
@@ -463,17 +451,6 @@ static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
 	int cs = 0;
 
 	switch (oinfo->ecc_mode) {
-	case OMAP_ECC_BCH4_CODE_HW:
-		if (mode == NAND_ECC_READ) {
-			eccsize1 = 0xD; eccsize0 = 0x48;
-			bch_mod = 0;
-			bch_wrapmode = 0x09;
-		} else {
-			eccsize1 = 0x20; eccsize0 = 0x00;
-			bch_mod = 0;
-			bch_wrapmode = 0x06;
-		}
-		break;
 	case OMAP_ECC_BCH8_CODE_HW:
 	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
 		if (mode == NAND_ECC_READ) {
@@ -764,17 +741,6 @@ static int omap_gpmc_eccmode(struct gpmc_nand_info *oinfo,
 		omap_oobinfo.oobfree->length = minfo->oobsize -
 					offset - omap_oobinfo.eccbytes;
 		break;
-	case OMAP_ECC_BCH4_CODE_HW:
-		oinfo->nand.ecc.bytes    = 7;
-		oinfo->nand.ecc.size     = 512;
-		oinfo->nand.ecc.strength = BCH4_MAX_ERROR;
-		omap_oobinfo.oobfree->offset = offset;
-		omap_oobinfo.oobfree->length = minfo->oobsize -
-					offset - omap_oobinfo.eccbytes;
-		offset = minfo->oobsize - oinfo->nand.ecc.bytes;
-		for (i = 0; i < oinfo->nand.ecc.bytes; i++)
-			omap_oobinfo.eccpos[i] = i + offset;
-		break;
 	case OMAP_ECC_BCH8_CODE_HW:
 		oinfo->nand.ecc.bytes    = 13 * 4;
 		oinfo->nand.ecc.size     = 512 * 4;
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] mtd: nand: omap_gpmc: Fix bitflips in empty page
  2016-04-11  8:28 [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support Teresa Remmet
@ 2016-04-11  8:28 ` Teresa Remmet
  2016-04-12  6:16 ` [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Teresa Remmet @ 2016-04-11  8:28 UTC (permalink / raw)
  To: barebox

When using BCH8 decoding, bitflips in an empty page are
not checked. This can cause issues if UBI/UBIFS are used.
Extend the omap_correct_bch() function to check for them.

Code is based on linux mainline mtd/nand/omap2.c driver.

Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
---
 drivers/mtd/nand/nand_omap_gpmc.c | 62 ++++++++++++++++++++++++++-------------
 1 file changed, 42 insertions(+), 20 deletions(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c b/drivers/mtd/nand/nand_omap_gpmc.c
index 1d1de5b..a4e6452 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -87,6 +87,9 @@
 
 #define BCH8_MAX_ERROR	8	/* upto 8 bit correctable */
 
+static const uint8_t bch8_vector[] = {0xf3, 0xdb, 0x14, 0x16, 0x8b, 0xd2,
+		0xbe, 0xcc, 0xac, 0x6b, 0xff, 0x99, 0x7b};
+
 int omap_gpmc_decode_bch(int select_4_8, unsigned char *ecc, unsigned int *err_loc);
 
 static const char *ecc_mode_strings[] = {
@@ -294,8 +297,11 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
 {
 	struct nand_chip *nand = (struct nand_chip *)(mtd->priv);
 	struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
-	int i, j, eccflag, count, totalcount, actual_eccsize;
+	int i, j, eccflag, totalcount, actual_eccsize;
+	const uint8_t *erased_ecc_vec;
 	unsigned int err_loc[8];
+	int bitflip_count;
+	int bch_max_err;
 
 	int eccsteps = oinfo->nand.ecc.steps;
 	int eccsize = oinfo->nand.ecc.bytes;
@@ -304,9 +310,13 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
 	case OMAP_ECC_BCH8_CODE_HW:
 		eccsize /= eccsteps;
 		actual_eccsize = eccsize;
+		erased_ecc_vec = bch8_vector;
+		bch_max_err = BCH8_MAX_ERROR;
 		break;
 	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
 		actual_eccsize = eccsize - 1;
+		erased_ecc_vec = bch8_vector;
+		bch_max_err = BCH8_MAX_ERROR;
 		break;
 	default:
 		dev_err(oinfo->pdev, "invalid driver configuration\n");
@@ -316,37 +326,49 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
 	totalcount = 0;
 
 	for (i = 0; i < eccsteps; i++) {
-		/* check if any ecc error */
+		bool is_error_reported = false;
+		bitflip_count = 0;
 		eccflag = 0;
+
+		/* check for any ecc error */
 		for (j = 0; (j < actual_eccsize) && (eccflag == 0); j++) {
-			if (calc_ecc[j] != 0)
+			if (calc_ecc[j] != 0) {
 				eccflag = 1;
+				break;
+			}
 		}
 
 		if (eccflag == 1) {
-			eccflag = 0;
-			for (j = 0; (j < actual_eccsize) &&
-					(eccflag == 0); j++)
-				if (read_ecc[j] != 0xFF)
-					eccflag = 1;
+			if (memcmp(calc_ecc, erased_ecc_vec, actual_eccsize) == 0) {
+				/*
+				 * calc_ecc[] matches pattern for ECC
+				 * (all 0xff) so this is definitely
+				 * an erased-page
+				 */
+			} else {
+				bitflip_count = nand_check_erased_ecc_chunk(
+						dat, oinfo->nand.ecc.size, read_ecc,
+						eccsize, NULL, 0, bch_max_err);
+				if (bitflip_count < 0)
+					is_error_reported = true;
+			}
 		}
 
-		count = 0;
-		if (eccflag == 1) {
-			count = omap_gpmc_decode_bch(1, calc_ecc, err_loc);
-			if (count < 0)
-				return count;
-			else
-				totalcount += count;
-		}
+		if (is_error_reported) {
+			bitflip_count = omap_gpmc_decode_bch(1,
+					calc_ecc, err_loc);
+			if (bitflip_count < 0)
+				return bitflip_count;
 
-		for (j = 0; j < count; j++) {
-			if (err_loc[j] < 4096)
-				dat[err_loc[j] >> 3] ^=
+			for (j = 0; j < bitflip_count; j++) {
+				if (err_loc[j] < 4096)
+					dat[err_loc[j] >> 3] ^=
 						1 << (err_loc[j] & 7);
-			/* else, not interested to correct ecc */
+				/* else, not interested to correct ecc */
+			}
 		}
 
+		totalcount += bitflip_count;
 		calc_ecc = calc_ecc + actual_eccsize;
 		read_ecc = read_ecc + eccsize;
 		dat += 512;
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support
  2016-04-11  8:28 [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support Teresa Remmet
  2016-04-11  8:28 ` [PATCH 2/2] mtd: nand: omap_gpmc: Fix bitflips in empty page Teresa Remmet
@ 2016-04-12  6:16 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2016-04-12  6:16 UTC (permalink / raw)
  To: Teresa Remmet; +Cc: barebox

On Mon, Apr 11, 2016 at 10:28:23AM +0200, Teresa Remmet wrote:
> This has no users and seems to be untested. Removed it.
> 
> Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
> ---
>  arch/arm/mach-omap/include/mach/gpmc_nand.h |  1 -
>  drivers/bus/omap-gpmc.c                     |  3 ---
>  drivers/mtd/nand/nand_omap_gpmc.c           | 36 +----------------------------
>  3 files changed, 1 insertion(+), 39 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/mach-omap/include/mach/gpmc_nand.h b/arch/arm/mach-omap/include/mach/gpmc_nand.h
> index 8839486..c9730a9 100644
> --- a/arch/arm/mach-omap/include/mach/gpmc_nand.h
> +++ b/arch/arm/mach-omap/include/mach/gpmc_nand.h
> @@ -32,7 +32,6 @@
>  enum gpmc_ecc_mode {
>  	OMAP_ECC_SOFT,
>  	OMAP_ECC_HAMMING_CODE_HW_ROMCODE,
> -	OMAP_ECC_BCH4_CODE_HW,
>  	OMAP_ECC_BCH8_CODE_HW,
>  	OMAP_ECC_BCH8_CODE_HW_ROMCODE,
>  };
> diff --git a/drivers/bus/omap-gpmc.c b/drivers/bus/omap-gpmc.c
> index 8ae909a..be9ef92 100644
> --- a/drivers/bus/omap-gpmc.c
> +++ b/drivers/bus/omap-gpmc.c
> @@ -446,9 +446,6 @@ static struct dt_eccmode modes[] = {
>  		.name = "hw-romcode",
>  		.mode = OMAP_ECC_HAMMING_CODE_HW_ROMCODE,
>  	}, {
> -		.name = "bch4",
> -		.mode = OMAP_ECC_BCH4_CODE_HW,
> -	}, {
>  		.name = "bch8",
>  		.mode = OMAP_ECC_BCH8_CODE_HW_ROMCODE,
>  	},
> diff --git a/drivers/mtd/nand/nand_omap_gpmc.c b/drivers/mtd/nand/nand_omap_gpmc.c
> index a920522..1d1de5b 100644
> --- a/drivers/mtd/nand/nand_omap_gpmc.c
> +++ b/drivers/mtd/nand/nand_omap_gpmc.c
> @@ -86,7 +86,6 @@
>  #define GPMC_ECC_SIZE_CONFIG_ECCSIZE1(x)	((x) << 22)
>  
>  #define BCH8_MAX_ERROR	8	/* upto 8 bit correctable */
> -#define BCH4_MAX_ERROR	4	/* upto 4 bit correctable */
>  
>  int omap_gpmc_decode_bch(int select_4_8, unsigned char *ecc, unsigned int *err_loc);
>  
> @@ -239,9 +238,6 @@ static int __omap_calculate_ecc(struct mtd_info *mtd, const uint8_t *dat,
>  	int ecc_size = 8;
>  
>  	switch (oinfo->ecc_mode) {
> -	case OMAP_ECC_BCH4_CODE_HW:
> -		ecc_size = 4;
> -		/* fall through */
>  	case OMAP_ECC_BCH8_CODE_HW:
>  	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
>  		for (i = 0; i < 4; i++) {
> @@ -300,24 +296,17 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
>  	struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
>  	int i, j, eccflag, count, totalcount, actual_eccsize;
>  	unsigned int err_loc[8];
> -	int select_4_8;
>  
>  	int eccsteps = oinfo->nand.ecc.steps;
>  	int eccsize = oinfo->nand.ecc.bytes;
>  
>  	switch (oinfo->ecc_mode) {
> -	case OMAP_ECC_BCH4_CODE_HW:
> -		actual_eccsize = eccsize;
> -		select_4_8 = 0;
> -		break;
>  	case OMAP_ECC_BCH8_CODE_HW:
>  		eccsize /= eccsteps;
>  		actual_eccsize = eccsize;
> -		select_4_8 = 1;
>  		break;
>  	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
>  		actual_eccsize = eccsize - 1;
> -		select_4_8 = 1;
>  		break;
>  	default:
>  		dev_err(oinfo->pdev, "invalid driver configuration\n");
> @@ -344,7 +333,7 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
>  
>  		count = 0;
>  		if (eccflag == 1) {
> -			count = omap_gpmc_decode_bch(select_4_8, calc_ecc, err_loc);
> +			count = omap_gpmc_decode_bch(1, calc_ecc, err_loc);
>  			if (count < 0)
>  				return count;
>  			else
> @@ -435,7 +424,6 @@ static int omap_correct_data(struct mtd_info *mtd, uint8_t *dat,
>  	switch (oinfo->ecc_mode) {
>  	case OMAP_ECC_HAMMING_CODE_HW_ROMCODE:
>  		return omap_correct_hamming(mtd, dat, read_ecc, calc_ecc);
> -	case OMAP_ECC_BCH4_CODE_HW:
>  	case OMAP_ECC_BCH8_CODE_HW:
>  	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
>  		/*
> @@ -463,17 +451,6 @@ static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
>  	int cs = 0;
>  
>  	switch (oinfo->ecc_mode) {
> -	case OMAP_ECC_BCH4_CODE_HW:
> -		if (mode == NAND_ECC_READ) {
> -			eccsize1 = 0xD; eccsize0 = 0x48;
> -			bch_mod = 0;
> -			bch_wrapmode = 0x09;
> -		} else {
> -			eccsize1 = 0x20; eccsize0 = 0x00;
> -			bch_mod = 0;
> -			bch_wrapmode = 0x06;
> -		}
> -		break;
>  	case OMAP_ECC_BCH8_CODE_HW:
>  	case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
>  		if (mode == NAND_ECC_READ) {
> @@ -764,17 +741,6 @@ static int omap_gpmc_eccmode(struct gpmc_nand_info *oinfo,
>  		omap_oobinfo.oobfree->length = minfo->oobsize -
>  					offset - omap_oobinfo.eccbytes;
>  		break;
> -	case OMAP_ECC_BCH4_CODE_HW:
> -		oinfo->nand.ecc.bytes    = 7;
> -		oinfo->nand.ecc.size     = 512;
> -		oinfo->nand.ecc.strength = BCH4_MAX_ERROR;
> -		omap_oobinfo.oobfree->offset = offset;
> -		omap_oobinfo.oobfree->length = minfo->oobsize -
> -					offset - omap_oobinfo.eccbytes;
> -		offset = minfo->oobsize - oinfo->nand.ecc.bytes;
> -		for (i = 0; i < oinfo->nand.ecc.bytes; i++)
> -			omap_oobinfo.eccpos[i] = i + offset;
> -		break;
>  	case OMAP_ECC_BCH8_CODE_HW:
>  		oinfo->nand.ecc.bytes    = 13 * 4;
>  		oinfo->nand.ecc.size     = 512 * 4;
> -- 
> 1.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-12  6:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-11  8:28 [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support Teresa Remmet
2016-04-11  8:28 ` [PATCH 2/2] mtd: nand: omap_gpmc: Fix bitflips in empty page Teresa Remmet
2016-04-12  6:16 ` [PATCH 1/2] mtd: nand: omap_gpmc: Remove BCH4 support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox