Skip to contentSkip to conversation

nand: Kconfig: Allow MTD_NAND_GPMI_NAND to be built as module

PATCH New Fabio Estevam 5 participants 12 messages Jul 28, 2012 – Aug 28, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nand: Kconfig: Allow MTD_NAND_GPMI_NAND to be built as module

From: Fabio Estevam <[email protected]>

Allow MTD_NAND_GPMI_NAND to be built as module.

---
 drivers/mtd/nand/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mtd/nand/Kconfig +1 -1
index f4e81a7..533eee7 100644
@@ -461,7 +461,7 @@ config MTD_NAND_NANDSIM
 	  MTD nand layer.
 
 config MTD_NAND_GPMI_NAND
-        bool "GPMI NAND Flash Controller driver"
+        tristate "GPMI NAND Flash Controller driver"
         depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28 || SOC_IMX6Q)
         help
 	 Enables NAND Flash support for IMX23 or IMX28.
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/2 nand: nand_bbt: Export nand_update_bbt

From: Fabio Estevam <[email protected]>

When building MTD_NAND_GPMI_NAND as module, the following error shows up:

ERROR: "nand_update_bbt" [drivers/mtd/nand/gpmi-nand/gpmi_nand.ko] undefined!

Export nand_update_bbt to fix it.

---
 drivers/mtd/nand/nand_bbt.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/mtd/nand/nand_bbt.c +1 -0
index 2d1d2fa..f4b6417 100644
@@ -1403,3 +1403,4 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
 
 EXPORT_SYMBOL(nand_scan_bbt);
 EXPORT_SYMBOL(nand_default_bbt);
+EXPORT_SYMBOL(nand_update_bbt);
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

When building MTD_NAND_GPMI_NAND as module, the following error shows up:

ERROR: "nand_update_bbt" [drivers/mtd/nand/gpmi-nand/gpmi_nand.ko] undefined!

Export nand_update_bbt to fix it.

Why this driver redefined ->block_markbad() at all, it is not supposed to do this. We should fix the driver instead.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#3 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

Quoted 5 lines · Artem Bityutskiy
Quoted 4 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

When building MTD_NAND_GPMI_NAND as module, the following error shows up:

Quoted 7 lines
Quoted 5 lines

ERROR: "nand_update_bbt" [drivers/mtd/nand/gpmi-nand/gpmi_nand.ko] undefined!

Export nand_update_bbt to fix it

Why this driver redefined ->block_markbad() at all, it is not supposed

For hardware reason, in mx23, the bad block mark is stored in the first byte of the nand page;
in mx28/mx50/mx6q, the bad block mark is stored in the first byte of the OOB.

That's why the driver redefined the ->block_markbad().

Is there any need to build the gpmi nand as a module?

Best Regards
Huang Shijie

Quoted 10 lines

to do this. We should fix the driver instead.

--
Best Regards,
Artem Bityutskiy

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#4 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

Quoted 10 lines · Huang Shijie
Quoted 9 lines · Artem Bityutskiy
Quoted 8 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

When building MTD_NAND_GPMI_NAND as module, the following error shows up:

ERROR: "nand_update_bbt" [drivers/mtd/nand/gpmi-nand/gpmi_nand.ko] undefined!

Export nand_update_bbt to fix it

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Why this driver redefined ->block_markbad() at all, it is not supposed

For hardware reason, in mx23, the bad block mark is stored in the first byte of the nand page;
in mx28/mx50/mx6q, the bad block mark is stored in the first byte of the OOB.

That's why the driver redefined the ->block_markbad().

The default function seem to do the same as your function does. You select where you keep your OOB using chip options, and the default function does the right thing, no?

From 5cdff78da6dde1e2eef472dcbbe7ca8f7fd64061 Mon Sep 17 00:00:00 2001
From: Artem Bityutskiy <[email protected]>
Date: Fri, 24 Aug 2012 09:26:29 +0300
Subject: [PATCH] gpmi-nand: use the default implementation of block_markbad

---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |   46 --------------------------------
 1 file changed, 46 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0 -46
index 8c0d2f0..8e193fb 100644
@@ -1179,51 +1179,6 @@ gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
 	return -EPERM;
 }
 
-static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
-{
-	struct nand_chip *chip = mtd->priv;
-	struct gpmi_nand_data *this = chip->priv;
-	int block, ret = 0;
-	uint8_t *block_mark;
-	int column, page, status, chipnr;
-
-	/* Get block number */
-	block = (int)(ofs >> chip->bbt_erase_shift);
-	if (chip->bbt)
-		chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
-
-	/* Do we have a flash based bad block table ? */
-	if (chip->bbt_options & NAND_BBT_USE_FLASH)
-		ret = nand_update_bbt(mtd, ofs);
-	else {
-		chipnr = (int)(ofs >> chip->chip_shift);
-		chip->select_chip(mtd, chipnr);
-
-		column = this->swap_block_mark ? mtd->writesize : 0;
-
-		/* Write the block mark. */
-		block_mark = this->data_buffer_dma;
-		block_mark[0] = 0; /* bad block marker */
-
-		/* Shift to get page */
-		page = (int)(ofs >> chip->page_shift);
-
-		chip->cmdfunc(mtd, NAND_CMD_SEQIN, column, page);
-		chip->write_buf(mtd, block_mark, 1);
-		chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
-
-		status = chip->waitfunc(mtd, chip);
-		if (status & NAND_STATUS_FAIL)
-			ret = -EIO;
-
-		chip->select_chip(mtd, -1);
-	}
-	if (!ret)
-		mtd->ecc_stats.badblocks++;
-
-	return ret;
-}
-
 static int nand_boot_set_geometry(struct gpmi_nand_data *this)
 {
 	struct boot_rom_geometry *geometry = &this->rom_geometry;
@@ -1562,7 +1517,6 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
 	chip->ecc.write_oob	= gpmi_ecc_write_oob;
 	chip->scan_bbt		= gpmi_scan_bbt;
 	chip->badblock_pattern	= &gpmi_bbt_descr;
-	chip->block_markbad	= gpmi_block_markbad;
 	chip->options		|= NAND_NO_SUBPAGE_WRITE;
 	chip->ecc.mode		= NAND_ECC_HW;
 	chip->ecc.size		= 1;
Signature · 5 lines
1.7.10.4

-- 
Best Regards,
Artem Bityutskiy
#5 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

Quoted 3 lines · Artem Bityutskiy

The default function seem to do the same as your function does. You select where you keep your OOB using chip options, and the default function does the right thing, no?

The key issue is that the mx23 should copies the bad block mark into the "first byte of the nand page", while the other chips does do this.

I don't think the default function do the same thing. You see:
nand_default_block_markbad() --> nand_do_write_oob() -->
chip->ecc.write_oob() -->gpmi_ecc_write_oob()

The gpmi_ecc_write_oob() does nothing,but return -EPERM.

Huang Shijie

#6 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

Quoted 9 lines · Huang Shijie
Quoted 3 lines · Artem Bityutskiy

The default function seem to do the same as your function does. You select where you keep your OOB using chip options, and the default function does the right thing, no?

The key issue is that the mx23 should copies the bad block mark into the "first byte of the nand page",
while the other chips does do this.

s/does/does not/

Quoted 12 lines

I don't think the default function do the same thing. You see:
nand_default_block_markbad() --> nand_do_write_oob() -->
chip->ecc.write_oob() -->gpmi_ecc_write_oob()

The gpmi_ecc_write_oob() does nothing,but return -EPERM.

Huang Shijie

#7 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

In reply to Huang Shijie

Hi,

Quoted 1 line

From Artem: "Why this driver redefined ->block_markbad() at all, it is

not supposed
to do this. We should fix the driver instead."

Why is ->block_markbad() a function pointer, then, if the driver is not allowed to redefine it? Admittedly, it often doesn't make sense to override it; plus, if you override ->block_markbad(), you probably want to also override ->block_bad(). But nand_base.c doesn't really have good infrastructure for that.

So, by the current, somewhat messy and incomplete state of the nand_base + nand_bbt code, it seems to be "supported" to override ->block_markbad() if you really need to. But some more work could be done to improve this.

Quoted 11 lines · Huang Shijie
Quoted 3 lines · Artem Bityutskiy

The default function seem to do the same as your function does. You select where you keep your OOB using chip options, and the default function does the right thing, no?

I don't think the default function do the same thing. You see:
nand_default_block_markbad() --> nand_do_write_oob() -->
chip->ecc.write_oob() -->gpmi_ecc_write_oob()

The gpmi_ecc_write_oob() does nothing,but return -EPERM.

Yeah, that's kind of strange. So you never have room in OOB even for bad block markers? How do you identify factory-marked bad blocks? Wouldn't they be indistinguishable from your ECC area? Or do you have free OOB space in which you could actually implement write_oob() properly?

None of my comments are really a disagreement with your patch. Your driver has a strange way of dealing with ECC + bad block markers, and assuming you figured out your swap_block_mark code safely (I didn't really study this) then I think it's OK ("supported") to provide your own ->block_markbad() function.

Brian

#8 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

Quoted 11 lines · Brian Norris
Quoted 9 lines
Quoted 3 lines

The default function seem to do the same as your function does. You select where you keep your OOB using chip options, and the default function does the right thing, no?

I don't think the default function do the same thing. You see:
nand_default_block_markbad() --> nand_do_write_oob() -->
chip->ecc.write_oob() -->gpmi_ecc_write_oob()

The gpmi_ecc_write_oob() does nothing,but return -EPERM.

Yeah, that's kind of strange. So you never have room in OOB even fo

yes. The different ROMs of mx23/mx28/mx50/mx6q make it strange.

In mx28/mx50/mx6q, the first byte of OOB is used to store the bad block marker. These chips's ROMs support the so-called swap feature which can swaps the bad block marker to a safe place.

But the mx23's ROM does not support the swap feature, so it really has no room in OOB to
store the bad block marker. When the mx23 first scan a nand chip, the factory-marked
bad block marker is copied to the first byte of the NAND page. When
the chip boots from
the nand, the ROM of mx23 will read the first byte of the NAND page to check whether this block is a bad block. Why copy to the first byte? the mx23 use the first 10 byte of the nand page as a so-called "metadata".

Quoted 4 lines

bad block markers? How do you identify factory-marked bad blocks? Wouldn't they be indistinguishable from your ECC area? Or do you have free OOB space in which you could actually implement write_oob() properly?

The original old gpmi-nand driver does implement the write_oob() which only allow the
block_markbad() run through. In another word, if the write_oob() is called by the block_markbad, it will
grant the operation. All the other operations are denied. In order to achieve this target, the old
code used an ugly hack code, it hooked the mtd->block_markbad(), such as:

         .....................................................
               mtd->hooked_block_markbad = mtd->block_markbad();
               mtd->block_markbad =              gpmi_block_markbad();

               nand->ecc.write_oob = mil_ecc_write_oob;
         .....................................................

             gpmi_block_markbad()
          {
               this->marking_a_block_bad = true;
              mtd->hooked_block_markbad();
              this->marking_a_block_bad = false;
           }

        mil_ecc_write_oob()
        {
            if (!this->marking_a_block_bad)
                    return;
            ..............................................
        }

     As i described above, the mil_ecc_write_oob() will write 0 to the

first byte of the OOB in mx28/mx50/mx6q;
the mil_ecc_write_oob() will write 0 to the first byte of the nand page in mx23.

For you see, the implementation of the write_oob() is too ugly. I fininally found if i implement the nand->block_markbad(), the code will very tidy and clean. The current code realizes the same feature as
the old code, but the current code is very simple.

what's more is that the nand->block_markbad is REPLACEABLE. so i do not break any rule. :)

I hope my poor english describes this issue clearly.

thanks
Huang Shijie

#9 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

In reply to Huang Shijie
Quoted 6 lines · Huang Shijie
Quoted 1 line

Why this driver redefined ->block_markbad() at all, it is not supposed

For hardware reason, in mx23, the bad block mark is stored in the first byte of the nand page;
in mx28/mx50/mx6q, the bad block mark is stored in the first byte of the OOB.

That's why the driver redefined the ->block_markbad().

OK. Would you please tell about the driver some more, I am particularly interested how th mx23 case works.

* So the bad block marker is the first byte of the eraseblock set to 0?
* What if the user data stars with zero? Or you hide the first NAND page from the user?
* Can you point me to the code where you check if the eraseblock is bad or not at the initialization time (sorry, I could find myself, by trying to save time).

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#10 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

Quoted 11 lines · Artem Bityutskiy
Quoted 6 lines · Huang Shijie
Quoted 1 line

Why this driver redefined ->block_markbad() at all, it is not supposed

For hardware reason, in mx23, the bad block mark is stored in the first byte of the nand page;
in mx28/mx50/mx6q, the bad block mark is stored in the first byte of the OOB.

That's why the driver redefined the ->block_markbad().

OK. Would you please tell about the driver some more, I am particularly interested how th mx23 case works.

* So the bad block marker is the first byte of the eraseblock set to 0?

yes.

Quoted 2 lines

* What if the user data stars with zero? Or you hide the first NAND page from the user?

Please see the picture in the common_nfc_set_geometry(). It's a real nand page layout.
The M is metadata, it's about 10 byte len.
The bad block marker is stored in the metadata, not the the
data section which save the user's data.

We do not hide the first NAND page.

Quoted 4 lines

* Can you point me to the code where you check if the eraseblock is bad or not at the initialization time (sorry, I could find myself, by trying to save time).

Please see the mx23_boot_init().

When mx23 reads a new nand chip in the first time, it will scan all
the nand chip. If it finds a bad block, it will call the nand->block_markbad() which is just the gpmi_block_markbad(). the gpmi_block_markbad() will mark the first byte of the nand page to 0 (the mx23 does not support the swap feature). So NAND boot mode, the ROM of mx23 will check the first byte of the NAND page, if it finds a 0, it knows that this is a bad block.

thanks
Huang Shijie

#11 lore raw

Re: [PATCH 1/2] nand: nand_bbt: Export nand_update_bbt

In reply to Fabio Estevam
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

When building MTD_NAND_GPMI_NAND as module, the following error shows up:

ERROR: "nand_update_bbt" [drivers/mtd/nand/gpmi-nand/gpmi_nand.ko] undefined!

Export nand_update_bbt to fix it.

Pushed both to l2-mtd.git, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy