ARM-Linux驱动--MTD驱动分析(三)
时间:11-20
来源:互联网
点击:
- slave->>mtd.unlock=part_unlock;
- if(master->block_isbad)
- slave->mtd.block_isbad=part_block_isbad;
- if(master->block_markbad)
- slave->mtd.block_markbad=part_block_markbad;
- slave->mtd.erase=part_erase;
- slave->master=master;
- slave->offset=part->offset;
- if(slave->offset==MTDPART_OFS_APPEND)
- slave->offset=cur_offset;
- if(slave->offset==MTDPART_OFS_NXTBLK){
- slave->offset=cur_offset;
- if(mtd_mod_by_eb(cur_offset,master)!=0){
- /*Rounduptonexterasesize*/
- slave->offset=(mtd_div_by_eb(cur_offset,master)+1)*master->erasesize;
- printk(KERN_NOTICE"Movingpartition%d:"
- "0x%012llx->0x%012llx\n",partno,
- (unsignedlonglong)cur_offset,(unsignedlonglong)slave->offset);
- }
- }
- if(slave->mtd.size==MTDPART_SIZ_FULL)
- slave->mtd.size=master->size-slave->offset;
- printk(KERN_NOTICE"0x%012llx-0x%012llx:\"%s\"\n",(unsignedlonglong)slave->offset,
- (unsignedlonglong)(slave->offset+slave->mtd.size),slave->mtd.name);
- /*letsdosomesanitychecks*/
- if(slave->offset>=master->size){
- /*letsregisteritanywaytopreserveordering*/
- slave->offset=0;
- slave->mtd.size=0;
- printk(KERN_ERR"mtd:partition\"%s\"isoutofreach--disabled\n",
- part->name);
- gotoout_register;
- }
- if(slave->offset+slave->mtd.size>master->size){
- slave->mtd.size=master->size-slave->offset;
- printk(KERN_WARNING"mtd:partition\"%s\"extendsbeyondtheendofdevice\"%s\"--sizetruncatedto%#llx\n",
- part->name,master->name,(unsignedlonglong)slave->mtd.size);
- }
- if(master->numeraseregions>1){
- /*Dealwithvariableerasesizestuff*/
- inti,max=master->numeraseregions;
- u64end=slave->offset+slave->mtd.size;
- structmtd_erase_region_info*regions=master->eraseregions;
- /*Findthefirsteraseregionswhichispartofthis
- *partition.*/
- for(i=0;i
offset;i++) - ;
- /*Theloopsearchedfortheregion_behind_thefirstone*/
- if(i>0)
- i--;
- /*Pickbiggesterasesize*/
- for(;i
- if(slave->mtd.erasesize
- slave->mtd.erasesize=regions[i].erasesize;
- }
- }
- BUG_ON(slave->mtd.erasesize==0);
- }else{
- /*Singleerasesize*/
- slave->mtd.erasesize=master->erasesize;
- }
- if((slave->mtd.flags&MTD_WRITEABLE)&&
- mtd_mod_by_eb(slave->offset,&slave->mtd)){
- /*Doesntstartonaboundaryofmajorerasesize*/
- /*FIXME:Letitbewritableifitisonaboundaryof
- *_minor_erasesizethough*/
- slave->mtd.flags&=~MTD_WRITEABLE;
- printk(KERN_WARNING"mtd:partition\"%s\"doesntstartonaneraseblockboundary--forceread-only\n",
- part->name);
- }
- if((slave->mtd.flags&MTD_WRITEABLE)&&
- mtd_mod_by_eb(slave->mtd.size,&slave->mtd)){
- slave->mtd.flags&=~MTD_WRITEABLE;
- printk(KERN_WARNING"mtd:partition\"%s\"doesntendonaneraseblock--forceread-only\n",
- part->name);
- }
- slave->mtd.ecclayout=master->ecclayout;
- if(master->block_isbad){
- uint64_toffs=0;
- while(offs
mtd.size){ - if(master->block_isbad(master,
- offs+slave->offset))
- slave->mtd.ecc_stats.badblocks++;
- offs+=slave->mtd.erasesize;
- }
- }
- out_register:
- /*registerourpartition*/
- //最后调用add_mtd_device根据该设备的mtd_info信息添加设备链表,将其作为一个独立的MTD原始设备
- add_mtd_device(&slave->mtd);
- returnslave;
- }
- if(slave->mtd.erasesize
4、del_mtd_partition函数
- /*
- *ThisfunctionunregistersanddestroyallslaveMTDobjectswhichare
- *attachedtothegivenmasterMTDobject.
- */
- //将一个主设备下的所有副设备删除
- intdel_mtd_partitions(structmtd_info*master)
- {
- structmtd_part*slave,*next;
- list_for_each_entry_safe(slave,next,&mtd_partitions,list)//遍历mtd_partitions链表,查找到指定的主设备
- if(slave->master==master){
- list_del(&slave->list);//将主设备下的附属设备删除
- del_mtd_device(&slave->mtd);//调用del_mtd_device函数将每个设备从MTD原始设备表中删除
- kfree(slave);//释放内存
- }
- return0;
- }
- EXPORT_SYMBOL(del_mtd_partitions);
5、其他的分区管理函数
- /*
- *MTDmethodswhichsimplytranslatetheeffectiveaddressandpassthrough
- *tothe_real_device.
- */
- //读取某个分区的指定数据
- staticintpart_read(structmtd_info*mtd,loff_tfrom,size_tlen,
- size_t*retlen,u_char*buf)
- {
- structmtd_part*part=PART(mtd);
- structmtd_ecc_statsstats;
- intres;
- stats=part->master->sta
上一篇: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)