ARM-Linux驱动--MTD驱动分析(三)
时间:11-20
来源:互联网
点击:
主机:Gentoo Linux 11.2 with linux kernel 3.0.6
2、分区链表mtd_partitions
3、add_mtd_partitions函数
而add_one_partition函数实现如下:
硬件平台:FL2440(S3C2440)with linux kernel 2.6.35
本文分析MTD设备的分区管理机制
分区管理实际上是将一个MTD设备分成几个分区,将其作为单独的MTD原始设备进行管理。
1、分区的结构体描述结构体mtd_part
- /*Ourpartitionnodestructure*/
- //分区结构信息
- structmtd_part{
- structmtd_infomtd;//mtd_info数据结构,会被加入mtd_table中
- structmtd_info*master;//该分区的主分区
- uint64_toffset;//该分区的偏移地址
- structlist_headlist;
- };
2、分区链表mtd_partitions
- /*Ourpartitionlinkedlist*/
- //声明mtd_partitions链表
- staticLIST_HEAD(mtd_partitions);
3、add_mtd_partitions函数
- /*
- *Thisfunction,givenamasterMTDobjectandapartitiontable,creates
- *andregistersslaveMTDobjectswhichareboundtothemasteraccordingto
- *thepartitiondefinitions.
- *
- *Wedontregisterthemaster,orexpectthecallertohavedoneso,
- *forreasonsofdataintegrity.
- */
- //根据一个MTD主设备和分区表,创建新的主设备下的副设备并记录到分区表中
- //这里我们不将注射被注册到分区表中,只注册副设备到到分区表中
- intadd_mtd_partitions(structmtd_info*master,
- conststructmtd_partition*parts,
- intnbparts)
- {
- structmtd_part*slave;
- uint64_tcur_offset=0;
- inti;
- printk(KERN_NOTICE"Creating%dMTDpartitionson\"%s\":\n",nbparts,master->name);
- for(i=0;i
- slave=add_one_partition(master,parts+i,i,cur_offset);
- if(!slave)
- return-ENOMEM;
- cur_offset=slave->offset+slave->mtd.size;
- }
- return0;
- }
- EXPORT_SYMBOL(add_mtd_partitions);
而add_one_partition函数实现如下:
- //创建一个分区
- staticstructmtd_part*add_one_partition(structmtd_info*master,
- conststructmtd_partition*part,intpartno,
- uint64_tcur_offset)
- {
- structmtd_part*slave;
- /*allocatethepartitionstructure*/
- slave=kzalloc(sizeof(*slave),GFP_KERNEL);//分配内存
- if(!slave){
- printk(KERN_ERR"memoryallocationerrorwhilecreatingpartitionsfor\"%s\"\n",
- master->name);
- del_mtd_partitions(master);
- returnNULL;
- }
- list_add(&slave->list,&mtd_partitions);//将原始设备表添加到分区表中
- /*setuptheMTDobjectforthispartition*/
- //大部分根据master相应的信息设置MTD分区slave的信息
- slave->mtd.type=master->type;
- slave->mtd.flags=master->flags&~part->mask_flags;
- slave->mtd.size=part->size;
- slave->mtd.writesize=master->writesize;
- slave->mtd.oobsize=master->oobsize;
- slave->mtd.oobavail=master->oobavail;
- slave->mtd.subpage_sft=master->subpage_sft;
- slave->mtd.name=part->name;
- slave->mtd.owner=master->owner;
- slave->mtd.backing_dev_info=master->backing_dev_info;
- /*NOTE:wedontarrangeMTDsasatree;itdbeerror-prone
- *tohavethesamedatabeintwodifferentpartitions.
- */
- slave->mtd.dev.parent=master->dev.parent;
- slave->mtd.read=part_read;
- slave->mtd.write=part_write;
- if(master->panic_write)
- slave->mtd.panic_write=part_panic_write;
- if(master->point&&master->unpoint){
- slave->mtd.point=part_point;
- slave->mtd.unpoint=part_unpoint;
- }
- if(master->get_unmapped_area)
- slave->mtd.get_unmapped_area=part_get_unmapped_area;
- if(master->read_oob)
- slave->mtd.read_oob=part_read_oob;
- if(master->write_oob)
- slave->mtd.write_oob=part_write_oob;
- if(master->read_user_prot_reg)
- slave->mtd.read_user_prot_reg=part_read_user_prot_reg;
- if(master->read_fact_prot_reg)
- slave->mtd.read_fact_prot_reg=part_read_fact_prot_reg;
- if(master->write_user_prot_reg)
- slave->mtd.write_user_prot_reg=part_write_user_prot_reg;
- if(master->lock_user_prot_reg)
- slave->mtd.lock_user_prot_reg=part_lock_user_prot_reg;
- if(master->get_user_prot_info)
- slave->mtd.get_user_prot_info=part_get_user_prot_info;
- if(master->get_fact_prot_info)
- slave->mtd.get_fact_prot_info=part_get_fact_prot_info;
- if(master->sync)
- slave->mtd.sync=part_sync;
- if(!partno&&!master->dev.class&&master->suspend&&master->resume){
- slave->mtd.suspend=part_suspend;
- slave->mtd.resume=part_resume;
- }
- if(master->writev)
- slave->mtd.writev=part_writev;
- if(master->lock)
- slave->mtd.lock=part_lock;
- if(master->unlock)
- slave->slave-
上一篇:ARM-Linux驱动--DM9000网卡驱动分析(四)
下一篇:ARM-Linux移植攻略--yaffs2 Partially written block xxx detected 问题解决
下一篇:ARM-Linux移植攻略--yaffs2 Partially written block xxx detected 问题解决
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)