tools/build-R2_19_3/fsboot/cbl/nand/nand_bbt.c File Reference

#include "mtd_nand.h"
#include "nand_ecc.h"
#include <axisrfl/mtd.h>
#include <axisrfl/mtd_nand.h>
#include <axisrfl/nand_ecc.h>
#include <axisrfl/funcs.h>
#include <bitops.h>
#include <hal_intr.h>
#include <string.h>
#include <axisrfl/linuxerr.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_2   (void *)(0xc4000000 - BBT_LEN_2)
#define dprintf   if(0)printf
#define udelay(x)   HAL_DELAY_US(x)
#define nop()   __asm__("nop")
#define ndelay(x)
#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)
size_t min (size_t a, size_t b)
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

char bbt_b_1 [BBT_LEN_1]
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_2   (void *)(0xc4000000 - BBT_LEN_2)

Definition at line 65 of file nand_bbt.c.

#define BBT_LEN_1   1024

Definition at line 61 of file nand_bbt.c.

#define BBT_LEN_2   (512 * 1024)

Definition at line 63 of file nand_bbt.c.

#define D ( x   )     x

Definition at line 136 of file nand_bbt.c.

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

Definition at line 134 of file nand_bbt.c.

#define dprintf   if(0)printf

Definition at line 85 of file nand_bbt.c.

#define GPIO_SYNC   0

Definition at line 131 of file nand_bbt.c.

#define ndelay ( x   ) 

Value:

do { nop(); nop(); nop(); nop(); \
                       nop(); nop(); nop(); nop(); } while (0)

Definition at line 128 of file nand_bbt.c.

 
#define nop (  )     __asm__("nop")

Definition at line 126 of file nand_bbt.c.

#define udelay ( x   )     HAL_DELAY_US(x)

Definition at line 124 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 750 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 152 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 193 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 358 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 863 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.

size_t min ( size_t  a,
size_t  b 
)

Definition at line 219 of file nand_bbt.c.

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 1134 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 1185 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 730 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 926 of file nand_bbt.c.

References bbt_b_1, bbt_b_2, BBT_LEN_1, BBT_LEN_2, buf, check_create(), GFP_KERNEL, KERN_ERR, kfree, kmalloc, mark_bbt_region(), memset(), NAND_BBT_ABSPAGE, nand_memory_bbt(), mtd_info::oobsize, nand_bbt_descr::options, printk, mtd_info::priv, 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 1003 of file nand_bbt.c.

References bbt_b_2, BBT_LEN_2, buf, int, KERN_ERR, NAND_BBT_PERCHIP, NAND_BBT_WRITE, mtd_info::oobsize, nand_bbt_descr::options, printk, 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 290 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 325 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 225 of file nand_bbt.c.

References nand_chip::bbt, min, nand_chip::page_shift, mtd_info::priv, 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 465 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, 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 533 of file nand_bbt.c.

References search_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, 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 1094 of file nand_bbt.c.

char bbt_b_1[BBT_LEN_1]

Definition at line 64 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 1106 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 1116 of file nand_bbt.c.

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

Definition at line 1103 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 1085 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 1071 of file nand_bbt.c.

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

Definition at line 1104 of file nand_bbt.c.

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

Definition at line 1092 of file nand_bbt.c.

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

Definition at line 1062 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 1078 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 1064 of file nand_bbt.c.


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