应用层:(使用mtd ioctl)
0.获取mtd基本信息
struct mtd_info_user {
unsigned char type; //flash类型
unsigned int flags;
unsigned int size; //分区大小
unsigned int erasesize; //块大小
unsigned int wri te size; //页数据大小
unsigned int oobsize; //OOB大小
unsigned int ecctype; //ECC类型
unsigned int ec csi ze; //ECC大小
};
fd = open("/dev/mtd", O_RDWR);
ioctl(fd, MEMGE TI NFO, &mtd_info);
1.读页数据
2.写页数据
unsigned char pag eda te[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);