MTD NAND Driver Programming Interface¶
- Author:
Thomas Gleixner
Introduction¶
The generic NAND driver supports almost all NAND and AG-AND based chipsand connects them to the Memory Technology Devices (MTD) subsystem ofthe Linux Kernel.
This documentation is provided for developers who want to implementboard drivers or filesystem drivers suitable for NAND devices.
Known Bugs And Assumptions¶
None.
Documentation hints¶
The function and structure docs are autogenerated. Each function andstructmember has a short description which is marked with an [XXX]identifier. The following chapters explain the meaning of thoseidentifiers.
Function identifiers [XXX]¶
The functions are marked with [XXX] identifiers in the short comment.The identifiers explain the usage and scope of the functions. Followingidentifiers are used:
[MTD Interface]
These functions provide the interface to the MTD kernel API. They arenot replaceable and provide functionality which is complete hardwareindependent.
[NAND Interface]
These functions are exported and provide the interface to the NANDkernel API.
[GENERIC]
Generic functions are not replaceable and provide functionality whichis complete hardware independent.
[DEFAULT]
Default functions provide hardware related functionality which issuitable for most of the implementations. These functions can bereplaced by the board driver if necessary. Those functions are calledvia pointers in the NAND chip description structure. The board drivercan set the functions which should be replaced by board dependentfunctions before calling
nand_scan(). If the function pointer isNULL on entry tonand_scan()then the pointer is set to the defaultfunction which is suitable for the detected chip type.
Struct member identifiers [XXX]¶
Thestructmembers are marked with [XXX] identifiers in the comment. Theidentifiers explain the usage and scope of the members. Followingidentifiers are used:
[INTERN]
These members are for NAND driver internal use only and must not bemodified. Most of these values are calculated from the chip geometryinformation which is evaluated during
nand_scan().[REPLACEABLE]
Replaceable members hold hardware related functions which can beprovided by the board driver. The board driver can set the functionswhich should be replaced by board dependent functions before calling
nand_scan(). If the function pointer is NULL on entry tonand_scan()then the pointer is set to the default function which issuitable for the detected chip type.[BOARDSPECIFIC]
Board specific members hold hardware related information which mustbe provided by the board driver. The board driver must set thefunction pointers and datafields before calling
nand_scan().[OPTIONAL]
Optional members can hold information relevant for the board driver.The generic NAND driver code does not use this information.
Basic board driver¶
For most boards it will be sufficient to provide just the basicfunctions and fill out some really board dependent members in the nandchip description structure.
Basic defines¶
At least you have to provide a nand_chip structure and a storage forthe ioremap’ed chip address. You can allocate the nand_chip structureusing kmalloc or you can allocate it statically. The NAND chip structureembeds an mtd structure which will be registered to the MTD subsystem.You can extract a pointer to the mtd structure from a nand_chip pointerusing thenand_to_mtd() helper.
Kmalloc based example
static struct mtd_info *board_mtd;static void __iomem *baseaddr;
Static example
static struct nand_chip board_chip;static void __iomem *baseaddr;
Partition defines¶
If you want to divide your device into partitions, then define apartitioning scheme suitable to your board.
#define NUM_PARTITIONS 2static struct mtd_partition partition_info[] = { { .name = "Flash partition 1", .offset = 0, .size = 8 * 1024 * 1024 }, { .name = "Flash partition 2", .offset = MTDPART_OFS_NEXT, .size = MTDPART_SIZ_FULL },};Hardware control function¶
The hardware control function provides access to the control pins of theNAND chip(s). The access can be done by GPIO pins or by address lines.If you use address lines, make sure that the timing requirements aremet.
GPIO based example
static void board_hwcontrol(struct mtd_info *mtd, int cmd){ switch(cmd){ case NAND_CTL_SETCLE: /* Set CLE pin high */ break; case NAND_CTL_CLRCLE: /* Set CLE pin low */ break; case NAND_CTL_SETALE: /* Set ALE pin high */ break; case NAND_CTL_CLRALE: /* Set ALE pin low */ break; case NAND_CTL_SETNCE: /* Set nCE pin low */ break; case NAND_CTL_CLRNCE: /* Set nCE pin high */ break; }}Address lines based example. It’s assumed that the nCE pin is drivenby a chip select decoder.
static void board_hwcontrol(struct mtd_info *mtd, int cmd){ struct nand_chip *this = mtd_to_nand(mtd); switch(cmd){ case NAND_CTL_SETCLE: this->legacy.IO_ADDR_W |= CLE_ADRR_BIT; break; case NAND_CTL_CLRCLE: this->legacy.IO_ADDR_W &= ~CLE_ADRR_BIT; break; case NAND_CTL_SETALE: this->legacy.IO_ADDR_W |= ALE_ADRR_BIT; break; case NAND_CTL_CLRALE: this->legacy.IO_ADDR_W &= ~ALE_ADRR_BIT; break; }}Device ready function¶
If the hardware interface has the ready busy pin of the NAND chipconnected to a GPIO or other accessible I/O pin, this function is usedto read back the state of the pin. The function has no arguments andshould return 0, if the device is busy (R/B pin is low) and 1, if thedevice is ready (R/B pin is high). If the hardware interface does notgive access to the ready busy pin, then the function must not be definedand the function pointer this->legacy.dev_ready is set to NULL.
Init function¶
The init function allocates memory and sets up all the board specificparameters and function pointers. When everything is set upnand_scan()is called. This function tries to detect and identify then chip. If achip is found all the internal data fields are initialized accordingly.The structure(s) have to be zeroed out first and then filled with thenecessary information about the device.
static int __init board_init (void){ struct nand_chip *this; int err = 0; /* Allocate memory for MTD device structure and private data */ this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL); if (!this) { printk ("Unable to allocate NAND MTD device structure.\n"); err = -ENOMEM; goto out; } board_mtd = nand_to_mtd(this); /* map physical address */ baseaddr = ioremap(CHIP_PHYSICAL_ADDRESS, 1024); if (!baseaddr) { printk("Ioremap to access NAND chip failed\n"); err = -EIO; goto out_mtd; } /* Set address of NAND IO lines */ this->legacy.IO_ADDR_R = baseaddr; this->legacy.IO_ADDR_W = baseaddr; /* Reference hardware control function */ this->hwcontrol = board_hwcontrol; /* Set command delay time, see datasheet for correct value */ this->legacy.chip_delay = CHIP_DEPENDEND_COMMAND_DELAY; /* Assign the device ready function, if available */ this->legacy.dev_ready = board_dev_ready; this->eccmode = NAND_ECC_SOFT; /* Scan to find existence of the device */ if (nand_scan (this, 1)) { err = -ENXIO; goto out_ior; } add_mtd_partitions(board_mtd, partition_info, NUM_PARTITIONS); goto out;out_ior: iounmap(baseaddr);out_mtd: kfree (this);out: return err;}module_init(board_init);Exit function¶
The exit function is only necessary if the driver is compiled as amodule. It releases all resources which are held by the chip driver andunregisters the partitions in the MTD layer.
#ifdef MODULEstatic void __exit board_cleanup (void){ /* Unregister device */ WARN_ON(mtd_device_unregister(board_mtd)); /* Release resources */ nand_cleanup(mtd_to_nand(board_mtd)); /* unmap physical address */ iounmap(baseaddr); /* Free the MTD device structure */ kfree (mtd_to_nand(board_mtd));}module_exit(board_cleanup);#endifAdvanced board driver functions¶
This chapter describes the advanced functionality of the NAND driver.For a list of functions which can be overridden by the board driver seethe documentation of the nand_chip structure.
Multiple chip control¶
The nand driver can control chip arrays. Therefore the board driver mustprovide an own select_chip function. This function must (de)select therequested chip. The function pointer in the nand_chip structure must beset before callingnand_scan(). The maxchip parameter ofnand_scan()defines the maximum number of chips to scan for. Make sure that theselect_chip function can handle the requested number of chips.
The nand driver concatenates the chips to one virtual chip and providesthis virtual chip to the MTD layer.
Note: The driver can only handle linear chip arrays of equally sizedchips. There is no support for parallel arrays which extend thebuswidth.
GPIO based example
static void board_select_chip (struct mtd_info *mtd, int chip){ /* Deselect all chips, set all nCE pins high */ GPIO(BOARD_NAND_NCE) |= 0xff; if (chip >= 0) GPIO(BOARD_NAND_NCE) &= ~ (1 << chip);}Address lines based example. Its assumed that the nCE pins areconnected to an address decoder.
static void board_select_chip (struct mtd_info *mtd, int chip){ struct nand_chip *this = mtd_to_nand(mtd); /* Deselect all chips */ this->legacy.IO_ADDR_R &= ~BOARD_NAND_ADDR_MASK; this->legacy.IO_ADDR_W &= ~BOARD_NAND_ADDR_MASK; switch (chip) { case 0: this->legacy.IO_ADDR_R |= BOARD_NAND_ADDR_CHIP0; this->legacy.IO_ADDR_W |= BOARD_NAND_ADDR_CHIP0; break; .... case n: this->legacy.IO_ADDR_R |= BOARD_NAND_ADDR_CHIPn; this->legacy.IO_ADDR_W |= BOARD_NAND_ADDR_CHIPn; break; }}Hardware ECC support¶
Functions and constants¶
The nand driver supports three different types of hardware ECC.
NAND_ECC_HW3_256
Hardware ECC generator providing 3 bytes ECC per 256 byte.
NAND_ECC_HW3_512
Hardware ECC generator providing 3 bytes ECC per 512 byte.
NAND_ECC_HW6_512
Hardware ECC generator providing 6 bytes ECC per 512 byte.
NAND_ECC_HW8_512
Hardware ECC generator providing 8 bytes ECC per 512 byte.
If your hardware generator has a different functionality add it at theappropriate place in nand_base.c
The board driver must provide following functions:
enable_hwecc
This function is called before reading / writing to the chip. Resetor initialize the hardware generator in this function. The functionis called with an argument which let you distinguish between read andwrite operations.
calculate_ecc
This function is called after read / write from / to the chip.Transfer the ECC from the hardware to the buffer. If the optionNAND_HWECC_SYNDROME is set then the function is only called onwrite. See below.
correct_data
In case of an ECC error this function is called for error detectionand correction. Return 1 respectively 2 in case the error can becorrected. If the error is not correctable return -1. If yourhardware generator matches the default algorithm of the nand_eccsoftware generator then use the correction function provided bynand_ecc instead of implementing duplicated code.
Hardware ECC with syndrome calculation¶
Many hardware ECC implementations provide Reed-Solomon codes andcalculate an error syndrome on read. The syndrome must be converted to astandard Reed-Solomon syndrome before calling the error correction codein the generic Reed-Solomon library.
The ECC bytes must be placed immediately after the data bytes in orderto make the syndrome generator work. This is contrary to the usuallayout used by software ECC. The separation of data and out of band areais not longer possible. The nand driver code handles this layout and theremaining free bytes in the oob area are managed by the autoplacementcode. Provide a matching oob-layout in this case. See rts_from4.c anddiskonchip.c for implementation reference. In those cases we must alsouse bad block tables on FLASH, because the ECC layout is interferingwith the bad block marker positions. See bad block table support fordetails.
Bad block table support¶
Most NAND chips mark the bad blocks at a defined position in the sparearea. Those blocks must not be erased under any circumstances as the badblock information would be lost. It is possible to check the bad blockmark each time when the blocks are accessed by reading the spare area ofthe first page in the block. This is time consuming so a bad block tableis used.
The nand driver supports various types of bad block tables.
Per device
The bad block table contains all bad block information of the devicewhich can consist of multiple chips.
Per chip
A bad block table is used per chip and contains the bad blockinformation for this particular chip.
Fixed offset
The bad block table is located at a fixed offset in the chip(device). This applies to various DiskOnChip devices.
Automatic placed
The bad block table is automatically placed and detected either atthe end or at the beginning of a chip (device)
Mirrored tables
The bad block table is mirrored on the chip (device) to allow updatesof the bad block table without data loss.
nand_scan() calls the functionnand_default_bbt().nand_default_bbt() selects appropriate default bad block tabledescriptors depending on the chip information which was retrieved bynand_scan().
The standard policy is scanning the device for bad blocks and build aram based bad block table which allows faster access than alwayschecking the bad block information on the flash chip itself.
Flash based tables¶
It may be desired or necessary to keep a bad block table in FLASH. ForAG-AND chips this is mandatory, as they have no factory marked badblocks. They have factory marked good blocks. The marker pattern iserased when the block is erased to be reused. So in case of powerlossbefore writing the pattern back to the chip this block would be lost andadded to the bad blocks. Therefore we scan the chip(s) when we detectthem the first time for good blocks and store this information in a badblock table before erasing any of the blocks.
The blocks in which the tables are stored are protected againstaccidental access by marking them bad in the memory bad block table. Thebad block table management functions are allowed to circumvent thisprotection.
The simplest way to activate the FLASH based bad block table support isto set the option NAND_BBT_USE_FLASH in the bbt_option field of thenand chip structure before callingnand_scan(). For AG-AND chips isthis done by default. This activates the default FLASH based bad blocktable functionality of the NAND driver. The default bad block tableoptions are
Store bad block table per chip
Use 2 bits per block
Automatic placement at the end of the chip
Use mirrored tables with version numbers
Reserve 4 blocks at the end of the chip
User defined tables¶
User defined tables are created by filling out a nand_bbt_descrstructure and storing the pointer in the nand_chip structure memberbbt_td before callingnand_scan(). If a mirror table is necessary asecond structure must be created and a pointer to this structure must bestored in bbt_md inside the nand_chip structure. If the bbt_md memberis set to NULL then only the main table is used and no scan for themirrored table is performed.
The most important field in the nand_bbt_descr structure is theoptions field. The options define most of the table properties. Use thepredefined constants from rawnand.h to define the options.
Number of bits per block
The supported number of bits is 1, 2, 4, 8.
Table per chip
Setting the constant NAND_BBT_PERCHIP selects that a bad blocktable is managed for each chip in a chip array. If this option is notset then a per device bad block table is used.
Table location is absolute
Use the option constant NAND_BBT_ABSPAGE and define the absolutepage number where the bad block table starts in the field pages. Ifyou have selected bad block tables per chip and you have a multi chiparray then the start page must be given for each chip in the chiparray. Note: there is no scan for a table ident pattern performed, sothe fields pattern, veroffs, offs, len can be left uninitialized
Table location is automatically detected
The table can either be located in the first or the last good blocksof the chip (device). Set NAND_BBT_LASTBLOCK to place the bad blocktable at the end of the chip (device). The bad block tables aremarked and identified by a pattern which is stored in the spare areaof the first page in the block which holds the bad block table. Storea pointer to the pattern in the pattern field. Further the length ofthe pattern has to be stored in len and the offset in the spare areamust be given in the offs member of the nand_bbt_descr structure.For mirrored bad block tables different patterns are mandatory.
Table creation
Set the option NAND_BBT_CREATE to enable the table creation if notable can be found during the scan. Usually this is done only once ifa new chip is found.
Table write support
Set the option NAND_BBT_WRITE to enable the table write support.This allows the update of the bad block table(s) in case a block hasto be marked bad due to wear. The MTD interface functionblock_markbad is calling the update function of the bad block table.If the write support is enabled then the table is updated on FLASH.
Note: Write support should only be enabled for mirrored tables withversion control.
Table version control
Set the option NAND_BBT_VERSION to enable the table versioncontrol. It’s highly recommended to enable this for mirrored tableswith write support. It makes sure that the risk of losing the badblock table information is reduced to the loss of the informationabout the one worn out block which should be marked bad. The versionis stored in 4 consecutive bytes in the spare area of the device. Theposition of the version number is defined by the member veroffs inthe bad block table descriptor.
Save block contents on write
In case that the block which holds the bad block table does containother useful information, set the option NAND_BBT_SAVECONTENT. Whenthe bad block table is written then the whole block is read the badblock table is updated and the block is erased and everything iswritten back. If this option is not set only the bad block table iswritten and everything else in the block is ignored and erased.
Number of reserved blocks
For automatic placement some blocks must be reserved for bad blocktable storage. The number of reserved blocks is defined in themaxblocks member of the bad block table description structure.Reserving 4 blocks for mirrored tables should be a reasonable number.This also limits the number of blocks which are scanned for the badblock table ident pattern.
Spare area (auto)placement¶
The nand driver implements different possibilities for placement offilesystem data in the spare area,
Placement defined by fs driver
Automatic placement
The default placement function is automatic placement. The nand driverhas built in default placement schemes for the various chiptypes. If dueto hardware ECC functionality the default placement does not fit thenthe board driver can provide a own placement scheme.
File system drivers can provide a own placement scheme which is usedinstead of the default placement scheme.
Placement schemes are defined by a nand_oobinfo structure
struct nand_oobinfo { int useecc; int eccbytes; int eccpos[24]; int oobfree[8][2];};useecc
The useecc member controls the ecc and placement function. The headerfile include/mtd/mtd-abi.h contains constants to select ecc andplacement. MTD_NANDECC_OFF switches off the ecc complete. This isnot recommended and available for testing and diagnosis only.MTD_NANDECC_PLACE selects caller defined placement,MTD_NANDECC_AUTOPLACE selects automatic placement.
eccbytes
The eccbytes member defines the number of ecc bytes per page.
eccpos
The eccpos array holds the byte offsets in the spare area where theecc codes are placed.
oobfree
The oobfree array defines the areas in the spare area which can beused for automatic placement. The information is given in the format{offset, size}. offset defines the start of the usable area, size thelength in bytes. More than one area can be defined. The list isterminated by an {0, 0} entry.
Placement defined by fs driver¶
The calling function provides a pointer to a nand_oobinfo structurewhich defines the ecc placement. For writes the caller must provide aspare area buffer along with the data buffer. The spare area buffer sizeis (number of pages) * (size of spare area). For reads the buffer sizeis (number of pages) * ((size of spare area) + (number of ecc steps perpage) * sizeof (int)). The driver stores the result of the ecc checkfor each tuple in the spare buffer. The storage sequence is:
<spare data page 0><ecc result 0>...<ecc result n>...<spare data page n><ecc result 0>...<ecc result n>
This is a legacy mode used by YAFFS1.
If the spare area buffer is NULL then only the ECC placement is doneaccording to the given scheme in the nand_oobinfo structure.
Automatic placement¶
Automatic placement uses the built in defaults to place the ecc bytes inthe spare area. If filesystem data have to be stored / read into thespare area then the calling function must provide a buffer. The buffersize per page is determined by the oobfree array in the nand_oobinfostructure.
If the spare area buffer is NULL then only the ECC placement is doneaccording to the default builtin scheme.
Spare area autoplacement default schemes¶
256 byte pagesize¶
Offset | Content | Comment |
|---|---|---|
0x00 | ECC byte 0 | Error correction code byte 0 |
0x01 | ECC byte 1 | Error correction code byte 1 |
0x02 | ECC byte 2 | Error correction code byte 2 |
0x03 | Autoplace 0 | |
0x04 | Autoplace 1 | |
0x05 | Bad block marker | If any bit in this byte is zero, then thisblock is bad. This applies only to the firstpage in a block. In the remaining pages thisbyte is reserved |
0x06 | Autoplace 2 | |
0x07 | Autoplace 3 |
512 byte pagesize¶
Offset | Content | Comment |
|---|---|---|
0x00 | ECC byte 0 | Error correction code byte 0 of the lower256 Byte data in this page |
0x01 | ECC byte 1 | Error correction code byte 1 of the lower256 Bytes of data in this page |
0x02 | ECC byte 2 | Error correction code byte 2 of the lower256 Bytes of data in this page |
0x03 | ECC byte 3 | Error correction code byte 0 of the upper256 Bytes of data in this page |
0x04 | reserved | reserved |
0x05 | Bad block marker | If any bit in this byte is zero, then thisblock is bad. This applies only to the firstpage in a block. In the remaining pages thisbyte is reserved |
0x06 | ECC byte 4 | Error correction code byte 1 of the upper256 Bytes of data in this page |
0x07 | ECC byte 5 | Error correction code byte 2 of the upper256 Bytes of data in this page |
0x08 - 0x0F | Autoplace 0 - 7 |
2048 byte pagesize¶
Offset | Content | Comment |
|---|---|---|
0x00 | Bad block marker | If any bit in this byte is zero, then this blockis bad. This applies only to the first page in ablock. In the remaining pages this byte isreserved |
0x01 | Reserved | Reserved |
0x02-0x27 | Autoplace 0 - 37 | |
0x28 | ECC byte 0 | Error correction code byte 0 of the first256 Byte data in this page |
0x29 | ECC byte 1 | Error correction code byte 1 of the first256 Bytes of data in this page |
0x2A | ECC byte 2 | Error correction code byte 2 of the first256 Bytes data in this page |
0x2B | ECC byte 3 | Error correction code byte 0 of the second256 Bytes of data in this page |
0x2C | ECC byte 4 | Error correction code byte 1 of the second256 Bytes of data in this page |
0x2D | ECC byte 5 | Error correction code byte 2 of the second256 Bytes of data in this page |
0x2E | ECC byte 6 | Error correction code byte 0 of the third256 Bytes of data in this page |
0x2F | ECC byte 7 | Error correction code byte 1 of the third256 Bytes of data in this page |
0x30 | ECC byte 8 | Error correction code byte 2 of the third256 Bytes of data in this page |
0x31 | ECC byte 9 | Error correction code byte 0 of the fourth256 Bytes of data in this page |
0x32 | ECC byte 10 | Error correction code byte 1 of the fourth256 Bytes of data in this page |
0x33 | ECC byte 11 | Error correction code byte 2 of the fourth256 Bytes of data in this page |
0x34 | ECC byte 12 | Error correction code byte 0 of the fifth256 Bytes of data in this page |
0x35 | ECC byte 13 | Error correction code byte 1 of the fifth256 Bytes of data in this page |
0x36 | ECC byte 14 | Error correction code byte 2 of the fifth256 Bytes of data in this page |
0x37 | ECC byte 15 | Error correction code byte 0 of the sixth256 Bytes of data in this page |
0x38 | ECC byte 16 | Error correction code byte 1 of the sixth256 Bytes of data in this page |
0x39 | ECC byte 17 | Error correction code byte 2 of the sixth256 Bytes of data in this page |
0x3A | ECC byte 18 | Error correction code byte 0 of the seventh256 Bytes of data in this page |
0x3B | ECC byte 19 | Error correction code byte 1 of the seventh256 Bytes of data in this page |
0x3C | ECC byte 20 | Error correction code byte 2 of the seventh256 Bytes of data in this page |
0x3D | ECC byte 21 | Error correction code byte 0 of the eighth256 Bytes of data in this page |
0x3E | ECC byte 22 | Error correction code byte 1 of the eighth256 Bytes of data in this page |
0x3F | ECC byte 23 | Error correction code byte 2 of the eighth256 Bytes of data in this page |
Filesystem support¶
The NAND driver provides all necessary functions for a filesystem viathe MTD interface.
Filesystems must be aware of the NAND peculiarities and restrictions.One major restrictions of NAND Flash is, that you cannot write as oftenas you want to a page. The consecutive writes to a page, before erasingit again, are restricted to 1-3 writes, depending on the manufacturersspecifications. This applies similar to the spare area.
Therefore NAND aware filesystems must either write in page size chunksor hold a writebuffer to collect smaller writes until they sum up topagesize. Available NAND aware filesystems: JFFS2, YAFFS.
The spare area usage to store filesystem data is controlled by the sparearea placement functionality which is described in one of the earlierchapters.
Tools¶
The MTD project provides a couple of helpful tools to handle NAND Flash.
flasherase, flasheraseall: Erase and format FLASH partitions
nandwrite: write filesystem images to NAND FLASH
nanddump: dump the contents of a NAND FLASH partitions
These tools are aware of the NAND restrictions. Please use those toolsinstead of complaining about errors which are caused by non NAND awareaccess methods.
Constants¶
This chapter describes the constants which might be relevant for adriver developer.
Chip option constants¶
Constants for chip id table¶
These constants are defined in rawnand.h. They are OR-ed together todescribe the chip functionality:
/* Buswitdh is 16 bit */#define NAND_BUSWIDTH_16 0x00000002/* Device supports partial programming without padding */#define NAND_NO_PADDING 0x00000004/* Chip has cache program function */#define NAND_CACHEPRG 0x00000008/* Chip has copy back function */#define NAND_COPYBACK 0x00000010/* AND Chip which has 4 banks and a confusing page / block * assignment. See Renesas datasheet for further information */#define NAND_IS_AND 0x00000020/* Chip has a array of 4 pages which can be read without * additional ready /busy waits */#define NAND_4PAGE_ARRAY 0x00000040
Constants for runtime options¶
These constants are defined in rawnand.h. They are OR-ed together todescribe the functionality:
/* The hw ecc generator provides a syndrome instead a ecc value on read * This can only work if we have the ecc bytes directly behind the * data bytes. Applies for DOC and AG-AND Renesas HW Reed Solomon generators */#define NAND_HWECC_SYNDROME 0x00020000
ECC selection constants¶
Use these constants to select the ECC algorithm:
/* No ECC. Usage is not recommended ! */#define NAND_ECC_NONE 0/* Software ECC 3 byte ECC per 256 Byte data */#define NAND_ECC_SOFT 1/* Hardware ECC 3 byte ECC per 256 Byte data */#define NAND_ECC_HW3_256 2/* Hardware ECC 3 byte ECC per 512 Byte data */#define NAND_ECC_HW3_512 3/* Hardware ECC 6 byte ECC per 512 Byte data */#define NAND_ECC_HW6_512 4/* Hardware ECC 8 byte ECC per 512 Byte data */#define NAND_ECC_HW8_512 6
Hardware control related constants¶
These constants describe the requested hardware access function when theboardspecific hardware control function is called:
/* Select the chip by setting nCE to low */#define NAND_CTL_SETNCE 1/* Deselect the chip by setting nCE to high */#define NAND_CTL_CLRNCE 2/* Select the command latch by setting CLE to high */#define NAND_CTL_SETCLE 3/* Deselect the command latch by setting CLE to low */#define NAND_CTL_CLRCLE 4/* Select the address latch by setting ALE to high */#define NAND_CTL_SETALE 5/* Deselect the address latch by setting ALE to low */#define NAND_CTL_CLRALE 6/* Set write protection by setting WP to high. Not used! */#define NAND_CTL_SETWP 7/* Clear write protection by setting WP to low. Not used! */#define NAND_CTL_CLRWP 8
Bad block table related constants¶
These constants describe the options used for bad block tabledescriptors:
/* Options for the bad block table descriptors *//* The number of bits used per block in the bbt on the device */#define NAND_BBT_NRBITS_MSK 0x0000000F#define NAND_BBT_1BIT 0x00000001#define NAND_BBT_2BIT 0x00000002#define NAND_BBT_4BIT 0x00000004#define NAND_BBT_8BIT 0x00000008/* The bad block table is in the last good block of the device */#define NAND_BBT_LASTBLOCK 0x00000010/* The bbt is at the given page, else we must scan for the bbt */#define NAND_BBT_ABSPAGE 0x00000020/* bbt is stored per chip on multichip devices */#define NAND_BBT_PERCHIP 0x00000080/* bbt has a version counter at offset veroffs */#define NAND_BBT_VERSION 0x00000100/* Create a bbt if none axists */#define NAND_BBT_CREATE 0x00000200/* Write bbt if necessary */#define NAND_BBT_WRITE 0x00001000/* Read and write back block contents when writing bbt */#define NAND_BBT_SAVECONTENT 0x00002000
Structures¶
This chapter contains the autogenerated documentation of the structureswhich are used in the NAND driver and might be relevant for a driverdeveloper. Eachstructmember has a short description which is markedwith an [XXX] identifier. See the chapter “Documentation hints” for anexplanation.
- structnand_parameters¶
NAND generic parameters from the parameter page
Definition:
struct nand_parameters { const char *model; bool supports_set_get_features; bool supports_read_cache; unsigned long set_feature_list[BITS_TO_LONGS(ONFI_FEATURE_NUMBER)]; unsigned long get_feature_list[BITS_TO_LONGS(ONFI_FEATURE_NUMBER)]; struct onfi_params *onfi;};Members
modelModel name
supports_set_get_featuresThe NAND chip supports setting/getting features
supports_read_cacheThe NAND chip supports read cache operations
set_feature_listBitmap of features that can be set
get_feature_listBitmap of features that can be get
onfiONFI specific parameters
- structnand_id¶
NAND id structure
Definition:
struct nand_id { u8 data[NAND_MAX_ID_LEN]; int len;};Members
databuffer containing the id bytes.
lenID length.
- structnand_ecc_step_info¶
ECC step information of ECC engine
Definition:
struct nand_ecc_step_info { int stepsize; const int *strengths; int nstrengths;};Members
stepsizedata bytes per ECC step
strengthsarray of supported strengths
nstrengthsnumber of supported strengths
- structnand_ecc_caps¶
capability of ECC engine
Definition:
struct nand_ecc_caps { const struct nand_ecc_step_info *stepinfos; int nstepinfos; int (*calc_ecc_bytes)(int step_size, int strength);};Members
stepinfosarray of ECC step information
nstepinfosnumber of ECC step information
calc_ecc_bytesdriver’s hook to calculate ECC bytes per step
- structnand_ecc_ctrl¶
Control structure for ECC
Definition:
struct nand_ecc_ctrl { enum nand_ecc_engine_type engine_type; enum nand_ecc_placement placement; enum nand_ecc_algo algo; int steps; int size; int bytes; int total; int strength; int prepad; int postpad; unsigned int options; u8 *calc_buf; u8 *code_buf; void (*hwctl)(struct nand_chip *chip, int mode); int (*calculate)(struct nand_chip *chip, const uint8_t *dat, uint8_t *ecc_code); int (*correct)(struct nand_chip *chip, uint8_t *dat, uint8_t *read_ecc, uint8_t *calc_ecc); int (*read_page_raw)(struct nand_chip *chip, uint8_t *buf, int oob_required, int page); int (*write_page_raw)(struct nand_chip *chip, const uint8_t *buf, int oob_required, int page); int (*read_page)(struct nand_chip *chip, uint8_t *buf, int oob_required, int page); int (*read_subpage)(struct nand_chip *chip, uint32_t offs, uint32_t len, uint8_t *buf, int page); int (*write_subpage)(struct nand_chip *chip, uint32_t offset, uint32_t data_len, const uint8_t *data_buf, int oob_required, int page); int (*write_page)(struct nand_chip *chip, const uint8_t *buf, int oob_required, int page); int (*write_oob_raw)(struct nand_chip *chip, int page); int (*read_oob_raw)(struct nand_chip *chip, int page); int (*read_oob)(struct nand_chip *chip, int page); int (*write_oob)(struct nand_chip *chip, int page);};Members
engine_typeECC engine type
placementOOB bytes placement
algoECC algorithm
stepsnumber of ECC steps per page
sizedata bytes per ECC step
bytesECC bytes per step
totaltotal number of ECC bytes per page
strengthmax number of correctible bits per ECC step
prepadpadding information for syndrome based ECC generators
postpadpadding information for syndrome based ECC generators
optionsECC specific options (see NAND_ECC_XXX flags defined above)
calc_bufbuffer for calculated ECC, size is oobsize.
code_bufbuffer for ECC read from flash, size is oobsize.
hwctlfunction to control hardware ECC generator. Must onlybe provided if an hardware ECC is available
calculatefunction for ECC calculation or readback from ECC hardware
correctfunction for ECC correction, matching to ECC generator (sw/hw).Should return a positive number representing the number ofcorrected bitflips, -EBADMSG if the number of bitflips exceedECC strength, or any other error code if the error is notdirectly related to correction.If -EBADMSG is returned the input buffers should be leftuntouched.
read_page_rawfunction to read a raw page without ECC. This functionshould hide the specific layout used by the ECCcontroller and always return contiguous in-band andout-of-band data even if they’re not storedcontiguously on the NAND chip (e.g.NAND_ECC_PLACEMENT_INTERLEAVED interleaves in-band andout-of-band data).
write_page_rawfunction to write a raw page without ECC. This functionshould hide the specific layout used by the ECCcontroller and consider the passed data as contiguousin-band and out-of-band data. ECC controller isresponsible for doing the appropriate transformationsto adapt to its specific layout (e.g.NAND_ECC_PLACEMENT_INTERLEAVED interleaves in-band andout-of-band data).
read_pagefunction to read a page according to the ECC generatorrequirements; returns maximum number of bitflips corrected inany single ECC step, -EIO hw error
read_subpagefunction to read parts of the page covered by ECC;returns same as
read_page()write_subpagefunction to write parts of the page covered by ECC.
write_pagefunction to write a page according to the ECC generatorrequirements.
write_oob_rawfunction to write chip OOB data without ECC
read_oob_rawfunction to read chip OOB data without ECC
read_oobfunction to read chip OOB data
write_oobfunction to write chip OOB data
- structnand_sdr_timings¶
SDR NAND chip timings
Definition:
struct nand_sdr_timings { u64 tBERS_max; u32 tCCS_min; u64 tPROG_max; u64 tR_max; u32 tALH_min; u32 tADL_min; u32 tALS_min; u32 tAR_min; u32 tCEA_max; u32 tCEH_min; u32 tCH_min; u32 tCHZ_max; u32 tCLH_min; u32 tCLR_min; u32 tCLS_min; u32 tCOH_min; u32 tCS_min; u32 tDH_min; u32 tDS_min; u32 tFEAT_max; u32 tIR_min; u32 tITC_max; u32 tRC_min; u32 tREA_max; u32 tREH_min; u32 tRHOH_min; u32 tRHW_min; u32 tRHZ_max; u32 tRLOH_min; u32 tRP_min; u32 tRR_min; u64 tRST_max; u32 tWB_max; u32 tWC_min; u32 tWH_min; u32 tWHR_min; u32 tWP_min; u32 tWW_min;};Members
tBERS_maxBlock erase time
tCCS_minChange column setup time
tPROG_maxPage program time
tR_maxPage read time
tALH_minALE hold time
tADL_minALE to data loading time
tALS_minALE setup time
tAR_minALE to RE# delay
tCEA_maxCE# access time
tCEH_minCE# high hold time
tCH_minCE# hold time
tCHZ_maxCE# high to output hi-Z
tCLH_minCLE hold time
tCLR_minCLE to RE# delay
tCLS_minCLE setup time
tCOH_minCE# high to output hold
tCS_minCE# setup time
tDH_minData hold time
tDS_minData setup time
tFEAT_maxBusy time for Set Features and Get Features
tIR_minOutput hi-Z to RE# low
tITC_maxInterface and Timing Mode Change time
tRC_minRE# cycle time
tREA_maxRE# access time
tREH_minRE# high hold time
tRHOH_minRE# high to output hold
tRHW_minRE# high to WE# low
tRHZ_maxRE# high to output hi-Z
tRLOH_minRE# low to output hold
tRP_minRE# pulse width
tRR_minReady to RE# low (data only)
tRST_maxDevice reset time, measured from the falling edge of R/B# to therising edge of R/B#.
tWB_maxWE# high to SR[6] low
tWC_minWE# cycle time
tWH_minWE# high hold time
tWHR_minWE# high to RE# low
tWP_minWE# pulse width
tWW_minWP# transition to WE# low
Description
Thisstructdefines the timing requirements of a SDR NAND chip.These information can be found in every NAND datasheets and the timingsmeaning are described in the ONFI specifications:https://media-www.micron.com/-/media/client/onfi/specs/onfi_3_1_spec.pdf(chapter 4.15 Timing Parameters)
All these timings are expressed in picoseconds.
- structnand_nvddr_timings¶
NV-DDR NAND chip timings
Definition:
struct nand_nvddr_timings { u64 tBERS_max; u32 tCCS_min; u64 tPROG_max; u64 tR_max; u32 tAC_min; u32 tAC_max; u32 tADL_min; u32 tCAD_min; u32 tCAH_min; u32 tCALH_min; u32 tCALS_min; u32 tCAS_min; u32 tCEH_min; u32 tCH_min; u32 tCK_min; u32 tCS_min; u32 tDH_min; u32 tDQSCK_min; u32 tDQSCK_max; u32 tDQSD_min; u32 tDQSD_max; u32 tDQSHZ_max; u32 tDQSQ_max; u32 tDS_min; u32 tDSC_min; u32 tFEAT_max; u32 tITC_max; u32 tQHS_max; u32 tRHW_min; u32 tRR_min; u32 tRST_max; u32 tWB_max; u32 tWHR_min; u32 tWRCK_min; u32 tWW_min;};Members
tBERS_maxBlock erase time
tCCS_minChange column setup time
tPROG_maxPage program time
tR_maxPage read time
tAC_minAccess window of DQ[7:0] from CLK
tAC_maxAccess window of DQ[7:0] from CLK
tADL_minALE to data loading time
tCAD_minCommand, Address, Data delay
tCAH_minCommand/Address DQ hold time
tCALH_minW/R_n, CLE and ALE hold time
tCALS_minW/R_n, CLE and ALE setup time
tCAS_minCommand/address DQ setup time
tCEH_minCE# high hold time
tCH_minCE# hold time
tCK_minAverage clock cycle time
tCS_minCE# setup time
tDH_minData hold time
tDQSCK_minStart of the access window of DQS from CLK
tDQSCK_maxEnd of the access window of DQS from CLK
tDQSD_minMin W/R_n low to DQS/DQ driven by device
tDQSD_maxMax W/R_n low to DQS/DQ driven by device
tDQSHZ_maxW/R_n high to DQS/DQ tri-state by device
tDQSQ_maxDQS-DQ skew, DQS to last DQ valid, per access
tDS_minData setup time
tDSC_minDQS cycle time
tFEAT_maxBusy time for Set Features and Get Features
tITC_maxInterface and Timing Mode Change time
tQHS_maxData hold skew factor
tRHW_minData output cycle to command, address, or data input cycle
tRR_minReady to RE# low (data only)
tRST_maxDevice reset time, measured from the falling edge of R/B# to therising edge of R/B#.
tWB_maxWE# high to SR[6] low
tWHR_minWE# high to RE# low
tWRCK_minW/R_n low to data output cycle
tWW_minWP# transition to WE# low
Description
Thisstructdefines the timing requirements of a NV-DDR NAND data interface.These information can be found in every NAND datasheets and the timingsmeaning are described in the ONFI specifications:https://media-www.micron.com/-/media/client/onfi/specs/onfi_4_1_gold.pdf(chapter 4.18.2 NV-DDR)
All these timings are expressed in picoseconds.
- enumnand_interface_type¶
NAND interface type
Constants
NAND_SDR_IFACESingle Data Rate interface
NAND_NVDDR_IFACEDouble Data Rate interface
- structnand_interface_config¶
NAND interface timing
Definition:
struct nand_interface_config { enum nand_interface_type type; struct nand_timings { unsigned int mode; union { struct nand_sdr_timings sdr; struct nand_nvddr_timings nvddr; }; } timings;};Members
typetype of the timing
timingsThe timing information
timings.modeTiming mode as defined in the specification
{unnamed_union}anonymous
timings.sdrUse it whentype is
NAND_SDR_IFACE.timings.nvddrUse it whentype is
NAND_NVDDR_IFACE.
- boolnand_interface_is_sdr(conststructnand_interface_config*conf)¶
get the interface type
Parameters
conststructnand_interface_config*confThe data interface
- boolnand_interface_is_nvddr(conststructnand_interface_config*conf)¶
get the interface type
Parameters
conststructnand_interface_config*confThe data interface
- conststructnand_sdr_timings*nand_get_sdr_timings(conststructnand_interface_config*conf)¶
get SDR timing from data interface
Parameters
conststructnand_interface_config*confThe data interface
- conststructnand_nvddr_timings*nand_get_nvddr_timings(conststructnand_interface_config*conf)¶
get NV-DDR timing from data interface
Parameters
conststructnand_interface_config*confThe data interface
- structnand_op_cmd_instr¶
Definition of a command instruction
Definition:
struct nand_op_cmd_instr { u8 opcode;};Members
opcodethe command to issue in one cycle
- structnand_op_addr_instr¶
Definition of an address instruction
Definition:
struct nand_op_addr_instr { unsigned int naddrs; const u8 *addrs;};Members
naddrslength of theaddrs array
addrsarray containing the address cycles to issue
- structnand_op_data_instr¶
Definition of a data instruction
Definition:
struct nand_op_data_instr { unsigned int len; union { void *in; const void *out; } buf; bool force_8bit;};Members
lennumber of data bytes to move
bufbuffer to fill
buf.inbuffer to fill when reading from the NAND chip
buf.outbuffer to read from when writing to the NAND chip
force_8bitforce 8-bit access
Description
Please note that “in” and “out” are inverted from the ONFI specificationand are from the controller perspective, so a “in” is a read from the NANDchip while a “out” is a write to the NAND chip.
- structnand_op_waitrdy_instr¶
Definition of a wait ready instruction
Definition:
struct nand_op_waitrdy_instr { unsigned int timeout_ms;};Members
timeout_msmaximum delay while waiting for the ready/busy pin in ms
- enumnand_op_instr_type¶
Definition of all instruction types
Constants
NAND_OP_CMD_INSTRcommand instruction
NAND_OP_ADDR_INSTRaddress instruction
NAND_OP_DATA_IN_INSTRdata in instruction
NAND_OP_DATA_OUT_INSTRdata out instruction
NAND_OP_WAITRDY_INSTRwait ready instruction
- structnand_op_instr¶
Instruction object
Definition:
struct nand_op_instr { enum nand_op_instr_type type; union { struct nand_op_cmd_instr cmd; struct nand_op_addr_instr addr; struct nand_op_data_instr data; struct nand_op_waitrdy_instr waitrdy; } ctx; unsigned int delay_ns;};Members
typethe instruction type
ctxextra data associated to the instruction. You’ll have to use theappropriate element depending ontype
ctx.cmduse it iftype is
NAND_OP_CMD_INSTRctx.addruse it iftype is
NAND_OP_ADDR_INSTRctx.datause it iftype is
NAND_OP_DATA_IN_INSTRorNAND_OP_DATA_OUT_INSTRctx.waitrdyuse it iftype is
NAND_OP_WAITRDY_INSTRdelay_nsdelay the controller should apply after the instruction has beenissued on the bus. Most modern controllers have internal timingscontrol logic, and in this case, the controller driver can ignorethis field.
- structnand_subop¶
a sub operation
Definition:
struct nand_subop { unsigned int cs; const struct nand_op_instr *instrs; unsigned int ninstrs; unsigned int first_instr_start_off; unsigned int last_instr_end_off;};Members
csthe CS line to select for this NAND sub-operation
instrsarray of instructions
ninstrslength of theinstrs array
first_instr_start_offoffset to start from for the first instructionof the sub-operation
last_instr_end_offoffset to end at (excluded) for the last instructionof the sub-operation
Description
Bothfirst_instr_start_off andlast_instr_end_off only apply to data oraddress instructions.
When an operation cannot be handled as is by the NAND controller, it willbe split by the parser into sub-operations which will be passed to thecontroller driver.
- structnand_op_parser_addr_constraints¶
Constraints for address instructions
Definition:
struct nand_op_parser_addr_constraints { unsigned int maxcycles;};Members
maxcyclesmaximum number of address cycles the controller can issue in asingle step
- structnand_op_parser_data_constraints¶
Constraints for data instructions
Definition:
struct nand_op_parser_data_constraints { unsigned int maxlen;};Members
maxlenmaximum data length that the controller can handle in a single step
- structnand_op_parser_pattern_elem¶
One element of a pattern
Definition:
struct nand_op_parser_pattern_elem { enum nand_op_instr_type type; bool optional; union { struct nand_op_parser_addr_constraints addr; struct nand_op_parser_data_constraints data; } ctx;};Members
typethe instructuction type
optionalwhether this element of the pattern is optional or mandatory
ctxaddress or data constraint
ctx.addraddress constraint (number of cycles)
ctx.datadata constraint (data length)
- structnand_op_parser_pattern¶
NAND sub-operation pattern descriptor
Definition:
struct nand_op_parser_pattern { const struct nand_op_parser_pattern_elem *elems; unsigned int nelems; int (*exec)(struct nand_chip *chip, const struct nand_subop *subop);};Members
elemsarray of pattern elements
nelemsnumber of pattern elements inelems array
execthe function that will issue a sub-operation
Description
A pattern is a list of elements, each element reprensenting one instructionwith its constraints. The pattern itself is used by the core to match NANDchip operation with NAND controller operations.Once a match between a NAND controller operation pattern and a NAND chipoperation (or a sub-set of a NAND operation) is found, the pattern ->exec()hook is called so that the controller driver can issue the operation on thebus.
Controller drivers should declare as many patterns as they support and passthis list of patterns (created with the help of the following macro) tothenand_op_parser_exec_op() helper.
- structnand_op_parser¶
NAND controller operation parser descriptor
Definition:
struct nand_op_parser { const struct nand_op_parser_pattern *patterns; unsigned int npatterns;};Members
patternsarray of supported patterns
npatternslength of thepatterns array
Description
The parser descriptor is just an array of supported patterns which will beiterated bynand_op_parser_exec_op() everytime it tries to execute anNAND operation (or tries to determine if a specific operation is supported).
It is worth mentioning that patterns will be tested in their declarationorder, and the first match will be taken, so it’s important to order patternsappropriately so that simple/inefficient patterns are placed at the end ofthe list. Usually, this is where you put single instruction patterns.
- structnand_operation¶
NAND operation descriptor
Definition:
struct nand_operation { unsigned int cs; bool deassert_wp; const struct nand_op_instr *instrs; unsigned int ninstrs;};Members
csthe CS line to select for this NAND operation
deassert_wpset to true when the operation requires the WP pin to bede-asserted (ERASE, PROG, ...)
instrsarray of instructions to execute
ninstrslength of theinstrs array
Description
The actual operation structure that will be passed to chip->exec_op().
- structnand_controller_ops¶
Controller operations
Definition:
struct nand_controller_ops { int (*attach_chip)(struct nand_chip *chip); void (*detach_chip)(struct nand_chip *chip); int (*exec_op)(struct nand_chip *chip, const struct nand_operation *op, bool check_only); int (*setup_interface)(struct nand_chip *chip, int chipnr, const struct nand_interface_config *conf);};Members
attach_chipthis method is called after the NAND detection phase afterflash ID and MTD fields such as erase size, page size and OOBsize have been set up. ECC requirements are available ifprovided by the NAND chip or device tree. Typically used tochoose the appropriate ECC configuration and allocateassociated resources.This hook is optional.
detach_chipfree all resources allocated/claimed innand_controller_ops->
attach_chip().This hook is optional.exec_opcontroller specific method to execute NAND operations.This method replaces chip->legacy.
cmdfunc(),chip->legacy.{read,write}_{buf,byte,word}(),chip->legacy.dev_ready()and chip->legacy.waitfunc().setup_interfacesetup the data interface and timing. If chipnr is set to
NAND_DATA_IFACE_CHECK_ONLYthis means the configurationshould not be applied but only checked.This hook is optional.
- structnand_controller¶
Structure used to describe a NAND controller
Definition:
struct nand_controller { struct mutex lock; const struct nand_controller_ops *ops; struct { unsigned int data_only_read: 1; unsigned int cont_read: 1; } supported_op; bool controller_wp;};Members
locklock used to serialize accesses to the NAND controller
opsNAND controller operations.
supported_opNAND controller known-to-be-supported operations,only writable by the core after initial checking.
supported_op.data_only_readThe controller supports reading more data fromthe bus without restarting an entire read operation norchanging the column.
supported_op.cont_readThe controller supports sequential cache reads.
controller_wpthe controller is in charge of handling the WP pin.
- structnand_legacy¶
NAND chip legacy fields/hooks
Definition:
struct nand_legacy { void __iomem *IO_ADDR_R; void __iomem *IO_ADDR_W; void (*select_chip)(struct nand_chip *chip, int cs); u8 (*read_byte)(struct nand_chip *chip); void (*write_byte)(struct nand_chip *chip, u8 byte); void (*write_buf)(struct nand_chip *chip, const u8 *buf, int len); void (*read_buf)(struct nand_chip *chip, u8 *buf, int len); void (*cmd_ctrl)(struct nand_chip *chip, int dat, unsigned int ctrl); void (*cmdfunc)(struct nand_chip *chip, unsigned command, int column, int page_addr); int (*dev_ready)(struct nand_chip *chip); int (*waitfunc)(struct nand_chip *chip); int (*block_bad)(struct nand_chip *chip, loff_t ofs); int (*block_markbad)(struct nand_chip *chip, loff_t ofs); int (*set_features)(struct nand_chip *chip, int feature_addr, u8 *subfeature_para); int (*get_features)(struct nand_chip *chip, int feature_addr, u8 *subfeature_para); int chip_delay; struct nand_controller dummy_controller;};Members
IO_ADDR_Raddress to read the 8 I/O lines of the flash device
IO_ADDR_Waddress to write the 8 I/O lines of the flash device
select_chipselect/deselect a specific target/die
read_byteread one byte from the chip
write_bytewrite a single byte to the chip on the low 8 I/O lines
write_bufwrite data from the buffer to the chip
read_bufread data from the chip into the buffer
cmd_ctrlhardware specific function for controlling ALE/CLE/nCE. Also usedto write command and address
cmdfunchardware specific function for writing commands to the chip.
dev_readyhardware specific function for accessing device ready/busy line.If set to NULL no access to ready/busy is available and theready/busy information is read from the chip status register.
waitfunchardware specific function for wait on ready.
block_badcheck if a block is bad, using OOB markers
block_markbadmark a block bad
set_featuresset the NAND chip features
get_featuresget the NAND chip features
chip_delaychip dependent delay for transferring data from array to readregs (tR).
dummy_controllerdummy controller implementation for drivers that canonly control a single chip
Description
If you look at this structure you’re already wrong. These fields/hooks areall deprecated.
- structnand_chip_ops¶
NAND chip operations
Definition:
struct nand_chip_ops { int (*suspend)(struct nand_chip *chip); void (*resume)(struct nand_chip *chip); int (*lock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); int (*unlock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); int (*choose_interface_config)(struct nand_chip *chip, struct nand_interface_config *iface);};Members
suspendSuspend operation
resumeResume operation
lock_areaLock operation
unlock_areaUnlock operation
setup_read_retrySet the read-retry mode (mostly needed for MLC NANDs)
choose_interface_configChoose the best interface configuration
- structnand_manufacturer¶
NAND manufacturer structure
Definition:
struct nand_manufacturer { const struct nand_manufacturer_desc *desc; void *priv;};Members
descThe manufacturer description
privPrivate information for the manufacturer driver
- structnand_secure_region¶
NAND secure region structure
Definition:
struct nand_secure_region { u64 offset; u64 size;};Members
offsetOffset of the start of the secure region
sizeSize of the secure region
- structnand_chip¶
NAND Private Flash Chip Data
Definition:
struct nand_chip { struct nand_device base; struct nand_id id; struct nand_parameters parameters; struct nand_manufacturer manufacturer; struct nand_chip_ops ops; struct nand_legacy legacy; unsigned int options; const struct nand_interface_config *current_interface_config; struct nand_interface_config *best_interface_config; unsigned int bbt_erase_shift; unsigned int bbt_options; unsigned int badblockpos; unsigned int badblockbits; struct nand_bbt_descr *bbt_td; struct nand_bbt_descr *bbt_md; struct nand_bbt_descr *badblock_pattern; u8 *bbt; unsigned int page_shift; unsigned int phys_erase_shift; unsigned int chip_shift; unsigned int pagemask; unsigned int subpagesize; u8 *data_buf; u8 *oob_poi; struct { unsigned int bitflips; int page; } pagecache; unsigned long buf_align; struct mutex lock; unsigned int suspended : 1; wait_queue_head_t resume_wq; int cur_cs; int read_retries; struct nand_secure_region *secure_regions; u8 nr_secure_regions; struct { bool ongoing; unsigned int first_page; unsigned int pause_page; unsigned int last_page; } cont_read; struct nand_controller *controller; struct nand_ecc_ctrl ecc; void *priv;};Members
baseInherit from the generic NAND device
idHolds NAND ID
parametersHolds generic parameters under an easily readable form
manufacturerManufacturer information
opsNAND chip operations
legacyAll legacy fields/hooks. If you develop a new driver, don’t even tryto use any of these fields/hooks, and if you’re modifying anexisting driver that is using those fields/hooks, you shouldconsider reworking the driver and avoid using them.
optionsVarious chip options. They can partly be set to inform nand_scanabout special functionality. See the defines for furtherexplanation.
current_interface_configThe currently used NAND interface configuration
best_interface_configThe best NAND interface configuration which fits boththe NAND chip and NAND controller constraints. Ifunset, the default reset interface configuration mustbe used.
bbt_erase_shiftNumber of address bits in a bbt entry
bbt_optionsBad block table specific options. All options used here mustcome from bbm.h. By default, these options will be copied tothe appropriate nand_bbt_descr’s.
badblockposBad block marker position in the oob area
badblockbitsMinimum number of set bits in a good block’s bad block markerposition; i.e., BBM = 11110111b is good when badblockbits = 7
bbt_tdBad block table descriptor for flash lookup
bbt_mdBad block table mirror descriptor
badblock_patternBad block scan pattern used for initial bad block scan
bbtBad block table pointer
page_shiftNumber of address bits in a page (column address bits)
phys_erase_shiftNumber of address bits in a physical eraseblock
chip_shiftNumber of address bits in one chip
pagemaskPage number mask = number of (pages / chip) - 1
subpagesizeHolds the subpagesize
data_bufBuffer for data, size is (page size + oobsize)
oob_poipointer on the OOB area covered by data_buf
pagecacheStructure containing page cache related fields
pagecache.bitflipsNumber of bitflips of the cached page
pagecache.pagePage number currently in the cache. -1 means no page iscurrently cached
buf_alignMinimum buffer alignment required by a platform
lockLock protecting the suspended field. Also used to serialize accessesto the NAND device
suspendedSet to 1 when the device is suspended, 0 when it’s not
resume_wqwait queue to sleep if rawnand is in suspended state.
cur_csCurrently selected target. -1 means no target selected, otherwise weshould always have cur_cs >= 0 && cur_cs <
nanddev_ntargets().NAND Controller drivers should not modify this value, but they’reallowed to read it.read_retriesThe number of read retry modes supported
secure_regionsStructure containing the secure regions info
nr_secure_regionsNumber of secure regions
cont_readSequential page read internals
cont_read.ongoingWhether a continuous read is ongoing or not
cont_read.first_pageStart of the continuous read operation
cont_read.pause_pageEnd of the current sequential cache read operation
cont_read.last_pageEnd of the continuous read operation
controllerThe hardware controller structure which is shared among multipleindependent devices
eccThe ECC controller structure
privChip private data
- conststructnand_interface_config*nand_get_interface_config(structnand_chip*chip)¶
Retrieve the current interface configuration of a NAND chip
Parameters
structnand_chip*chipThe NAND chip
- structnand_flash_dev¶
NAND Flash Device ID Structure
Definition:
struct nand_flash_dev { char *name; union { struct { uint8_t mfr_id; uint8_t dev_id; }; uint8_t id[NAND_MAX_ID_LEN]; }; unsigned int pagesize; unsigned int chipsize; unsigned int erasesize; unsigned int options; uint16_t id_len; uint16_t oobsize; struct { uint16_t strength_ds; uint16_t step_ds; } ecc;};Members
namea human-readable name of the NAND chip
{unnamed_union}anonymous
{unnamed_struct}anonymous
mfr_idmanufacturer ID part of the full chip ID array (refers the samememory address as
id[0])dev_iddevice ID part of the full chip ID array (refers the same memoryaddress as
id[1])idfull device ID array
pagesizesize of the NAND page in bytes; if 0, then the real page size (aswell as the eraseblock size) is determined from the extended NANDchip ID array)
chipsizetotal chip size in MiB
erasesizeeraseblock size in bytes (determined from the extended ID if 0)
optionsstores various chip bit options
id_lenThe valid length of theid.
oobsizeOOB size
eccECC correctability and step information from the datasheet.
ecc.strength_dsThe ECC correctability from the datasheet, same as theecc_strength_ds in nand_chip{}.
ecc.step_dsThe ECC step required by theecc.strength_ds, same as theecc_step_ds in nand_chip{}, also from the datasheet.For example, the “4bit ECC for each 512Byte” can be set withNAND_ECC_INFO(4, 512).
- intnand_opcode_8bits(unsignedintcommand)¶
Check if the opcode’s address should be sent only on the lower 8 bits
Parameters
unsignedintcommandopcode to check
Parameters
structnand_chip*chipNAND chip object
Description
Returns the pre-allocated page buffer after invalidating the cache. Thisfunction should be used by drivers that do not want to allocate their ownbounce buffer and still need such a buffer for specific operations (mostcommonly when reading OOB data only).
Be careful to never call this function in the write/write_oob path, becausethe core may have placed the data to be written out in this buffer.
Return
pointer to the page cache buffer
Public Functions Provided¶
This chapter contains the autogenerated documentation of the NAND kernelAPI functions which are exported. Each function has a short descriptionwhich is marked with an [XXX] identifier. See the chapter “Documentationhints” for an explanation.
- voidnand_extract_bits(u8*dst,unsignedintdst_off,constu8*src,unsignedintsrc_off,unsignedintnbits)¶
Copy unaligned bits from one buffer to another one
Parameters
u8*dstdestination buffer
unsignedintdst_offbit offset at which the writing starts
constu8*srcsource buffer
unsignedintsrc_offbit offset at which the reading starts
unsignedintnbitsnumber of bits to copy fromsrc todst
Description
Copy bits from one memory region to another (overlap authorized).
Parameters
structnand_chip*chipNAND chip object
unsignedintcsthe CS line to select. Note that this CS id is always from the chipPoV, not the controller one
Description
Select a NAND target so that further operations executed onchip go to theselected NAND target.
Parameters
structnand_chip*chipNAND chip object
Description
Deselect the currently selected NAND target. The result of operationsexecuted onchip after the target has been deselected is undefined.
- intnand_soft_waitrdy(structnand_chip*chip,unsignedlongtimeout_ms)¶
Poll STATUS reg until RDY bit is set to 1
Parameters
structnand_chip*chipNAND chip structure
unsignedlongtimeout_msTimeout in ms
Description
Poll the STATUS register using ->exec_op() until the RDY bit becomes 1.If that does not happen whitin the specified timeout, -ETIMEDOUT isreturned.
This helper is intended to be used when the controller does not have accessto the NAND R/B pin.
Be aware that calling this helper from an ->exec_op() implementation means->exec_op() must be re-entrant.
Return 0 if the NAND chip is ready, a negative error otherwise.
- intnand_gpio_waitrdy(structnand_chip*chip,structgpio_desc*gpiod,unsignedlongtimeout_ms)¶
Poll R/B GPIO pin until ready
Parameters
structnand_chip*chipNAND chip structure
structgpio_desc*gpiodGPIO descriptor of R/B pin
unsignedlongtimeout_msTimeout in ms
Description
Poll the R/B GPIO pin until it becomes ready. If that does not happenwhitin the specified timeout, -ETIMEDOUT is returned.
This helper is intended to be used when the controller has access to theNAND R/B pin over GPIO.
Return 0 if the R/B pin indicates chip is ready, a negative error otherwise.
- intnand_read_page_op(structnand_chip*chip,unsignedintpage,unsignedintoffset_in_page,void*buf,unsignedintlen)¶
Do a READ PAGE operation
Parameters
structnand_chip*chipThe NAND chip
unsignedintpagepage to read
unsignedintoffset_in_pageoffset within the page
void*bufbuffer used to store the data
unsignedintlenlength of the buffer
Description
This function issues a READ PAGE operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_change_read_column_op(structnand_chip*chip,unsignedintoffset_in_page,void*buf,unsignedintlen,boolforce_8bit)¶
Do a CHANGE READ COLUMN operation
Parameters
structnand_chip*chipThe NAND chip
unsignedintoffset_in_pageoffset within the page
void*bufbuffer used to store the data
unsignedintlenlength of the buffer
boolforce_8bitforce 8-bit bus access
Description
This function issues a CHANGE READ COLUMN operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_read_oob_op(structnand_chip*chip,unsignedintpage,unsignedintoffset_in_oob,void*buf,unsignedintlen)¶
Do a READ OOB operation
Parameters
structnand_chip*chipThe NAND chip
unsignedintpagepage to read
unsignedintoffset_in_ooboffset within the OOB area
void*bufbuffer used to store the data
unsignedintlenlength of the buffer
Description
This function issues a READ OOB operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_prog_page_begin_op(structnand_chip*chip,unsignedintpage,unsignedintoffset_in_page,constvoid*buf,unsignedintlen)¶
starts a PROG PAGE operation
Parameters
structnand_chip*chipThe NAND chip
unsignedintpagepage to write
unsignedintoffset_in_pageoffset within the page
constvoid*bufbuffer containing the data to write to the page
unsignedintlenlength of the buffer
Description
This function issues the first half of a PROG PAGE operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
Description
This function issues the second half of a PROG PAGE operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_prog_page_op(structnand_chip*chip,unsignedintpage,unsignedintoffset_in_page,constvoid*buf,unsignedintlen)¶
Do a full PROG PAGE operation
Parameters
structnand_chip*chipThe NAND chip
unsignedintpagepage to write
unsignedintoffset_in_pageoffset within the page
constvoid*bufbuffer containing the data to write to the page
unsignedintlenlength of the buffer
Description
This function issues a full PROG PAGE operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_change_write_column_op(structnand_chip*chip,unsignedintoffset_in_page,constvoid*buf,unsignedintlen,boolforce_8bit)¶
Do a CHANGE WRITE COLUMN operation
Parameters
structnand_chip*chipThe NAND chip
unsignedintoffset_in_pageoffset within the page
constvoid*bufbuffer containing the data to send to the NAND
unsignedintlenlength of the buffer
boolforce_8bitforce 8-bit bus access
Description
This function issues a CHANGE WRITE COLUMN operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
u8addraddress cycle to pass after the READID command
void*bufbuffer used to store the ID
unsignedintlenlength of the buffer
Description
This function sends a READID command and reads back the ID returned by theNAND.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
u8*statusout variable to store the NAND status
Description
This function sends a STATUS command and reads back the status returned bythe NAND.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
Description
This function sends a READ0 command to cancel the effect of the STATUScommand to avoid reading only the status until a new read command is sent.
This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
unsignedinteraseblockblock to erase
Description
This function sends an ERASE command and waits for the NAND to be readybefore returning.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
Description
This function sends a RESET command and waits for the NAND to be readybefore returning.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_read_data_op(structnand_chip*chip,void*buf,unsignedintlen,boolforce_8bit,boolcheck_only)¶
Read data from the NAND
Parameters
structnand_chip*chipThe NAND chip
void*bufbuffer used to store the data
unsignedintlenlength of the buffer
boolforce_8bitforce 8-bit bus access
boolcheck_onlydo not actually run the command, only checks if thecontroller driver supports it
Description
This function does a raw data read on the bus. Usually used after launchinganother NAND operation likenand_read_page_op().This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_write_data_op(structnand_chip*chip,constvoid*buf,unsignedintlen,boolforce_8bit)¶
Write data from the NAND
Parameters
structnand_chip*chipThe NAND chip
constvoid*bufbuffer containing the data to send on the bus
unsignedintlenlength of the buffer
boolforce_8bitforce 8-bit bus access
Description
This function does a raw data write on the bus. Usually used after launchinganother NAND operation likenand_write_page_begin_op().This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- intnand_op_parser_exec_op(structnand_chip*chip,conststructnand_op_parser*parser,conststructnand_operation*op,boolcheck_only)¶
exec_op parser
Parameters
structnand_chip*chipthe NAND chip
conststructnand_op_parser*parserpatterns description provided by the controller driver
conststructnand_operation*opthe NAND operation to address
boolcheck_onlywhen true, the function only checks ifop can be handled butdoes not execute the operation
Description
Helper function designed to ease integration of NAND controller drivers thatonly support a limited set of instruction sequences. The supported sequencesare described inparser, and the framework takes care of splittingop intomultiple sub-operations (if required) and pass them back to the ->exec()callback of the matching pattern ifcheck_only is set to false.
NAND controller drivers should call this function from their own ->exec_op()implementation.
Returns 0 on success, a negative error code otherwise. A failure can becaused by an unsupported operation (none of the supported patterns is ableto handle the requested operation), or an error returned by one of thematching pattern->exec() hook.
- unsignedintnand_subop_get_addr_start_off(conststructnand_subop*subop,unsignedintinstr_idx)¶
Get the start offset in an address array
Parameters
conststructnand_subop*subopThe entire sub-operation
unsignedintinstr_idxIndex of the instruction inside the sub-operation
Description
During driver development, one could be tempted to directly use the->addr.addrs field of address instructions. This is wrong as addressinstructions might be split.
Given an address instruction, returns the offset of the first cycle to issue.
- unsignedintnand_subop_get_num_addr_cyc(conststructnand_subop*subop,unsignedintinstr_idx)¶
Get the remaining address cycles to assert
Parameters
conststructnand_subop*subopThe entire sub-operation
unsignedintinstr_idxIndex of the instruction inside the sub-operation
Description
During driver development, one could be tempted to directly use the->addr->naddrs field of a data instruction. This is wrong as instructionsmight be split.
Given an address instruction, returns the number of address cycle to issue.
- unsignedintnand_subop_get_data_start_off(conststructnand_subop*subop,unsignedintinstr_idx)¶
Get the start offset in a data array
Parameters
conststructnand_subop*subopThe entire sub-operation
unsignedintinstr_idxIndex of the instruction inside the sub-operation
Description
During driver development, one could be tempted to directly use the->data->buf.{in,out} field of data instructions. This is wrong as datainstructions might be split.
Given a data instruction, returns the offset to start from.
- unsignedintnand_subop_get_data_len(conststructnand_subop*subop,unsignedintinstr_idx)¶
Get the number of bytes to retrieve
Parameters
conststructnand_subop*subopThe entire sub-operation
unsignedintinstr_idxIndex of the instruction inside the sub-operation
Description
During driver development, one could be tempted to directly use the->data->len field of a data instruction. This is wrong as data instructionsmight be split.
Returns the length of the chunk of data to send/receive.
Parameters
structnand_chip*chipThe NAND chip
intchipnrInternal die id
Description
Save the timings data structure, then apply SDR timings mode 0 (seenand_reset_interface for details), do the reset operation, and applyback the previous timings.
Returns 0 on success, a negative error code otherwise.
- intnand_read_page_raw(structnand_chip*chip,uint8_t*buf,intoob_required,intpage)¶
[INTERN] read raw page data without ecc
Parameters
structnand_chip*chipnand chip info structure
uint8_t*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
Description
Not for syndrome calculating ECC controllers, which use a special oob layout.
- intnand_monolithic_read_page_raw(structnand_chip*chip,u8*buf,intoob_required,intpage)¶
Monolithic page read in raw mode
Parameters
structnand_chip*chipNAND chip info structure
u8*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
Description
This is a raw page read, ie. without any error detection/correction.Monolithic means we are requesting all the relevant data (main pluseventually OOB) to be loaded in the NAND cache and sent over thebus (from the NAND chip to the NAND controller) in a singleoperation. This is an alternative tonand_read_page_raw(), whichfirst reads the main data, and if the OOB data is requested too,then reads more data on the bus.
- intnand_read_page_hwecc_oob_first(structnand_chip*chip,uint8_t*buf,intoob_required,intpage)¶
Hardware ECC page read with ECC data read from OOB area
Parameters
structnand_chip*chipnand chip info structure
uint8_t*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
Description
Hardware ECC for large page chips, which requires the ECC data to beextracted from the OOB before the actual data is read.
- intnand_read_oob_std(structnand_chip*chip,intpage)¶
[REPLACEABLE] the most common OOB data read function
Parameters
structnand_chip*chipnand chip info structure
intpagepage number to read
- intnand_write_oob_std(structnand_chip*chip,intpage)¶
[REPLACEABLE] the most common OOB data write function
Parameters
structnand_chip*chipnand chip info structure
intpagepage number to write
- intnand_write_page_raw(structnand_chip*chip,constuint8_t*buf,intoob_required,intpage)¶
[INTERN] raw page write function
Parameters
structnand_chip*chipnand chip info structure
constuint8_t*bufdata buffer
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
Description
Not for syndrome calculating ECC controllers, which use a special oob layout.
- intnand_monolithic_write_page_raw(structnand_chip*chip,constu8*buf,intoob_required,intpage)¶
Monolithic page write in raw mode
Parameters
structnand_chip*chipNAND chip info structure
constu8*bufdata buffer to write
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
Description
This is a raw page write, ie. without any error detection/correction.Monolithic means we are requesting all the relevant data (main pluseventually OOB) to be sent over the bus and effectively programmedinto the NAND chip arrays in a single operation. This is analternative tonand_write_page_raw(), which first sends the maindata, then eventually send the OOB data by latching more datacycles on the NAND bus, and finally sends the program command tosynchronyze the NAND chip cache.
- intrawnand_dt_parse_gpio_cs(structdevice*dev,structgpio_desc***cs_array,unsignedint*ncs_array)¶
Parse the gpio-cs property of a controller
Parameters
structdevice*devDevice that will be parsed. Also used for managed allocations.
structgpio_desc***cs_arrayArray of GPIO desc pointers allocated on success
unsignedint*ncs_arrayNumber of entries incs_array updated on success.return 0 on success, an error otherwise.
- intnand_ecc_choose_conf(structnand_chip*chip,conststructnand_ecc_caps*caps,intoobavail)¶
Set the ECC strength and ECC step size
Parameters
structnand_chip*chipnand chip info structure
conststructnand_ecc_caps*capsECC engine caps info structure
intoobavailOOB size that the ECC engine can use
Description
Choose the ECC configuration according to following logic.
If both ECC step size and ECC strength are already set (usually by DT)then check if it is supported by this controller.
If the user provided the nand-ecc-maximize property, then select maximumECC strength.
Otherwise, try to match the ECC step size and ECC strength closestto the chip’s requirement. If available OOB size can’t fit the chiprequirement then fallback to the maximum ECC step size and ECC strength.
On success, the chosen ECC settings are set.
- intnand_scan_with_ids(structnand_chip*chip,unsignedintmaxchips,structnand_flash_dev*ids)¶
[NAND Interface] Scan for the NAND device
Parameters
structnand_chip*chipNAND chip object
unsignedintmaxchipsnumber of chips to scan for.
structnand_flash_dev*idsoptional flash IDs table
Description
This fills out all the uninitialized function pointers with the defaults.The flash ID is read and the mtd/chip structures are filled with theappropriate values.
Parameters
structnand_chip*chipNAND chip object
Internal Functions Provided¶
This chapter contains the autogenerated documentation of the NAND driverinternal functions. Each function has a short description which ismarked with an [XXX] identifier. See the chapter “Documentation hints”for an explanation. The functions marked with [DEFAULT] might berelevant for a board driver developer.
Parameters
structnand_chip*chipNAND chip object
Description
Release chip lock and wake up anyone waiting on the device.
Parameters
structnand_chip*chipNAND chip object
intpageFirst page to start checking for bad block marker usage
Description
Returns an integer that corresponds to the page offset within a block, fora page that is used to store bad block markers. If no more pages areavailable, -EINVAL is returned.
Parameters
structnand_chip*chipNAND chip object
loff_tofsoffset from device start
Description
Check, if the block is bad.
- boolnand_region_is_secured(structnand_chip*chip,loff_toffset,u64size)¶
Check if the region is secured
Parameters
structnand_chip*chipNAND chip object
loff_toffsetOffset of the region to check
u64sizeSize of the region to check
Description
Checks if the region is secured by comparing the offset and size with thelist of secure regions obtained from DT. Returns true if the region issecured else false.
Parameters
structnand_chip*chipNAND chip structure
Description
Lock the device and its controller for exclusive access
Parameters
structnand_chip*chipNAND chip object
Description
Check, if the device is write protected. The function expects, that thedevice is already selected.
- uint8_t*nand_fill_oob(structnand_chip*chip,uint8_t*oob,size_tlen,structmtd_oob_ops*ops)¶
[INTERN] Transfer client buffer to oob
Parameters
structnand_chip*chipNAND chip object
uint8_t*ooboob data buffer
size_tlenoob data write length
structmtd_oob_ops*opsoob ops structure
- intnand_do_write_oob(structnand_chip*chip,loff_tto,structmtd_oob_ops*ops)¶
[MTD Interface] NAND write out-of-band
Parameters
structnand_chip*chipNAND chip object
loff_ttooffset to write to
structmtd_oob_ops*opsoob operation description structure
Description
NAND write out-of-band.
- intnand_default_block_markbad(structnand_chip*chip,loff_tofs)¶
[DEFAULT] mark a block bad via bad block marker
Parameters
structnand_chip*chipNAND chip object
loff_tofsoffset from device start
Description
This is the default implementation, which can be overridden by a hardwarespecific driver. It provides the details for writing a bad block marker to ablock.
Parameters
structnand_chip*chipNAND chip object
loff_tofsoffset of the block to mark bad
Parameters
structnand_chip*chipNAND chip object
loff_tofsoffset from device start
Description
This function performs the generic NAND bad block marking steps (i.e., badblock table(s) and/or marker(s)). We only allow the hardware driver tospecify how to write bad block markers to OOB (chip->legacy.block_markbad).
We try operations in the following order:
erase the affected block, to allow OOB marker to be written cleanly
write bad block marker to OOB area of affected block (unless flagNAND_BBT_NO_OOB_BBM is present)
update the BBT
Note that we retain the first error encountered in (2) or (3), finish theprocedures, and dump the error in the end.
- intnand_block_isreserved(structmtd_info*mtd,loff_tofs)¶
[GENERIC] Check if a block is marked reserved.
Parameters
structmtd_info*mtdMTD device structure
loff_tofsoffset from device start
Description
Check if the block is marked as reserved.
- intnand_block_checkbad(structnand_chip*chip,loff_tofs,intallowbbt)¶
[GENERIC] Check if a block is marked bad
Parameters
structnand_chip*chipNAND chip object
loff_tofsoffset from device start
intallowbbt1, if its allowed to access the bbt area
Description
Check, if the block is bad. Either by reading the bad block table orcalling of the scan function.
- voidpanic_nand_wait(structnand_chip*chip,unsignedlongtimeo)¶
[GENERIC] wait until the command is done
Parameters
structnand_chip*chipNAND chip structure
unsignedlongtimeotimeout
Description
Wait for command done. This is a helper function for nand_wait used whenwe are in interrupt context. May happen when in panic and trying to writean oops through mtdoops.
Parameters
structnand_chip*chipThe NAND chip
intchipnrInternal die id
Description
Reset the Data interface and timings to ONFI mode 0.
Returns 0 for success or negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
intchipnrInternal die id
Description
Configure what has been reported to be the best data interface and NANDtimings supported by the chip and the driver.
Returns 0 for success or negative error code otherwise.
- intnand_choose_best_sdr_timings(structnand_chip*chip,structnand_interface_config*iface,structnand_sdr_timings*spec_timings)¶
Pick up the best SDR timings that both the NAND controller and the NAND chip support
Parameters
structnand_chip*chipthe NAND chip
structnand_interface_config*ifacethe interface configuration (can eventually be updated)
structnand_sdr_timings*spec_timingsspecific timings, when not fitting the ONFI specification
Description
If specific timings are provided, use them. Otherwise, retrieve supportedtiming modes from ONFI information.
- intnand_choose_best_nvddr_timings(structnand_chip*chip,structnand_interface_config*iface,structnand_nvddr_timings*spec_timings)¶
Pick up the best NVDDR timings that both the NAND controller and the NAND chip support
Parameters
structnand_chip*chipthe NAND chip
structnand_interface_config*ifacethe interface configuration (can eventually be updated)
structnand_nvddr_timings*spec_timingsspecific timings, when not fitting the ONFI specification
Description
If specific timings are provided, use them. Otherwise, retrieve supportedtiming modes from ONFI information.
- intnand_choose_best_timings(structnand_chip*chip,structnand_interface_config*iface)¶
Pick up the best NVDDR or SDR timings that both NAND controller and the NAND chip support
Parameters
structnand_chip*chipthe NAND chip
structnand_interface_config*ifacethe interface configuration (can eventually be updated)
Description
If specific timings are provided, use them. Otherwise, retrieve supportedtiming modes from ONFI information.
Parameters
structnand_chip*chipThe NAND chip
Description
Find the best data interface and NAND timings supported by the chipand the driver. Eventually let the NAND manufacturer driver propose his ownset of timings.
After this function nand_chip->interface_config is initialized with the besttiming mode available.
Returns 0 for success or negative error code otherwise.
- intnand_fill_column_cycles(structnand_chip*chip,u8*addrs,unsignedintoffset_in_page)¶
fill the column cycles of an address
Parameters
structnand_chip*chipThe NAND chip
u8*addrsArray of address cycles to fill
unsignedintoffset_in_pageThe offset in the page
Description
Fills the first or the first two bytes of theaddrs field dependingon the NAND bus width and the page size.
Returns the number of cycles needed to encode the column, or a negativeerror code in case one of the arguments is invalid.
- intnand_read_param_page_op(structnand_chip*chip,u8page,void*buf,unsignedintlen)¶
Do a READ PARAMETER PAGE operation
Parameters
structnand_chip*chipThe NAND chip
u8pageparameter page to read
void*bufbuffer used to store the data
unsignedintlenlength of the buffer
Description
This function issues a READ PARAMETER PAGE operation.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
u8featurefeature id
constvoid*data4 bytes of data
Description
This function sends a SET FEATURES command and waits for the NAND to beready before returning.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
Parameters
structnand_chip*chipThe NAND chip
u8featurefeature id
void*data4 bytes of data
Description
This function sends a GET FEATURES command and waits for the NAND to beready before returning.This function does not select/unselect the CS line.
Returns 0 on success, a negative error code otherwise.
- structnand_op_parser_ctx¶
Context used by the parser
Definition:
struct nand_op_parser_ctx { const struct nand_op_instr *instrs; unsigned int ninstrs; struct nand_subop subop;};Members
instrsarray of all the instructions that must be addressed
ninstrslength of theinstrs array
subopSub-operation to be passed to the NAND controller
Description
This structure is used by the core to split NAND operations intosub-operations that can be handled by the NAND controller.
- boolnand_op_parser_must_split_instr(conststructnand_op_parser_pattern_elem*pat,conststructnand_op_instr*instr,unsignedint*start_offset)¶
Checks if an instruction must be split
Parameters
conststructnand_op_parser_pattern_elem*patthe parser pattern element that matchesinstr
conststructnand_op_instr*instrpointer to the instruction to check
unsignedint*start_offsetthis is an in/out parameter. Ifinstr has already beensplit, thenstart_offset is the offset from which to start(either an address cycle or an offset in the data buffer).Conversely, if the function returns true (ie. instr must besplit), this parameter is updated to point to the firstdata/address cycle that has not been taken care of.
Description
Some NAND controllers are limited and cannot send X address cycles with aunique operation, or cannot read/write more than Y bytes at the same time.In this case, split the instruction that does not fit in a singlecontroller-operation into two or more chunks.
Returns true if the instruction must be split, false otherwise.Thestart_offset parameter is also updated to the offset at which the nextbundle of instruction must start (if an address or a data instruction).
- boolnand_op_parser_match_pat(conststructnand_op_parser_pattern*pat,structnand_op_parser_ctx*ctx)¶
Checks if a pattern matches the instructions remaining in the parser context
Parameters
conststructnand_op_parser_pattern*patthe pattern to test
structnand_op_parser_ctx*ctxthe parser context structure to match with the patternpat
Description
Check ifpat matches the set or a sub-set of instructions remaining inctx.Returns true if this is the case, false ortherwise. When true is returned,ctx->subop is updated with the set of instructions to be passed to thecontroller driver.
- intnand_get_features(structnand_chip*chip,intaddr,u8*subfeature_param)¶
wrapper to perform a GET_FEATURE
Parameters
structnand_chip*chipNAND chip info structure
intaddrfeature address
u8*subfeature_paramthe subfeature parameters, a four bytes array
Description
Returns 0 for success, a negative error otherwise. Returns -ENOTSUPP if theoperation cannot be handled.
- intnand_set_features(structnand_chip*chip,intaddr,u8*subfeature_param)¶
wrapper to perform a SET_FEATURE
Parameters
structnand_chip*chipNAND chip info structure
intaddrfeature address
u8*subfeature_paramthe subfeature parameters, a four bytes array
Description
Returns 0 for success, a negative error otherwise. Returns -ENOTSUPP if theoperation cannot be handled.
- intnand_read_page_raw_notsupp(structnand_chip*chip,u8*buf,intoob_required,intpage)¶
dummy read raw page function
Parameters
structnand_chip*chipnand chip info structure
u8*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
Description
Returns -ENOTSUPP unconditionally.
- intnand_read_page_raw_syndrome(structnand_chip*chip,uint8_t*buf,intoob_required,intpage)¶
[INTERN] read raw page data without ecc
Parameters
structnand_chip*chipnand chip info structure
uint8_t*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
Description
We need a special oob layout and handling even when OOB isn’t used.
- intnand_read_page_swecc(structnand_chip*chip,uint8_t*buf,intoob_required,intpage)¶
[REPLACEABLE] software ECC based page read function
Parameters
structnand_chip*chipnand chip info structure
uint8_t*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
- intnand_read_subpage(structnand_chip*chip,uint32_tdata_offs,uint32_treadlen,uint8_t*bufpoi,intpage)¶
[REPLACEABLE] ECC based sub-page read function
Parameters
structnand_chip*chipnand chip info structure
uint32_tdata_offsoffset of requested data within the page
uint32_treadlendata length
uint8_t*bufpoibuffer to store read data
intpagepage number to read
- intnand_read_page_hwecc(structnand_chip*chip,uint8_t*buf,intoob_required,intpage)¶
[REPLACEABLE] hardware ECC based page read function
Parameters
structnand_chip*chipnand chip info structure
uint8_t*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
Description
Not for syndrome calculating ECC controllers which need a special oob layout.
- intnand_read_page_syndrome(structnand_chip*chip,uint8_t*buf,intoob_required,intpage)¶
[REPLACEABLE] hardware ECC syndrome based page read
Parameters
structnand_chip*chipnand chip info structure
uint8_t*bufbuffer to store read data
intoob_requiredcaller requires OOB data read to chip->oob_poi
intpagepage number to read
Description
The hw generator calculates the error syndrome automatically. Therefore weneed a special oob layout and handling.
- uint8_t*nand_transfer_oob(structnand_chip*chip,uint8_t*oob,structmtd_oob_ops*ops,size_tlen)¶
[INTERN] Transfer oob to client buffer
Parameters
structnand_chip*chipNAND chip object
uint8_t*ooboob destination address
structmtd_oob_ops*opsoob ops structure
size_tlensize of oob to transfer
Parameters
structnand_chip*chipNAND chip object
intretry_modethe retry mode to use
Description
Some vendors supply a special command to shift the Vt threshold, to be usedwhen there are too many bitflips in a page (i.e., ECC error). After settinga new threshold, the host should retry reading the page.
- intnand_do_read_ops(structnand_chip*chip,loff_tfrom,structmtd_oob_ops*ops)¶
[INTERN] Read data with ECC
Parameters
structnand_chip*chipNAND chip object
loff_tfromoffset to read from
structmtd_oob_ops*opsoob ops structure
Description
Internal function. Called with chip held.
- intnand_read_oob_syndrome(structnand_chip*chip,intpage)¶
[REPLACEABLE] OOB data read function for HW ECC with syndromes
Parameters
structnand_chip*chipnand chip info structure
intpagepage number to read
- intnand_write_oob_syndrome(structnand_chip*chip,intpage)¶
[REPLACEABLE] OOB data write function for HW ECC with syndrome - only for large page flash
Parameters
structnand_chip*chipnand chip info structure
intpagepage number to write
- intnand_do_read_oob(structnand_chip*chip,loff_tfrom,structmtd_oob_ops*ops)¶
[INTERN] NAND read out-of-band
Parameters
structnand_chip*chipNAND chip object
loff_tfromoffset to read from
structmtd_oob_ops*opsoob operations description structure
Description
NAND read out-of-band data from the spare area.
- intnand_read_oob(structmtd_info*mtd,loff_tfrom,structmtd_oob_ops*ops)¶
[MTD Interface] NAND read data and/or out-of-band
Parameters
structmtd_info*mtdMTD device structure
loff_tfromoffset to read from
structmtd_oob_ops*opsoob operation description structure
Description
NAND read data and/or out-of-band data.
- intnand_write_page_raw_notsupp(structnand_chip*chip,constu8*buf,intoob_required,intpage)¶
dummy raw page write function
Parameters
structnand_chip*chipnand chip info structure
constu8*bufdata buffer
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
Description
Returns -ENOTSUPP unconditionally.
- intnand_write_page_raw_syndrome(structnand_chip*chip,constuint8_t*buf,intoob_required,intpage)¶
[INTERN] raw page write function
Parameters
structnand_chip*chipnand chip info structure
constuint8_t*bufdata buffer
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
Description
We need a special oob layout and handling even when ECC isn’t checked.
- intnand_write_page_swecc(structnand_chip*chip,constuint8_t*buf,intoob_required,intpage)¶
[REPLACEABLE] software ECC based page write function
Parameters
structnand_chip*chipnand chip info structure
constuint8_t*bufdata buffer
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
- intnand_write_page_hwecc(structnand_chip*chip,constuint8_t*buf,intoob_required,intpage)¶
[REPLACEABLE] hardware ECC based page write function
Parameters
structnand_chip*chipnand chip info structure
constuint8_t*bufdata buffer
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
- intnand_write_subpage_hwecc(structnand_chip*chip,uint32_toffset,uint32_tdata_len,constuint8_t*buf,intoob_required,intpage)¶
[REPLACEABLE] hardware ECC based subpage write
Parameters
structnand_chip*chipnand chip info structure
uint32_toffsetcolumn address of subpage within the page
uint32_tdata_lendata length
constuint8_t*bufdata buffer
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
- intnand_write_page_syndrome(structnand_chip*chip,constuint8_t*buf,intoob_required,intpage)¶
[REPLACEABLE] hardware ECC syndrome based page write
Parameters
structnand_chip*chipnand chip info structure
constuint8_t*bufdata buffer
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
Description
The hw generator calculates the error syndrome automatically. Therefore weneed a special oob layout and handling.
- intnand_write_page(structnand_chip*chip,uint32_toffset,intdata_len,constuint8_t*buf,intoob_required,intpage,intraw)¶
write one page
Parameters
structnand_chip*chipNAND chip descriptor
uint32_toffsetaddress offset within the page
intdata_lenlength of actual data to be written
constuint8_t*bufthe data to write
intoob_requiredmust write chip->oob_poi to OOB
intpagepage number to write
intrawuse _raw version of write_page
- intnand_do_write_ops(structnand_chip*chip,loff_tto,structmtd_oob_ops*ops)¶
[INTERN] NAND write with ECC
Parameters
structnand_chip*chipNAND chip object
loff_ttooffset to write to
structmtd_oob_ops*opsoob operations description structure
Description
NAND write with ECC.
- intpanic_nand_write(structmtd_info*mtd,loff_tto,size_tlen,size_t*retlen,constuint8_t*buf)¶
[MTD Interface] NAND write with ECC
Parameters
structmtd_info*mtdMTD device structure
loff_ttooffset to write to
size_tlennumber of bytes to write
size_t*retlenpointer to variable to store the number of written bytes
constuint8_t*bufthe data to write
Description
NAND write with ECC. Used when performing writes in interrupt context, thismay for example be called by mtdoops when writing an oops while in panic.
- intnand_write_oob(structmtd_info*mtd,loff_tto,structmtd_oob_ops*ops)¶
[MTD Interface] NAND write data and/or out-of-band
Parameters
structmtd_info*mtdMTD device structure
loff_ttooffset to write to
structmtd_oob_ops*opsoob operation description structure
- intnand_erase(structmtd_info*mtd,structerase_info*instr)¶
[MTD Interface] erase block(s)
Parameters
structmtd_info*mtdMTD device structure
structerase_info*instrerase instruction
Description
Erase one ore more blocks.
Parameters
structnand_chip*chipNAND chip object
structerase_info*instrerase instruction
intallowbbtallow erasing the bbt area
Description
Erase one ore more blocks.
- voidnand_sync(structmtd_info*mtd)¶
[MTD Interface] sync
Parameters
structmtd_info*mtdMTD device structure
Description
Sync is actually a wait for chip ready function.
- intnand_block_isbad(structmtd_info*mtd,loff_toffs)¶
[MTD Interface] Check if block at offset is bad
Parameters
structmtd_info*mtdMTD device structure
loff_toffsoffset relative to mtd start
- intnand_block_markbad(structmtd_info*mtd,loff_tofs)¶
[MTD Interface] Mark block at the given offset as bad
Parameters
structmtd_info*mtdMTD device structure
loff_tofsoffset relative to mtd start
- intnand_suspend(structmtd_info*mtd)¶
[MTD Interface] Suspend the NAND flash
Parameters
structmtd_info*mtdMTD device structure
Description
Returns 0 for success or negative error code otherwise.
- voidnand_resume(structmtd_info*mtd)¶
[MTD Interface] Resume the NAND flash
Parameters
structmtd_info*mtdMTD device structure
- voidnand_shutdown(structmtd_info*mtd)¶
[MTD Interface] Finish the current NAND operation and prevent further operations
Parameters
structmtd_info*mtdMTD device structure
- intnand_lock(structmtd_info*mtd,loff_tofs,uint64_tlen)¶
[MTD Interface] Lock the NAND flash
Parameters
structmtd_info*mtdMTD device structure
loff_tofsoffset byte address
uint64_tlennumber of bytes to lock (must be a multiple of block/page size)
- intnand_unlock(structmtd_info*mtd,loff_tofs,uint64_tlen)¶
[MTD Interface] Unlock the NAND flash
Parameters
structmtd_info*mtdMTD device structure
loff_tofsoffset byte address
uint64_tlennumber of bytes to unlock (must be a multiple of block/page size)
- intnand_scan_ident(structnand_chip*chip,unsignedintmaxchips,structnand_flash_dev*table)¶
Scan for the NAND device
Parameters
structnand_chip*chipNAND chip object
unsignedintmaxchipsnumber of chips to scan for
structnand_flash_dev*tablealternative NAND ID table
Description
This is the first phase of the normalnand_scan() function. It reads theflash ID and sets up MTD fields accordingly.
This helper used to be called directly from controller drivers that neededto tweak some ECC-related parameters beforenand_scan_tail(). This separationprevented dynamic allocations during this phase which was unconvenient andas been banned for the benefit of the ->init_ecc()/cleanup_ecc() hooks.
- intnand_check_ecc_caps(structnand_chip*chip,conststructnand_ecc_caps*caps,intoobavail)¶
check the sanity of preset ECC settings
Parameters
structnand_chip*chipnand chip info structure
conststructnand_ecc_caps*capsECC caps info structure
intoobavailOOB size that the ECC engine can use
Description
When ECC step size and strength are already set, check if they are supportedby the controller and the calculated ECC bytes fit within the chip’s OOB.On success, the calculated ECC bytes is set.
- intnand_match_ecc_req(structnand_chip*chip,conststructnand_ecc_caps*caps,intoobavail)¶
meet the chip’s requirement with least ECC bytes
Parameters
structnand_chip*chipnand chip info structure
conststructnand_ecc_caps*capsECC engine caps info structure
intoobavailOOB size that the ECC engine can use
Description
If a chip’s ECC requirement is provided, try to meet it with the leastnumber of ECC bytes (i.e. with the largest number of OOB-free bytes).On success, the chosen ECC settings are set.
- intnand_maximize_ecc(structnand_chip*chip,conststructnand_ecc_caps*caps,intoobavail)¶
choose the max ECC strength available
Parameters
structnand_chip*chipnand chip info structure
conststructnand_ecc_caps*capsECC engine caps info structure
intoobavailOOB size that the ECC engine can use
Description
Choose the max ECC strength that is supported on the controller, and can fitwithin the chip’s OOB. On success, the chosen ECC settings are set.
Parameters
structnand_chip*chipNAND chip object
Description
This is the second phase of the normalnand_scan() function. It fills outall the uninitialized function pointers with the defaults and scans for abad block table if appropriate.
- intcheck_pattern(uint8_t*buf,intlen,intpaglen,structnand_bbt_descr*td)¶
[GENERIC] check if a pattern is in the buffer
Parameters
uint8_t*bufthe buffer to search
intlenthe length of buffer to search
intpaglenthe pagelength
structnand_bbt_descr*tdsearch pattern descriptor
Description
Check for a pattern at the given place. Used to search bad block tables andgood / bad block identifiers.
- intcheck_short_pattern(uint8_t*buf,structnand_bbt_descr*td)¶
[GENERIC] check if a pattern is in the buffer
Parameters
uint8_t*bufthe buffer to search
structnand_bbt_descr*tdsearch pattern descriptor
Description
Check for a pattern at the given place. Used to search bad block tables andgood / bad block identifiers. Same as check_pattern, but no optional emptycheck.
- u32add_marker_len(structnand_bbt_descr*td)¶
compute the length of the marker in data area
Parameters
structnand_bbt_descr*tdBBT descriptor used for computation
Description
The length will be 0 if the marker is located in OOB area.
- intread_bbt(structnand_chip*this,uint8_t*buf,intpage,intnum,structnand_bbt_descr*td,intoffs)¶
[GENERIC] Read the bad block table starting from page
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
intpagethe starting page
intnumthe number of bbt descriptors to read
structnand_bbt_descr*tdthe bbt describtion table
intoffsblock number offset in the table
Description
Read the bad block table starting from page.
- intread_abs_bbt(structnand_chip*this,uint8_t*buf,structnand_bbt_descr*td,intchip)¶
[GENERIC] Read the bad block table starting at a given page
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
structnand_bbt_descr*tddescriptor for the bad block table
intchipread the table for a specific chip, -1 read all chips; applies only ifNAND_BBT_PERCHIP option is set
Description
Read the bad block table for all chips starting at a given page. We assumethat the bbt bits are in consecutive order.
- intscan_read_oob(structnand_chip*this,uint8_t*buf,loff_toffs,size_tlen)¶
[GENERIC] Scan data+OOB region to buffer
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
loff_toffsoffset at which to scan
size_tlenlength of data region to read
Description
Scan read data from data+OOB. May traverse multiple pages, interleavingpage,OOB,page,OOB,... in buf. Completes transfer and returns the “strongest”ECC condition (error or bitflip). May quit on the first (non-ECC) error.
- voidread_abs_bbts(structnand_chip*this,uint8_t*buf,structnand_bbt_descr*td,structnand_bbt_descr*md)¶
[GENERIC] Read the bad block table(s) for all chips starting at a given page
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
structnand_bbt_descr*tddescriptor for the bad block table
structnand_bbt_descr*mddescriptor for the bad block table mirror
Description
Read the bad block table(s) for all chips starting at a given page. Weassume that the bbt bits are in consecutive order.
- intcreate_bbt(structnand_chip*this,uint8_t*buf,structnand_bbt_descr*bd,intchip)¶
[GENERIC] Create a bad block table by scanning the device
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
structnand_bbt_descr*bddescriptor for the good/bad block search pattern
intchipcreate the table for a specific chip, -1 read all chips; applies onlyif NAND_BBT_PERCHIP option is set
Description
Create a bad block table by scanning the device for the given good/bad blockidentify pattern.
- intsearch_bbt(structnand_chip*this,uint8_t*buf,structnand_bbt_descr*td)¶
[GENERIC] scan the device for a specific bad block table
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
structnand_bbt_descr*tddescriptor for the bad block table
Description
Read the bad block table by searching for a given ident pattern. Search ispreformed either from the beginning up or from the end of the devicedownwards. The search starts always at the start of a block. If the optionNAND_BBT_PERCHIP is given, each chip is searched for a bbt, which containsthe bad block information of this chip. This is necessary to provide supportfor certain DOC devices.
The bbt ident pattern resides in the oob area of the first page in a block.
- voidsearch_read_bbts(structnand_chip*this,uint8_t*buf,structnand_bbt_descr*td,structnand_bbt_descr*md)¶
[GENERIC] scan the device for bad block table(s)
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
structnand_bbt_descr*tddescriptor for the bad block table
structnand_bbt_descr*mddescriptor for the bad block table mirror
Description
Search and read the bad block table(s).
- intget_bbt_block(structnand_chip*this,structnand_bbt_descr*td,structnand_bbt_descr*md,intchip)¶
Get the first valid eraseblock suitable to store a BBT
Parameters
structnand_chip*thisthe NAND device
structnand_bbt_descr*tdthe BBT description
structnand_bbt_descr*mdthe mirror BBT descriptor
intchipthe CHIP selector
Description
This functions returns a positive block number pointing a valid eraseblocksuitable to store a BBT (i.e. in the range reserved for BBT), or -ENOSPC ifall blocks are already used of marked bad. If td->pages[chip] was alreadypointing to a valid block we re-use it, otherwise we search for the nextvalid one.
- voidmark_bbt_block_bad(structnand_chip*this,structnand_bbt_descr*td,intchip,intblock)¶
Mark one of the block reserved for BBT bad
Parameters
structnand_chip*thisthe NAND device
structnand_bbt_descr*tdthe BBT description
intchipthe CHIP selector
intblockthe BBT block to mark
Description
Blocks reserved for BBT can become bad. This functions is an helper to marksuch blocks as bad. It takes care of updating the in-memory BBT, marking theblock as bad using a bad block marker and invalidating the associatedtd->pages[] entry.
- intwrite_bbt(structnand_chip*this,uint8_t*buf,structnand_bbt_descr*td,structnand_bbt_descr*md,intchipsel)¶
[GENERIC] (Re)write the bad block table
Parameters
structnand_chip*thisNAND chip object
uint8_t*buftemporary buffer
structnand_bbt_descr*tddescriptor for the bad block table
structnand_bbt_descr*mddescriptor for the bad block table mirror
intchipselselector for a specific chip, -1 for all
Description
(Re)write the bad block table.
- intnand_memory_bbt(structnand_chip*this,structnand_bbt_descr*bd)¶
[GENERIC] create a memory based bad block table
Parameters
structnand_chip*thisNAND chip object
structnand_bbt_descr*bddescriptor for the good/bad block search pattern
Description
The function creates a memory based bbt by scanning the device formanufacturer / software marked good / bad blocks.
- intcheck_create(structnand_chip*this,uint8_t*buf,structnand_bbt_descr*bd)¶
[GENERIC] create and write bbt(s) if necessary
Parameters
structnand_chip*thisthe NAND device
uint8_t*buftemporary buffer
structnand_bbt_descr*bddescriptor for the good/bad block search pattern
Description
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 foundfor the chip/device. Update is necessary if one of the tables is missing orthe version nr. of one table is less than the other.
Parameters
structnand_chip*thisthe NAND device
loff_toffsthe offset of the newly marked block
Description
The function updates the bad block table(s).
- voidmark_bbt_region(structnand_chip*this,structnand_bbt_descr*td)¶
[GENERIC] mark the bad block table regions
Parameters
structnand_chip*thisthe NAND device
structnand_bbt_descr*tdbad block table descriptor
Description
The bad block table regions are marked as “bad” to prevent accidentalerasures / writes. The regions are identified by the mark 0x02.
Parameters
structnand_chip*thisthe NAND device
structnand_bbt_descr*bdthe table to verify
Description
This functions performs a few sanity checks on the bad block descriptiontable.
- intnand_scan_bbt(structnand_chip*this,structnand_bbt_descr*bd)¶
[NAND Interface] scan, find, read and maybe create bad block table(s)
Parameters
structnand_chip*thisthe NAND device
structnand_bbt_descr*bddescriptor for the good/bad block search pattern
Description
The function checks, if a bad block table(s) is/are already available. Ifnot it scans the device for manufacturer marked good / bad blocks and writesthe bad block table(s) to the selected place.
The bad block table memory is allocated here. It must be freed by callingthe nand_free_bbt function.
Parameters
structnand_chip*thisNAND chip to create descriptor for
Description
This function allocates and initializes a nand_bbt_descr for BBM detectionbased on the properties ofthis. The new descriptor is stored inthis->badblock_pattern. Thus, this->badblock_pattern should be NULL whenpassed to this function.
- intnand_isreserved_bbt(structnand_chip*this,loff_toffs)¶
[NAND Interface] Check if a block is reserved
Parameters
structnand_chip*thisNAND chip object
loff_toffsoffset in the device
- intnand_isbad_bbt(structnand_chip*this,loff_toffs,intallowbbt)¶
[NAND Interface] Check if a block is bad
Parameters
structnand_chip*thisNAND chip object
loff_toffsoffset in the device
intallowbbtallow access to bad block table region
Parameters
structnand_chip*thisNAND chip object
loff_toffsoffset of the bad block
Credits¶
The following people have contributed to the NAND driver:
Steven J. Hillsjhill@realitydiluted.com
David Woodhousedwmw2@infradead.org
Thomas Gleixnertglx@kernel.org
A lot of users have provided bugfixes, improvements and helping handsfor testing. Thanks a lot.
The following people have contributed to this document:
Thomas Gleixnertglx@kernel.org