Building Embedded Linux Systems by Karim Yaghmour & Jon Masters & Gilad Ben-Yossef & Philippe Gerum

Building Embedded Linux Systems by Karim Yaghmour & Jon Masters & Gilad Ben-Yossef & Philippe Gerum

Author:Karim Yaghmour & Jon Masters & Gilad Ben-Yossef & Philippe Gerum [Karim Yaghmour]
Language: eng
Format: epub
Tags: COMPUTERS / Operating Systems / Linux
ISBN: 9780596159085
Publisher: O'Reilly Media
Published: 2009-02-08T16:00:00+00:00


Writing and reading

Whereas flash filesystems such as JFFS2 take advantage of their capability to continue clearing bits to 0 in an erase block to allow transparent read and write access, you cannot usually use user-level tools to write to an MTD device more than once. This is mostly because the tools usually will want to replace an image wholesale, and thus would want to set some bits from 0 to 1, which is not possible with erasing. If you want to update the content of an MTD device or partition using its raw char /dev entry, for example, you generally must erase this device or partition before you can write new data to it.

Although writing to a raw flash device can be done using traditional filesystem commands such as cat and dd, it is better to use the MTD utilities—flashcp for NOR flash and nandwrite for NAND—because they are more suited to the task. The flashcp command will erase flash before writing, and will read back the contents afterward to verify correct programming. The nandwrite command will detect bad blocks on a NAND flash device, and skip over them as appropriate. To write a new initial RAM disk image to the “initrd” partition on my control module, for example, I use the following command:

# flashcp /tmp/initrd.bin /dev/mtd3

In this case, my target’s root filesystem is mounted via NFS, and I am running the MTD commands on my target.

Reading from a CFI MTD partition is no different from reading from any other device. The following command on my control module, for instance, will copy the binary image of the bootloader partition to a file:

# dd if=/dev/mtd0 of=/tmp/ppcboot.img

Since the bootloader image itself may not fill the entire partition, the ppcboot.img file may contain some extra unrelated data in addition to the bootloader image.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.