AM335x NAND Driver's Guide

= Introduction = The general-purpose memory controller (GPMC) is an unified memory controller dedicated to interfacing external memory devices:
 * Asynchronous SRAM-like memories and application-specific integrated circuit (ASIC) devices
 * Asynchronous, synchronous, and page mode (only available in non-multiplexed mode) burst NOR flash devices
 * NAND Flash
 * Pseudo-SRAM devices

= Features =

Hardware Features
The GPMC can access various external devices through the L3 Slow Interconnect. The flexible programming model allows a wide range of attached device types and access schemes.

The GPMC consists of six blocks:


 * Interconnect port interface
 * Address decoder, GPMC configuration, and chip-select configuration register file
 * Access engine
 * Prefetch and write-posting engine
 * Error correction code engine (ECC)
 * External device/memory port interface



Software Features

 * Access 8-bit NAND
 * BCH8 ECC scheme with 8-bit error correction. BCH8 ECC Scheme used to make compatible with all other components (RBL, U-Boot..)
 * Polled Prefetch Mode

= AM335x NAND Device Layout = Layout for NAND flash device is described here.

= ECC schemes usage table = ECC scheme used by different components is described in the table

= Driver Configuration =

To enable/disable NAND support, start the Linux Kernel Configuration tool:

host$ make menuconfig

Select Device Drivers from the main menu. ...   ...    [ ] Networking support ---&gt; Device Drivers ---&gt; File systems ---&gt; ...   ...

Device Drivers ---&gt; &lt;*&gt; Memory Technology Device (MTD) support ---&gt; [*]  Command line partition table parsing &lt;*&gt;  Direct char device access to MTD devices &lt;*&gt;  Caching block device access to MTD devices &lt;*&gt;  NAND Device Support  ---> &lt;*&gt;   NAND Flash device on OMAP2 and OMAP3 &lt;*&gt;  Enable UBI - Unsorted block images  --->
 * Enable below Configs to enable MTD Support along with MTD nand driver support

Module Build
Module build for the NAND driver is supported. To do this, make the changes as below Device Drivers ---&gt; &lt;*&gt; Memory Technology Device (MTD) support ---&gt; [*]  Command line partition table parsing &lt;*&gt;  Direct char device access to MTD devices &lt;*&gt;  Caching block device access to MTD devices &lt;M&gt;  NAND Device Support  ---> &lt;M&gt;   NAND Flash device on OMAP2 and OMAP3 &lt;*&gt;  Enable UBI - Unsorted block images  --->

For loading modules follow the steps below

target$ insmod drivers/mtd/nand/nand_ecc.ko       target$ insmod drivers/mtd/nand/nand_ids.ko       target$ insmod drivers/mtd/nand/nand.ko       target$ insmod drivers/mtd/devices/omap2_elm.ko       target$ insmod drivers/mtd/nand/omap2.ko

= Device Interface =

You always need a pair mtdx/mtdblockx of device nodes to access your flash file system. The mtdx is used to access the raw flash device, the mtdblockx is used to access the disk/block established in the raw flash.

Use MTD-Utils user space tools to access NAND partition from Linux console

Below are some of the examples for accessing NAND partitions


 * Erase the nand partition (assume partition 3)

target$ flash_eraseall /dev/mtd3


 * write a file to nand partition (assume partition 4)

target$ nandwrite -p /dev/mtd4 u-boot.img


 * Mount nand partition from U-Boot as Root file system partition for Linux

'''u-boot&gt; setenv bootargs 'console=ttyO0,115200n8 root=ubi0:rootfs rw ubi.mtd=,2048 noinitrd rootfstype=ubifs mem=256M rootwait=1'

The value of PARTITION_ID depends on MTD device which holds the root filesystem. The below example assumes UBIFS file system is flashed on MTD partition 7 and respective device is enabled on the board.

'''u-boot&gt; setenv bootargs 'console=ttyO0,115200n8 root=ubi0:rootfs rw ubi.mtd=7,2048 noinitrd rootfstype=ubifs mem=256M rootwait=1'

= Proc Interface =

The  kernel interface is a status interface. A lot of useful information about the nand system can be found in the  file.


 * Use /proc/mtd to get information on how many partitions are currently configured by the kernels flash driver.

target$ cat /proc/mtd

You should see output similar to:

target$ cat /proc/mtd dev:   size   erasesize  name mtd0: 00020000 00020000 "SPL" mtd1: 00020000 00020000 "SPL.backup1" mtd2: 00020000 00020000 "SPL.backup2" mtd3: 00020000 00020000 "SPL.backup3" mtd4: 001e0000 00020000 "U-Boot" mtd5: 00020000 00020000 "U-Boot Env" mtd6: 00500000 00020000 "Kernel" mtd7: 0f880000 00020000 "File System"

= AM335x NAND File system support =

 On AM335x, JFFS2 support has been super-seeded by UBIFS. JFFS2 support is disabled in default config.

For more information of UBIFS refer UBIFS Support Guide

To enable JFFS2, Refer AM335x JFFS2 Support Guide