Differences between/dev/MTD and/dev/mtdblock in Linux, that is, differences between MTD character devices and block Devices

Source: Internet
Author: User

1./dev/mtdn: In the MTD architecture of Linux, The MTD partition implemented by the system correspondsCharacter DeviceWhich contains some IOCTL and supports many commands, such as memgetinfo and memerase.

Tools such as flash_eraseall in MTD-util are implemented based on these IOCTL to implement some flash operations. For example, in flash_eraseall of MTD:

If (IOCTL (FD,Memgetinfo, & Meminfo )! = 0 ){
Fprintf (stderr, "% s: Unable to get MTD device info/N", exe_name, mtd_device );
Return 1;
}

Among them, memgetinfo is the drivers/MTD/NAND/mtdchar. C in Linux MTD:

Static int mtd_ioctl (struct inode * inode, struct file * file,
U_int cmd, u_long Arg)
{

.....

CaseMemgetinfo:
Info. type = MTD-> type;
Info. Flags = MTD-> flags;
Info. size = MTD-> size;
Info. erasesize = MTD-> erasesize;
Info. writesize = MTD-> writesize;
Info. oobsize = MTD-> oobsize;
/* The below fields are obsolete */
Info. ecctype =-1;
Info. eccsize = 0;
If (copy_to_user (argp, & info, sizeof (struct mtd_info_user )))
Return-efault;
Break;

...

}

While/dev/mtdblockn is in the NAND Flash Driver, the driver adds MTD device partitions with add_mtd_partitions (), and the correspondingBlock Device.

Based on the above content, we can better understand why nandwrite, flash_eraseall, flash_erase, and other tools cannot be used to operate on/dev/mtdblockn. This operation is not supported because/dev/mtdblock does not contain the corresponding IOCTL.

2. The master device number of the mtd char device is 90, while that of the MTD block device is 31:

# Ls/dev/MTD? -L
CrW-r ----- 1 Root 90, 0 May 30 2007/dev/mtd0
CrW-r ----- 1 Root 90, 2 May 30 2007/dev/mtd1
CrW-r ----- 1 Root 90, 4 Jul 17 2009/dev/mtd2
CrW-r ----- 1 Root 90, 6 May 30 2007/dev/mtd3
Crwxrwxrwx 1 Root 90, 8 May 30 2007/dev/mtd4
Crwxrwxrwx 1 Root 90, 10 May 30 2007/dev/mtd5
Crwxrwxrwx 1 Root 90, 12 May 30 2007/dev/mtd6
Crwxrwxrwx 1 Root 90, 14 May 30 2007/dev/mtd7
Crwxrwxrwx 1 Root 90, 16 May 30 2007/dev/mtd8
Crwxrwxrwx 1 Root 90, 18 May 30 2007/dev/mtd9
# Ls/dev/mtdblock? -L
BRW-r ----- 1 Root 31, 0 May 30 2007/dev/mtdblock0
BRW-r ----- 1 Root 31, 1 May 30 2007/dev/mtdblock1
BRW-r ----- 1 Root 31, 2 May 30 2007/dev/mtdblock2
BRW-r ----- 1 Root 31, 3 May 30 2007/dev/mtdblock3
Brwxrwxrwx 1 Root 31, 4 May 30 2007/dev/mtdblock4
Brwxrwxrwx 1 Root 31, 5 May 30 2007/dev/mtdblock5
Brwxrwxrwx 1 Root 31, 6 May 30 2007/dev/mtdblock6
Brwxrwxrwx 1 Root 31, 7 May 30 2007/dev/mtdblock7
Brwxrwxrwx 1 Root 31, 8 May 30 2007/dev/mtdblock8
Brwxrwxrwx 1 Root 31, 9 May 30 2007/dev/mtdblock9

This device number is defined in/include/Linux/MTD. h:

# Define mtd_char_major 90
# Define mtd_block_major 31

3. The size of the MTD block device can be obtained by viewing the partition information:

# Cat/proc/Partitions
Major minor # Blocks name

31 0 1024 mtdblock0
31 1 8192 mtdblock1
31 2 204800 mtdblock2
31 3 65536 mtdblock3
31 4 225280 mtdblock4

The block device size shown above is the number of blocks, each of which is 1 kb.

Each character device corresponds to each block device above. That is,/dev/mtd0 corresponds to/dev/mtdblock0, and so on. In other words, some attributes of mtdblockn, that is, the attributes of mtdn, such as the size.

4. The operation on each MTD character device. For example, if you use nandwrite to write data to/dev/mtd0, the operation is actually/dev/mtdblock0.

The offset involved in these operations refers to the offset in the MTD partition. For example, to write data to the position where the offset of/dev/mtd1 is 0, the actual operation is the physical offset =/dev/mtd0 size = 1 MB = 0x100000.

5. The naming rules for MTD character devices and Block devices can be found in the following table:

Table 7-1. MTD/dev entries, corresponding MTD user modules, and relevant device major numbers

/Dev entry

Accessible MTD User Module

Device Type

Major number

MTDN

Char device

Char

90

MtdrN

Char device

Char

90

MtdblockN

Block device, read-only block device, jffs, and jffs2

Block

31

NftlLn

Nftl

Block

93

FTLLn

FTL

Block

44

Table 7-2. MTD/dev entries, minor numbers, and naming schemes

/Dev entry

Minor number range

Naming Scheme

MTDN

0 to 32 per increments of 2

N= Minor/2

MtdrN

1 to 33 per increments of 2

N= (Minor-1)/2

MtdblockN

0 to 16 per increments of 1

N= Minor

NftlLn

0 to 255 per sets of 16

L= Set;[2]N= Minor-(set-1) x 16;NIs not appended to entry name if its value is zero.

FTLLn

0 to 255 per sets of 16

Same as nftl.

For more information, see appendix 2.

[Appendix]

1.The latest mtd-utils-1.3.0.tar.bz2: ftp://ftp.infradead.org/pub/mtd-utils/mtd-utils-1.3.0.tar.bz2

2.7.1 MTD-supported devices

Http://book.opensourceproject.org.cn/embedded/oreillybuildembed/opensource/belinuxsys-chp-7-sect-1.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.