// SPDX-License-Identifier: GPL-2.0 /* * Bad Block Table support for the OneNAND driver * * Copyright(c) 2005 Samsung Electronics * Kyungmin Park <[email protected]> * * Derived from nand_bbt.c * * TODO: * Split BBT core and chip specific BBT. */ #include <linux/slab.h> #include <linux/mtd/mtd.h> #include <linux/mtd/onenand.h> #include <linux/export.h> /** * check_short_pattern - [GENERIC] check if a pattern is in the buffer * @buf: the buffer to search * @len: the length of buffer to search * @paglen: the pagelength * @td: search pattern descriptor * * Check for a pattern at the given place. Used to search bad block * tables and good / bad block identifiers. Same as check_pattern, but * no optional empty check and the pattern is expected to start * at offset 0. * */ static int check_short_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) { … } /** * create_bbt - [GENERIC] Create a bad block table by scanning the device * @mtd: MTD device structure * @buf: temporary buffer * @bd: descriptor for the good/bad block search pattern * @chip: create the table for a specific chip, -1 read all chips. * Applies only if NAND_BBT_PERCHIP option is set * * Create a bad block table by scanning the device * for the given good/bad block identify pattern */ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip) { … } /** * onenand_memory_bbt - [GENERIC] create a memory based bad block table * @mtd: MTD device structure * @bd: descriptor for the good/bad block search pattern * * The function creates a memory based bbt by scanning the device * for manufacturer / software marked good / bad blocks */ static inline int onenand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) { … } /** * onenand_isbad_bbt - [OneNAND Interface] Check if a block is bad * @mtd: MTD device structure * @offs: offset in the device * @allowbbt: allow access to bad block table region */ static int onenand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) { … } /** * onenand_scan_bbt - [OneNAND Interface] scan, find, read and maybe create bad block table(s) * @mtd: MTD device structure * @bd: descriptor for the good/bad block search pattern * * The function checks, if a bad block table(s) is/are already * available. If not it scans the device for manufacturer * marked good / bad blocks and writes the bad block table(s) to * the selected place. * * The bad block table memory is allocated here. It is freed * by the onenand_release function. * */ static int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) { … } /* * Define some generic bad / good block scan pattern which are used * while scanning a device for factory marked good / bad blocks. */ static uint8_t scan_ff_pattern[] = …; static struct nand_bbt_descr largepage_memorybased = …; /** * onenand_default_bbt - [OneNAND Interface] Select a default bad block table for the device * @mtd: MTD device structure * * This function selects the default bad block table * support for the device and calls the onenand_scan_bbt function */ int onenand_default_bbt(struct mtd_info *mtd) { … }