Linux Kernel
3.7.1
|
#include <linux/init.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/vmalloc.h>
#include <linux/math64.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_bch.h>
#include <linux/mtd/partitions.h>
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/random.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
Go to the source code of this file.
Data Structures | |
union | ns_mem |
struct | nandsim |
struct | nandsim_operations |
struct | weak_block |
struct | weak_page |
struct | grave_page |
Macros | |
#define | CONFIG_NANDSIM_FIRST_ID_BYTE 0x98 |
#define | CONFIG_NANDSIM_SECOND_ID_BYTE 0x39 |
#define | CONFIG_NANDSIM_THIRD_ID_BYTE 0xFF /* No byte */ |
#define | CONFIG_NANDSIM_FOURTH_ID_BYTE 0xFF /* No byte */ |
#define | CONFIG_NANDSIM_ACCESS_DELAY 25 |
#define | CONFIG_NANDSIM_PROGRAMM_DELAY 200 |
#define | CONFIG_NANDSIM_ERASE_DELAY 2 |
#define | CONFIG_NANDSIM_OUTPUT_CYCLE 40 |
#define | CONFIG_NANDSIM_INPUT_CYCLE 50 |
#define | CONFIG_NANDSIM_BUS_WIDTH 8 |
#define | CONFIG_NANDSIM_DO_DELAYS 0 |
#define | CONFIG_NANDSIM_LOG 0 |
#define | CONFIG_NANDSIM_DBG 0 |
#define | CONFIG_NANDSIM_MAX_PARTS 32 |
#define | NS_LARGEST_PAGE_SIZE 4096 |
#define | NS_OUTPUT_PREFIX "[nandsim]" |
#define | NS_LOG(args...) do { if (log) printk(KERN_DEBUG NS_OUTPUT_PREFIX " log: " args); } while(0) |
#define | NS_DBG(args...) do { if (dbg) printk(KERN_DEBUG NS_OUTPUT_PREFIX " debug: " args); } while(0) |
#define | NS_WARN(args...) do { printk(KERN_WARNING NS_OUTPUT_PREFIX " warning: " args); } while(0) |
#define | NS_ERR(args...) do { printk(KERN_ERR NS_OUTPUT_PREFIX " error: " args); } while(0) |
#define | NS_INFO(args...) do { printk(KERN_INFO NS_OUTPUT_PREFIX " " args); } while(0) |
#define | NS_UDELAY(us) do { if (do_delays) udelay(us); } while(0) |
#define | NS_MDELAY(us) do { if (do_delays) mdelay(us); } while(0) |
#define | NS_IS_INITIALIZED(ns) ((ns)->geom.totsz != 0) |
#define | NS_STATUS_OK(ns) (NAND_STATUS_READY | (NAND_STATUS_WP * ((ns)->lines.wp == 0))) |
#define | NS_STATUS_FAILED(ns) (NAND_STATUS_FAIL | NS_STATUS_OK(ns)) |
#define | NS_RAW_OFFSET(ns) (((ns)->regs.row << (ns)->geom.pgshift) + ((ns)->regs.row * (ns)->geom.oobsz) + (ns)->regs.column) |
#define | NS_RAW_OFFSET_OOB(ns) (NS_RAW_OFFSET(ns) + ns->geom.pgsz) |
#define | STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */ |
#define | STATE_CMD_READ1 0x00000002 /* read data from the second half of page */ |
#define | STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */ |
#define | STATE_CMD_PAGEPROG 0x00000004 /* start page program */ |
#define | STATE_CMD_READOOB 0x00000005 /* read OOB area */ |
#define | STATE_CMD_ERASE1 0x00000006 /* sector erase first command */ |
#define | STATE_CMD_STATUS 0x00000007 /* read status */ |
#define | STATE_CMD_STATUS_M 0x00000008 /* read multi-plane status (isn't implemented) */ |
#define | STATE_CMD_SEQIN 0x00000009 /* sequential data input */ |
#define | STATE_CMD_READID 0x0000000A /* read ID */ |
#define | STATE_CMD_ERASE2 0x0000000B /* sector erase second command */ |
#define | STATE_CMD_RESET 0x0000000C /* reset */ |
#define | STATE_CMD_RNDOUT 0x0000000D /* random output command */ |
#define | STATE_CMD_RNDOUTSTART 0x0000000E /* random output start command */ |
#define | STATE_CMD_MASK 0x0000000F /* command states mask */ |
#define | STATE_ADDR_PAGE 0x00000010 /* full (row, column) address is accepted */ |
#define | STATE_ADDR_SEC 0x00000020 /* sector address was accepted */ |
#define | STATE_ADDR_COLUMN 0x00000030 /* column address was accepted */ |
#define | STATE_ADDR_ZERO 0x00000040 /* one byte zero address was accepted */ |
#define | STATE_ADDR_MASK 0x00000070 /* address states mask */ |
#define | STATE_DATAIN 0x00000100 /* waiting for data input */ |
#define | STATE_DATAIN_MASK 0x00000100 /* data input states mask */ |
#define | STATE_DATAOUT 0x00001000 /* waiting for page data output */ |
#define | STATE_DATAOUT_ID 0x00002000 /* waiting for ID bytes output */ |
#define | STATE_DATAOUT_STATUS 0x00003000 /* waiting for status output */ |
#define | STATE_DATAOUT_STATUS_M 0x00004000 /* waiting for multi-plane status output */ |
#define | STATE_DATAOUT_MASK 0x00007000 /* data output states mask */ |
#define | STATE_READY 0x00000000 |
#define | STATE_UNKNOWN 0x10000000 |
#define | ACTION_CPY 0x00100000 /* copy page/OOB to the internal buffer */ |
#define | ACTION_PRGPAGE 0x00200000 /* program the internal buffer to flash */ |
#define | ACTION_SECERASE 0x00300000 /* erase sector */ |
#define | ACTION_ZEROOFF 0x00400000 /* don't add any offset to address */ |
#define | ACTION_HALFOFF 0x00500000 /* add to address half of page */ |
#define | ACTION_OOBOFF 0x00600000 /* add to address OOB offset */ |
#define | ACTION_MASK 0x00700000 /* action mask */ |
#define | NS_OPER_NUM 13 /* Number of operations supported by the simulator */ |
#define | NS_OPER_STATES 6 /* Maximum number of states in operation */ |
#define | OPT_ANY 0xFFFFFFFF /* any chip supports this operation */ |
#define | OPT_PAGE256 0x00000001 /* 256-byte page chips */ |
#define | OPT_PAGE512 0x00000002 /* 512-byte page chips */ |
#define | OPT_PAGE2048 0x00000008 /* 2048-byte page chips */ |
#define | OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */ |
#define | OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */ |
#define | OPT_PAGE4096 0x00000080 /* 4096-byte page chips */ |
#define | OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */ |
#define | OPT_SMALLPAGE (OPT_PAGE256 | OPT_PAGE512) /* 256 and 512-byte page chips */ |
#define | NS_STATE(x) ((x) & ~ACTION_MASK) |
#define | NS_MAX_PREVSTATES 1 |
#define | NS_MAX_HELD_PAGES 16 |
Functions | |
module_param (first_id_byte, uint, 0400) | |
module_param (second_id_byte, uint, 0400) | |
module_param (third_id_byte, uint, 0400) | |
module_param (fourth_id_byte, uint, 0400) | |
module_param (access_delay, uint, 0400) | |
module_param (programm_delay, uint, 0400) | |
module_param (erase_delay, uint, 0400) | |
module_param (output_cycle, uint, 0400) | |
module_param (input_cycle, uint, 0400) | |
module_param (bus_width, uint, 0400) | |
module_param (do_delays, uint, 0400) | |
module_param (log, uint, 0400) | |
module_param (dbg, uint, 0400) | |
module_param_array (parts, ulong,&parts_num, 0400) | |
module_param (badblocks, charp, 0400) | |
module_param (weakblocks, charp, 0400) | |
module_param (weakpages, charp, 0400) | |
module_param (bitflips, uint, 0400) | |
module_param (gravepages, charp, 0400) | |
module_param (rptwear, uint, 0400) | |
module_param (overridesize, uint, 0400) | |
module_param (cache_file, charp, 0400) | |
module_param (bbt, uint, 0400) | |
module_param (bch, uint, 0400) | |
MODULE_PARM_DESC (first_id_byte,"The first byte returned by NAND Flash 'read ID' command (manufacturer ID)") | |
MODULE_PARM_DESC (second_id_byte,"The second byte returned by NAND Flash 'read ID' command (chip ID)") | |
MODULE_PARM_DESC (third_id_byte,"The third byte returned by NAND Flash 'read ID' command") | |
MODULE_PARM_DESC (fourth_id_byte,"The fourth byte returned by NAND Flash 'read ID' command") | |
MODULE_PARM_DESC (access_delay,"Initial page access delay (microseconds)") | |
MODULE_PARM_DESC (programm_delay,"Page programm delay (microseconds") | |
MODULE_PARM_DESC (erase_delay,"Sector erase delay (milliseconds)") | |
MODULE_PARM_DESC (output_cycle,"Word output (from flash) time (nanoseconds)") | |
MODULE_PARM_DESC (input_cycle,"Word input (to flash) time (nanoseconds)") | |
MODULE_PARM_DESC (bus_width,"Chip's bus width (8- or 16-bit)") | |
MODULE_PARM_DESC (do_delays,"Simulate NAND delays using busy-waits if not zero") | |
MODULE_PARM_DESC (log,"Perform logging if not zero") | |
MODULE_PARM_DESC (dbg,"Output debug information if not zero") | |
MODULE_PARM_DESC (parts,"Partition sizes (in erase blocks) separated by commas") | |
MODULE_PARM_DESC (badblocks,"Erase blocks that are initially marked bad, separated by commas") | |
MODULE_PARM_DESC (weakblocks,"Weak erase blocks [: remaining erase cycles (defaults to 3)]"" separated by commas e.g. 113:2 means eb 113"" can be erased only twice before failing") | |
MODULE_PARM_DESC (weakpages,"Weak pages [: maximum writes (defaults to 3)]"" separated by commas e.g. 1401:2 means page 1401"" can be written only twice before failing") | |
MODULE_PARM_DESC (bitflips,"Maximum number of random bit flips per page (zero by default)") | |
MODULE_PARM_DESC (gravepages,"Pages that lose data [: maximum reads (defaults to 3)]"" separated by commas e.g. 1401:2 means page 1401"" can be read only twice before failing") | |
MODULE_PARM_DESC (rptwear,"Number of erases between reporting wear, if not zero") | |
MODULE_PARM_DESC (overridesize,"Specifies the NAND Flash size overriding the ID bytes. ""The size is specified in erase blocks and as the exponent of a power of two"" e.g. 5 means a size of 32 erase blocks") | |
MODULE_PARM_DESC (cache_file,"File to use to cache nand pages instead of memory") | |
MODULE_PARM_DESC (bbt,"0 OOB, 1 BBT with marker in OOB, 2 BBT with marker in data area") | |
MODULE_PARM_DESC (bch,"Enable BCH ecc and set how many bits should ""be correctable in 512-byte blocks") | |
int | do_read_error (struct nandsim *ns, int num) |
void | do_bit_flips (struct nandsim *ns, int num) |
module_init (ns_init_module) | |
module_exit (ns_cleanup_module) | |
MODULE_LICENSE ("GPL") | |
MODULE_AUTHOR ("Artem B. Bityuckiy") | |
MODULE_DESCRIPTION ("The NAND flash simulator") | |
#define ACTION_CPY 0x00100000 /* copy page/OOB to the internal buffer */ |
#define ACTION_HALFOFF 0x00500000 /* add to address half of page */ |
#define ACTION_OOBOFF 0x00600000 /* add to address OOB offset */ |
#define ACTION_PRGPAGE 0x00200000 /* program the internal buffer to flash */ |
#define ACTION_ZEROOFF 0x00400000 /* don't add any offset to address */ |
#define NS_DBG | ( | args... | ) | do { if (dbg) printk(KERN_DEBUG NS_OUTPUT_PREFIX " debug: " args); } while(0) |
#define NS_ERR | ( | args... | ) | do { printk(KERN_ERR NS_OUTPUT_PREFIX " error: " args); } while(0) |
#define NS_INFO | ( | args... | ) | do { printk(KERN_INFO NS_OUTPUT_PREFIX " " args); } while(0) |
#define NS_LOG | ( | args... | ) | do { if (log) printk(KERN_DEBUG NS_OUTPUT_PREFIX " log: " args); } while(0) |
#define NS_RAW_OFFSET_OOB | ( | ns | ) | (NS_RAW_OFFSET(ns) + ns->geom.pgsz) |
#define NS_STATE | ( | x | ) | ((x) & ~ACTION_MASK) |
#define NS_STATUS_FAILED | ( | ns | ) | (NAND_STATUS_FAIL | NS_STATUS_OK(ns)) |
#define NS_STATUS_OK | ( | ns | ) | (NAND_STATUS_READY | (NAND_STATUS_WP * ((ns)->lines.wp == 0))) |
#define NS_WARN | ( | args... | ) | do { printk(KERN_WARNING NS_OUTPUT_PREFIX " warning: " args); } while(0) |
#define OPT_ANY 0xFFFFFFFF /* any chip supports this operation */ |
#define OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */ |
#define OPT_PAGE2048 0x00000008 /* 2048-byte page chips */ |
#define OPT_PAGE4096 0x00000080 /* 4096-byte page chips */ |
#define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */ |
#define OPT_SMALLPAGE (OPT_PAGE256 | OPT_PAGE512) /* 256 and 512-byte page chips */ |
#define OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */ |
#define STATE_ADDR_COLUMN 0x00000030 /* column address was accepted */ |
#define STATE_ADDR_MASK 0x00000070 /* address states mask */ |
#define STATE_ADDR_PAGE 0x00000010 /* full (row, column) address is accepted */ |
#define STATE_ADDR_SEC 0x00000020 /* sector address was accepted */ |
#define STATE_ADDR_ZERO 0x00000040 /* one byte zero address was accepted */ |
#define STATE_CMD_ERASE1 0x00000006 /* sector erase first command */ |
#define STATE_CMD_ERASE2 0x0000000B /* sector erase second command */ |
#define STATE_CMD_MASK 0x0000000F /* command states mask */ |
#define STATE_CMD_PAGEPROG 0x00000004 /* start page program */ |
#define STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */ |
#define STATE_CMD_READ1 0x00000002 /* read data from the second half of page */ |
#define STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */ |
#define STATE_CMD_RNDOUT 0x0000000D /* random output command */ |
#define STATE_CMD_RNDOUTSTART 0x0000000E /* random output start command */ |
#define STATE_CMD_SEQIN 0x00000009 /* sequential data input */ |
#define STATE_CMD_STATUS_M 0x00000008 /* read multi-plane status (isn't implemented) */ |
#define STATE_DATAIN 0x00000100 /* waiting for data input */ |
#define STATE_DATAIN_MASK 0x00000100 /* data input states mask */ |
#define STATE_DATAOUT 0x00001000 /* waiting for page data output */ |
#define STATE_DATAOUT_ID 0x00002000 /* waiting for ID bytes output */ |
#define STATE_DATAOUT_MASK 0x00007000 /* data output states mask */ |
#define STATE_DATAOUT_STATUS 0x00003000 /* waiting for status output */ |
#define STATE_DATAOUT_STATUS_M 0x00004000 /* waiting for multi-plane status output */ |
MODULE_AUTHOR | ( | "Artem B. Bityuckiy" | ) |
MODULE_DESCRIPTION | ( | "The NAND flash simulator" | ) |
module_exit | ( | ns_cleanup_module | ) |
module_init | ( | ns_init_module | ) |
MODULE_LICENSE | ( | "GPL" | ) |
module_param | ( | first_id_byte | , |
uint | , | ||
0400 | |||
) |
module_param | ( | second_id_byte | , |
uint | , | ||
0400 | |||
) |
module_param | ( | third_id_byte | , |
uint | , | ||
0400 | |||
) |
module_param | ( | fourth_id_byte | , |
uint | , | ||
0400 | |||
) |
module_param | ( | access_delay | , |
uint | , | ||
0400 | |||
) |
module_param | ( | programm_delay | , |
uint | , | ||
0400 | |||
) |
module_param | ( | erase_delay | , |
uint | , | ||
0400 | |||
) |
module_param | ( | output_cycle | , |
uint | , | ||
0400 | |||
) |
module_param | ( | input_cycle | , |
uint | , | ||
0400 | |||
) |
module_param | ( | do_delays | , |
uint | , | ||
0400 | |||
) |
module_param | ( | badblocks | , |
charp | , | ||
0400 | |||
) |
module_param | ( | weakblocks | , |
charp | , | ||
0400 | |||
) |
module_param | ( | weakpages | , |
charp | , | ||
0400 | |||
) |
module_param | ( | bitflips | , |
uint | , | ||
0400 | |||
) |
module_param | ( | gravepages | , |
charp | , | ||
0400 | |||
) |
module_param | ( | rptwear | , |
uint | , | ||
0400 | |||
) |
module_param | ( | overridesize | , |
uint | , | ||
0400 | |||
) |
module_param | ( | cache_file | , |
charp | , | ||
0400 | |||
) |
module_param | ( | bbt | , |
uint | , | ||
0400 | |||
) |
module_param | ( | bch | , |
uint | , | ||
0400 | |||
) |
module_param_array | ( | parts | , |
ulong | , | ||
& | parts_num, | ||
0400 | |||
) |
MODULE_PARM_DESC | ( | first_id_byte | , |
"The first byte returned by NAND Flash 'read ID' command (manufacturer ID)" | |||
) |
MODULE_PARM_DESC | ( | second_id_byte | , |
"The second byte returned by NAND Flash 'read ID' command (chip ID)" | |||
) |
MODULE_PARM_DESC | ( | access_delay | , |
"Initial page access delay (microseconds)" | |||
) |
MODULE_PARM_DESC | ( | programm_delay | ) |
MODULE_PARM_DESC | ( | erase_delay | , |
"Sector erase delay (milliseconds)" | |||
) |
MODULE_PARM_DESC | ( | badblocks | , |
"Erase blocks that are initially marked | bad, | ||
separated by commas" | |||
) |
MODULE_PARM_DESC | ( | weakblocks | , |
"Weak erase blocks "" separated by commas e.g. 113:2 means eb 113"" can be erased only twice before failing" | [:remaining erase cycles(defaults to 3)] | ||
) |
MODULE_PARM_DESC | ( | weakpages | , |
"Weak pages "" separated by commas e.g. 1401:2 means page 1401"" can be written only twice before failing" | [:maximum writes(defaults to 3)] | ||
) |
MODULE_PARM_DESC | ( | gravepages | , |
"Pages that lose data "" separated by commas e.g. 1401:2 means page 1401"" can be read only twice before failing" | [:maximum reads(defaults to 3)] | ||
) |
MODULE_PARM_DESC | ( | overridesize | , |
"Specifies the NAND Flash size overriding the ID bytes. ""The size is specified in erase blocks and as the exponent of a power of two"" e.g. 5 means a size of 32 erase blocks" | |||
) |