[U-Boot] handling of bad blocks in nand

Scott Wood scottwood at freescale.com
Mon Aug 16 20:55:40 CEST 2010


On Fri, Aug 13, 2010 at 09:22:21PM +0000, Grant Edwards wrote:
> I'm using 1.3.4 (that's what's supported by Atmel).  While that's the
> current "released" version, it appears to be over two years old?
> 
> I've been reading nand flash docs and source code for a while now, and
> I must admit the more I read the more questions I have.
> 
>  1) Is there any documentation for the "nand" commands?
>  
>     There's nothing in the manual, and doc/README.nand appears to be
>     incomplete, and self-contradictory.  [There's no mention at all of
>     .e or .i, and there are contradictory descriptions for .jffs2.]
> 
>  2) Are the behaviors of ".jffs2", ".e", and ".i" the same? (It
>     appears so from the source code.) If not how do they differ?

At one point in the legacy NAND code, a distinction was made when reading
between completely skipping bad blocks, and filling the buffer with zeroes
in place of the bad blocks.  It looks like ".jffs2" or ".e" would get you
zeroes, and ".jffs2s" or ".i" would get you block skipping.

The zero-fill mode is no longer supported.  In 1.3.4, assuming you're not
using the legacy NAND code, you need to specify one of ".jffs2", ".e", or
".i" to get block skipping.  It doesn't matter which one.  In current u-boot
these suffixes are accepted and ignored as legacy (bad blocks are always
skipped), except for "jffs2s" which apparently never made an appearance
outside the legacy code.

Yes, it's a bit of a mess.

>  3) In the 1.3.4 source code, there are lots of instances where there
>     are boolean flags with names like "jffs2".  AFAICT those flags
>     have nothing to do with the JFFS2 filesystem, but simply control
>     whether or not bad flash blocks are skipped during read/write
>     operations.  Am I reading the code correctly?

The user interface .jffs2 suffix was to indicate bad block skipping, but
opts->jffs2 (which is still around) refers to writing JFFS2 cleanmarkers
after erasing a block.

>  4) If in a custom command, I want to read/write a large block of data
>     to/from nand flash while skipping bad blocks what functions do I
>     call?  Right now I'm doing something like this:
> 
>       nand_info[0].read(nand_info+0, offset, sizeof(buffer), &len, buffer)
>     
>       nand_info[0].write(nand_info+0, offset, bytecount, &len, buffer)
>     
>     but, I have a feeling that's not right (though it seems to work, I
>     suspect it's not going to skip bad blocks).

You suspect correctly.

In current code there is nand_write_skip_bad() and nand_read_skip_bad() in
drivers/mtd/nand/nand_util.c.

In 1.3.4 use nand_read_opts()/nand_write_opts().  Or convince Atmel to
support something more recent.  :-)

-Scott



More information about the U-Boot mailing list