mtdnand.rst 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. =====================================
  2. MTD NAND Driver Programming Interface
  3. =====================================
  4. :Author: Thomas Gleixner
  5. Introduction
  6. ============
  7. The generic NAND driver supports almost all NAND and AG-AND based chips
  8. and connects them to the Memory Technology Devices (MTD) subsystem of
  9. the Linux Kernel.
  10. This documentation is provided for developers who want to implement
  11. board drivers or filesystem drivers suitable for NAND devices.
  12. Known Bugs And Assumptions
  13. ==========================
  14. None.
  15. Documentation hints
  16. ===================
  17. The function and structure docs are autogenerated. Each function and
  18. struct member has a short description which is marked with an [XXX]
  19. identifier. The following chapters explain the meaning of those
  20. identifiers.
  21. Function identifiers [XXX]
  22. --------------------------
  23. The functions are marked with [XXX] identifiers in the short comment.
  24. The identifiers explain the usage and scope of the functions. Following
  25. identifiers are used:
  26. - [MTD Interface]
  27. These functions provide the interface to the MTD kernel API. They are
  28. not replaceable and provide functionality which is complete hardware
  29. independent.
  30. - [NAND Interface]
  31. These functions are exported and provide the interface to the NAND
  32. kernel API.
  33. - [GENERIC]
  34. Generic functions are not replaceable and provide functionality which
  35. is complete hardware independent.
  36. - [DEFAULT]
  37. Default functions provide hardware related functionality which is
  38. suitable for most of the implementations. These functions can be
  39. replaced by the board driver if necessary. Those functions are called
  40. via pointers in the NAND chip description structure. The board driver
  41. can set the functions which should be replaced by board dependent
  42. functions before calling nand_scan(). If the function pointer is
  43. NULL on entry to nand_scan() then the pointer is set to the default
  44. function which is suitable for the detected chip type.
  45. Struct member identifiers [XXX]
  46. -------------------------------
  47. The struct members are marked with [XXX] identifiers in the comment. The
  48. identifiers explain the usage and scope of the members. Following
  49. identifiers are used:
  50. - [INTERN]
  51. These members are for NAND driver internal use only and must not be
  52. modified. Most of these values are calculated from the chip geometry
  53. information which is evaluated during nand_scan().
  54. - [REPLACEABLE]
  55. Replaceable members hold hardware related functions which can be
  56. provided by the board driver. The board driver can set the functions
  57. which should be replaced by board dependent functions before calling
  58. nand_scan(). If the function pointer is NULL on entry to
  59. nand_scan() then the pointer is set to the default function which is
  60. suitable for the detected chip type.
  61. - [BOARDSPECIFIC]
  62. Board specific members hold hardware related information which must
  63. be provided by the board driver. The board driver must set the
  64. function pointers and datafields before calling nand_scan().
  65. - [OPTIONAL]
  66. Optional members can hold information relevant for the board driver.
  67. The generic NAND driver code does not use this information.
  68. Basic board driver
  69. ==================
  70. For most boards it will be sufficient to provide just the basic
  71. functions and fill out some really board dependent members in the nand
  72. chip description structure.
  73. Basic defines
  74. -------------
  75. At least you have to provide a nand_chip structure and a storage for
  76. the ioremap'ed chip address. You can allocate the nand_chip structure
  77. using kmalloc or you can allocate it statically. The NAND chip structure
  78. embeds an mtd structure which will be registered to the MTD subsystem.
  79. You can extract a pointer to the mtd structure from a nand_chip pointer
  80. using the nand_to_mtd() helper.
  81. Kmalloc based example
  82. ::
  83. static struct mtd_info *board_mtd;
  84. static void __iomem *baseaddr;
  85. Static example
  86. ::
  87. static struct nand_chip board_chip;
  88. static void __iomem *baseaddr;
  89. Partition defines
  90. -----------------
  91. If you want to divide your device into partitions, then define a
  92. partitioning scheme suitable to your board.
  93. ::
  94. #define NUM_PARTITIONS 2
  95. static struct mtd_partition partition_info[] = {
  96. { .name = "Flash partition 1",
  97. .offset = 0,
  98. .size = 8 * 1024 * 1024 },
  99. { .name = "Flash partition 2",
  100. .offset = MTDPART_OFS_NEXT,
  101. .size = MTDPART_SIZ_FULL },
  102. };
  103. Hardware control function
  104. -------------------------
  105. The hardware control function provides access to the control pins of the
  106. NAND chip(s). The access can be done by GPIO pins or by address lines.
  107. If you use address lines, make sure that the timing requirements are
  108. met.
  109. *GPIO based example*
  110. ::
  111. static void board_hwcontrol(struct mtd_info *mtd, int cmd)
  112. {
  113. switch(cmd){
  114. case NAND_CTL_SETCLE: /* Set CLE pin high */ break;
  115. case NAND_CTL_CLRCLE: /* Set CLE pin low */ break;
  116. case NAND_CTL_SETALE: /* Set ALE pin high */ break;
  117. case NAND_CTL_CLRALE: /* Set ALE pin low */ break;
  118. case NAND_CTL_SETNCE: /* Set nCE pin low */ break;
  119. case NAND_CTL_CLRNCE: /* Set nCE pin high */ break;
  120. }
  121. }
  122. *Address lines based example.* It's assumed that the nCE pin is driven
  123. by a chip select decoder.
  124. ::
  125. static void board_hwcontrol(struct mtd_info *mtd, int cmd)
  126. {
  127. struct nand_chip *this = mtd_to_nand(mtd);
  128. switch(cmd){
  129. case NAND_CTL_SETCLE: this->legacy.IO_ADDR_W |= CLE_ADRR_BIT; break;
  130. case NAND_CTL_CLRCLE: this->legacy.IO_ADDR_W &= ~CLE_ADRR_BIT; break;
  131. case NAND_CTL_SETALE: this->legacy.IO_ADDR_W |= ALE_ADRR_BIT; break;
  132. case NAND_CTL_CLRALE: this->legacy.IO_ADDR_W &= ~ALE_ADRR_BIT; break;
  133. }
  134. }
  135. Device ready function
  136. ---------------------
  137. If the hardware interface has the ready busy pin of the NAND chip
  138. connected to a GPIO or other accessible I/O pin, this function is used
  139. to read back the state of the pin. The function has no arguments and
  140. should return 0, if the device is busy (R/B pin is low) and 1, if the
  141. device is ready (R/B pin is high). If the hardware interface does not
  142. give access to the ready busy pin, then the function must not be defined
  143. and the function pointer this->legacy.dev_ready is set to NULL.
  144. Init function
  145. -------------
  146. The init function allocates memory and sets up all the board specific
  147. parameters and function pointers. When everything is set up nand_scan()
  148. is called. This function tries to detect and identify then chip. If a
  149. chip is found all the internal data fields are initialized accordingly.
  150. The structure(s) have to be zeroed out first and then filled with the
  151. necessary information about the device.
  152. ::
  153. static int __init board_init (void)
  154. {
  155. struct nand_chip *this;
  156. int err = 0;
  157. /* Allocate memory for MTD device structure and private data */
  158. this = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
  159. if (!this) {
  160. printk ("Unable to allocate NAND MTD device structure.\n");
  161. err = -ENOMEM;
  162. goto out;
  163. }
  164. board_mtd = nand_to_mtd(this);
  165. /* map physical address */
  166. baseaddr = ioremap(CHIP_PHYSICAL_ADDRESS, 1024);
  167. if (!baseaddr) {
  168. printk("Ioremap to access NAND chip failed\n");
  169. err = -EIO;
  170. goto out_mtd;
  171. }
  172. /* Set address of NAND IO lines */
  173. this->legacy.IO_ADDR_R = baseaddr;
  174. this->legacy.IO_ADDR_W = baseaddr;
  175. /* Reference hardware control function */
  176. this->hwcontrol = board_hwcontrol;
  177. /* Set command delay time, see datasheet for correct value */
  178. this->legacy.chip_delay = CHIP_DEPENDEND_COMMAND_DELAY;
  179. /* Assign the device ready function, if available */
  180. this->legacy.dev_ready = board_dev_ready;
  181. this->eccmode = NAND_ECC_SOFT;
  182. /* Scan to find existence of the device */
  183. if (nand_scan (this, 1)) {
  184. err = -ENXIO;
  185. goto out_ior;
  186. }
  187. add_mtd_partitions(board_mtd, partition_info, NUM_PARTITIONS);
  188. goto out;
  189. out_ior:
  190. iounmap(baseaddr);
  191. out_mtd:
  192. kfree (this);
  193. out:
  194. return err;
  195. }
  196. module_init(board_init);
  197. Exit function
  198. -------------
  199. The exit function is only necessary if the driver is compiled as a
  200. module. It releases all resources which are held by the chip driver and
  201. unregisters the partitions in the MTD layer.
  202. ::
  203. #ifdef MODULE
  204. static void __exit board_cleanup (void)
  205. {
  206. /* Unregister device */
  207. WARN_ON(mtd_device_unregister(board_mtd));
  208. /* Release resources */
  209. nand_cleanup(mtd_to_nand(board_mtd));
  210. /* unmap physical address */
  211. iounmap(baseaddr);
  212. /* Free the MTD device structure */
  213. kfree (mtd_to_nand(board_mtd));
  214. }
  215. module_exit(board_cleanup);
  216. #endif
  217. Advanced board driver functions
  218. ===============================
  219. This chapter describes the advanced functionality of the NAND driver.
  220. For a list of functions which can be overridden by the board driver see
  221. the documentation of the nand_chip structure.
  222. Multiple chip control
  223. ---------------------
  224. The nand driver can control chip arrays. Therefore the board driver must
  225. provide an own select_chip function. This function must (de)select the
  226. requested chip. The function pointer in the nand_chip structure must be
  227. set before calling nand_scan(). The maxchip parameter of nand_scan()
  228. defines the maximum number of chips to scan for. Make sure that the
  229. select_chip function can handle the requested number of chips.
  230. The nand driver concatenates the chips to one virtual chip and provides
  231. this virtual chip to the MTD layer.
  232. *Note: The driver can only handle linear chip arrays of equally sized
  233. chips. There is no support for parallel arrays which extend the
  234. buswidth.*
  235. *GPIO based example*
  236. ::
  237. static void board_select_chip (struct mtd_info *mtd, int chip)
  238. {
  239. /* Deselect all chips, set all nCE pins high */
  240. GPIO(BOARD_NAND_NCE) |= 0xff;
  241. if (chip >= 0)
  242. GPIO(BOARD_NAND_NCE) &= ~ (1 << chip);
  243. }
  244. *Address lines based example.* Its assumed that the nCE pins are
  245. connected to an address decoder.
  246. ::
  247. static void board_select_chip (struct mtd_info *mtd, int chip)
  248. {
  249. struct nand_chip *this = mtd_to_nand(mtd);
  250. /* Deselect all chips */
  251. this->legacy.IO_ADDR_R &= ~BOARD_NAND_ADDR_MASK;
  252. this->legacy.IO_ADDR_W &= ~BOARD_NAND_ADDR_MASK;
  253. switch (chip) {
  254. case 0:
  255. this->legacy.IO_ADDR_R |= BOARD_NAND_ADDR_CHIP0;
  256. this->legacy.IO_ADDR_W |= BOARD_NAND_ADDR_CHIP0;
  257. break;
  258. ....
  259. case n:
  260. this->legacy.IO_ADDR_R |= BOARD_NAND_ADDR_CHIPn;
  261. this->legacy.IO_ADDR_W |= BOARD_NAND_ADDR_CHIPn;
  262. break;
  263. }
  264. }
  265. Hardware ECC support
  266. --------------------
  267. Functions and constants
  268. ~~~~~~~~~~~~~~~~~~~~~~~
  269. The nand driver supports three different types of hardware ECC.
  270. - NAND_ECC_HW3_256
  271. Hardware ECC generator providing 3 bytes ECC per 256 byte.
  272. - NAND_ECC_HW3_512
  273. Hardware ECC generator providing 3 bytes ECC per 512 byte.
  274. - NAND_ECC_HW6_512
  275. Hardware ECC generator providing 6 bytes ECC per 512 byte.
  276. - NAND_ECC_HW8_512
  277. Hardware ECC generator providing 8 bytes ECC per 512 byte.
  278. If your hardware generator has a different functionality add it at the
  279. appropriate place in nand_base.c
  280. The board driver must provide following functions:
  281. - enable_hwecc
  282. This function is called before reading / writing to the chip. Reset
  283. or initialize the hardware generator in this function. The function
  284. is called with an argument which let you distinguish between read and
  285. write operations.
  286. - calculate_ecc
  287. This function is called after read / write from / to the chip.
  288. Transfer the ECC from the hardware to the buffer. If the option
  289. NAND_HWECC_SYNDROME is set then the function is only called on
  290. write. See below.
  291. - correct_data
  292. In case of an ECC error this function is called for error detection
  293. and correction. Return 1 respectively 2 in case the error can be
  294. corrected. If the error is not correctable return -1. If your
  295. hardware generator matches the default algorithm of the nand_ecc
  296. software generator then use the correction function provided by
  297. nand_ecc instead of implementing duplicated code.
  298. Hardware ECC with syndrome calculation
  299. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  300. Many hardware ECC implementations provide Reed-Solomon codes and
  301. calculate an error syndrome on read. The syndrome must be converted to a
  302. standard Reed-Solomon syndrome before calling the error correction code
  303. in the generic Reed-Solomon library.
  304. The ECC bytes must be placed immediately after the data bytes in order
  305. to make the syndrome generator work. This is contrary to the usual
  306. layout used by software ECC. The separation of data and out of band area
  307. is not longer possible. The nand driver code handles this layout and the
  308. remaining free bytes in the oob area are managed by the autoplacement
  309. code. Provide a matching oob-layout in this case. See rts_from4.c and
  310. diskonchip.c for implementation reference. In those cases we must also
  311. use bad block tables on FLASH, because the ECC layout is interfering
  312. with the bad block marker positions. See bad block table support for
  313. details.
  314. Bad block table support
  315. -----------------------
  316. Most NAND chips mark the bad blocks at a defined position in the spare
  317. area. Those blocks must not be erased under any circumstances as the bad
  318. block information would be lost. It is possible to check the bad block
  319. mark each time when the blocks are accessed by reading the spare area of
  320. the first page in the block. This is time consuming so a bad block table
  321. is used.
  322. The nand driver supports various types of bad block tables.
  323. - Per device
  324. The bad block table contains all bad block information of the device
  325. which can consist of multiple chips.
  326. - Per chip
  327. A bad block table is used per chip and contains the bad block
  328. information for this particular chip.
  329. - Fixed offset
  330. The bad block table is located at a fixed offset in the chip
  331. (device). This applies to various DiskOnChip devices.
  332. - Automatic placed
  333. The bad block table is automatically placed and detected either at
  334. the end or at the beginning of a chip (device)
  335. - Mirrored tables
  336. The bad block table is mirrored on the chip (device) to allow updates
  337. of the bad block table without data loss.
  338. nand_scan() calls the function nand_default_bbt().
  339. nand_default_bbt() selects appropriate default bad block table
  340. descriptors depending on the chip information which was retrieved by
  341. nand_scan().
  342. The standard policy is scanning the device for bad blocks and build a
  343. ram based bad block table which allows faster access than always
  344. checking the bad block information on the flash chip itself.
  345. Flash based tables
  346. ~~~~~~~~~~~~~~~~~~
  347. It may be desired or necessary to keep a bad block table in FLASH. For
  348. AG-AND chips this is mandatory, as they have no factory marked bad
  349. blocks. They have factory marked good blocks. The marker pattern is
  350. erased when the block is erased to be reused. So in case of powerloss
  351. before writing the pattern back to the chip this block would be lost and
  352. added to the bad blocks. Therefore we scan the chip(s) when we detect
  353. them the first time for good blocks and store this information in a bad
  354. block table before erasing any of the blocks.
  355. The blocks in which the tables are stored are protected against
  356. accidental access by marking them bad in the memory bad block table. The
  357. bad block table management functions are allowed to circumvent this
  358. protection.
  359. The simplest way to activate the FLASH based bad block table support is
  360. to set the option NAND_BBT_USE_FLASH in the bbt_option field of the
  361. nand chip structure before calling nand_scan(). For AG-AND chips is
  362. this done by default. This activates the default FLASH based bad block
  363. table functionality of the NAND driver. The default bad block table
  364. options are
  365. - Store bad block table per chip
  366. - Use 2 bits per block
  367. - Automatic placement at the end of the chip
  368. - Use mirrored tables with version numbers
  369. - Reserve 4 blocks at the end of the chip
  370. User defined tables
  371. ~~~~~~~~~~~~~~~~~~~
  372. User defined tables are created by filling out a nand_bbt_descr
  373. structure and storing the pointer in the nand_chip structure member
  374. bbt_td before calling nand_scan(). If a mirror table is necessary a
  375. second structure must be created and a pointer to this structure must be
  376. stored in bbt_md inside the nand_chip structure. If the bbt_md member
  377. is set to NULL then only the main table is used and no scan for the
  378. mirrored table is performed.
  379. The most important field in the nand_bbt_descr structure is the
  380. options field. The options define most of the table properties. Use the
  381. predefined constants from rawnand.h to define the options.
  382. - Number of bits per block
  383. The supported number of bits is 1, 2, 4, 8.
  384. - Table per chip
  385. Setting the constant NAND_BBT_PERCHIP selects that a bad block
  386. table is managed for each chip in a chip array. If this option is not
  387. set then a per device bad block table is used.
  388. - Table location is absolute
  389. Use the option constant NAND_BBT_ABSPAGE and define the absolute
  390. page number where the bad block table starts in the field pages. If
  391. you have selected bad block tables per chip and you have a multi chip
  392. array then the start page must be given for each chip in the chip
  393. array. Note: there is no scan for a table ident pattern performed, so
  394. the fields pattern, veroffs, offs, len can be left uninitialized
  395. - Table location is automatically detected
  396. The table can either be located in the first or the last good blocks
  397. of the chip (device). Set NAND_BBT_LASTBLOCK to place the bad block
  398. table at the end of the chip (device). The bad block tables are
  399. marked and identified by a pattern which is stored in the spare area
  400. of the first page in the block which holds the bad block table. Store
  401. a pointer to the pattern in the pattern field. Further the length of
  402. the pattern has to be stored in len and the offset in the spare area
  403. must be given in the offs member of the nand_bbt_descr structure.
  404. For mirrored bad block tables different patterns are mandatory.
  405. - Table creation
  406. Set the option NAND_BBT_CREATE to enable the table creation if no
  407. table can be found during the scan. Usually this is done only once if
  408. a new chip is found.
  409. - Table write support
  410. Set the option NAND_BBT_WRITE to enable the table write support.
  411. This allows the update of the bad block table(s) in case a block has
  412. to be marked bad due to wear. The MTD interface function
  413. block_markbad is calling the update function of the bad block table.
  414. If the write support is enabled then the table is updated on FLASH.
  415. Note: Write support should only be enabled for mirrored tables with
  416. version control.
  417. - Table version control
  418. Set the option NAND_BBT_VERSION to enable the table version
  419. control. It's highly recommended to enable this for mirrored tables
  420. with write support. It makes sure that the risk of losing the bad
  421. block table information is reduced to the loss of the information
  422. about the one worn out block which should be marked bad. The version
  423. is stored in 4 consecutive bytes in the spare area of the device. The
  424. position of the version number is defined by the member veroffs in
  425. the bad block table descriptor.
  426. - Save block contents on write
  427. In case that the block which holds the bad block table does contain
  428. other useful information, set the option NAND_BBT_SAVECONTENT. When
  429. the bad block table is written then the whole block is read the bad
  430. block table is updated and the block is erased and everything is
  431. written back. If this option is not set only the bad block table is
  432. written and everything else in the block is ignored and erased.
  433. - Number of reserved blocks
  434. For automatic placement some blocks must be reserved for bad block
  435. table storage. The number of reserved blocks is defined in the
  436. maxblocks member of the bad block table description structure.
  437. Reserving 4 blocks for mirrored tables should be a reasonable number.
  438. This also limits the number of blocks which are scanned for the bad
  439. block table ident pattern.
  440. Spare area (auto)placement
  441. --------------------------
  442. The nand driver implements different possibilities for placement of
  443. filesystem data in the spare area,
  444. - Placement defined by fs driver
  445. - Automatic placement
  446. The default placement function is automatic placement. The nand driver
  447. has built in default placement schemes for the various chiptypes. If due
  448. to hardware ECC functionality the default placement does not fit then
  449. the board driver can provide a own placement scheme.
  450. File system drivers can provide a own placement scheme which is used
  451. instead of the default placement scheme.
  452. Placement schemes are defined by a nand_oobinfo structure
  453. ::
  454. struct nand_oobinfo {
  455. int useecc;
  456. int eccbytes;
  457. int eccpos[24];
  458. int oobfree[8][2];
  459. };
  460. - useecc
  461. The useecc member controls the ecc and placement function. The header
  462. file include/mtd/mtd-abi.h contains constants to select ecc and
  463. placement. MTD_NANDECC_OFF switches off the ecc complete. This is
  464. not recommended and available for testing and diagnosis only.
  465. MTD_NANDECC_PLACE selects caller defined placement,
  466. MTD_NANDECC_AUTOPLACE selects automatic placement.
  467. - eccbytes
  468. The eccbytes member defines the number of ecc bytes per page.
  469. - eccpos
  470. The eccpos array holds the byte offsets in the spare area where the
  471. ecc codes are placed.
  472. - oobfree
  473. The oobfree array defines the areas in the spare area which can be
  474. used for automatic placement. The information is given in the format
  475. {offset, size}. offset defines the start of the usable area, size the
  476. length in bytes. More than one area can be defined. The list is
  477. terminated by an {0, 0} entry.
  478. Placement defined by fs driver
  479. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  480. The calling function provides a pointer to a nand_oobinfo structure
  481. which defines the ecc placement. For writes the caller must provide a
  482. spare area buffer along with the data buffer. The spare area buffer size
  483. is (number of pages) \* (size of spare area). For reads the buffer size
  484. is (number of pages) \* ((size of spare area) + (number of ecc steps per
  485. page) \* sizeof (int)). The driver stores the result of the ecc check
  486. for each tuple in the spare buffer. The storage sequence is::
  487. <spare data page 0><ecc result 0>...<ecc result n>
  488. ...
  489. <spare data page n><ecc result 0>...<ecc result n>
  490. This is a legacy mode used by YAFFS1.
  491. If the spare area buffer is NULL then only the ECC placement is done
  492. according to the given scheme in the nand_oobinfo structure.
  493. Automatic placement
  494. ~~~~~~~~~~~~~~~~~~~
  495. Automatic placement uses the built in defaults to place the ecc bytes in
  496. the spare area. If filesystem data have to be stored / read into the
  497. spare area then the calling function must provide a buffer. The buffer
  498. size per page is determined by the oobfree array in the nand_oobinfo
  499. structure.
  500. If the spare area buffer is NULL then only the ECC placement is done
  501. according to the default builtin scheme.
  502. Spare area autoplacement default schemes
  503. ----------------------------------------
  504. 256 byte pagesize
  505. ~~~~~~~~~~~~~~~~~
  506. ======== ================== ===================================================
  507. Offset Content Comment
  508. ======== ================== ===================================================
  509. 0x00 ECC byte 0 Error correction code byte 0
  510. 0x01 ECC byte 1 Error correction code byte 1
  511. 0x02 ECC byte 2 Error correction code byte 2
  512. 0x03 Autoplace 0
  513. 0x04 Autoplace 1
  514. 0x05 Bad block marker If any bit in this byte is zero, then this
  515. block is bad. This applies only to the first
  516. page in a block. In the remaining pages this
  517. byte is reserved
  518. 0x06 Autoplace 2
  519. 0x07 Autoplace 3
  520. ======== ================== ===================================================
  521. 512 byte pagesize
  522. ~~~~~~~~~~~~~~~~~
  523. ============= ================== ==============================================
  524. Offset Content Comment
  525. ============= ================== ==============================================
  526. 0x00 ECC byte 0 Error correction code byte 0 of the lower
  527. 256 Byte data in this page
  528. 0x01 ECC byte 1 Error correction code byte 1 of the lower
  529. 256 Bytes of data in this page
  530. 0x02 ECC byte 2 Error correction code byte 2 of the lower
  531. 256 Bytes of data in this page
  532. 0x03 ECC byte 3 Error correction code byte 0 of the upper
  533. 256 Bytes of data in this page
  534. 0x04 reserved reserved
  535. 0x05 Bad block marker If any bit in this byte is zero, then this
  536. block is bad. This applies only to the first
  537. page in a block. In the remaining pages this
  538. byte is reserved
  539. 0x06 ECC byte 4 Error correction code byte 1 of the upper
  540. 256 Bytes of data in this page
  541. 0x07 ECC byte 5 Error correction code byte 2 of the upper
  542. 256 Bytes of data in this page
  543. 0x08 - 0x0F Autoplace 0 - 7
  544. ============= ================== ==============================================
  545. 2048 byte pagesize
  546. ~~~~~~~~~~~~~~~~~~
  547. =========== ================== ================================================
  548. Offset Content Comment
  549. =========== ================== ================================================
  550. 0x00 Bad block marker If any bit in this byte is zero, then this block
  551. is bad. This applies only to the first page in a
  552. block. In the remaining pages this byte is
  553. reserved
  554. 0x01 Reserved Reserved
  555. 0x02-0x27 Autoplace 0 - 37
  556. 0x28 ECC byte 0 Error correction code byte 0 of the first
  557. 256 Byte data in this page
  558. 0x29 ECC byte 1 Error correction code byte 1 of the first
  559. 256 Bytes of data in this page
  560. 0x2A ECC byte 2 Error correction code byte 2 of the first
  561. 256 Bytes data in this page
  562. 0x2B ECC byte 3 Error correction code byte 0 of the second
  563. 256 Bytes of data in this page
  564. 0x2C ECC byte 4 Error correction code byte 1 of the second
  565. 256 Bytes of data in this page
  566. 0x2D ECC byte 5 Error correction code byte 2 of the second
  567. 256 Bytes of data in this page
  568. 0x2E ECC byte 6 Error correction code byte 0 of the third
  569. 256 Bytes of data in this page
  570. 0x2F ECC byte 7 Error correction code byte 1 of the third
  571. 256 Bytes of data in this page
  572. 0x30 ECC byte 8 Error correction code byte 2 of the third
  573. 256 Bytes of data in this page
  574. 0x31 ECC byte 9 Error correction code byte 0 of the fourth
  575. 256 Bytes of data in this page
  576. 0x32 ECC byte 10 Error correction code byte 1 of the fourth
  577. 256 Bytes of data in this page
  578. 0x33 ECC byte 11 Error correction code byte 2 of the fourth
  579. 256 Bytes of data in this page
  580. 0x34 ECC byte 12 Error correction code byte 0 of the fifth
  581. 256 Bytes of data in this page
  582. 0x35 ECC byte 13 Error correction code byte 1 of the fifth
  583. 256 Bytes of data in this page
  584. 0x36 ECC byte 14 Error correction code byte 2 of the fifth
  585. 256 Bytes of data in this page
  586. 0x37 ECC byte 15 Error correction code byte 0 of the sixth
  587. 256 Bytes of data in this page
  588. 0x38 ECC byte 16 Error correction code byte 1 of the sixth
  589. 256 Bytes of data in this page
  590. 0x39 ECC byte 17 Error correction code byte 2 of the sixth
  591. 256 Bytes of data in this page
  592. 0x3A ECC byte 18 Error correction code byte 0 of the seventh
  593. 256 Bytes of data in this page
  594. 0x3B ECC byte 19 Error correction code byte 1 of the seventh
  595. 256 Bytes of data in this page
  596. 0x3C ECC byte 20 Error correction code byte 2 of the seventh
  597. 256 Bytes of data in this page
  598. 0x3D ECC byte 21 Error correction code byte 0 of the eighth
  599. 256 Bytes of data in this page
  600. 0x3E ECC byte 22 Error correction code byte 1 of the eighth
  601. 256 Bytes of data in this page
  602. 0x3F ECC byte 23 Error correction code byte 2 of the eighth
  603. 256 Bytes of data in this page
  604. =========== ================== ================================================
  605. Filesystem support
  606. ==================
  607. The NAND driver provides all necessary functions for a filesystem via
  608. the MTD interface.
  609. Filesystems must be aware of the NAND peculiarities and restrictions.
  610. One major restrictions of NAND Flash is, that you cannot write as often
  611. as you want to a page. The consecutive writes to a page, before erasing
  612. it again, are restricted to 1-3 writes, depending on the manufacturers
  613. specifications. This applies similar to the spare area.
  614. Therefore NAND aware filesystems must either write in page size chunks
  615. or hold a writebuffer to collect smaller writes until they sum up to
  616. pagesize. Available NAND aware filesystems: JFFS2, YAFFS.
  617. The spare area usage to store filesystem data is controlled by the spare
  618. area placement functionality which is described in one of the earlier
  619. chapters.
  620. Tools
  621. =====
  622. The MTD project provides a couple of helpful tools to handle NAND Flash.
  623. - flasherase, flasheraseall: Erase and format FLASH partitions
  624. - nandwrite: write filesystem images to NAND FLASH
  625. - nanddump: dump the contents of a NAND FLASH partitions
  626. These tools are aware of the NAND restrictions. Please use those tools
  627. instead of complaining about errors which are caused by non NAND aware
  628. access methods.
  629. Constants
  630. =========
  631. This chapter describes the constants which might be relevant for a
  632. driver developer.
  633. Chip option constants
  634. ---------------------
  635. Constants for chip id table
  636. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  637. These constants are defined in rawnand.h. They are OR-ed together to
  638. describe the chip functionality::
  639. /* Buswitdh is 16 bit */
  640. #define NAND_BUSWIDTH_16 0x00000002
  641. /* Device supports partial programming without padding */
  642. #define NAND_NO_PADDING 0x00000004
  643. /* Chip has cache program function */
  644. #define NAND_CACHEPRG 0x00000008
  645. /* Chip has copy back function */
  646. #define NAND_COPYBACK 0x00000010
  647. /* AND Chip which has 4 banks and a confusing page / block
  648. * assignment. See Renesas datasheet for further information */
  649. #define NAND_IS_AND 0x00000020
  650. /* Chip has a array of 4 pages which can be read without
  651. * additional ready /busy waits */
  652. #define NAND_4PAGE_ARRAY 0x00000040
  653. Constants for runtime options
  654. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  655. These constants are defined in rawnand.h. They are OR-ed together to
  656. describe the functionality::
  657. /* The hw ecc generator provides a syndrome instead a ecc value on read
  658. * This can only work if we have the ecc bytes directly behind the
  659. * data bytes. Applies for DOC and AG-AND Renesas HW Reed Solomon generators */
  660. #define NAND_HWECC_SYNDROME 0x00020000
  661. ECC selection constants
  662. -----------------------
  663. Use these constants to select the ECC algorithm::
  664. /* No ECC. Usage is not recommended ! */
  665. #define NAND_ECC_NONE 0
  666. /* Software ECC 3 byte ECC per 256 Byte data */
  667. #define NAND_ECC_SOFT 1
  668. /* Hardware ECC 3 byte ECC per 256 Byte data */
  669. #define NAND_ECC_HW3_256 2
  670. /* Hardware ECC 3 byte ECC per 512 Byte data */
  671. #define NAND_ECC_HW3_512 3
  672. /* Hardware ECC 6 byte ECC per 512 Byte data */
  673. #define NAND_ECC_HW6_512 4
  674. /* Hardware ECC 8 byte ECC per 512 Byte data */
  675. #define NAND_ECC_HW8_512 6
  676. Hardware control related constants
  677. ----------------------------------
  678. These constants describe the requested hardware access function when the
  679. boardspecific hardware control function is called::
  680. /* Select the chip by setting nCE to low */
  681. #define NAND_CTL_SETNCE 1
  682. /* Deselect the chip by setting nCE to high */
  683. #define NAND_CTL_CLRNCE 2
  684. /* Select the command latch by setting CLE to high */
  685. #define NAND_CTL_SETCLE 3
  686. /* Deselect the command latch by setting CLE to low */
  687. #define NAND_CTL_CLRCLE 4
  688. /* Select the address latch by setting ALE to high */
  689. #define NAND_CTL_SETALE 5
  690. /* Deselect the address latch by setting ALE to low */
  691. #define NAND_CTL_CLRALE 6
  692. /* Set write protection by setting WP to high. Not used! */
  693. #define NAND_CTL_SETWP 7
  694. /* Clear write protection by setting WP to low. Not used! */
  695. #define NAND_CTL_CLRWP 8
  696. Bad block table related constants
  697. ---------------------------------
  698. These constants describe the options used for bad block table
  699. descriptors::
  700. /* Options for the bad block table descriptors */
  701. /* The number of bits used per block in the bbt on the device */
  702. #define NAND_BBT_NRBITS_MSK 0x0000000F
  703. #define NAND_BBT_1BIT 0x00000001
  704. #define NAND_BBT_2BIT 0x00000002
  705. #define NAND_BBT_4BIT 0x00000004
  706. #define NAND_BBT_8BIT 0x00000008
  707. /* The bad block table is in the last good block of the device */
  708. #define NAND_BBT_LASTBLOCK 0x00000010
  709. /* The bbt is at the given page, else we must scan for the bbt */
  710. #define NAND_BBT_ABSPAGE 0x00000020
  711. /* bbt is stored per chip on multichip devices */
  712. #define NAND_BBT_PERCHIP 0x00000080
  713. /* bbt has a version counter at offset veroffs */
  714. #define NAND_BBT_VERSION 0x00000100
  715. /* Create a bbt if none axists */
  716. #define NAND_BBT_CREATE 0x00000200
  717. /* Write bbt if necessary */
  718. #define NAND_BBT_WRITE 0x00001000
  719. /* Read and write back block contents when writing bbt */
  720. #define NAND_BBT_SAVECONTENT 0x00002000
  721. Structures
  722. ==========
  723. This chapter contains the autogenerated documentation of the structures
  724. which are used in the NAND driver and might be relevant for a driver
  725. developer. Each struct member has a short description which is marked
  726. with an [XXX] identifier. See the chapter "Documentation hints" for an
  727. explanation.
  728. .. kernel-doc:: include/linux/mtd/rawnand.h
  729. :internal:
  730. Public Functions Provided
  731. =========================
  732. This chapter contains the autogenerated documentation of the NAND kernel
  733. API functions which are exported. Each function has a short description
  734. which is marked with an [XXX] identifier. See the chapter "Documentation
  735. hints" for an explanation.
  736. .. kernel-doc:: drivers/mtd/nand/raw/nand_base.c
  737. :export:
  738. Internal Functions Provided
  739. ===========================
  740. This chapter contains the autogenerated documentation of the NAND driver
  741. internal functions. Each function has a short description which is
  742. marked with an [XXX] identifier. See the chapter "Documentation hints"
  743. for an explanation. The functions marked with [DEFAULT] might be
  744. relevant for a board driver developer.
  745. .. kernel-doc:: drivers/mtd/nand/raw/nand_base.c
  746. :internal:
  747. .. kernel-doc:: drivers/mtd/nand/raw/nand_bbt.c
  748. :internal:
  749. Credits
  750. =======
  751. The following people have contributed to the NAND driver:
  752. 1. Steven J. Hill\ [email protected]
  753. 2. David Woodhouse\ [email protected]
  754. 3. Thomas Gleixner\ [email protected]
  755. A lot of users have provided bugfixes, improvements and helping hands
  756. for testing. Thanks a lot.
  757. The following people have contributed to this document:
  758. 1. Thomas Gleixner\ [email protected]