linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] write bad block marker even with BBT
@ 2010-10-25  8:38 Matthieu CASTET
  2010-10-27 18:26 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Matthieu CASTET @ 2010-10-25  8:38 UTC (permalink / raw)
  To: linux-mtd

[-- Attachment #1: Type: text/plain, Size: 209 bytes --]

Add a new flag to force writing bad block marker if we use bad block table.
This allow to solve problem where bootloader don't support reading BBT.

Signed-off-by: Matthieu CASTET <matthieu.castet@parrot.com>

[-- Attachment #2: mtd_btt.diff --]
[-- Type: text/x-diff, Size: 1574 bytes --]

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ddffe76..4d79a8d 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -396,7 +396,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
 	struct nand_chip *chip = mtd->priv;
 	uint8_t buf[2] = { 0, 0 };
-	int block, ret, i = 0;
+	int block, ret = 0, i = 0;
 
 	if (chip->options & NAND_BBT_SCANLASTPAGE)
 		ofs += mtd->erasesize - mtd->writesize;
@@ -409,7 +409,12 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 	/* Do we have a flash based bad block table ? */
 	if (chip->options & NAND_USE_FLASH_BBT)
 		ret = nand_update_bbt(mtd, ofs);
-	else {
+
+	/* Write the bad block marker if we don't have BBT, or driver
+	 * request it (in case the bootloader doesn't support reading it
+	 * or we loose BBT).
+	 */
+	if (!(chip->options & NAND_USE_FLASH_BBT) || chip->options & NAND_WRITE_BB) {
 		nand_get_device(chip, mtd, FL_WRITING);
 
 		/* Write to first two pages and to byte 1 and 6 if necessary.
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 102e12c..2efd2f9 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -215,6 +215,8 @@ typedef enum {
 #define NAND_OWN_BUFFERS	0x00040000
 /* Chip may not exist, so silence any errors in scan */
 #define NAND_SCAN_SILENT_NODEV	0x00080000
+/* in case of NAND_USE_FLASH_BBT, write also bad block marker */
+#define NAND_WRITE_BB	0x00100000
 
 /* Options set by nand scan */
 /* Nand scan has allocated controller struct */

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

* Re: [PATCH] write bad block marker even with BBT
  2010-10-25  8:38 [PATCH] write bad block marker even with BBT Matthieu CASTET
@ 2010-10-27 18:26 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2010-10-27 18:26 UTC (permalink / raw)
  To: Matthieu CASTET; +Cc: linux-mtd

Sorry for being PITA, but

On Mon, 2010-10-25 at 10:38 +0200, Matthieu CASTET wrote:
> +
> +	/* Write the bad block marker if we don't have BBT, or driver
> +	 * request it (in case the bootloader doesn't support reading it
> +	 * or we loose BBT).
> +	 */

Still not proper comment :-)

> +	if (!(chip->options & NAND_USE_FLASH_BBT) || chip->options & NAND_WRITE_BB) {
>  		nand_get_device(chip, mtd, FL_WRITING);
>  
>  		/* Write to first two pages and to byte 1 and 6 if necessary.
> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> index 102e12c..2efd2f9 100644
> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -215,6 +215,8 @@ typedef enum {
>  #define NAND_OWN_BUFFERS	0x00040000
>  /* Chip may not exist, so silence any errors in scan */
>  #define NAND_SCAN_SILENT_NODEV	0x00080000
> +/* in case of NAND_USE_FLASH_BBT, write also bad block marker */
> +#define NAND_WRITE_BB	0x00100000

I think the comment should be a bit more descriptive and tell that this
is about using BBT _and_ writing BB marker to OOB area. Use proper
comment style, start with capital letter.

Also, add a BUG_ON to catch misuse cases when NAND_WRITE_BB is used
without NAND_USE_FLASH_BBT - they should go in pair.

And also, how about cases when BBT is updated, but OOB did not because
of a power cut :-)) ?

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

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

end of thread, other threads:[~2010-10-27 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-25  8:38 [PATCH] write bad block marker even with BBT Matthieu CASTET
2010-10-27 18:26 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).