Skip to contentSkip to conversation

Possible bug in NAND driver

U-Boot New Paulraj 3 participants 6 messages Jul 13, 2009 – Jul 17, 2009

Subsystems (2)
lore
Share & tools
lore

Paulraj

#0 lore raw

If we refer to the following code snippet from nand_util.c

rval = nand_read (nand, offset, &read_length, p_buffer);

                if (rval != 0) {

                          printf ("NAND read from offset %llx failed %d\n",

                                  offset, rval);

                         *length -= left_to_read;

                          return rval;

                  }

The above code will return failure even after ECC errors are corrected.

This is because of the following line of code in nand_base.c

return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;

This is in the nand_do_read_ops in nand_bsae.c

I see that changing

if (rval != 0)

to

if (rval != 0 && rval != -EUCLEAN )

solves the problem.

I can submit a patch if required.

Thanks,
Sandeep

#1 lore raw

You are right, this is a bug.

I've already fixed it in our code tree some monthes ago but forgotten to send the patch to the list.

Best regards,
Valeriy Glushkov

----- Original Message -----
From: "Paulraj, Sandeep" <[email protected]>
To: <[email protected]>
Sent: 13 ???? 2009 ?. 22:34
Subject: [U-Boot] Possible bug in NAND driver

Quoted 49 lines

If we refer to the following code snippet from nand_util.c

rval = nand_read (nand, offset, &read_length, p_buffer);

               if (rval != 0) {

                         printf ("NAND read from offset %llx failed %d\n",

                                 offset, rval);

                        *length -= left_to_read;

                         return rval;

                 }

The above code will return failure even after ECC errors are corrected.

This is because of the following line of code in nand_base.c

return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;

This is in the nand_do_read_ops in nand_bsae.c

I see that changing

if (rval != 0)

to

if (rval != 0 && rval != -EUCLEAN )

solves the problem.

I can submit a patch if required.

Thanks,
Sandeep

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#2 lore raw

PATCH 1/1 nand: fixed failed reads on corrected ECC errors in nand_util.c

---
 drivers/mtd/nand/nand_util.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_util.c +5 -5
index fc16282..694ead6 100644
@@ -567,10 +567,10 @@ int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 
 	if (len_incl_bad == *length) {
 		rval = nand_read (nand, offset, length, buffer);
-		if (rval != 0)
-			printf ("NAND read from offset %llx failed %d\n",
-				offset, rval);
-
+		if (!rval || rval == -EUCLEAN)
+			return 0;
+		printf ("NAND read from offset %llx failed %d\n",
+			offset, rval);
 		return rval;
 	}
 
@@ -591,7 +591,7 @@ int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 			read_length = nand->erasesize - block_offset;
 
 		rval = nand_read (nand, offset, &read_length, p_buffer);
-		if (rval != 0) {
+		if (rval && rval != -EUCLEAN) {
 			printf ("NAND read from offset %llx failed %d\n",
 				offset, rval);
 			*length -= left_to_read;
Signature · 1 line
1.5.2.5
#3 lore raw

PATCH 1/1 nand: fixed failed reads on corrected ECC errors in nand_util.c

Quoted 4 lines · Valeriy Glushkov

---

Applied to u-boot-nand-flash.

Quoted 9 lines
 drivers/mtd/nand/nand_util.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_util.c +0 -0
index fc16282..694ead6 100644
@@ -567,10 +567,10 @@ int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
 

drivers/mtd/nand/nand_util.c int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, · line 573

Quoted 10 lines
drivers/mtd/nand/nand_util.c +4 -4
 	if (len_incl_bad == *length) {
 		rval = nand_read (nand, offset, length, buffer);
-		if (rval != 0)
-			printf ("NAND read from offset %llx failed %d\n",
-				offset, rval);
-
+		if (!rval || rval == -EUCLEAN)
+			return 0;
+		printf ("NAND read from offset %llx failed %d\n",
+			offset, rval);

Out of curiosity, why invert the logic from if (error) print; return to if (!error) return; print; return?

-Scott

#4 lore raw

PATCH 1/1 nand: fixed failed reads on corrected ECC errors in nand_util.c

Hi Scott,

Quoted 11 lines
Quoted 10 lines

if (len_incl_bad == *length) {
rval = nand_read (nand, offset, length, buffer);
- if (rval != 0)
- printf ("NAND read from offset %llx failed %d\n",
- offset, rval);
-
+ if (!rval || rval == -EUCLEAN)
+ return 0;
+ printf ("NAND read from offset %llx failed %d\n",
+ offset, rval);

Quoted 2 lines

Out of curiosity, why invert the logic from if (error) print; return to if (!error) return; print; return?

Because it looks a bit better for me than 2 other versions. And saves a line. :)
-------
if (!rval || rval == -EUCLEAN)
return 0;
printf ("NAND read from offset %llx failed %d\n",
offset, rval);
return rval;
--------
if (rval && rval != -EUCLEAN) {
printf ("NAND read from offset %llx failed %d\n",
offset, rval);
return rval;
}
return 0;
-------

if (rval && rval != -EUCLEAN)
printf ("NAND read from offset %llx failed %d\n",
offset, rval);
else
rval = 0;
return rval;
--------

Best regards,
Valeriy Glushkov

#5 lore raw
In reply to Paulraj
Quoted 5 lines · Sandeep

I see that changing

if (rval != 0)

Quoted 8 lines

to

if (rval != 0 && rval != -EUCLEAN )

solves the problem.

I can submit a patch if required.

Yes, please submit a patch. Thanks!

-Scott