English
Language : 

UM0851 Datasheet, PDF (134/245 Pages) STMicroelectronics – SPEAr is a family of highly customizable ARM-based embedded
Non-volatile memory device drivers
UM0851
The MTD project provides a number of helpful tools to handle NAND Flash:
● flasherase, flasheraseall: erase and format FLASH partitions
● nandwrite: write file-system images to NAND FLASH
● nanddump: dump the contents of a NAND FLASH partitions
These tools are aware of the NAND restrictions. Please use those tools and avoid
unnecessary trouble with errors caused by non NAND aware access methods like copy or
cat commands.
Raw mode usage from kernel space
Calls such as "mtd->read", "mtd->erase" and "mtd->write" can be used to read, erase and
write into MTD devices. The following code snippet shows an example where 512 bytes are
read and write in the same location of the MTD partition number 4.
struct mtd_info *mtd;
int ret = 0;
void *buffer;
size_t retlen = 0;
/* Get MTD info of 4th partition */
mtd = get_mtd_device(NULL, 4);
if (!mtd) {
err( "Err in get mtd\n");
return;
}
/* Read 512 bytes from partition 4 and store in 'buffer' */
ret = mtd->read(mtd, 0, 512, &retlen, buffer);
if (ret < 0) {
err("Err MTD read=%d\n", ret);
return;
}
/* Write 512 bytes into the partition 4 from the 'buffer' */
ret = (*(mtd->write)) (mtd, 0, 512, &retlen, buffer);
if (ret < 0) {
err("Err MTD write=%d\n", ret);
return;
}
Logical mode usage from user space
An MTD partition can be mounted using a file system (such as JFFS2 or YAFFS) and then
that partition can be used. Commands like 'cp' and 'rm' can be used to write/erase in the
NAND Flash.
# mount -t jffs2 /dev/mtdblock7 /mnt
#cp /tmp/song.mp3 /mnt/
#ls /mnt
Song.mp3
#
Before mounting JFFS2 make sure that valid JFFS2 image is already present in the
partition, to avoid getting a lot of error messages. For YAFFS if YAFFS image is present then
it is fine otherwise YAFFS can initialize an empty partition structure.
134/245
Doc ID 16604 Rev 2