[琪琪雜貨舖]

2015年12月23日 星期三

【CHICHI ETUTOR@ARM/MIPS/PPC】FILE SYSTEM 5 _ MTD (MeMORY TECHNOLOGY DEVICE ) Introduction 



1. MTD overview (from http://www.linux-mtd.infradead.org/doc/general.html)

MTD subsystem (stands for Memory Technology Devices) provides an abstraction layer for raw flash devices. It makes it possible to use the same API when working with different flash types and technologies, e.g. NAND, OneNAND, NOR, AG-AND, ECC'd NOR, etc.
MTD subsystem does not deal with block devices like MMC, eMMC, SD, CompactFlash, etc. These devices are not raw flashes but they have a Flash Translation layer inside, which makes them look like block devices. These devices are the subject of the Linux block subsystem, not MTD. Please, refer to this FAQ section for a short list of the main differences between block and MTD devices. And the raw flash vs. FTL devices UBIFS section discusses this in more details.
MTD subsystem has the following interfaces.
  • MTD character devices - usually referred to as /dev/mtd0/dev/mtd1, and so on. These character devices provide I/O access to the raw flash. They support a number of ioctl calls for erasing eraseblocks, marking them as bad or checking if an eraseblock is bad, getting information about MTD devices, etc.
  • The sysfs interface is relatively newer and it provides full information about each MTD device in the system. This interface is easily extensible and developers are encouraged to use the sysfs interface instead of older ioctl or /proc/mtd interfaces, when possible. The sysfs interface for the mtd subsystem is documentated in the kernel, and currently can be found at Documentation/ABI/testing/sysfs-class-mtd.
  • The /proc/mtd proc file system file provides general MTD information. This is a legacy interface and the sysfs interface provides more information.
MTD subsystem supports bare NAND flashes with software and hardware ECC, OneNAND flashes, CFI (Common Flash Interface) NOR flashes, and other flash types.


2.  MTD driver (e.g. Kernel version 2.6.35.7) and support Files system drivers need to be added 

        Device Drivers  --->
                 <*> Memory Technology Device (MTD) support  --->
                               [*]   MTD partitioning support

        File systems  --->
                Miscellaneous filesystems  --->
                        <*> YAFFS2 file system support
                        <*> Journalling Flash File System v2 (JFFS2) support
                        <*> Compressed ROM file system support (cramfs)

3. partitions  definitions in a NAND flash (e.g. Tiger board QT210 NAND flash)

 code snppet in file "s3c_nand.c"

 struct mtd_partition s3c_partition_info[] = {

{
                .name           = "Bootloader",
                .offset         = 0,
                .size           = 0x00100000,
        },
        {
                .name           = "Kernel",
                .offset         = 0x00600000,
                .size           = 0x00500000,
        },
        {
                .name           = "cramfs",
                .offset         = 0x00B00000,
                .size           = 0x00300000,
        },
         {
                .name           = "DATA",
                .offset         = 0x00E00000,
                .size           = 0x04000000,
        },
        {
                .name           = "Jffs2",
                .offset         = 0x04E00000,
                .size           = 0x00f00000,
        },
      {
                .name           = "RAMDISK",
                .offset         = 0x0C640000,
                .size           = 0x00300000,
        },
        {
                .name           = "UBIFS",
                .offset         = 0x0CA00000,
                .size           = MTDPART_SIZ_FULL,
        }
}



4. kernel output message (dmesg) for notification of MTD partitions

                [    0.735000] Creating 7 MTD partitions on "s5pv210-nand":
                [    0.740000] 0x000000000000-0x000000100000 : "Bootloader"
                [    0.745000] 0x000000600000-0x000000b00000 : "Kernel"
                [    0.750000] 0x000000b00000-0x000000e00000 : "cramfs"
                [    0.755000] 0x000000e00000-0x000004e00000 : "DATA"
                [    0.770000] 0x000004e00000-0x000005d00000 : "Jffs2"
                [    0.775000] 0x00000c640000-0x00000c940000 : "RAMDISK"
                [    0.775000] 0x00000ca00000-0x000010000000 : "UBIFS"


5. device files created by MTD

[root@QT210 /]# ls /dev/mtd*
                /dev/mtd0       /dev/mtd2ro     /dev/mtd5       /dev/mtdblock1  /dev/mtdblock6
                /dev/mtd0ro     /dev/mtd3       /dev/mtd5ro     /dev/mtdblock2
                /dev/mtd1       /dev/mtd3ro     /dev/mtd6       /dev/mtdblock3
                /dev/mtd1ro     /dev/mtd4       /dev/mtd6ro     /dev/mtdblock4
                /dev/mtd2       /dev/mtd4ro     /dev/mtdblock0  /dev/mtdblock5




6. Erase one of the partitions as JFFS2 file system

                        [root@QT210 /]# flash_eraseall -j /dev/mtd3
                        Erasing 128 Kibyte @ 1260000 -- 28 % complete. Cleanmarker written at 1260000.
                        Skipping bad block at 0x01280000
                        Erasing 128 Kibyte @ 3e80000 -- 97 % complete. Cleanmarker written at 3e80000.
                        Skipping bad block at 0x03ea0000
                        Erasing 128 Kibyte @ 3fe0000 -- 99 % complete. Cleanmarker written at 3fe0000.

0 意見:

張貼留言

[琪琪雜貨舖]