summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorYoshio Furuyama <ytc-mb-yfuruyama7@kioxia.com>2021-02-16 09:37:55 +0900
committerSascha Hauer <s.hauer@pengutronix.de>2021-02-17 09:28:35 +0100
commitce0733564d1a114ca649dc266f0c3321c4877c07 (patch)
tree7aae566188df0fb2959250c78d0684db0651f9f8 /drivers
parent3a5917ddaedb1256a712a6287f7f050038021a98 (diff)
downloadbarebox-ce0733564d1a114ca649dc266f0c3321c4877c07.tar.gz
barebox-ce0733564d1a114ca649dc266f0c3321c4877c07.tar.xz
mtd: nand: Fix BBT update issue
Fixed issue of manages BBT (Bad Block Table). It didn't mark correctly when a specific block was bad block. This issue occurs when the bad block mark (3-bit chunk) is crosses over 32 bit (e.g. Block10, Block21...) unit. Signed-off-by: Yoshio Furuyama <ytc-mb-yfuruyama7@kioxia.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/nand/bbt.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
index 172ab5ffbc..8a78f9046f 100644
--- a/drivers/mtd/nand/bbt.c
+++ b/drivers/mtd/nand/bbt.c
@@ -113,18 +113,20 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
((entry * bits_per_block) / BITS_PER_LONG);
unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
unsigned long val = status & GENMASK(bits_per_block - 1, 0);
+ unsigned long shift = ((bits_per_block + offs <= BITS_PER_LONG) ?
+ (offs + bits_per_block - 1) : (BITS_PER_LONG - 1));
if (entry >= nanddev_neraseblocks(nand))
return -ERANGE;
- pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs);
+ pos[0] &= ~GENMASK(shift, offs);
pos[0] |= val << offs;
if (bits_per_block + offs > BITS_PER_LONG) {
unsigned int rbits = bits_per_block + offs - BITS_PER_LONG;
pos[1] &= ~GENMASK(rbits - 1, 0);
- pos[1] |= val >> rbits;
+ pos[1] |= (val >> (BITS_PER_LONG - offs));
}
return 0;