微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM-Linux驱动--MTD驱动分析(三)

ARM-Linux驱动--MTD驱动分析(三)

时间:11-20 来源:互联网 点击:

  1. slave->>mtd.unlock=part_unlock;
  2. if(master->block_isbad)
  3. slave->mtd.block_isbad=part_block_isbad;
  4. if(master->block_markbad)
  5. slave->mtd.block_markbad=part_block_markbad;
  6. slave->mtd.erase=part_erase;
  7. slave->master=master;
  8. slave->offset=part->offset;
  9. if(slave->offset==MTDPART_OFS_APPEND)
  10. slave->offset=cur_offset;
  11. if(slave->offset==MTDPART_OFS_NXTBLK){
  12. slave->offset=cur_offset;
  13. if(mtd_mod_by_eb(cur_offset,master)!=0){
  14. /*Rounduptonexterasesize*/
  15. slave->offset=(mtd_div_by_eb(cur_offset,master)+1)*master->erasesize;
  16. printk(KERN_NOTICE"Movingpartition%d:"
  17. "0x%012llx->0x%012llx\n",partno,
  18. (unsignedlonglong)cur_offset,(unsignedlonglong)slave->offset);
  19. }
  20. }
  21. if(slave->mtd.size==MTDPART_SIZ_FULL)
  22. slave->mtd.size=master->size-slave->offset;
  23. printk(KERN_NOTICE"0x%012llx-0x%012llx:\"%s\"\n",(unsignedlonglong)slave->offset,
  24. (unsignedlonglong)(slave->offset+slave->mtd.size),slave->mtd.name);
  25. /*letsdosomesanitychecks*/
  26. if(slave->offset>=master->size){
  27. /*letsregisteritanywaytopreserveordering*/
  28. slave->offset=0;
  29. slave->mtd.size=0;
  30. printk(KERN_ERR"mtd:partition\"%s\"isoutofreach--disabled\n",
  31. part->name);
  32. gotoout_register;
  33. }
  34. if(slave->offset+slave->mtd.size>master->size){
  35. slave->mtd.size=master->size-slave->offset;
  36. printk(KERN_WARNING"mtd:partition\"%s\"extendsbeyondtheendofdevice\"%s\"--sizetruncatedto%#llx\n",
  37. part->name,master->name,(unsignedlonglong)slave->mtd.size);
  38. }
  39. if(master->numeraseregions>1){
  40. /*Dealwithvariableerasesizestuff*/
  41. inti,max=master->numeraseregions;
  42. u64end=slave->offset+slave->mtd.size;
  43. structmtd_erase_region_info*regions=master->eraseregions;
  44. /*Findthefirsteraseregionswhichispartofthis
  45. *partition.*/
  46. for(i=0;ioffset;i++)
  47. ;
  48. /*Theloopsearchedfortheregion_behind_thefirstone*/
  49. if(i>0)
  50. i--;
  51. /*Pickbiggesterasesize*/
  52. for(;i
  53. if(slave->mtd.erasesize
  54. slave->mtd.erasesize=regions[i].erasesize;
  55. }
  56. }
  57. BUG_ON(slave->mtd.erasesize==0);
  58. }else{
  59. /*Singleerasesize*/
  60. slave->mtd.erasesize=master->erasesize;
  61. }
  62. if((slave->mtd.flags&MTD_WRITEABLE)&&
  63. mtd_mod_by_eb(slave->offset,&slave->mtd)){
  64. /*Doesntstartonaboundaryofmajorerasesize*/
  65. /*FIXME:Letitbewritableifitisonaboundaryof
  66. *_minor_erasesizethough*/
  67. slave->mtd.flags&=~MTD_WRITEABLE;
  68. printk(KERN_WARNING"mtd:partition\"%s\"doesntstartonaneraseblockboundary--forceread-only\n",
  69. part->name);
  70. }
  71. if((slave->mtd.flags&MTD_WRITEABLE)&&
  72. mtd_mod_by_eb(slave->mtd.size,&slave->mtd)){
  73. slave->mtd.flags&=~MTD_WRITEABLE;
  74. printk(KERN_WARNING"mtd:partition\"%s\"doesntendonaneraseblock--forceread-only\n",
  75. part->name);
  76. }
  77. slave->mtd.ecclayout=master->ecclayout;
  78. if(master->block_isbad){
  79. uint64_toffs=0;
  80. while(offsmtd.size){
  81. if(master->block_isbad(master,
  82. offs+slave->offset))
  83. slave->mtd.ecc_stats.badblocks++;
  84. offs+=slave->mtd.erasesize;
  85. }
  86. }
  87. out_register:
  88. /*registerourpartition*/
  89. //最后调用add_mtd_device根据该设备的mtd_info信息添加设备链表,将其作为一个独立的MTD原始设备
  90. add_mtd_device(&slave->mtd);
  91. returnslave;
  92. }


4、del_mtd_partition函数

  1. /*
  2. *ThisfunctionunregistersanddestroyallslaveMTDobjectswhichare
  3. *attachedtothegivenmasterMTDobject.
  4. */
  5. //将一个主设备下的所有副设备删除
  6. intdel_mtd_partitions(structmtd_info*master)
  7. {
  8. structmtd_part*slave,*next;
  9. list_for_each_entry_safe(slave,next,&mtd_partitions,list)//遍历mtd_partitions链表,查找到指定的主设备
  10. if(slave->master==master){
  11. list_del(&slave->list);//将主设备下的附属设备删除
  12. del_mtd_device(&slave->mtd);//调用del_mtd_device函数将每个设备从MTD原始设备表中删除
  13. kfree(slave);//释放内存
  14. }
  15. return0;
  16. }
  17. EXPORT_SYMBOL(del_mtd_partitions);


5、其他的分区管理函数

  1. /*
  2. *MTDmethodswhichsimplytranslatetheeffectiveaddressandpassthrough
  3. *tothe_real_device.
  4. */
  5. //读取某个分区的指定数据
  6. staticintpart_read(structmtd_info*mtd,loff_tfrom,size_tlen,
  7. size_t*retlen,u_char*buf)
  8. {
  9. structmtd_part*part=PART(mtd);
  10. structmtd_ecc_statsstats;
  11. intres;
  12. stats=part->master->sta

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top