ARM-Linux驱动--MTD驱动分析(一)
时间:11-20
来源:互联网
点击:
主机:Gentoo Linux 11.2 with linux kernel 3.0.6![](../img/eep/emb/emb-58071yqn5jvocxoy.jpg)
硬件平台:FL2440(S3C2440)with linux kernel 2.6.35
MTD(memory technology device内存技术设备) 在硬件和文件系统层之间的提供了一个抽象的接口,MTD是用来访问内存设备(如:ROM、flash)的中间层,它将内存设备的共有特性抽取出来,从而使增加新的内存设备驱动程序变得更简单。MTD的源代码都在/drivers/mtd目录中。
MTD中间层细分为四层,按从上到下依次为:设备节点、MTD设备层、MTD原始设备层和硬件驱动层。MTD中间层层次结构图如下:
![](../img/eep/emb/emb-58071yqn5jvocxoy.jpg)
从上图可以看出,原始设备是MTD字符设备和MTD块设备的抽象。
MTD设备层、MTD原始设备层和Flash硬件驱动层之间的接口关系如下图:
下面首先分析下MTD原始层设备
1、mtd_info数据结构
- structmtd_info{
- u_chartype;//内存技术类型,例如MTD_RAM,MTD_ROM,MTD_NORFLASH,MTD_NAND_FLASH,MTD_PEROM等
- uint32_tflags;//标志位
- uint64_tsize;//TotalsizeoftheMTD//MTD设备的大小
- /*"Major"erasesizeforthedevice.Naïveusersmaytakethis
- *tobetheonlyerasesizeavailable,ormayusethemoredetailed
- *informationbelowiftheydesire
- */
- uint32_terasesize;//最小的擦除块大小
- /*Minimalwritableflashunitsize.IncaseofNORflashitis1(even
- *thoughindividualbitscanbecleared),incaseofNANDflashitis
- *oneNANDpage(orhalf,orone-fourthsofit),incaseofECC-edNOR
- *itisofECCblocksize,etc.Itisillegaltohavewritesize=0.
- *Anydriverregisteringastructmtd_infomustensureawritesizeof
- *1orlarger.
- */
- uint32_twritesize;//编程块大小
- uint32_toobsize;//AmountofOOBdataperblock(e.g.16)//oob(Outofband)块大小
- uint32_toobavail;//AvailableOOBbytesperblock//每块的可用的oob字节
- /*
- *Iferasesizeisapowerof2thentheshiftisstoredin
- *erasesize_shiftotherwiseerasesize_shiftiszero.Dittowritesize.
- */
- unsignedinterasesize_shift;
- unsignedintwritesize_shift;
- /*Masksbasedonerasesize_shiftandwritesize_shift*/
- unsignedinterasesize_mask;
- unsignedintwritesize_mask;
- //Kernel-onlystuffstartshere.
- constchar*name;
- intindex;
- /*ecclayoutstructurepointer-readonly!*/
- structnand_ecclayout*ecclayout;//eec布局结构
- /*Dataforvariableeraseregions.Ifnumeraseregionsiszero,
- *itmeansthatthewholedevicehaserasesizeasgivenabove.
- */
- intnumeraseregions;//擦除区域个数,通常为1
- structmtd_erase_region_info*eraseregions;//擦除区域的区域信息地址
- /*
- *Eraseisanasynchronousoperation.Devicedriversaresupposed
- *tocallinstr->callback()whenevertheoperationcompletes,even
- *ifitcompleteswithafailure.
- *Callersaresupposedtopassacallbackfunctionandwaitforit
- *tobecalledbeforewritingtotheblock.
- */
- int(*erase)(structmtd_info*mtd,structerase_info*instr);//函数指针,erase函数的功能是将一个erase_info加入擦除队列
- /*ThisstuffforeXecute-In-Place*/
- /*physisoptionalandmaybesettoNULL*/
- int(*point)(structmtd_info*mtd,loff_tfrom,size_tlen,
- size_t*retlen,void**virt,resource_size_t*phys);//point函数功能是允许片内执行(XIP)
- /*WeprobablyshouldntallowXIPiftheunpointisntaNULL*/
- void(*unpoint)(structmtd_info*mtd,loff_tfrom,size_tlen);//unpoint函数与point函数相反,是禁止片内执行(XIP)
- /*AllowNOMMUmmap()todirectlymapthedevice(ifnotNULL)
- *-returntheaddresstowhichtheoffsetmaps
- *-return-ENOSYStoindicaterefusaltodothemapping
- */
- //如果不是NULL,则允许无MMU单元的地址映射,返回偏移地址
- unsignedlong(*get_unmapped_area)(structmtd_info*mtd,
- unsignedlonglen,
- unsignedlongoffset,
- unsignedlongflags);
- /*Backingdevicecapabilitiesforthisdevice
- *-providesmmapcapabilities
- */
- structbacking_dev_info*backing_dev_info;
- //MTD设备的读写函数
- int(*read)(structmtd_info*mtd,loff_tfrom,size_tlen,size_t*retlen,u_char*buf);
- int(*write)(structmtd_info*mtd,loff_tto,size_tlen,size_t*retlen,constu_char*buf);
- /*Inblackboxflightrecorderlikescenarioswewanttomakesuccessful
- writesininterruptcontext.panic_write()isonlyintendedtobe
- calledwhenitsknownthekernelisabouttopanicandweneedthe
- writetosucceed.Sincethekernelisnotgoingtoberunningformuch
- longer,thisfunctioncanbreaklock
ARM-Linux驱动MTD驱动分 相关文章:
- ARM-Linux驱动--MTD驱动分析(二)(11-20)
- ARM-Linux驱动--MTD驱动分析(三)(11-20)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)