Section 10.2. MTD Basics


10.2. MTD Basics

Now that we have enabled a simple MTD configuration in our kernel, we can examine how this subsystem works on our Linux development workstation. Using the test RAM driver we just configured in the previous section, we can mount a JFFS2 image using an MTD device. Assuming that you created a JFFS2 image as detailed in Chapter 9, "File Systems," you might want to mount it and examine it. The Linux kernel does not support mounting a JFFS2 file system image directly on a loopback device, such as is possible with ext2 and other file system images. So we must use a different method. This can be achieved using the MTD RAM test driver on our development Linux workstation with MTD enabled, as in Figure 10-1. Listing 10-3 illustrates the steps.

Listing 10-3. Mounting JFFS2 on an MTD RAM Device

# modprobe jffs2 # modprobe mtdblock # modprobe mtdram # dd if=jffs2.bin of=/dev/mtdblock0  4690+1 records in  4690+1 records out # mkdir /mnt/flash # mount -t jffs2 /dev/mtdblock0/mnt/flash # ls -l /mnt/flash total 0 drwxr-xr-x  2 root root 0 Sep 17 22:02 bin drwxr-xr-x  2 root root 0 Sep 17 21:59 dev drwxr-xr-x  7 root root 0 Sep 17 15:31 etc drwxr-xr-x  2 root root 0 Sep 17 15:31 home drwxr-xr-x  2 root root 0 Sep 17 22:02 lib drwxr-xr-x  2 root root 0 Sep 17 15:31 proc drws------  2 root root 0 Sep 17 15:31 root drwxr-xr-x  2 root root 0 Sep 17 22:02 sbin drwxrwxrwt  2 root root 0 Sep 17 15:31 tmp drwxr-xr-x  9 root root 0 Sep 17 15:31 usr drwxr-xr-x 14 root root 0 Sep 17 15:31 var #

From Listing 10-3, first we install the loadable modules that the Linux kernel requires to support JFFS2 and the MTD subsystem. We load the JFFS2 module followed by the mTDblock and mtdram modules. After the necessary device drivers are loaded, we use the Linux dd command to copy our JFFS2 file system image into the MTD RAM test driver using the mTDblock device. In essence, we are using system RAM as a backing device to emulate an MTD block device.

After we have copied our JFFS2 file system image into the MTD block device, we can mount it using the mount command, in the manner shown in Listing 10-3. After the MTD pseudo-device has been mounted, we can work with the JFFS2 file system image in any way we choose. The only limitation using this method is that we can't enlarge the image. The size of the image is limited by two factors. First, when we configured the MTD RAM test device, we gave it a maximum size of 8MB.[1] Second, when we created the JFFS2 image, we fixed the size of the image using the mkfs.jffs2 utility. The image size was determined by the contents of the directory we specified when we created it. Refer back to Listing 9-9, in Chapter 9, to recall how our jffs2.bin image was built.

[1] The size was fixed in the kernel configuration when we enabled the MTD RAM test device in the Linux kernel configuration.

It is important to realize the limitations of using this method to examine the contents of a JFFS2 file system. Consider what we did: We copied the contents of a file (the JFFS2 file system binary image) into a kernel block device (/dev/mtdblock0). Then we mounted the kernel block device (/dev/mtdblock) as a JFFS2 file system. After we did this, we could use all the traditional file system utilities to examine and even modify the file system. Tools such as ls,df,dh,mv,rm, and cp can all be used to examine and modify the file system. However, unlike the loopback device, there is no connection between the file we copied and the mounted JFFS2 file system image. Therefore, if we unmount the file system after making changes, the changes will be lost. If you want to save the changes, you must copy them back into a file. One such method is the following:

# dd if=/dev/mtdblock0 of=./your-modified-fs-image.bin


This command creates a file called your-modified-fs-image.bin that is the same size as the mtdblock0 device which was specified during configuration. In our example, it would be 8MB. Lacking suitable JFFS2 editing facilities, this is a perfectly valid way to examine and modify a JFFS2 file system. More important, it illustrates the basics of the MTD subsystem on our development system without real Flash memory. Now let's look at some hardware that contains Flash physical devices.

10.2.1. Configuring MTD

To use MTD with the Flash memory on your board, you must have MTD configured correctly. The following list contains the requirements that must be satisfied to configure MTD for your board, Flash, and Flash layout.

  • Specify the partitioning on your Flash device

  • Specify the type of Flash and location

  • Configure the proper Flash driver for your chosen chip

  • Configure the kernel with the appropriate driver(s)

Each of these steps is explored in the following sections.



Embedded Linux Primer(c) A Practical Real-World Approach
Embedded Linux Primer: A Practical Real-World Approach
ISBN: 0131679848
EAN: 2147483647
Year: 2007
Pages: 167

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net