应用层:(运用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