public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed)
@ 2008-10-21  6:11 Du Zhongdong
  2008-10-21  6:21 ` Artem Bityutskiy
  2008-10-21  6:50 ` Ricard Wanderlof
  0 siblings, 2 replies; 6+ messages in thread
From: Du Zhongdong @ 2008-10-21  6:11 UTC (permalink / raw)
  To: linux-mtd

Hi,

I'm doing a NAND flash driver, and I suppose if ecc cannot be
corrected while read something from NAND flash, that block should be
marked bad, is that right?

Reading through nand_base.c I notice that mtd->read = nand_read;
nand_read() [MTD Interface] calls nand_do_read_ops() [Internal] to do
the work,  and in nand_do_read_ops():
        if (mtd->ecc_stats.failed - stats.failed)
		return -EBADMSG;
-EBADMSG then is returned to the MTD layer. I tried to trace this
information in the MTD code, but there seems to be so many and I
cannot be sure how MTD handles this "-EBADMSG".  Any help or
information is appreciated.


Best regards,
Du Zhongdong

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

* Re: [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed)
  2008-10-21  6:11 [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed) Du Zhongdong
@ 2008-10-21  6:21 ` Artem Bityutskiy
       [not found]   ` <7ccead5b0810202351n5db8e66ep1fbec555707950f6@mail.gmail.com>
  2008-10-21  6:50 ` Ricard Wanderlof
  1 sibling, 1 reply; 6+ messages in thread
From: Artem Bityutskiy @ 2008-10-21  6:21 UTC (permalink / raw)
  To: Du Zhongdong; +Cc: linux-mtd

On Tue, 2008-10-21 at 14:11 +0800, Du Zhongdong wrote:
> Hi,
> 
> I'm doing a NAND flash driver, and I suppose if ecc cannot be
> corrected while read something from NAND flash, that block should be
> marked bad, is that right?
> 
> Reading through nand_base.c I notice that mtd->read = nand_read;
> nand_read() [MTD Interface] calls nand_do_read_ops() [Internal] to do
> the work,  and in nand_do_read_ops():
>         if (mtd->ecc_stats.failed - stats.failed)
> 		return -EBADMSG;
> -EBADMSG then is returned to the MTD layer. I tried to trace this
> information in the MTD code, but there seems to be so many and I
> cannot be sure how MTD handles this "-EBADMSG".  Any help or
> information is appreciated.

Hi, -EBADMSG means an uncorrectable ECC error. MTD layer user should
treat it like "MTD returned some data, but it is probably corrupted,
because there was an uncorrectable ECC error".

Glance drivers/mtd/ubi/io.c if you are interested about users which
handle this -EBADMSG.

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

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

* Re: [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed)
  2008-10-21  6:11 [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed) Du Zhongdong
  2008-10-21  6:21 ` Artem Bityutskiy
@ 2008-10-21  6:50 ` Ricard Wanderlof
       [not found]   ` <7ccead5b0810202358l60368b79q2aae53bd1afc218@mail.gmail.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Ricard Wanderlof @ 2008-10-21  6:50 UTC (permalink / raw)
  To: Du Zhongdong; +Cc: linux-mtd@lists.infradead.org


On Tue, 21 Oct 2008, Du Zhongdong wrote:

> Hi,
>
> I'm doing a NAND flash driver, and I suppose if ecc cannot be
> corrected while read something from NAND flash, that block should be
> marked bad, is that right?

No, not necessarily. A block should be marked bad if it cannot reliably 
hold data, i.e. if the block refuses to write or erase properly.

Normally, uncorrectable errors occur after there have been correctable 
errors for a while. When correctable errors start occurring, this is a 
sign that the block should be erased and rewritten. As someone pointed 
out, UBI does this, plain JFFS2 does not.

/Ricard
--
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
  --- PLEASE NOTE - I have moved - from F407 to F117 - PLEASE NOTE ---

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

* Re: [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed)
       [not found]   ` <7ccead5b0810202351n5db8e66ep1fbec555707950f6@mail.gmail.com>
@ 2008-10-21  7:09     ` Artem Bityutskiy
  2008-10-21  7:36       ` Du Zhongdong
  0 siblings, 1 reply; 6+ messages in thread
From: Artem Bityutskiy @ 2008-10-21  7:09 UTC (permalink / raw)
  To: Du Zhongdong; +Cc: linux-mtd

On Tue, 2008-10-21 at 14:51 +0800, Du Zhongdong wrote:
> I got another question: if, in my nand flash driver, there's an ECC
> error cannot be corrected during a read procedure, I think now the
> block should be marked as a bad block

Read errors do not indicate that the block became bad. For example, if
you write twice (and different data) to the same NAND page, you'll
probably end up with ECC errors. But the block will not be bad.

For example, a silly user wrote something to /dev/mtd several times. And
you have many read errors. Is whole /dev/mtd bad? No, it does not.

> , then two options:
> 1, I mark that block BAD in my nand flash driver(specifically, I would
> insert some code in the nand_read() function in nand_base.c to handle
> this error);

Current model is so that MTD driver is not intelligent. It just reads,
writes, erases, etc when it is asked to. All bad block management is
done in upper layers. So this is not your driver's pain.

> 2, I return some error msg the upper layer(ie. MTD layer), which is
> what nand_read() do at present. Then I would expect the MTD layer
> would mark that block BAD.

Not the MTD layer, but stuff like UBI or JFFS2 - the _client_ of the MTD
layer.

> I read s3c2410.c and find that it chose option 2. But I can't find the
> place in the code where  the MTD layer mark that block BAD.

Right. MTD layer does not do this. It is stupid, and marks blocks as bad
only when someone calls mtd->block_markbad().

Think about MTD as the very low layer, which just provides the interface
to work with raw flash chip. Nothing else, no intelligence.

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

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

* Re: [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed)
  2008-10-21  7:09     ` Artem Bityutskiy
@ 2008-10-21  7:36       ` Du Zhongdong
  0 siblings, 0 replies; 6+ messages in thread
From: Du Zhongdong @ 2008-10-21  7:36 UTC (permalink / raw)
  To: dedekind

On Tue, Oct 21, 2008 at 3:09 PM, Artem Bityutskiy
<dedekind@infradead.org> wrote:
> On Tue, 2008-10-21 at 14:51 +0800, Du Zhongdong wrote:
>> I got another question: if, in my nand flash driver, there's an ECC
>> error cannot be corrected during a read procedure, I think now the
>> block should be marked as a bad block
>
> Read errors do not indicate that the block became bad. For example, if
> you write twice (and different data) to the same NAND page, you'll
> probably end up with ECC errors. But the block will not be bad.
>
> For example, a silly user wrote something to /dev/mtd several times. And
> you have many read errors. Is whole /dev/mtd bad? No, it does not.
>
>> , then two options:
>> 1, I mark that block BAD in my nand flash driver(specifically, I would
>> insert some code in the nand_read() function in nand_base.c to handle
>> this error);
>
> Current model is so that MTD driver is not intelligent. It just reads,
> writes, erases, etc when it is asked to. All bad block management is
> done in upper layers. So this is not your driver's pain.
>
>> 2, I return some error msg the upper layer(ie. MTD layer), which is
>> what nand_read() do at present. Then I would expect the MTD layer
>> would mark that block BAD.
>
> Not the MTD layer, but stuff like UBI or JFFS2 - the _client_ of the MTD
> layer.
>
>> I read s3c2410.c and find that it chose option 2. But I can't find the
>> place in the code where  the MTD layer mark that block BAD.
>
> Right. MTD layer does not do this. It is stupid, and marks blocks as bad
> only when someone calls mtd->block_markbad().
>
> Think about MTD as the very low layer, which just provides the interface
> to work with raw flash chip. Nothing else, no intelligence.
>
> --
> Best regards,
> Artem Bityutskiy (Битюцкий Артём)
>
>

Got it, really appreciate your help

Best regards,
Du Zhongdong

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

* Re: [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed)
       [not found]     ` <Pine.LNX.4.64.0810210915260.6120@lnxricardw.se.axis.com>
@ 2008-10-21  7:39       ` Du Zhongdong
  0 siblings, 0 replies; 6+ messages in thread
From: Du Zhongdong @ 2008-10-21  7:39 UTC (permalink / raw)
  To: Ricard Wanderlof; +Cc: linux-mtd

On Tue, Oct 21, 2008 at 3:16 PM, Ricard Wanderlof
<ricard.wanderlof@axis.com> wrote:
>
> On Tue, 21 Oct 2008, Du Zhongdong wrote:
>
>>> Normally, uncorrectable errors occur after there have been correctable
>>> errors for a while. When correctable errors start occurring, this is a
>>> sign
>>> that the block should be erased and rewritten. As someone pointed out,
>>> UBI
>>> does this, plain JFFS2 does not.
>>>
>> Thanks, Rechard :)
>>
>> So, If I detect correctable errors start occurring, I can erase that block
>> and rewritten to it, all these can happen in my nand flash driver, am I
>> right?
>
> Normally this would happen at a higher level, such as UBI. I'm not sure
> exactly what you mean by 'nand flash driver', but the actual driver for a
> specific flash should not have to contain code that is common to a whole
> range of devices.
>
> /Ricard
> --
> Ricard Wolf Wanderlöf                           ricardw(at)axis.com
> Axis Communications AB, Lund, Sweden            www.axis.com
> Phone +46 46 272 2016                           Fax +46 46 13 61 30
>  --- PLEASE NOTE - I have moved - from F407 to F117 - PLEASE NOTE ---
>


Thank you, Richard, I think I got it :)

Best regards,
Du Zhongdong

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

end of thread, other threads:[~2008-10-21  7:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-21  6:11 [NAND flash driver] What would mtd do if read returns -EBADMSG (ecc failed) Du Zhongdong
2008-10-21  6:21 ` Artem Bityutskiy
     [not found]   ` <7ccead5b0810202351n5db8e66ep1fbec555707950f6@mail.gmail.com>
2008-10-21  7:09     ` Artem Bityutskiy
2008-10-21  7:36       ` Du Zhongdong
2008-10-21  6:50 ` Ricard Wanderlof
     [not found]   ` <7ccead5b0810202358l60368b79q2aae53bd1afc218@mail.gmail.com>
     [not found]     ` <Pine.LNX.4.64.0810210915260.6120@lnxricardw.se.axis.com>
2008-10-21  7:39       ` Du Zhongdong

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