mtd: atmel_nand: replace printk with dev_info
PATCH 1/3 mtd: atmel_nand: replace printk with dev_info
Signed-off-by Ladislav Michl <[email protected]>
--- drivers/mtd/nand/atmel_nand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/atmel_nand.c +2 -2
@@ -1429,14 +1429,14 @@ static int __init atmel_nand_probe(struct device_d *dev) }if (gpio_get_value (host->board->det_pin)) { -printk ("No SmartMedia card inserted.\n" ); +dev_info (dev,"No SmartMedia card inserted.\n" ); res = -ENXIO ; goto err_no_card; } }if (host->board->on_flash_bbt) { -printk (KERN_INFO "atmel_nand: Use On Flash BBT\n" ); +dev_info (dev,"Use On Flash BBT\n" ); nand_chip->bbt_options |=NAND_BBT_USE_FLASH ; }
Signature · 7 lines
2.19.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/3 mtd: nand: add accessors, macros for in-memory BBT
Linux commit 771c568bcf91:
There is an abundance of magic numbers and complicated shifting/masking logic in the in-memory BBT code which makes the code unnecessary complex and hard to read.
This patch adds macros to represent the 00b, 01b, 10b, and 11b memory-BBT magic numbers, as well as two accessor functions for reading and marking the memory-BBT bitfield for a given block.
Signed-off-by Ladislav Michl <[email protected]>
--- drivers/mtd/nand/nand_bbt.c | 70 +++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 22 deletions(-)
drivers/mtd/nand/nand_bbt.c +48 -22
@@ -69,6 +69,28 @@#include <errno.h> #include <malloc.h> +#define BBT_BLOCK_GOOD 0x00 +#define BBT_BLOCK_WORN 0x01 +#define BBT_BLOCK_RESERVED 0x02 +#define BBT_BLOCK_FACTORY_BAD 0x03 + +#define BBT_ENTRY_MASK 0x03 +#define BBT_ENTRY_SHIFT 2 + +static inline uint8_t bbt_get_entry (struct nand_chip *chip,int block) +{ +uint8_t entry = chip->bbt[block >>BBT_ENTRY_SHIFT ]; + entry >>= (block &BBT_ENTRY_MASK ) *2 ; +return entry &BBT_ENTRY_MASK ; +} + +static inline void bbt_mark_entry (struct nand_chip *chip,int block, +uint8_t mark) +{ +uint8_t msk = (mark &BBT_ENTRY_MASK ) << ((block &BBT_ENTRY_MASK ) *2 ); + chip->bbt[block >>BBT_ENTRY_SHIFT ] |= msk; +} +static int check_pattern_no_oob (uint8_t *buf,struct nand_bbt_descr *td) {if (memcmp (buf, td->pattern, td->len))
@@ -214,7 +236,9 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,if (reserved_block_code && (tmp == reserved_block_code)) {pr_info ("nand_read_bbt: reserved block at 0x%012llx\n" , (loff_t)((offs <<2 ) + (act >>1 )) << this->bbt_erase_shift); - this->bbt[offs + (act >>3 )] |=0x2 << (act &0x06 ); +bbt_mark_entry (this, (offs <<2 ) + + (act >>1 ), +BBT_BLOCK_RESERVED ); mtd->ecc_stats.bbtblocks++;continue ; }
@@ -222,9 +246,13 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift);/* Factory marked bad or worn out? */ if (tmp ==0 ) - this->bbt[offs + (act >>3 )] |=0x3 << (act &0x06 ); +bbt_mark_entry (this, (offs <<2 ) + + (act >>1 ), +BBT_BLOCK_FACTORY_BAD );else - this->bbt[offs + (act >>3 )] |=0x1 << (act &0x06 ); +bbt_mark_entry (this, (offs <<2 ) + + (act >>1 ), +BBT_BLOCK_WORN ); mtd->ecc_stats.badblocks++; } }
@@ -520,7 +548,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,return ret;if (ret) { - this->bbt[i >>3 ] |=0x03 << (i &0x6 ); +bbt_mark_entry (this, i >>1 ,BBT_BLOCK_FACTORY_BAD );pr_warn ("Bad eraseblock %d at 0x%012llx\n" , i >>1 , (unsigned long long )from); mtd->ecc_stats.badblocks++;
@@ -704,10 +732,9 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,for (i =0 ; i < td->maxblocks; i++) {int block = startblock + dir * i;/* Check, if the block is bad */ -switch ((this->bbt[block >>2 ] >> - (2 * (block &0x03 ))) &0x03 ) { -case 0x01 : -case 0x03 : +switch (bbt_get_entry (this, block)) { +case BBT_BLOCK_WORN : +case BBT_BLOCK_FACTORY_BAD :continue ; } page = block <<
@@ -807,7 +834,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,/* Walk through the memory table */ for (i =0 ; i < numblocks;) {uint8_t dat; - dat = this->bbt[bbtoffs + (i >>2 )]; + dat =bbt_get_entry (this, (bbtoffs <<2 ) + i);for (j =0 ; j <4 ; j++, i++) {int sftcnt = (i << (3 - sft)) & sftmsk;/* Do not store the reserved bbt blocks! */
@@ -1000,7 +1027,7 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) {struct nand_chip *this = mtd->priv;int i, j, chips, block, nrblocks, update; -uint8_t oldval, newval; +uint8_t oldval;/* Do we have a bbt per chip? */ if (td->options &NAND_BBT_PERCHIP ) {
@@ -1018,10 +1045,10 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)continue ; block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift); block <<=1 ; - oldval = this->bbt[(block >>3 )]; - newval = oldval | (0x2 << (block &0x06 )); - this->bbt[(block >>3 )] = newval; -if ((oldval != newval) && td->reserved_block_code) + oldval =bbt_get_entry (this, block >>1 ); +bbt_mark_entry (this, block >>1 ,BBT_BLOCK_RESERVED ); +if ((oldval !=BBT_BLOCK_RESERVED ) && + td->reserved_block_code)nand_update_bbt (mtd, (loff_t )block << (this->bbt_erase_shift -1 ));continue ; }
@@ -1032,10 +1059,9 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) block = i * nrblocks; block <<=1 ;for (j =0 ; j < td->maxblocks; j++) { - oldval = this->bbt[(block >>3 )]; - newval = oldval | (0x2 << (block &0x06 )); - this->bbt[(block >>3 )] = newval; -if (oldval != newval) + oldval =bbt_get_entry (this, block >>1 ); +bbt_mark_entry (this, block >>1 ,BBT_BLOCK_RESERVED ); +if (oldval !=BBT_BLOCK_RESERVED ) update =1 ; block +=2 ; }
@@ -1352,18 +1378,18 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)/* Get block number * 2 */ block = (int )(offs >> (this->bbt_erase_shift -1 )); - res = (this->bbt[block >>3 ] >> (block &0x06 )) &0x03 ; + res =bbt_get_entry (this, block >>1 );pr_debug ("nand_isbad_bbt(): bbt info for offs 0x%08x: " "(block %d) 0x%02x\n" , (unsigned int )offs, block >>1 , res);switch ((int )res) { -case 0x00 : +case BBT_BLOCK_GOOD :return 0 ; -case 0x01 : +case BBT_BLOCK_WORN :return 1 ; -case 0x02 : +case BBT_BLOCK_RESERVED :return allowbbt ?0 :1 ; }return 1 ;
Signature · 7 lines
2.19.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/3 mtd: nand: don't break long print messages
In reply to Ladislav MichlLinux commit 2ac63d901b11 adapted for Barebox:
...However, never break user-visible strings such as printk messages, because that breaks the ability to grep for them.
Signed-off-by Ladislav Michl <[email protected]>
--- drivers/mtd/nand/nand_base.c | 6 ++---- drivers/mtd/nand/nand_bbt.c | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-)
drivers/mtd/nand/nand_base.c +2 -4
@@ -3565,8 +3565,7 @@ int nand_scan_tail(struct mtd_info *mtd)/* Similar to NAND_ECC_HW, but a separate read_page handle */ if (!chip->ecc.calculate || !chip->ecc.correct || !chip->ecc.hwctl) { -pr_warn ("No ECC functions supplied; " -"hardware ECC not possible\n" ); +pr_warn ("No ECC functions supplied; hardware ECC not possible\n" );BUG (); }if (!chip->ecc.read_page)
@@ -3681,8 +3680,7 @@ int nand_scan_tail(struct mtd_info *mtd)#endif #ifdef CONFIG_NAND_ECC_NONE case NAND_ECC_NONE : -pr_warn ("NAND_ECC_NONE selected by board driver. " -"This is not recommended!\n" ); +pr_warn ("NAND_ECC_NONE selected by board driver. This is not recommended!\n" ); chip->ecc.read_page = nand_read_page_raw; chip->ecc.write_page = nand_write_page_raw; chip->ecc.read_oob = nand_read_oob_std;
drivers/mtd/nand/nand_bbt.c +10 -13
@@ -213,12 +213,12 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, res =mtd_read (mtd, from, len, &retlen, buf);if (res <0 ) {if (mtd_is_eccerr (res)) { -pr_info ("nand_bbt: ECC error in BBT at " -"0x%012llx\n" , from & ~mtd->writesize); +pr_info ("nand_bbt: ECC error in BBT at 0x%012llx\n" , + from & ~mtd->writesize);return res; }else if (mtd_is_bitflip (res)) { -pr_info ("nand_bbt: corrected error in BBT at " -"0x%012llx\n" , from & ~mtd->writesize); +pr_info ("nand_bbt: corrected error in BBT at 0x%012llx\n" , + from & ~mtd->writesize); ret = res; }else {pr_info ("nand_bbt: error reading BBT\n" );
@@ -631,8 +631,8 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descrif (td->pages[i] ==-1 )pr_warn ("Bad block table not found for chip %d\n" , i);else -pr_info ("Bad block table found at page %d, version " -"0x%02X\n" , td->pages[i], td->version[i]); +pr_info ("Bad block table found at page %d, version 0x%02X\n" , + td->pages[i], td->version[i]); }return 0 ; }
@@ -778,12 +778,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, res =mtd_read (mtd, to, len, &retlen, buf);if (res <0 ) {if (retlen != len) { -pr_info ("nand_bbt: error reading block " -"for writing the bad block table\n" ); +pr_info ("nand_bbt: error reading block for writing the bad block table\n" );return res; } -pr_warn ("nand_bbt: ECC error while reading " -"block for writing bad block table\n" ); +pr_warn ("nand_bbt: ECC error while reading block for writing bad block table\n" ); }/* Read oob data */ ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
@@ -1380,9 +1378,8 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) block = (int )(offs >> (this->bbt_erase_shift -1 )); res =bbt_get_entry (this, block >>1 ); -pr_debug ("nand_isbad_bbt(): bbt info for offs 0x%08x: " -"(block %d) 0x%02x\n" , - (unsigned int )offs, block >>1 , res); +pr_debug ("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n" , + (unsigned int )offs, block >>1 , res);switch ((int )res) {case BBT_BLOCK_GOOD :
Signature · 7 lines
2.19.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 5 lines · Ladislav Michl
Signed-off-by Ladislav Michl <[email protected]>--- drivers/mtd/nand/atmel_nand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied, thanks
Sascha
Quoted 30 lines
drivers/mtd/nand/atmel_nand.c +2
-2@@ -1429,14 +1429,14 @@ static int __init atmel_nand_probe(struct device_d *dev) }if (gpio_get_value (host->board->det_pin)) { -printk ("No SmartMedia card inserted.\n" ); +dev_info (dev,"No SmartMedia card inserted.\n" ); res = -ENXIO ; goto err_no_card; } }if (host->board->on_flash_bbt) { -printk (KERN_INFO "atmel_nand: Use On Flash BBT\n" ); +dev_info (dev,"Use On Flash BBT\n" ); nand_chip->bbt_options |=NAND_BBT_USE_FLASH ; }Signature · 7 lines
2.19.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox