os/nandboot-R2_0_4/mtd/nand_bbt.c File Reference

#include <linux/errno.h>
#include <linux/types.h>
#include <linux/bitops.h>
#include "mtd.h"
#include "nand.h"
#include "nand_ecc.h"
#include "delay.h"

Include dependency graph for nand_bbt.c:

Go to the source code of this file.

Defines

#define BBT_LEN_1   1024
#define BBT_LEN_2   (512 * 1024)
#define bbt_b_1   ((void *)(0xc4000000 - BBT_LEN_2 - 0x02000000 - BBT_LEN_1))
#define bbt_b_2   ((void *)(0xc4000000 - BBT_LEN_2 - 0x02000000))
#define dprintf   if(0)printf
#define nop()   __asm__("nop")
#define GPIO_SYNC   0
#define DEBUG(n, args...)   do { } while(0)
#define D(x)   x

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 read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
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


Define Documentation

#define bbt_b_1   ((void *)(0xc4000000 - BBT_LEN_2 - 0x02000000 - BBT_LEN_1))

Definition at line 74 of file nand_bbt.c.

Referenced by nand_scan_bbt().

#define bbt_b_2   ((void *)(0xc4000000 - BBT_LEN_2 - 0x02000000))

Definition at line 75 of file nand_bbt.c.

Referenced by nand_scan_bbt(), and nand_update_bbt().

#define BBT_LEN_1   1024

Definition at line 70 of file nand_bbt.c.

Referenced by nand_scan_bbt().

#define BBT_LEN_2   (512 * 1024)

Definition at line 72 of file nand_bbt.c.

Referenced by nand_scan_bbt(), and nand_update_bbt().

#define D ( x   )     x

Definition at line 146 of file nand_bbt.c.

#define DEBUG ( n,
args...   )     do { } while(0)

Definition at line 144 of file nand_bbt.c.

#define dprintf   if(0)printf

Definition at line 96 of file nand_bbt.c.

Referenced by nand_block_bad(), nand_block_checkbad(), nand_block_isbad(), nand_command(), nand_read_buf(), nand_read_byte(), nand_read_raw(), nand_scan(), nand_wait(), nand_write_buf(), and nand_write_byte().

#define GPIO_SYNC   0

Definition at line 141 of file nand_bbt.c.

 
#define nop (  )     __asm__("nop")

Definition at line 137 of file nand_bbt.c.


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 neccecary : 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 neccecary Creation is neccecary if no bbt was found for the chip/device Update is neccecary if one of the tables is missing or the version nr. of one table is less than the other

Definition at line 798 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.

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 162 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.

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 203 of file nand_bbt.c.

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

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 375 of file nand_bbt.c.

References nand_chip::bbt, nand_chip::bbt_erase_shift, check_short_pattern(), nand_chip::chipsize, nand_bbt_descr::len, NAND_BBT_SCAN2NDPAGE, NAND_BBT_SCANALLPAGES, NAND_BBT_SCANEMPTY, mtd_info::oobblock, mtd_info::oobsize, nand_bbt_descr::options, nand_chip::page_shift, mtd_info::priv, mtd_info::read_oob, and mtd_info::size.

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 911 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.

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 1224 of file nand_bbt.c.

References agand_flashbased, nand_chip::badblock_pattern, bbt_main_descr, nand_chip::bbt_md, bbt_mirror_descr, nand_chip::bbt_td, largepage_flashbased, largepage_memorybased, NAND_IS_AND, nand_scan_bbt(), NAND_USE_FLASH_BBT, mtd_info::oobblock, nand_chip::options, mtd_info::priv, smallpage_flashbased, and smallpage_memorybased.

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 1275 of file nand_bbt.c.

References nand_chip::bbt, DEBUG, int, MTD_DEBUG_LEVEL2, and mtd_info::priv.

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 778 of file nand_bbt.c.

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

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 974 of file nand_bbt.c.

References bbt_b_1, bbt_b_2, BBT_LEN_1, BBT_LEN_2, buf, check_create(), mark_bbt_region(), memset(), NAND_BBT_ABSPAGE, nand_memory_bbt(), mtd_info::oobsize, nand_bbt_descr::options, mtd_info::priv, putnl(), puts(), putx(), read_abs_bbts(), search_read_bbts(), and mtd_info::size.

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 1093 of file nand_bbt.c.

References bbt_b_2, BBT_LEN_2, buf, int, NAND_BBT_PERCHIP, NAND_BBT_WRITE, mtd_info::oobsize, nand_bbt_descr::options, mtd_info::priv, mtd_info::size, nand_bbt_descr::version, and write_bbt().

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 307 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 342 of file nand_bbt.c.

References NAND_BBT_VERSION, nand_read_raw(), nand_bbt_descr::options, nand_bbt_descr::pages, mtd_info::priv, nand_bbt_descr::veroffs, and nand_bbt_descr::version.

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 236 of file nand_bbt.c.

References nand_chip::bbt, min, nand_chip::page_shift, mtd_info::priv, putnl(), puts(), putx(), and mtd_info::read_ecc.

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 neccecary 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 482 of file nand_bbt.c.

References nand_chip::bbt_erase_shift, check_pattern(), nand_chip::chipsize, nand_bbt_descr::maxblocks, NAND_BBT_LASTBLOCK, NAND_BBT_NRBITS_MSK, NAND_BBT_PERCHIP, NAND_BBT_VERSION, nand_read_raw(), nand_chip::numchips, mtd_info::oobblock, mtd_info::oobsize, nand_bbt_descr::options, nand_chip::page_shift, nand_bbt_descr::pages, mtd_info::priv, putnl(), puts(), putx(), mtd_info::size, nand_bbt_descr::veroffs, and nand_bbt_descr::version.

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 574 of file nand_bbt.c.

References putnl(), puts(), putx(), search_bbt(), and mtd_info::size.

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 607 of file nand_bbt.c.

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


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 1184 of file nand_bbt.c.

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 1196 of file nand_bbt.c.

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 1206 of file nand_bbt.c.

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

Definition at line 1193 of file nand_bbt.c.

struct nand_bbt_descr largepage_flashbased [static]

Initial value:

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

Definition at line 1175 of file nand_bbt.c.

struct nand_bbt_descr largepage_memorybased [static]

Initial value:

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

Definition at line 1161 of file nand_bbt.c.

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

Definition at line 1194 of file nand_bbt.c.

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

Definition at line 1182 of file nand_bbt.c.

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

Definition at line 1152 of file nand_bbt.c.

struct nand_bbt_descr smallpage_flashbased [static]

Initial value:

 {
        .options = NAND_BBT_SCANEMPTY | NAND_BBT_SCANALLPAGES,
        .offs = 5,
        .len = 1,
        .pattern = scan_ff_pattern
}

Definition at line 1168 of file nand_bbt.c.

struct nand_bbt_descr smallpage_memorybased [static]

Initial value:

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

Definition at line 1154 of file nand_bbt.c.


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