Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
* NAND bad block checking when no memory based BBT is available
@ 2007-04-26 15:38 Knobloch, Thomas
  2007-04-26 16:31 ` David Woodhouse
  2007-04-26 16:40 ` David Woodhouse
  0 siblings, 2 replies; 4+ messages in thread
From: Knobloch, Thomas @ 2007-04-26 15:38 UTC (permalink / raw)
  To: linux-mtd

Hello,

I'm using the MTD code as part of the u-boot Bootloader. I implemented
a NAND device that is not generating a bad block table at all. The
reason for that this decreases boot time of our device. So every
time the code checks for a bad block it actually reads the OOB data
from the device directly.

This is done in function nand_block_checkbad() in file
drivers/mtd/nand/nand_base.c:

static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int
getchip,
			       int allowbbt)
{
	struct nand_chip *chip = mtd->priv;

	if (!chip->bbt)
		return chip->block_bad(mtd, ofs, getchip);

	/* Return info from the table */
	return nand_isbad_bbt(mtd, ofs, allowbbt);
}



If no BBT is available (as in our implementation) the function will
call chip->bad_block() whose default implementation is
nand_block_bad() in nand_base.c:

static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
{
	int page, chipnr, res = 0;
	struct nand_chip *chip = mtd->priv;
	u16 bad;

	if (getchip) {
		page = (int)(ofs >> chip->page_shift);
		chipnr = (int)(ofs >> chip->chip_shift);

		nand_get_device(chip, mtd, FL_READING);

		/* Select the NAND device */
		chip->select_chip(mtd, chipnr);
	} else
		page = (int)ofs;


	...

}


The interesting thing is that the page number is calculated
differently depending on the parameter getchip. With getchip set to
one it will shift the offset to get the page number. With getchip set
to zero it will not. This really leads to the situation where the page
number is calculated wrong. Function nand_erase_nand() in nand_base.c
calls nand_block_bad() with getchip=0. However it also shifts the page
number to the left before calling this function:

int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
		    int allowbbt)
{
	...

		/*
		 * heck if we have a bad block, we do not erase bad
blocks !
		 */
		if (nand_block_checkbad(mtd, ((loff_t) page) <<
					chip->page_shift, 0, allowbbt))
{
			printk(KERN_WARNING "nand_erase: attempt to
erase a "
			       "bad block at page 0x%08x\n", page);
			...
		}

	...
}


By doing so the code will check for the wrong page number as the offset
is not shifted back to the right in nand_block_bad(). I clearly
see that our bootloader will check the wrong page number/offset in
the case that the NAND driver does not generate a BBT.

Do you think there is some problem with this code or am I missing some
point.

Thanks & regards,
Thomas

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

* Re: NAND bad block checking when no memory based BBT is available
  2007-04-26 15:38 NAND bad block checking when no memory based BBT is available Knobloch, Thomas
@ 2007-04-26 16:31 ` David Woodhouse
  2007-04-26 17:23   ` Thomas Gleixner
  2007-04-26 16:40 ` David Woodhouse
  1 sibling, 1 reply; 4+ messages in thread
From: David Woodhouse @ 2007-04-26 16:31 UTC (permalink / raw)
  To: Knobloch, Thomas; +Cc: linux-mtd

On Thu, 2007-04-26 at 17:38 +0200, Knobloch, Thomas wrote:
> Do you think there is some problem with this code or am I missing some
> point. 

Looks entirely screwed in the head to me. Thomas?

-- 
dwmw2

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

* Re: NAND bad block checking when no memory based BBT is available
  2007-04-26 15:38 NAND bad block checking when no memory based BBT is available Knobloch, Thomas
  2007-04-26 16:31 ` David Woodhouse
@ 2007-04-26 16:40 ` David Woodhouse
  1 sibling, 0 replies; 4+ messages in thread
From: David Woodhouse @ 2007-04-26 16:40 UTC (permalink / raw)
  To: Knobloch, Thomas; +Cc: linux-mtd

On Thu, 2007-04-26 at 17:38 +0200, Knobloch, Thomas wrote:
>         if (getchip) {
>                 page = (int)(ofs >> chip->page_shift);
>                 chipnr = (int)(ofs >> chip->chip_shift);
> 
>                 nand_get_device(chip, mtd, FL_READING);
> 
>                 /* Select the NAND device */
>                 chip->select_chip(mtd, chipnr);
>         } else
>                 page = (int)ofs; 

I think we'll accept a patch which makes that last line also shift right
by chip->page_shift.

-- 
dwmw2

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

* Re: NAND bad block checking when no memory based BBT is available
  2007-04-26 16:31 ` David Woodhouse
@ 2007-04-26 17:23   ` Thomas Gleixner
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Gleixner @ 2007-04-26 17:23 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Knobloch, Thomas, linux-mtd

On Thu, 2007-04-26 at 17:31 +0100, David Woodhouse wrote:
> On Thu, 2007-04-26 at 17:38 +0200, Knobloch, Thomas wrote:
> > Do you think there is some problem with this code or am I missing some
> > point. 
> 
> Looks entirely screwed in the head to me. Thomas?

Yep, it's screwed. Nobody noticed, as this code path is usually never
taken. I kept it as there was some academic discussion, why not using a
bad block table is superior, but I forgot the details.

Sure it needs the shift as well.

	tglx

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

end of thread, other threads:[~2007-04-26 17:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-26 15:38 NAND bad block checking when no memory based BBT is available Knobloch, Thomas
2007-04-26 16:31 ` David Woodhouse
2007-04-26 17:23   ` Thomas Gleixner
2007-04-26 16:40 ` David Woodhouse

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