@@ -264,18 +264,19 @@ static int read_abs_bbt(struct nand_chip *this, uint8_t *buf,
264264 struct nand_bbt_descr * td , int chip )
265265{
266266 struct mtd_info * mtd = nand_to_mtd (this );
267+ u64 targetsize = nanddev_target_size (& this -> base );
267268 int res = 0 , i ;
268269
269270 if (td -> options & NAND_BBT_PERCHIP ) {
270271 int offs = 0 ;
271272 for (i = 0 ; i < this -> numchips ; i ++ ) {
272273 if (chip == -1 || chip == i )
273274 res = read_bbt (this , buf , td -> pages [i ],
274- this -> chipsize >> this -> bbt_erase_shift ,
275+ targetsize >> this -> bbt_erase_shift ,
275276 td , offs );
276277 if (res )
277278 return res ;
278- offs += this -> chipsize >> this -> bbt_erase_shift ;
279+ offs += targetsize >> this -> bbt_erase_shift ;
279280 }
280281 } else {
281282 res = read_bbt (this , buf , td -> pages [0 ],
@@ -459,6 +460,7 @@ static int scan_block_fast(struct nand_chip *this, struct nand_bbt_descr *bd,
459460static int create_bbt (struct nand_chip * this , uint8_t * buf ,
460461 struct nand_bbt_descr * bd , int chip )
461462{
463+ u64 targetsize = nanddev_target_size (& this -> base );
462464 struct mtd_info * mtd = nand_to_mtd (this );
463465 int i , numblocks , numpages ;
464466 int startblock ;
@@ -481,7 +483,7 @@ static int create_bbt(struct nand_chip *this, uint8_t *buf,
481483 chip + 1 , this -> numchips );
482484 return - EINVAL ;
483485 }
484- numblocks = this -> chipsize >> this -> bbt_erase_shift ;
486+ numblocks = targetsize >> this -> bbt_erase_shift ;
485487 startblock = chip * numblocks ;
486488 numblocks += startblock ;
487489 from = (loff_t )startblock << this -> bbt_erase_shift ;
@@ -529,6 +531,7 @@ static int create_bbt(struct nand_chip *this, uint8_t *buf,
529531static int search_bbt (struct nand_chip * this , uint8_t * buf ,
530532 struct nand_bbt_descr * td )
531533{
534+ u64 targetsize = nanddev_target_size (& this -> base );
532535 struct mtd_info * mtd = nand_to_mtd (this );
533536 int i , chips ;
534537 int startblock , block , dir ;
@@ -548,7 +551,7 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
548551 /* Do we have a bbt per chip? */
549552 if (td -> options & NAND_BBT_PERCHIP ) {
550553 chips = this -> numchips ;
551- bbtblocks = this -> chipsize >> this -> bbt_erase_shift ;
554+ bbtblocks = targetsize >> this -> bbt_erase_shift ;
552555 startblock &= bbtblocks - 1 ;
553556 } else {
554557 chips = 1 ;
@@ -576,7 +579,7 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
576579 break ;
577580 }
578581 }
579- startblock += this -> chipsize >> this -> bbt_erase_shift ;
582+ startblock += targetsize >> this -> bbt_erase_shift ;
580583 }
581584 /* Check, if we found a bbt for each requested chip */
582585 for (i = 0 ; i < chips ; i ++ ) {
@@ -626,6 +629,7 @@ static void search_read_bbts(struct nand_chip *this, uint8_t *buf,
626629static int get_bbt_block (struct nand_chip * this , struct nand_bbt_descr * td ,
627630 struct nand_bbt_descr * md , int chip )
628631{
632+ u64 targetsize = nanddev_target_size (& this -> base );
629633 int startblock , dir , page , numblocks , i ;
630634
631635 /*
@@ -637,7 +641,7 @@ static int get_bbt_block(struct nand_chip *this, struct nand_bbt_descr *td,
637641 return td -> pages [chip ] >>
638642 (this -> bbt_erase_shift - this -> page_shift );
639643
640- numblocks = (int )(this -> chipsize >> this -> bbt_erase_shift );
644+ numblocks = (int )(targetsize >> this -> bbt_erase_shift );
641645 if (!(td -> options & NAND_BBT_PERCHIP ))
642646 numblocks *= this -> numchips ;
643647
@@ -717,6 +721,7 @@ static int write_bbt(struct nand_chip *this, uint8_t *buf,
717721 struct nand_bbt_descr * td , struct nand_bbt_descr * md ,
718722 int chipsel )
719723{
724+ u64 targetsize = nanddev_target_size (& this -> base );
720725 struct mtd_info * mtd = nand_to_mtd (this );
721726 struct erase_info einfo ;
722727 int i , res , chip = 0 ;
@@ -737,7 +742,7 @@ static int write_bbt(struct nand_chip *this, uint8_t *buf,
737742 rcode = 0xff ;
738743 /* Write bad block table per chip rather than per device? */
739744 if (td -> options & NAND_BBT_PERCHIP ) {
740- numblocks = (int )(this -> chipsize >> this -> bbt_erase_shift );
745+ numblocks = (int )(targetsize >> this -> bbt_erase_shift );
741746 /* Full device write or specific chip? */
742747 if (chipsel == -1 ) {
743748 nrchips = this -> numchips ;
@@ -1099,14 +1104,15 @@ static int nand_update_bbt(struct nand_chip *this, loff_t offs)
10991104 */
11001105static void mark_bbt_region (struct nand_chip * this , struct nand_bbt_descr * td )
11011106{
1107+ u64 targetsize = nanddev_target_size (& this -> base );
11021108 struct mtd_info * mtd = nand_to_mtd (this );
11031109 int i , j , chips , block , nrblocks , update ;
11041110 uint8_t oldval ;
11051111
11061112 /* Do we have a bbt per chip? */
11071113 if (td -> options & NAND_BBT_PERCHIP ) {
11081114 chips = this -> numchips ;
1109- nrblocks = (int )(this -> chipsize >> this -> bbt_erase_shift );
1115+ nrblocks = (int )(targetsize >> this -> bbt_erase_shift );
11101116 } else {
11111117 chips = 1 ;
11121118 nrblocks = (int )(mtd -> size >> this -> bbt_erase_shift );
@@ -1159,6 +1165,7 @@ static void mark_bbt_region(struct nand_chip *this, struct nand_bbt_descr *td)
11591165 */
11601166static void verify_bbt_descr (struct nand_chip * this , struct nand_bbt_descr * bd )
11611167{
1168+ u64 targetsize = nanddev_target_size (& this -> base );
11621169 struct mtd_info * mtd = nand_to_mtd (this );
11631170 u32 pattern_len ;
11641171 u32 bits ;
@@ -1187,7 +1194,7 @@ static void verify_bbt_descr(struct nand_chip *this, struct nand_bbt_descr *bd)
11871194 }
11881195
11891196 if (bd -> options & NAND_BBT_PERCHIP )
1190- table_size = this -> chipsize >> this -> bbt_erase_shift ;
1197+ table_size = targetsize >> this -> bbt_erase_shift ;
11911198 else
11921199 table_size = mtd -> size >> this -> bbt_erase_shift ;
11931200 table_size >>= 3 ;
0 commit comments