mtd/nand: Edit macro flag for BBT scan of last page in block
Subsystems (2)
PATCH 1/1 mtd/nand: Edit macro flag for BBT scan of last page in block
NAND_BB_LAST_PAGE used to be in nand.h, but it pertained to bad block management and so belongs next to NAND_BBT_SCAN2NDPAGE in bbm.h. Also, its previous flag value (0x00000400) conflicted with NAND_BBT_SCANALLPAGES so I changed its value to 0x00008000. All uses of the name were modified to provide consistency with other "NAND_BBT_*" flags.
--- drivers/mtd/nand/nand_base.c | 6 +++--- drivers/mtd/nand/nand_bbt.c | 2 +- include/linux/mtd/bbm.h | 2 ++ include/linux/mtd/nand.h | 2 -- 4 files changed, 6 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +3 -3
@@ -347,7 +347,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)struct nand_chip *chip = mtd->priv;u16 bad; -if (chip->options &NAND_BB_LAST_PAGE ) +if (chip->options &NAND_BBT_SCANLASTPAGE ) ofs += mtd->erasesize - mtd->writesize; page = (int )(ofs >> chip->page_shift) & chip->pagemask;
@@ -399,7 +399,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)uint8_t buf[2 ] = {0 ,0 };int block, ret; -if (chip->options &NAND_BB_LAST_PAGE ) +if (chip->options &NAND_BBT_SCANLASTPAGE ) ofs += mtd->erasesize - mtd->writesize;/* Get block number */
@@ -2946,7 +2946,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,if ((chip->cellinfo &NAND_CI_CELLTYPE_MSK ) && (*maf_id ==NAND_MFR_SAMSUNG || *maf_id ==NAND_MFR_HYNIX )) - chip->options |=NAND_BB_LAST_PAGE ; + chip->options |=NAND_BBT_SCANLASTPAGE ;/* Check for AND chips with 4 page planes */ if (chip->options &NAND_4PAGE_ARRAY )
drivers/mtd/nand/nand_bbt.c +1 -1
@@ -432,7 +432,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, from = (loff_t )startblock << (this->bbt_erase_shift -1 ); } -if (this->options &NAND_BB_LAST_PAGE ) +if (this->options &NAND_BBT_SCANLASTPAGE ) from += mtd->erasesize - (mtd->writesize * len);for (i = startblock; i < numblocks;) {
include/linux/mtd/bbm.h +2 -0
@@ -82,6 +82,8 @@ struct nand_bbt_descr {#define NAND_BBT_SAVECONTENT 0x00002000/* Search good / bad pattern on the first and the second page */ #define NAND_BBT_SCAN2NDPAGE 0x00004000 +/* Search good / bad pattern on the last page of the eraseblock */ +#define NAND_BBT_SCANLASTPAGE 0x00008000/* The maximum number of blocks to scan for a bbt */ #define NAND_BBT_SCAN_MAXBLOCKS 4
include/linux/mtd/nand.h +0 -2
@@ -181,8 +181,6 @@ typedef enum {#define NAND_NO_READRDY 0x00000100/* Chip does not allow subpage writes */ #define NAND_NO_SUBPAGE_WRITE 0x00000200 -/* Chip stores bad block marker on the last page of the eraseblock */ -#define NAND_BB_LAST_PAGE 0x00000400/* Device is one of 'new' xD cards that expose fake nand command set */ #define NAND_BROKEN_XD 0x00000400
Signature · 1 line
1.7.1
PATCH 1/1 mtd/nand, BB detect: factory marker in page 1, 2, last and byte 1 or 6
Some level of support for various scanning locations was already built in, but this required clean-up. First, BB marker location cannot be determined _only_ by the page size. Instead, I implemented some heuristic detection based on data sheets from various manufacturers (all found in nand_base.c:nand_get_flash_type()).
Second, once these options were identified, they were not handled properly by nand_bbt.c:nand_default_bbt(). I believe there are only 5 combinations of page location/byte offset, so I updated the nand_bbt_desc structs accordingly.
I have tested these changes with several chips, but particularly a Micron 29F8G08MAA chip. We use a memory-based, not flash-based, BBT; hence the edits only to the "memory_based" side of things. Most edits could be applicable to both, but I can't verify that. For instance, I do not understand why the small discrepancies between the "memory_based" and "flash_based" nand_bbt_descr structs.
Finally, please provide any feedback you can. I'm sure there's something I have overlooked, but I feel this is a step in the right direction.
--- drivers/mtd/nand/nand_base.c | 23 +++++++++++++++++++---- drivers/mtd/nand/nand_bbt.c | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 11 deletions(-)
drivers/mtd/nand/nand_base.c +19 -4
@@ -2920,9 +2920,13 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->chip_shift =ffs ((unsigned )(chip->chipsize >>32 )) +32 -1 ;/* Set the bad block position */ - chip->badblockpos = mtd->writesize >512 ? -NAND_LARGE_BADBLOCK_POS :NAND_SMALL_BADBLOCK_POS ; - chip->badblockbits =8 ; + chip->badblockpos = (!(busw &NAND_BUSWIDTH_16 ) && + (*maf_id ==NAND_MFR_STMICRO || + (*maf_id ==NAND_MFR_SAMSUNG && + mtd->writesize ==512 ) || + *maf_id ==NAND_MFR_AMD )) + ?NAND_SMALL_BADBLOCK_POS :NAND_LARGE_BADBLOCK_POS ; +/* Get chip options, preserve non chip based options */ chip->options &= ~NAND_CHIPOPTIONS_MSK ;
@@ -2941,12 +2945,23 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,/* * Bad block marker is stored in the last page of each block -* on Samsung and Hynix MLC devices +* on Samsung and Hynix MLC devices; stored in first two pages +* of each block on Micron devices with 2KiB pages and on +* SLC Samsung, Hynix, and AMD/Spansion. All others scan only +* the first page. */ if ((chip->cellinfo &NAND_CI_CELLTYPE_MSK ) && (*maf_id ==NAND_MFR_SAMSUNG || *maf_id ==NAND_MFR_HYNIX )) chip->options |=NAND_BBT_SCANLASTPAGE ; +else if ((!(chip->cellinfo &NAND_CI_CELLTYPE_MSK ) && + (*maf_id ==NAND_MFR_SAMSUNG || + *maf_id ==NAND_MFR_HYNIX || + *maf_id ==NAND_MFR_AMD )) || + (mtd->writesize ==2048 && + *maf_id ==NAND_MFR_MICRON )) + chip->options |=NAND_BBT_SCAN2NDPAGE ; +/* Check for AND chips with 4 page planes */ if (chip->options &NAND_4PAGE_ARRAY )
drivers/mtd/nand/nand_bbt.c +34 -7
71 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 2] mtd/nand, BB detect: factory marker in page 1, 2, last and byte 1 or 6
drivers/mtd/nand/nand_base.c static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, · line 2928
Quoted 13 lines · Brian Norris
drivers/mtd/nand/nand_base.c +6
-3@@ -2920,9 +2920,13 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->chip_shift =ffs ((unsigned )(chip->chipsize >>32 )) +32 -1 ;/* Set the bad block position */ - chip->badblockpos = mtd->writesize >512 ? -NAND_LARGE_BADBLOCK_POS :NAND_SMALL_BADBLOCK_POS ; - chip->badblockbits =8 ; + chip->badblockpos = (!(busw &NAND_BUSWIDTH_16 ) && + (*maf_id ==NAND_MFR_STMICRO || + (*maf_id ==NAND_MFR_SAMSUNG && + mtd->writesize ==512 ) || + *maf_id ==NAND_MFR_AMD )) + ?NAND_SMALL_BADBLOCK_POS :NAND_LARGE_BADBLOCK_POS ;
I'd prefer if () else, ? : is not appropriate for such huge conditions.
Nevertheless, you patch looks indeed like a step in the right direction, but I cannot really test it and do not have time to review.
But could you please re-send it without trailing white-spaces - I'll put it to my l2 tree then? You can do a 'git am' to your own patches - it'll check for trailing white-spaces for you.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
v2 cover Improved BB Scanning
This is a two-patch correction and update to my previous attempt to address a few issues with bad block scanning. Overall, they should help renovate some incorrect and unwieldy code.
I included the top few maintainers from get_maintainers.pl. Sorry if these were incorrect addressees.
Brian Norris (2):
mtd/nand, BB detect: factory marker in page 1, 2, last and byte 1 or 6 mtd/nand: More BB Detection, dynamic scan options
drivers/mtd/nand/nand_base.c | 38 ++++++++++++++++-- drivers/mtd/nand/nand_bbt.c | 89 +++++++++++++++++++++++++++++------------ include/linux/mtd/bbm.h | 4 ++ 3 files changed, 101 insertions(+), 30 deletions(-)
PATCH v2 1/2 mtd/nand, BB detect: factory marker in page 1, 2, last and byte 1 or 6
Some level of support for various scanning locations was already built in, but this required clean-up. First, BB marker location cannot be determined _only_ by the page size. Instead, I implemented some heuristic detection based on data sheets from various manufacturers (all found in nand_base.c:nand_get_flash_type()).
Second, once these options were identified, they were not handled properly by nand_bbt.c:nand_default_bbt(). I updated the static nand_bbt_desc structs to reflect the need for more combinations of detection. The memory allocation here probably needs to be done dynamically in the very near future (see next patches).
--- drivers/mtd/nand/nand_base.c | 24 ++++++++++++++++++--- drivers/mtd/nand/nand_bbt.c | 45 +++++++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 11 deletions(-)
drivers/mtd/nand/nand_base.c +20 -4
@@ -2920,9 +2920,14 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->chip_shift =ffs ((unsigned )(chip->chipsize >>32 )) +32 -1 ;/* Set the bad block position */ - chip->badblockpos = mtd->writesize >512 ? -NAND_LARGE_BADBLOCK_POS :NAND_SMALL_BADBLOCK_POS ; - chip->badblockbits =8 ; +if (!(busw &NAND_BUSWIDTH_16 ) && (*maf_id ==NAND_MFR_STMICRO || + (*maf_id ==NAND_MFR_SAMSUNG && + mtd->writesize ==512 ) || + *maf_id ==NAND_MFR_AMD )) + chip->badblockpos =NAND_SMALL_BADBLOCK_POS ; +else + chip->badblockpos =NAND_LARGE_BADBLOCK_POS ; +/* Get chip options, preserve non chip based options */ chip->options &= ~NAND_CHIPOPTIONS_MSK ;
@@ -2941,12 +2946,23 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,/* * Bad block marker is stored in the last page of each block -* on Samsung and Hynix MLC devices +* on Samsung and Hynix MLC devices; stored in first two pages +* of each block on Micron devices with 2KiB pages and on +* SLC Samsung, Hynix, and AMD/Spansion. All others scan only +* the first page. */ if ((chip->cellinfo &NAND_CI_CELLTYPE_MSK ) && (*maf_id ==NAND_MFR_SAMSUNG || *maf_id ==NAND_MFR_HYNIX )) chip->options |=NAND_BBT_SCANLASTPAGE ; +else if ((!(chip->cellinfo &NAND_CI_CELLTYPE_MSK ) && + (*maf_id ==NAND_MFR_SAMSUNG || + *maf_id ==NAND_MFR_HYNIX || + *maf_id ==NAND_MFR_AMD )) || + (mtd->writesize ==2048 && + *maf_id ==NAND_MFR_MICRON )) + chip->options |=NAND_BBT_SCAN2NDPAGE ; +/* Check for AND chips with 4 page planes */ if (chip->options &NAND_4PAGE_ARRAY )
drivers/mtd/nand/nand_bbt.c +38 -7
75 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v2 2/2 mtd/nand: More BB Detection, dynamic scan options
In reply to Brian NorrisAdded new flag for scanning of both bytes 1 and 6 of the OOB for a BB marker (instead of simply one or the other).
In order to handle increases in variety of necessary scanning patterns, I implemented dynamic memory allocation of nand_bbt_descr structs in new function 'nand_create_default_bbt_descr()'. This replaces some increasingly-unwieldy, statically-declared descriptors. It can replace several more (e.g. "flashbased" structs). However, I do not test the flashbased options personally.
--- drivers/mtd/nand/nand_base.c | 14 +++++ drivers/mtd/nand/nand_bbt.c | 116 ++++++++++++++++++++++-------------------- include/linux/mtd/bbm.h | 4 ++ 3 files changed, 79 insertions(+), 55 deletions(-)
drivers/mtd/nand/nand_base.c +14 -0
@@ -2963,6 +2963,15 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, *maf_id == NAND_MFR_MICRON)) chip->options |=NAND_BBT_SCAN2NDPAGE ; +/* +* Numonyx/ST 2K pages, x8 bus use BOTH byte 1 and 6 +*/ +if (!(busw &NAND_BUSWIDTH_16 ) && + *maf_id ==NAND_MFR_STMICRO && + mtd->writesize ==2048 ) { + chip->options |=NAND_BBT_SCANBYTE1AND6 ; + chip->badblockpos =0 ; + }/* Check for AND chips with 4 page planes */ if (chip->options &NAND_4PAGE_ARRAY )
@@ -3322,6 +3331,11 @@ void nand_release(struct mtd_info *mtd)kfree (chip->bbt);if (!(chip->options &NAND_OWN_BUFFERS ))kfree (chip->buffers); + +/* Free bad block descriptor memory */ +if (chip->badblock_pattern && chip->badblock_pattern->options + &NAND_BBT_DYNAMICSTRUCT ) +kfree (chip->badblock_pattern); }EXPORT_SYMBOL_GPL (nand_lock);
drivers/mtd/nand/nand_bbt.c +61 -55
146 lines not on this page · raw message
include/linux/mtd/bbm.h +4 -0
@@ -84,6 +84,10 @@ struct nand_bbt_descr {#define NAND_BBT_SCAN2NDPAGE 0x00004000/* Search good / bad pattern on the last page of the eraseblock */ #define NAND_BBT_SCANLASTPAGE 0x00008000 +/* Chip stores bad block marker on BOTH 1st and 6th bytes of OOB */ +#define NAND_BBT_SCANBYTE1AND6 0x00100000 +/* The nand_bbt_descr was created dynamicaly and must be freed */ +#define NAND_BBT_DYNAMICSTRUCT 0x00200000/* The maximum number of blocks to scan for a bbt */ #define NAND_BBT_SCAN_MAXBLOCKS 4
Signature · 1 line
1.7.0.4
Re: [PATCH v2 2/2] mtd/nand: More BB Detection, dynamic scan options
I have a few comments/questions about the following sections.
Quoted 2 lines · Brian Norris
Added new flag for scanning of both bytes 1 and 6 of the OOB for a BB marker (instead of simply one or the other).
<snip>
Quoted 4 lines
drivers/mtd/nand/nand_bbt.c +0
-0
<snip>
Quoted 15 lines
drivers/mtd/nand/nand_bbt.c +11
-0@@ -447,6 +445,24 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,if (ret<0 )return ret; +/* Check if we need a second scan for the 6th byte +* Perhaps there is a more efficient way of doing this? +*/ +if (!ret&& bd->options&NAND_BBT_SCANBYTE1AND6 ) { + bd->offs =NAND_SMALL_BADBLOCK_POS ; +if (bd->options&NAND_BBT_SCANALLPAGES ) + ret =scan_block_full (mtd, bd, from, buf, + readlen, scanlen, len); +else + ret =scan_block_fast (mtd, bd, from, buf, len); +
drivers/mtd/nand/nand_bbt.c static int create_bbt(struct mtd_info *mtd, uint8_t *buf, · line 468
Quoted 10 lines
drivers/mtd/nand/nand_bbt.c +7
-0+/* Reset offset for future scans */ + bd->offs =NAND_LARGE_BADBLOCK_POS ; + +if (ret<0 ) +return ret; + } +if (ret) { this->bbt[i>>3 ] |=0x03 << (i&0x6 ); printk(KERN_WARNING "Bad eraseblock %d at 0x%012llx\n",
I realize it's probably not the best practice to just duplicate/modify the detection code as I did above. I am trying to find the best place to implement the scanning of both bytes 1 and 6 of the OOB. Perhaps nand_bbt.c:check_pattern() and check_short_pattern()?
Also, it seems to me that in addition to the main scanning routines, I should update the nand_default_block_markbad() function in nand_base.c so that it writes its BB marker to the proper bytes in the OOB. Does this sound reasonable?
Comments/corrections are appreciated!
Brian
PATCH v3 2/2 mtd/nand: More BB Detection, dynamic scan options
This is a revision to PATCH 2/2 that I sent. Link:
http://lists.infradead.org/pipermail/linux-mtd/2010-July/030911.html
Added new flag for scanning of both bytes 1 and 6 of the OOB for a BB marker (instead of simply one or the other).
The "check_pattern" and "check_short_pattern" functions were updated to include support for scanning the two different locations in the OOB.
In order to handle increases in variety of necessary scanning patterns, I implemented dynamic memory allocation of nand_bbt_descr structs in new function 'nand_create_default_bbt_descr()'. This replaces some increasingly-unwieldy, statically-declared descriptors. It can replace several more (e.g. "flashbased" structs). However, I do not test the flashbased options personally.
--- drivers/mtd/nand/nand_base.c | 14 +++++ drivers/mtd/nand/nand_bbt.c | 127 ++++++++++++++++++++++++------------------ include/linux/mtd/bbm.h | 4 + 3 files changed, 90 insertions(+), 55 deletions(-)
drivers/mtd/nand/nand_base.c +14 -0
@@ -2963,6 +2963,15 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, *maf_id == NAND_MFR_MICRON)) chip->options |=NAND_BBT_SCAN2NDPAGE ; +/* +* Numonyx/ST 2K pages, x8 bus use BOTH byte 1 and 6 +*/ +if (!(busw &NAND_BUSWIDTH_16 ) && + *maf_id ==NAND_MFR_STMICRO && + mtd->writesize ==2048 ) { + chip->options |=NAND_BBT_SCANBYTE1AND6 ; + chip->badblockpos =0 ; + }/* Check for AND chips with 4 page planes */ if (chip->options &NAND_4PAGE_ARRAY )
@@ -3322,6 +3331,11 @@ void nand_release(struct mtd_info *mtd)kfree (chip->bbt);if (!(chip->options &NAND_OWN_BUFFERS ))kfree (chip->buffers); + +/* Free bad block descriptor memory */ +if (chip->badblock_pattern && chip->badblock_pattern->options + &NAND_BBT_DYNAMICSTRUCT ) +kfree (chip->badblock_pattern); }EXPORT_SYMBOL_GPL (nand_lock);
drivers/mtd/nand/nand_bbt.c +72 -55
163 lines not on this page · raw message
include/linux/mtd/bbm.h +4 -0
@@ -84,6 +84,10 @@ struct nand_bbt_descr {#define NAND_BBT_SCAN2NDPAGE 0x00004000/* Search good / bad pattern on the last page of the eraseblock */ #define NAND_BBT_SCANLASTPAGE 0x00008000 +/* Chip stores bad block marker on BOTH 1st and 6th bytes of OOB */ +#define NAND_BBT_SCANBYTE1AND6 0x00100000 +/* The nand_bbt_descr was created dynamicaly and must be freed */ +#define NAND_BBT_DYNAMICSTRUCT 0x00200000/* The maximum number of blocks to scan for a bbt */ #define NAND_BBT_SCAN_MAXBLOCKS 4
Signature · 1 line
1.7.0.4
Re: [PATCH v2 0/2] Improved BB Scanning
In reply to Brian NorrisQuoted 7 lines · Brian Norris
This is a two-patch correction and update to my previous attempt to address a few issues with bad block scanning. Overall, they should help renovate some incorrect and unwieldy code.
I included the top few maintainers from get_maintainers.pl. Sorry if these were incorrect addressees.
Quoted 8 lines
Brian Norris (2):
mtd/nand, BB detect: factory marker in page 1, 2, last and byte 1 or 6 mtd/nand: More BB Detection, dynamic scan optionsdrivers/mtd/nand/nand_base.c | 38 ++++++++++++++++-- drivers/mtd/nand/nand_bbt.c | 89 +++++++++++++++++++++++++++++------------ include/linux/mtd/bbm.h | 4 ++ 3 files changed, 101 insertions(+), 30 deletions(-)
I did not _really_ review this, it the patches look good. How did you test them? Did you test on both large and small page NANDs?
I pushed your patches to my l2-mtd-2.6.git / master
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v2 0/2] Improved BB Scanning
Quoted 2 lines · Artem Bityutskiy
I did not _really_ review this, it the patches look good. How did you test them? Did you test on both large and small page NANDs?
I referenced 30+ data sheets (covering 100+ parts), and I tested a selection of 10 different chips to varying degrees. Particularly, I tested the creation of bad-block descriptors and basic BB scanning on three parts:
ST NAND04GW3B2D, 2K page
ST NAND128W3A, 512B page
Samsung K9F1G08U0A, 2K page
To test these, I wrote some fake bad block markers to the flash (in OOB bytes 1, 6, and elsewhere) to see if the scanning routine would detect them properly. However, this method was somewhat limited because the driver I am using has some bugs in its OOB write functionality.
Re: [PATCH v2 0/2] Improved BB Scanning
Quoted 9 lines · Brian Norris
Quoted 2 lines · Artem Bityutskiy
I did not _really_ review this, it the patches look good. How did you test them? Did you test on both large and small page NANDs?
I referenced 30+ data sheets (covering 100+ parts), and I tested a selection of 10 different chips to varying degrees. Particularly, I tested the creation of bad-block descriptors and basic BB scanning on three parts:
Quoted 8 lines
ST NAND04GW3B2D, 2K page
ST NAND128W3A, 512B page
Samsung K9F1G08U0A, 2K pageTo test these, I wrote some fake bad block markers to the flash (in OOB bytes 1, 6, and elsewhere) to see if the scanning routine would detect them properly. However, this method was somewhat limited because the driver I am using has some bugs in its OOB write functionality.
Sounds like you did a lot of work. I'll add this information to the patch description.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v2 0/2] Improved BB Scanning
Quoted 14 lines · Artem Bityutskiy
Quoted 13 lines · Brian Norris
Quoted 2 lines · Artem Bityutskiy
I did not _really_ review this, it the patches look good. How did you test them? Did you test on both large and small page NANDs?
I referenced 30+ data sheets (covering 100+ parts), and I tested a selection of 10 different chips to varying degrees. Particularly, I tested the creation of bad-block descriptors and basic BB scanning on three parts:
ST NAND04GW3B2D, 2K page
ST NAND128W3A, 512B page
Samsung K9F1G08U0A, 2K page
Quoted 8 lines
Quoted 4 lines
To test these, I wrote some fake bad block markers to the flash (in OOB bytes 1, 6, and elsewhere) to see if the scanning routine would detect them properly. However, this method was somewhat limited because the driver I am using has some bugs in its OOB write functionality.
Sounds like you did a lot of work. I'll add this information to the patch description.
I haven't seen many nandsim feedback, though it allows precise test scenarios and easy flash forensics.
Still, FWIW, I too laud the effort.
Signature · 1 line
Karl
PATCH 1/1 mtd/nand: Update nand_default_block_markbad()
In reply to Brian NorrisThis is an update that depends on the previous patches I sent.
We can now write to all the appropriate BB marker locations (i.e. pages 1 AND 2, bytes 1 AND 6) with nand_default_block_markbad() if necessary, according to the flags marked in chip->options.
Note that I removed the line:
ofs += mtd->oobsize;
Unless I am wrong, this line was completely unnecessary in the first place.
--- drivers/mtd/nand/nand_base.c | 34 ++++++++++++++++++++++++---------- 1 files changed, 24 insertions(+), 10 deletions(-)
drivers/mtd/nand/nand_base.c +24 -10
@@ -397,7 +397,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; +int block, ret, i =0 ;if (chip->options &NAND_BBT_SCANLASTPAGE ) ofs += mtd->erasesize - mtd->writesize;
@@ -411,17 +411,31 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)if (chip->options &NAND_USE_FLASH_BBT ) ret =nand_update_bbt (mtd, ofs);else { -/* We write two bytes, so we dont have to mess with 16 bit -* access -*/ nand_get_device (chip, mtd,FL_WRITING ); - ofs += mtd->oobsize; - chip->ops.len = chip->ops.ooblen =2 ; - chip->ops.datbuf =NULL ; - chip->ops.oobbuf = buf; - chip->ops.ooboffs = chip->badblockpos & ~0x01 ; - ret =nand_do_write_oob (mtd, ofs, &chip->ops); +/* Write to first two pages and to byte 1 and 6 if necessary. +* If we write to more than one location, the first error +* encountered quits the procedure. We write two bytes per +* location, so we dont have to mess with 16 bit access. +*/ +do { + chip->ops.len = chip->ops.ooblen =2 ; + chip->ops.datbuf =NULL ; + chip->ops.oobbuf = buf; + chip->ops.ooboffs = chip->badblockpos & ~0x01 ; + + ret =nand_do_write_oob (mtd, ofs, &chip->ops); + +if (!ret && (chip->options &NAND_BBT_SCANBYTE1AND6 )) { + chip->ops.ooboffs =NAND_SMALL_BADBLOCK_POS + & ~0x01 ; + ret =nand_do_write_oob (mtd, ofs, &chip->ops); + } + i++; + ofs += mtd->writesize; + }while (!ret && (chip->options &NAND_BBT_SCAN2NDPAGE ) && + i <2 ); +nand_release_device (mtd); }if (!ret)
Signature · 1 line
1.7.0.4
Artem Bityutskiy
AppliedRe: [PATCH] mtd/nand: Update nand_default_block_markbad()
Quoted 6 lines · Brian Norris
This is an update that depends on the previous patches I sent.
We can now write to all the appropriate BB marker locations (i.e. pages 1 AND 2, bytes 1 AND 6) with
nand_default_block_markbad()if necessary, according to the flags marked inchip->options.
Quoted 6 lines
Note that I removed the line:
ofs += mtd->oobsize;Unless I am wrong, this line was completely unnecessary in the first place.
Signed-off-by Brian Norris <[email protected]>
Pushed to mtd-2.6.git / master, thanks.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Artem Bityutskiy
AppliedQuoted 7 lines · Brian Norris
NAND_BB_LAST_PAGEused to be innand.h, but it pertained to bad block management and so belongs next toNAND_BBT_SCAN2NDPAGEinbbm.h. Also, its previous flag value (0x00000400) conflicted withNAND_BBT_SCANALLPAGESso I changed its value to0x00008000. All uses of the name were modified to provide consistency with other "NAND_BBT_*" flags.Signed-off-by Brian Norris <[email protected]>
Pushed to l2-mtd-2.6.git / master, thanks.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Artem Bityutskiy
AppliedQuoted 7 lines · Brian Norris
NAND_BB_LAST_PAGEused to be innand.h, but it pertained to bad block management and so belongs next toNAND_BBT_SCAN2NDPAGEinbbm.h. Also, its previous flag value (0x00000400) conflicted withNAND_BBT_SCANALLPAGESso I changed its value to0x00008000. All uses of the name were modified to provide consistency with other "NAND_BBT_*" flags.Signed-off-by Brian Norris <[email protected]>
Pushed to l2-mtd-2.6.git / master, thanks.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)