当前位置: 技术问答>linux和unix
关于直接编写应用程序读写/dev/mtd0 或者 /dev/mtdblock0的问题。
来源: 互联网 发布时间:2016-05-31
本文导语: 关于直接编写应用程序读写/dev/mtd0 或者 /dev/mtdblock0的问题。 开发板的Linux环境: # uname -a Linux 192.168.102.213 2.6.12-4.2-brcmstb #73 Tue Apr 14 16:06:50 CST 2009 7403a0 unknown 我的开发板的Nor flash分区情况是 # cat /proc/mtd...
关于直接编写应用程序读写/dev/mtd0 或者 /dev/mtdblock0的问题。
开发板的Linux环境:
# uname -a
Linux 192.168.102.213 2.6.12-4.2-brcmstb #73 Tue Apr 14 16:06:50 CST 2009 7403a0 unknown
我的开发板的Nor flash分区情况是
# cat /proc/mtd
dev: size erasesize name
mtd0: 01800000 00020000 "rootfs"
mtd1: 00200000 00020000 "vmlinux"
mtd2: 00400000 00020000 "config"
mtd3: 00080000 00020000 "splash"
mtd4: 00080000 00020000 "cfe"
mtd5: 00000080 00020000 "mactype"
mtd6: 00040000 00020000 "nvram"
mtd7: 00040000 00020000 "feature"
# ls /dev/mtd* -al
crwxr-xr-x 1 nobody nobody 90, 0 Mar 2 2009 /dev/mtd0
crwxr-xr-x 1 nobody nobody 90, 2 Mar 2 2009 /dev/mtd1
crwxr-xr-x 1 nobody nobody 90, 4 Mar 2 2009 /dev/mtd2
crwxr-xr-x 1 nobody nobody 90, 6 Mar 2 2009 /dev/mtd3
crwxr-xr-x 1 nobody nobody 90, 8 Mar 2 2009 /dev/mtd4
crwxr-xr-x 1 nobody nobody 90, 10 Mar 2 2009 /dev/mtd5
crwxr-xr-x 1 nobody nobody 90, 12 Mar 2 2009 /dev/mtd6
-rw-r--r-- 1 root root 19 Apr 15 2009 /dev/mtd9
brwxr-xr-x 1 nobody nobody 31, 0 Mar 2 2009 /dev/mtdblock0
brwxr-xr-x 1 nobody nobody 31, 1 Mar 2 2009 /dev/mtdblock1
brwxr-xr-x 1 nobody nobody 31, 2 Mar 2 2009 /dev/mtdblock2
brwxr-xr-x 1 nobody nobody 31, 3 Mar 2 2009 /dev/mtdblock3
brwxr-xr-x 1 nobody nobody 31, 4 Mar 2 2009 /dev/mtdblock4
brwxr-xr-x 1 nobody nobody 31, 5 Mar 2 2009 /dev/mtdblock5
brwxr-xr-x 1 nobody nobody 31, 6 Mar 2 2009 /dev/mtdblock6
crwxr-xr-x 1 nobody nobody 90, 1 Mar 2 2009 /dev/mtdr0
crwxr-xr-x 1 nobody nobody 90, 3 Mar 2 2009 /dev/mtdr1
crwxr-xr-x 1 nobody nobody 90, 5 Mar 2 2009 /dev/mtdr2
crwxr-xr-x 1 nobody nobody 90, 7 Mar 2 2009 /dev/mtdr3
crwxr-xr-x 1 nobody nobody 90, 9 Mar 2 2009 /dev/mtdr4
crwxr-xr-x 1 nobody nobody 90, 11 Mar 2 2009 /dev/mtdr5
crwxr-xr-x 1 nobody nobody 90, 13 Mar 2 2009 /dev/mtdr6
通过NFS启动系统后,执行应用程序能读出 /dev/mtd6里面的数据,但是我要写入数据,该如何做?是不是在wriere()前要调用
ioctl()来擦除某个块,然后才能写? 请大家帮助,谢谢!
贴上我的一些关键代码:
FILE *fd = open("/dev/mtd6", O_RDWR)
read_len = read(fd, buff, sizeof(buff)-1);
int ret = ioctl(fd, MEMGETBADBLOCK, &offset); /* 擦某个块 */
write_len = write(buff, 1024/*sizeof(buff)-1*/, fd); /* 写入1K 数据 */
开发板的Linux环境:
# uname -a
Linux 192.168.102.213 2.6.12-4.2-brcmstb #73 Tue Apr 14 16:06:50 CST 2009 7403a0 unknown
我的开发板的Nor flash分区情况是
# cat /proc/mtd
dev: size erasesize name
mtd0: 01800000 00020000 "rootfs"
mtd1: 00200000 00020000 "vmlinux"
mtd2: 00400000 00020000 "config"
mtd3: 00080000 00020000 "splash"
mtd4: 00080000 00020000 "cfe"
mtd5: 00000080 00020000 "mactype"
mtd6: 00040000 00020000 "nvram"
mtd7: 00040000 00020000 "feature"
# ls /dev/mtd* -al
crwxr-xr-x 1 nobody nobody 90, 0 Mar 2 2009 /dev/mtd0
crwxr-xr-x 1 nobody nobody 90, 2 Mar 2 2009 /dev/mtd1
crwxr-xr-x 1 nobody nobody 90, 4 Mar 2 2009 /dev/mtd2
crwxr-xr-x 1 nobody nobody 90, 6 Mar 2 2009 /dev/mtd3
crwxr-xr-x 1 nobody nobody 90, 8 Mar 2 2009 /dev/mtd4
crwxr-xr-x 1 nobody nobody 90, 10 Mar 2 2009 /dev/mtd5
crwxr-xr-x 1 nobody nobody 90, 12 Mar 2 2009 /dev/mtd6
-rw-r--r-- 1 root root 19 Apr 15 2009 /dev/mtd9
brwxr-xr-x 1 nobody nobody 31, 0 Mar 2 2009 /dev/mtdblock0
brwxr-xr-x 1 nobody nobody 31, 1 Mar 2 2009 /dev/mtdblock1
brwxr-xr-x 1 nobody nobody 31, 2 Mar 2 2009 /dev/mtdblock2
brwxr-xr-x 1 nobody nobody 31, 3 Mar 2 2009 /dev/mtdblock3
brwxr-xr-x 1 nobody nobody 31, 4 Mar 2 2009 /dev/mtdblock4
brwxr-xr-x 1 nobody nobody 31, 5 Mar 2 2009 /dev/mtdblock5
brwxr-xr-x 1 nobody nobody 31, 6 Mar 2 2009 /dev/mtdblock6
crwxr-xr-x 1 nobody nobody 90, 1 Mar 2 2009 /dev/mtdr0
crwxr-xr-x 1 nobody nobody 90, 3 Mar 2 2009 /dev/mtdr1
crwxr-xr-x 1 nobody nobody 90, 5 Mar 2 2009 /dev/mtdr2
crwxr-xr-x 1 nobody nobody 90, 7 Mar 2 2009 /dev/mtdr3
crwxr-xr-x 1 nobody nobody 90, 9 Mar 2 2009 /dev/mtdr4
crwxr-xr-x 1 nobody nobody 90, 11 Mar 2 2009 /dev/mtdr5
crwxr-xr-x 1 nobody nobody 90, 13 Mar 2 2009 /dev/mtdr6
通过NFS启动系统后,执行应用程序能读出 /dev/mtd6里面的数据,但是我要写入数据,该如何做?是不是在wriere()前要调用
ioctl()来擦除某个块,然后才能写? 请大家帮助,谢谢!
贴上我的一些关键代码:
FILE *fd = open("/dev/mtd6", O_RDWR)
read_len = read(fd, buff, sizeof(buff)-1);
int ret = ioctl(fd, MEMGETBADBLOCK, &offset); /* 擦某个块 */
write_len = write(buff, 1024/*sizeof(buff)-1*/, fd); /* 写入1K 数据 */
|
早上的帖子不是已经回你了嘛,给了一个简短的 dd 源码,稍微改一下就行了。你想要的那些东西貌似 dd 都能完成:
# dd if=/dev/mtd4 of=/dev/mtd5 bs=1024
|
前面那部分就是处理 mtd_erase(), mtd_eraseall() 的,但是现在找不到了...