Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to read/write from/to flash device with MTD (Memory Technology Device) in linux

1 view
Skip to first unread message

Edward Chan

unread,
Nov 15, 2002, 4:37:36 PM11/15/02
to
Hi,
Would some please point me out how to read/write from/to flash
device with MTD (Memory Technology Device) in linux? Is there any
specification on the web that tells me to do read/write from/read
flash device with MTD? Can someone also provide me some sample code
on how to do that?

Thank you very much,
Best regards,
Edward

Robert Kaiser

unread,
Nov 18, 2002, 5:45:59 AM11/18/02
to
In article <ab61afc0.02111...@posting.google.com>,

etf...@hotmail.com (Edward Chan) writes:
> Hi,
> Would some please point me out how to read/write from/to flash
> device with MTD (Memory Technology Device) in linux? Is there any
> specification on the web that tells me to do read/write from/read
> flash device with MTD? Can someone also provide me some sample code
> on how to do that?

Do you want to do raw read/write accesses or do you want to use a
filesystem ?

If the former: you can an use the read()/write()/lseek() calls in the
same way as, e.g. for a disk device, except that, before you can write
to a portion of flash, you must make sure it is erased. There are
two utilities in the MTD distribution to do the erase (called -what
a surprise- "erase" and "eraseall"). These work through MTD-specific
ioctl() calls.

Example:

# eraseall /dev/mtdXX
# cat data_i_want_to_store >/dev/mtdXX

If the latter: there are two filesystems specifically designed
for use with MTD devices: JFFS and JFFS2. These use the block
MTD devices. If the device is erased, a mount will implicitly
"format" it (i.e. create an empty filesystem structure on it).

Example:

# eraseall /dev/mtdXX
# mount -t jffs2 /dev/mtdblockXX /mnt
# cp data_i_want_to_store /mnt

It is also possible to create an initial filesystem image off-line
(e.g. with mkfs.jffs2) and write that image to the raw device using the
above method.

Example:

# eraseall /dev/mtdXX
# cat jffs2_image_prepared_offline >/dev/mtdXX
# mount -t jffs2 /dev/mtdblockXX /mnt
# ls /mnt

HTH

Rob

--
Robert Kaiser email: rkaiser AT sysgo DOT de
SYSGO AG http://www.elinos.com
Klein-Winternheim / Germany http://www.sysgo.de

0 new messages