drivers/mtd/nand/raw/nand_bbt.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/raw/nand_bbt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/raw/nand_bbt.c- Extension
.c- Size
- 41684 bytes
- Lines
- 1491
- Domain
- Driver Families
- Bucket
- drivers/mtd
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/types.hlinux/mtd/mtd.hlinux/mtd/bbm.hlinux/bitops.hlinux/delay.hlinux/vmalloc.hlinux/export.hlinux/string.hinternals.h
Detected Declarations
function descriptorfunction bbt_mark_entryfunction check_pattern_no_oobfunction check_patternfunction check_short_patternfunction add_marker_lenfunction read_bbtfunction read_abs_bbtfunction scan_read_datafunction conditionfunction scan_readfunction scan_write_bbtfunction bbt_get_ver_offsfunction tablefunction scan_block_fastfunction bbt_block_checkbadfunction create_bbtfunction search_bbtfunction tablefunction BBTfunction mark_bbt_block_badfunction write_bbtfunction nand_memory_bbtfunction check_createfunction tablefunction mark_bbt_regionfunction verify_bbt_descrfunction tablefunction nand_create_badblock_patternfunction nand_create_bbtfunction nand_isreserved_bbtfunction nand_isbad_bbtfunction nand_markbad_bbtexport nand_create_bbt
Annotated Snippet
if (marker_len) {
/*
* In case the BBT marker is not in the OOB area it
* will be just in the first page.
*/
len -= marker_len;
from += marker_len;
marker_len = 0;
}
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);
return res;
} else if (mtd_is_bitflip(res)) {
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");
return res;
}
}
/* Analyse data */
for (i = 0; i < len; i++) {
uint8_t dat = buf[i];
for (j = 0; j < 8; j += bits, act++) {
uint8_t tmp = (dat >> j) & msk;
if (tmp == msk)
continue;
if (reserved_block_code && (tmp == reserved_block_code)) {
pr_info("nand_read_bbt: reserved block at 0x%012llx\n",
(loff_t)(offs + act) <<
this->bbt_erase_shift);
bbt_mark_entry(this, offs + act,
BBT_BLOCK_RESERVED);
mtd->ecc_stats.bbtblocks++;
continue;
}
/*
* Leave it for now, if it's matured we can
* move this message to pr_debug.
*/
pr_info("nand_read_bbt: bad block at 0x%012llx\n",
(loff_t)(offs + act) <<
this->bbt_erase_shift);
/* Factory marked bad or worn out? */
if (tmp == 0)
bbt_mark_entry(this, offs + act,
BBT_BLOCK_FACTORY_BAD);
else
bbt_mark_entry(this, offs + act,
BBT_BLOCK_WORN);
mtd->ecc_stats.badblocks++;
}
}
totlen -= len;
from += len;
}
return ret;
}
/**
* read_abs_bbt - [GENERIC] Read the bad block table starting at a given page
* @this: NAND chip object
* @buf: temporary buffer
* @td: descriptor for the bad block table
* @chip: read the table for a specific chip, -1 read all chips; applies only if
* NAND_BBT_PERCHIP option is set
*
* Read the bad block table for all chips starting at a given page. We assume
* that the bbt bits are in consecutive order.
*/
static int read_abs_bbt(struct nand_chip *this, uint8_t *buf,
struct nand_bbt_descr *td, int chip)
{
struct mtd_info *mtd = nand_to_mtd(this);
u64 targetsize = nanddev_target_size(&this->base);
int res = 0, i;
if (td->options & NAND_BBT_PERCHIP) {
int offs = 0;
for (i = 0; i < nanddev_ntargets(&this->base); i++) {
if (chip == -1 || chip == i)
res = read_bbt(this, buf, td->pages[i],
targetsize >> this->bbt_erase_shift,
td, offs);
if (res)
Annotation
- Immediate include surface: `linux/slab.h`, `linux/types.h`, `linux/mtd/mtd.h`, `linux/mtd/bbm.h`, `linux/bitops.h`, `linux/delay.h`, `linux/vmalloc.h`, `linux/export.h`.
- Detected declarations: `function descriptor`, `function bbt_mark_entry`, `function check_pattern_no_oob`, `function check_pattern`, `function check_short_pattern`, `function add_marker_len`, `function read_bbt`, `function read_abs_bbt`, `function scan_read_data`, `function condition`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.