os/linux-2.6-tag--devboard-R2_10-4/drivers/mtd/nand/nand_bbt.c File Reference

#include <linux/slab.h>
#include <linux/types.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/compatmac.h>
#include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/vmalloc.h>

Include dependency graph for nand_bbt.c:

Go to the source code of this file.

Functions

static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td)
static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num, int bits, int offs, int reserved_block_code)
static int read_abs_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
static int scan_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t offs, size_t len)
static int scan_write_bbt (struct mtd_info *mtd, loff_t offs, size_t len, uint8_t *buf, uint8_t *oob)
static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
static int scan_block_full (struct mtd_info *mtd, struct nand_bbt_descr *bd, loff_t offs, uint8_t *buf, size_t readlen, int scanlen, int len)
static int scan_block_fast (struct mtd_info *mtd, struct nand_bbt_descr *bd, loff_t offs, uint8_t *buf, int len)
static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip)
static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
static int write_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md, int chipsel)
static int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
int nand_default_bbt (struct mtd_info *mtd)
int nand_isbad_bbt (struct mtd_info *mtd, loff_t offs, int allowbbt)
 EXPORT_SYMBOL (nand_scan_bbt)
 EXPORT_SYMBOL (nand_default_bbt)

Variables

static uint8_t scan_ff_pattern [] = { 0xff, 0xff }
static struct nand_bbt_descr smallpage_memorybased
static struct nand_bbt_descr largepage_memorybased
static struct nand_bbt_descr smallpage_flashbased
static struct nand_bbt_descr largepage_flashbased
static uint8_t scan_agand_pattern [] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 }
static struct nand_bbt_descr agand_flashbased
static uint8_t bbt_pattern [] = {'B', 'b', 't', '0' }
static uint8_t mirror_pattern [] = {'1', 't', 'b', 'B' }
static struct nand_bbt_descr bbt_main_descr
static struct nand_bbt_descr bbt_mirror_descr


Function Documentation

static int check_create ( struct mtd_info mtd,
uint8_t *  buf,
struct nand_bbt_descr bd 
) [static]

check_create - [GENERIC] create and write bbt(s) if necessary : MTD device structure : temporary buffer : descriptor for the good/bad block search pattern

The function checks the results of the previous call to read_bbt and creates / updates the bbt(s) if necessary Creation is necessary if no bbt was found for the chip/device Update is necessary if one of the tables is missing or the version nr. of one table is less than the other

Definition at line 777 of file nand_bbt.c.

References NAND_BBT_PERCHIP, nand_bbt_descr::options, nand_bbt_descr::pages, mtd_info::priv, and nand_bbt_descr::version.

Referenced by nand_scan_bbt().

static int check_pattern ( uint8_t *  buf,
int  len,
int  paglen,
struct nand_bbt_descr td 
) [static]

check_pattern - [GENERIC] check if a pattern is in the buffer : the buffer to search : the length of buffer to search : the pagelength : search pattern descriptor

Check for a pattern at the given place. Used to search bad block tables and good / bad block identifiers. If the SCAN_EMPTY option is set then check, if all bytes except the pattern area contain 0xff

Definition at line 78 of file nand_bbt.c.

References nand_bbt_descr::len, NAND_BBT_SCANEMPTY, nand_bbt_descr::offs, nand_bbt_descr::options, and nand_bbt_descr::pattern.

Referenced by scan_block_full(), and search_bbt().

static int check_short_pattern ( uint8_t *  buf,
struct nand_bbt_descr td 
) [static]

check_short_pattern - [GENERIC] check if a pattern is in the buffer : the buffer to search : 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

Definition at line 119 of file nand_bbt.c.

References nand_bbt_descr::len, nand_bbt_descr::offs, and nand_bbt_descr::pattern.

Referenced by create_bbt(), and scan_block_fast().

static int create_bbt ( struct mtd_info mtd,
uint8_t *  buf,
struct nand_bbt_descr bd,
int  chip 
) [static]

create_bbt - [GENERIC] Create a bad block table by scanning the device : MTD device structure : temporary buffer : descriptor for the good/bad block search pattern : 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

Definition at line 372 of file nand_bbt.c.

References nand_chip::bbt, nand_chip::bbt_erase_shift, nand_chip::chipsize, KERN_INFO, KERN_WARNING, nand_bbt_descr::len, NAND_BBT_SCAN2NDPAGE, NAND_BBT_SCANALLPAGES, NAND_BBT_SCANEMPTY, mtd_info::oobsize, nand_bbt_descr::options, nand_chip::page_shift, printk, mtd_info::priv, scan_block_fast(), scan_block_full(), and mtd_info::size.

Referenced by nand_memory_bbt().

EXPORT_SYMBOL ( nand_default_bbt   ) 

EXPORT_SYMBOL ( nand_scan_bbt   ) 

static void mark_bbt_region ( struct mtd_info mtd,
struct nand_bbt_descr td 
) [static]

mark_bbt_regions - [GENERIC] mark the bad block table regions : MTD device structure : bad block table descriptor

The bad block table regions are marked as "bad" to prevent accidental erasures / writes. The regions are identified by the mark 0x02.

Definition at line 890 of file nand_bbt.c.

References int, nand_bbt_descr::maxblocks, NAND_BBT_ABSPAGE, NAND_BBT_LASTBLOCK, NAND_BBT_PERCHIP, NAND_BBT_WRITE, nand_update_bbt(), nand_chip::numchips, nand_bbt_descr::options, nand_bbt_descr::pages, mtd_info::priv, nand_bbt_descr::reserved_block_code, and mtd_info::size.

Referenced by nand_scan_bbt().

int nand_default_bbt ( struct mtd_info mtd  ) 

nand_default_bbt - [NAND Interface] Select a default bad block table for the device : MTD device structure

This function selects the default bad block table support for the device and calls the nand_scan_bbt function

Definition at line 1152 of file nand_bbt.c.

Referenced by nand_scan(), and nand_set_defaults().

int nand_isbad_bbt ( struct mtd_info mtd,
loff_t  offs,
int  allowbbt 
)

nand_isbad_bbt - [NAND Interface] Check if a block is bad : MTD device structure : offset in the device : allow access to bad block table region

Definition at line 1201 of file nand_bbt.c.

Referenced by nand_block_checkbad().

static int nand_memory_bbt ( struct mtd_info mtd,
struct nand_bbt_descr bd 
) [inline, static]

nand_memory_bbt - [GENERIC] create a memory based bad block table : MTD device structure : 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

Definition at line 757 of file nand_bbt.c.

References create_bbt(), NAND_BBT_SCANEMPTY, nand_bbt_descr::options, and mtd_info::priv.

Referenced by nand_scan_bbt().

int nand_scan_bbt ( struct mtd_info mtd,
struct nand_bbt_descr bd 
)

nand_scan_bbt - [NAND Interface] scan, find, read and maybe create bad block table(s) : MTD device structure : 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 must be freed by calling the nand_free_bbt function.

Definition at line 955 of file nand_bbt.c.

Referenced by nand_default_bbt().

int nand_update_bbt ( struct mtd_info mtd,
loff_t  offs 
)

nand_update_bbt - [NAND Interface] update bad block table(s) : MTD device structure : the offset of the newly marked block

The function updates the bad block table(s)

Definition at line 1023 of file nand_bbt.c.

Referenced by mark_bbt_region(), nand_default_block_markbad(), and nand_erase_nand().

static int read_abs_bbt ( struct mtd_info mtd,
uint8_t *  buf,
struct nand_bbt_descr td,
int  chip 
) [static]

read_abs_bbt - [GENERIC] Read the bad block table starting at a given page : MTD device structure : temporary buffer : descriptor for the bad block table : 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.

Definition at line 211 of file nand_bbt.c.

References nand_chip::bbt_erase_shift, nand_chip::chipsize, NAND_BBT_NRBITS_MSK, NAND_BBT_PERCHIP, nand_chip::numchips, nand_bbt_descr::options, nand_bbt_descr::pages, mtd_info::priv, read_bbt(), nand_bbt_descr::reserved_block_code, and mtd_info::size.

static int read_abs_bbts ( struct mtd_info mtd,
uint8_t *  buf,
struct nand_bbt_descr td,
struct nand_bbt_descr md 
) [static]

read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page : MTD device structure : temporary buffer : descriptor for the bad block table : descriptor for the bad block table mirror

Read the bad block table(s) for all chips starting at a given page We assume that the bbt bits are in consecutive order.

Definition at line 282 of file nand_bbt.c.

References KERN_DEBUG, NAND_BBT_VERSION, nand_bbt_descr::options, nand_bbt_descr::pages, printk, mtd_info::priv, scan_read_raw(), nand_bbt_descr::veroffs, and nand_bbt_descr::version.

Referenced by nand_scan_bbt().

static int read_bbt ( struct mtd_info mtd,
uint8_t *  buf,
int  page,
int  num,
int  bits,
int  offs,
int  reserved_block_code 
) [static]

Definition at line 145 of file nand_bbt.c.

References nand_chip::bbt, KERN_DEBUG, KERN_INFO, KERN_WARNING, min, nand_chip::page_shift, printk, mtd_info::priv, and mtd_info::read.

Referenced by read_abs_bbt().

static int scan_block_fast ( struct mtd_info mtd,
struct nand_bbt_descr bd,
loff_t  offs,
uint8_t *  buf,
int  len 
) [static]

Definition at line 330 of file nand_bbt.c.

References check_short_pattern(), mtd_info::oobsize, and mtd_info::read_oob.

Referenced by create_bbt().

static int scan_block_full ( struct mtd_info mtd,
struct nand_bbt_descr bd,
loff_t  offs,
uint8_t *  buf,
size_t  readlen,
int  scanlen,
int  len 
) [static]

Definition at line 310 of file nand_bbt.c.

References check_pattern(), and scan_read_raw().

Referenced by create_bbt().

static int scan_read_raw ( struct mtd_info mtd,
uint8_t *  buf,
loff_t  offs,
size_t  len 
) [static]

Definition at line 238 of file nand_bbt.c.

References mtd_info::oobsize, and mtd_info::read_oob.

Referenced by read_abs_bbts(), scan_block_full(), and search_bbt().

static int scan_write_bbt ( struct mtd_info mtd,
loff_t  offs,
size_t  len,
uint8_t *  buf,
uint8_t *  oob 
) [static]

Definition at line 256 of file nand_bbt.c.

References mtd_info::oobsize, and mtd_info::write_oob.

static int search_bbt ( struct mtd_info mtd,
uint8_t *  buf,
struct nand_bbt_descr td 
) [static]

search_bbt - [GENERIC] scan the device for a specific bad block table : MTD device structure : temporary buffer : descriptor for the bad block table

Read the bad block table by searching for a given ident pattern. Search is preformed either from the beginning up or from the end of the device downwards. The search starts always at the start of a block. If the option NAND_BBT_PERCHIP is given, each chip is searched for a bbt, which contains the bad block information of this chip. This is necessary to provide support for certain DOC devices.

The bbt ident pattern resides in the oob area of the first page in a block.

Definition at line 462 of file nand_bbt.c.

References nand_chip::bbt_erase_shift, check_pattern(), nand_chip::chipsize, KERN_DEBUG, KERN_WARNING, nand_bbt_descr::maxblocks, NAND_BBT_LASTBLOCK, NAND_BBT_NRBITS_MSK, NAND_BBT_PERCHIP, NAND_BBT_VERSION, nand_chip::numchips, mtd_info::oobsize, nand_bbt_descr::options, nand_chip::page_shift, nand_bbt_descr::pages, printk, mtd_info::priv, scan_read_raw(), mtd_info::size, nand_bbt_descr::veroffs, and nand_bbt_descr::version.

Referenced by search_read_bbts().

static int search_read_bbts ( struct mtd_info mtd,
uint8_t *  buf,
struct nand_bbt_descr td,
struct nand_bbt_descr md 
) [static]

search_read_bbts - [GENERIC] scan the device for bad block table(s) : MTD device structure : temporary buffer : descriptor for the bad block table : descriptor for the bad block table mirror

Search and read the bad block table(s)

Definition at line 535 of file nand_bbt.c.

References search_bbt().

Referenced by nand_scan_bbt().

static int write_bbt ( struct mtd_info mtd,
uint8_t *  buf,
struct nand_bbt_descr td,
struct nand_bbt_descr md,
int  chipsel 
) [static]

write_bbt - [GENERIC] (Re)write the bad block table

: MTD device structure : temporary buffer : descriptor for the bad block table : descriptor for the bad block table mirror : selector for a specific chip, -1 for all

(Re)write the bad block table

Definition at line 560 of file nand_bbt.c.

References int, erase_info::len, NAND_BBT_LASTBLOCK, NAND_BBT_PERCHIP, mtd_info::oobsize, nand_bbt_descr::options, nand_bbt_descr::pages, mtd_info::priv, nand_bbt_descr::reserved_block_code, mtd_info::size, and write.

Referenced by nand_update_bbt().


Variable Documentation

struct nand_bbt_descr agand_flashbased [static]

Initial value:

 {
        .options = NAND_BBT_SCANEMPTY | NAND_BBT_SCANALLPAGES,
        .offs = 0x20,
        .len = 6,
        .pattern = scan_agand_pattern
}

Definition at line 1112 of file nand_bbt.c.

Referenced by nand_default_bbt().

struct nand_bbt_descr bbt_main_descr [static]

Initial value:

 {
        .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
                | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
        .offs = 8,
        .len = 4,
        .veroffs = 12,
        .maxblocks = 4,
        .pattern = bbt_pattern
}

Definition at line 1124 of file nand_bbt.c.

Referenced by nand_default_bbt().

struct nand_bbt_descr bbt_mirror_descr [static]

Initial value:

 {
        .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
                | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
        .offs = 8,
        .len = 4,
        .veroffs = 12,
        .maxblocks = 4,
        .pattern = mirror_pattern
}

Definition at line 1134 of file nand_bbt.c.

Referenced by nand_default_bbt().

uint8_t bbt_pattern[] = {'B', 'b', 't', '0' } [static]

Definition at line 1121 of file nand_bbt.c.

struct nand_bbt_descr largepage_flashbased [static]

Initial value:

 {
        .options = NAND_BBT_SCAN2NDPAGE,
        .offs = 0,
        .len = 2,
        .pattern = scan_ff_pattern
}

Definition at line 1103 of file nand_bbt.c.

Referenced by nand_default_bbt().

struct nand_bbt_descr largepage_memorybased [static]

Initial value:

 {
        .options = 0,
        .offs = 0,
        .len = 2,
        .pattern = scan_ff_pattern
}

Definition at line 1089 of file nand_bbt.c.

Referenced by nand_default_bbt().

uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' } [static]

Definition at line 1122 of file nand_bbt.c.

uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 } [static]

Definition at line 1110 of file nand_bbt.c.

uint8_t scan_ff_pattern[] = { 0xff, 0xff } [static]

Definition at line 1080 of file nand_bbt.c.

struct nand_bbt_descr smallpage_flashbased [static]

Initial value:

 {
        .options = NAND_BBT_SCAN2NDPAGE,
        .offs = 5,
        .len = 1,
        .pattern = scan_ff_pattern
}

Definition at line 1096 of file nand_bbt.c.

Referenced by nand_default_bbt().

struct nand_bbt_descr smallpage_memorybased [static]

Initial value:

 {
        .options = NAND_BBT_SCAN2NDPAGE,
        .offs = 5,
        .len = 1,
        .pattern = scan_ff_pattern
}

Definition at line 1082 of file nand_bbt.c.

Referenced by nand_default_bbt().


Generated on Fri Nov 28 00:08:23 2008 for elphel by  doxygen 1.5.1