嵌入式技术
应用层:(使用mtd ioctl)
0.获取mtd基本信息
struct mtd_info_user {
unsigned char type; //flash类型
unsigned int flags;
unsigned int size; //分区大小
unsigned int erasesize; //块大小
unsigned int writesize; //页数据大小
unsigned int oobsize; //OOB大小
unsigned int ecctype; //ECC类型
unsigned int eccsize; //ECC大小
};
fd = open("/dev/mtd", O_RDWR);
ioctl(fd, MEMGETINFO, &mtd_info);
1.读页数据
2.写页数据
unsigned char pagedate[2048] = {...};
write(fd, pagedate, mtd_info.writesize);
3.读OOB
struct mtd_oob_buf {
unsigned int start;
unsigned int length;
unsigned char *ptr;
};
unsigned char oobbuf2[64];
OOB_INFO.start = page_num * (2048);
OOB_INFO.ptr = oobbuf2;
ioctl(fd, MEMREADOOB, &OOB_INFO);
4.写OOB
unsigned char oobbuf[64] = {...};
OOB_INFO.start = page_num * (2048);
OOB_INFO.ptr = oobbuf;
ioctl(fd, MEMWRITEOOB, &OOB_INFO);
mtd demo
全部0条评论
快来发表一下你的评论吧 !