加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

NandFlash驱动分析(一)

发布时间:2020-12-15 17:46:47 所属栏目:百科 来源:网络整理
导读:内核启动信息,NAND部分: S3C24XX NAND Driver,(c) 2004 Simtec Electronics s3c2440-nand s3c2440-nand: Tacls=2,20ns Twrph0=3 30ns,Twrph1=2 20ns NAND device: Manufacturer ID: 0xec,Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit) Scanning device f

内核启动信息,NAND部分:

S3C24XX NAND Driver,(c) 2004 Simtec Electronics

s3c2440-nand s3c2440-nand: Tacls=2,20ns Twrph0=3 30ns,Twrph1=2 20ns

NAND device: Manufacturer ID: 0xec,Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)

Scanning device for bad blocks

Creating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":

0x00000000-0x00040000 : "boot"

0x0004c000-0x0024c000 : "kernel"

0x0024c000-0x03ffc000 : "yaffs2"

第一行,在driver/mtd/nand/s3c2410.c中第910行,s3c2410_nand_init函数:

printk("S3C24XX NAND Driver,(c) 2004 Simtec Electronicsn");

行二行,同一文件,第212行,s3c2410_nand_inithw函数:

dev_info(info->device,"Tacls=%d,%dns Twrph0=%d %dns,Twrph1=%d %dnsn",tacls,to_ns(tacls,clkrate),twrph0,to_ns(twrph0,twrph1,to_ns(twrph1,clkrate));

第三行,在driver/mtd/nand/nand_base.c中第2346行,

printk(KERN_INFO "NAND device: Manufacturer ID:" " 0x%02x,Chip ID: 0x%02x (%s %s)n",*maf_id,dev_id,nand_manuf_ids[maf_idx].name,type->name);

第四行,在driver/mtd/nand/nand_bbt.c中第380行,creat_bbt函数:

Printk(KERN INFO " Scanning device for bad blocks n");

第五行,在driver/mtd/mtdpart.c中第340行,add_mtd_partitions函数:

printk (KERN_NOTICE "Creating %d MTD partitions on "%s":n",nbparts,master->name);

下面三行,是flash分区表,也在mtdpart.c同一函数中,第430行:

printk (KERN_NOTICE "0x%08x-0x%08x : "%s"n",slave->offset,slave->offset + slave->mtd.size,slave->mtd.name);

MTD体系结构:

在linux中提供了MTD(Memory Technology Device,内存技术设备)系统来建立Flash针对linux的统一、抽象的接口

引入MTD后,linux系统中的Flash设备驱动及接口可分为4层:

设备节点

MTD设备层

MTD原始设备层

硬件驱动层

硬件驱动层:Flash硬件驱动层负责底层硬件设备实际的读、写、擦除,Linux MTD设备的NAND型Flash驱动位于driver/mtd/nand子目录下

s3c2410对应的nand Flash驱动为s3c2410.c

MTD原始设备层:MTD原始设备层由两部分构成,一部分是MTD原始设备的通用代码,另一部分是各个特定Flash的数据,比如分区

主要构成的文件有:

drivers/mtd/mtdcore.c 支持mtd字符设备

driver/mtd/mtdpart.c 支持mtd块设备

MTD设备层:基于MTD原始设备,Linux系统可以定义出MTD的块设备(主设备号31) 和字符设备(设备号90),构成MTD设备层

简单的说就是:使用一个mtd层来作为具体的硬件设备驱动和上层文件系统的桥梁。mtd给出了系统中所有mtd设备(nand,nor,diskonchip)的统一组织方式。

mtd层用一个数组struct mtd_info *mtd_table[MAX_MTD_DEVICES]保存系统中所有的设备,mtd设备利用struct mtd_info 这个结构来描述,该结构中描述了存储设备的基本信息和具体操作所需要的内核函数,mtd系统的那个机制主要就是围绕这个结构来实现的。结构体在include/linux/mtd/mtd.h中定义:

struct mtd_info {

u_char type;????????? ??//MTD 设备类型

u_int32_t flags;??? ????//MTD设备属性标志

u_int32_t size; ????????//标示了这个mtd设备的大小

u_int32_t erasesize; ???//MTD设备的擦除单元大小,对于NandFlash来说就是Block的大小

u_int32_t oobblock; ????//oob区在页内的位置,对于512字节一页的nand来说是512

u_int32_t oobsize;?? ???//oob区的大小,对于512字节一页的nand来说是16

u_int32_t ecctype;????? //ecc校验类型

u_int32_t eccsize; ?????//ecc的大小

char *name;???????????? //设备的名字

int index;????????????? //设备在MTD列表中的位置

struct nand_oobinfo oobinfo; //oob区的信息,包括是否使用ecc,ecc的大小

//以下是关于mtd的一些读写函数,将在nand_base中的nand_scan中重载

int (*erase)

int (*read)

int (*write)

int (*read_ecc)

int (*write_ecc)

int (*read_oob)

int (*read_oob)

void *priv;//设备私有数据指针,对于NandFlash来说指nand芯片的结构

...

}

下面看nand_chip结构,在include/linux/mtd/nand.h中定义:

struct nand_chip {

void __iomem?? *IO_ADDR_R; ??//这是nandflash的读写寄存器

void __iomem???? *IO_ADDR_W;

//以下都是nandflash的操作函数,这些函数将根据相应的配置进行重载

u_char??? (*read_byte)(struct mtd_info *mtd);

void????? (*write_byte)(struct mtd_info *mtd,u_char byte);

u16?????? (*read_word)(struct mtd_info *mtd);

void????? (*write_word)(struct mtd_info *mtd,u16 word);

void???? (*write_buf)(struct mtd_info *mtd,const u_char *buf,int len);

void???? (*read_buf)(struct mtd_info *mtd,u_char *buf,int len);

int???? (*verify_buf)(struct mtd_info *mtd,int len);

void???? (*select_chip)(struct mtd_info *mtd,int chip);

int???? (*block_bad)(struct mtd_info *mtd,loff_t ofs,int getchip);

int????? (*block_markbad)(struct mtd_info *mtd,loff_t ofs);

void???? (*hwcontrol)(struct mtd_info *mtd,int cmd);

int????? (*dev_ready)(struct mtd_info *mtd);

void?? ??(*cmdfunc)(struct mtd_info *mtd,unsigned command,int column,int page_addr);

int??? (*waitfunc)(struct mtd_info *mtd,struct nand_chip *this,int state);

int???? (*calculate_ecc)(struct mtd_info *mtd,const u_char *dat,u_char *ecc_code);

int (*correct_data)(struct mtd_info *mtd,u_char *dat,u_char *read_ecc,u_char *calc_ecc);

void ??(*enable_hwecc)(struct mtd_info *mtd,int mode);

void??? (*erase_cmd)(struct mtd_info *mtd,int page);

int???? (*scan_bbt)(struct mtd_info *mtd);

int?????? eccmode;?? ??//ecc的校验模式(软件,硬件)

int ?????chip_delay; //芯片时序延迟参数

int?????? page_shift; //页偏移,对于512B/页的,一般是9

u_char??? *data_buf; ??//数据缓存区

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读