有网友碰到这样的问题“linux 中mtd设备一般用来干啥的? mtdblock呢,又是干啥的????”。小编为您整理了以下解决方案,希望对您有帮助:
解决方案1:
mtd是字符设备,mtdblock是块设备
可以看看dd命令的实现,在busybox里有
补充:
/dev/mtd/* 或者 /dev/mtd* 这两种表示方式一般表示的是字符设备/dev/mtdblock/* 或者 /dev/mtdblock* 这两种是块设备的表示方式mount 的一般都是块设备貌似dd只对字符设备进行操作
举例:
The mtd0 is char device of mtdblock0.
Create char mtd devices >
> mknod /dev/mtd0 c 90 0
> mknod /dev/mtd1 c 90 2
Linux系统中/dev/mtd与/dev/mtdblock的区别,即MTD字符设备和块设备的区别
1. /dev/mtdN 是Linux 中的MTD架构中,系统自己实现的mtd分区所对应的字符设备,其里面添加了一些ioctl,支持很多命令,如MEMGETINFO,MEMERASE等。而mtd-util中的flash_eraseall等工具,就是以这些ioctl为基础而实现的工具,实现一些关于Flash的操作。比如,mtd 工具中的 flash_eraseall中的:if (ioctl(fd, MEMGETINFO, &meminfo) != 0) { fprintf(stderr, "%s: %s: unable to get MTD device info\n", exe_name, mtd_device); return 1;}其中,MEMGETINFO,就是Linux MTD中的drivers/mtd/nand/mtdchar.c中的:static int mtd_ioctl(struct inode *inode, struct file *file, u_int cmd, u_long arg){。。。。。case MEMGETINFO: 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;。。。}而/dev/mtdblockN,是Nand Flash驱动中,驱动在用add_mtd_partitions()添加MTD设备分区,而生成的对应的块设备。根据以上内容,也就更加明白,为什么不能用nandwrite,flash_eraseall,flash_erase等工具去对/dev/mtdblockN去操作了。因为/dev/mtdblock中不包含对应的ioctl,不支持你这么操作。2. mtd char 设备的主设备号是90,而mtd block设备的主设备号是31:# ls /dev/mtd? -l crw-r----- 1 root root 90, 0 May 30 2007 /dev/mtd0crw-r----- 1 root root 90, 2 May 30 2007 /dev/mtd1crw-r----- 1 root root 90, 4 Jul 17 2009 /dev/mtd2crw-r----- 1 root root 90, 6 May 30 2007 /dev/mtd3crwxrwxrwx 1 root root 90, 8 May 30 2007 /dev/mtd4crwxrwxrwx 1 root root 90, 10 May 30 2007 /dev/mtd5crwxrwxrwx 1 root root 90, 12 May 30 2007 /dev/mtd6crwxrwxrwx 1 root root 90, 14 May 30 2007 /dev/mtd7crwxrwxrwx 1 root root 90, 16 May 30 2007 /dev/mtd8crwxrwxrwx 1 root root 90, 18 May 30 2007 /dev/mtd9# ls /dev/mtdblock? -lbrw-r----- 1 root root 31, 0 May 30 2007 /dev/mtdblock0brw-r----- 1 root root 31, 1 May 30 2007 /dev/mtdblock1brw-r----- 1 root root 31, 2 May 30 2007 /dev/mtdblock2brw-r----- 1 root root 31, 3 May 30 2007 /dev/mtdblock3brwxrwxrwx 1 root root 31, 4 May 30 2007 /dev/mtdblock4brwxrwxrwx 1 root root 31, 5 May 30 2007 /dev/mtdblock5brwxrwxrwx 1 root root 31, 6 May 30 2007 /dev/mtdblock6brwxrwxrwx 1 root root 31, 7 May 30 2007 /dev/mtdblock7brwxrwxrwx 1 root root 31, 8 May 30 2007 /dev/mtdblock8brwxrwxrwx 1 root root 31, 9 May 30 2007 /dev/mtdblock9此设备号,定义在/include/linux/mtd/mtd.h中 :#define MTD_CHAR_MAJOR 90#define MTD_BLOCK_MAJOR 313. 其中,mtd的块设备的大小,可以通过查看分区信息获得:# cat /proc/partitionsmajor minor #blocks name31 0 1024 mtdblock031 1 8192 mtdblock131 2 204800 mtdblock231 3 65536 mtdblock331 4 225280 mtdblock4上面中显示的块设备大小,是block的数目,每个block是1KB。而每个字符设备,其实就是对应着上面的每个块设备。即/dev/mtd0对应/dev/mtdblock0,其他以此类推。换句话说,mtdblockN的一些属性,也就是mtdN的属性,比如大小。4。对每个mtd字符设备的操作,比如利用nandwrite去对/dev/mtd0写数据,实际就是操作/dev/mtdblock0。而这些操作里面涉及到的偏移量offset,都指的是此mtd 分区内的偏移。比如向/dev/mtd1的offset为0的位置写入数据,实际操作的是物理偏移offset=/dev/mtd0的大小=1MB=0x100000。
解决方案2:
http://baike.baidu.com/view/1741385.htm
嵌入式设备上面常见的一种存储设备接口。