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

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

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

  1. stats=part->master->ts=part->master->ecc_ts;
  2. if(from>=mtd->size)
  3. len=0;
  4. elseif(from+len>mtd->size)
  5. len=mtd->size-from;
  6. res=part->master->read(part->master,from+part->offset,
  7. len,retlen,buf);
  8. if(unlikely(res)){
  9. if(res==-EUCLEAN)
  10. mtd->ecc_stats.corrected+=part->master->ecc_stats.corrected-stats.corrected;
  11. if(res==-EBADMSG)
  12. mtd->ecc_stats.failed+=part->master->ecc_stats.failed-stats.failed;
  13. }
  14. returnres;
  15. }
  16. staticintpart_point(structmtd_info*mtd,loff_tfrom,size_tlen,
  17. size_t*retlen,void**virt,resource_size_t*phys)
  18. {
  19. structmtd_part*part=PART(mtd);
  20. if(from>=mtd->size)
  21. len=0;
  22. elseif(from+len>mtd->size)
  23. len=mtd->size-from;
  24. returnpart->master->point(part->master,from+part->offset,
  25. len,retlen,virt,phys);
  26. }
  27. staticvoidpart_unpoint(structmtd_info*mtd,loff_tfrom,size_tlen)
  28. {
  29. structmtd_part*part=PART(mtd);
  30. part->master->unpoint(part->master,from+part->offset,len);
  31. }
  32. //获取空闲的内存驱动
  33. staticunsignedlongpart_get_unmapped_area(structmtd_info*mtd,
  34. unsignedlonglen,
  35. unsignedlongoffset,
  36. unsignedlongflags)
  37. {
  38. structmtd_part*part=PART(mtd);
  39. offset+=part->offset;
  40. returnpart->master->get_unmapped_area(part->master,len,offset,
  41. flags);
  42. }
  43. staticintpart_read_oob(structmtd_info*mtd,loff_tfrom,
  44. structmtd_oob_ops*ops)
  45. {
  46. structmtd_part*part=PART(mtd);
  47. intres;
  48. if(from>=mtd->size)
  49. return-EINVAL;
  50. if(ops->datbuf&&from+ops->len>mtd->size)
  51. return-EINVAL;
  52. res=part->master->read_oob(part->master,from+part->offset,ops);
  53. if(unlikely(res)){
  54. if(res==-EUCLEAN)
  55. mtd->ecc_stats.corrected++;
  56. if(res==-EBADMSG)
  57. mtd->ecc_stats.failed++;
  58. }
  59. returnres;
  60. }
  61. staticintpart_read_user_prot_reg(structmtd_info*mtd,loff_tfrom,
  62. size_tlen,size_t*retlen,u_char*buf)
  63. {
  64. structmtd_part*part=PART(mtd);
  65. returnpart->master->read_user_prot_reg(part->master,from,
  66. len,retlen,buf);
  67. }
  68. staticintpart_get_user_prot_info(structmtd_info*mtd,
  69. structotp_info*buf,size_tlen)
  70. {
  71. structmtd_part*part=PART(mtd);
  72. returnpart->master->get_user_prot_info(part->master,buf,len);
  73. }
  74. staticintpart_read_fact_prot_reg(structmtd_info*mtd,loff_tfrom,
  75. size_tlen,size_t*retlen,u_char*buf)
  76. {
  77. structmtd_part*part=PART(mtd);
  78. returnpart->master->read_fact_prot_reg(part->master,from,
  79. len,retlen,buf);
  80. }
  81. staticintpart_get_fact_prot_info(structmtd_info*mtd,structotp_info*buf,
  82. size_tlen)
  83. {
  84. structmtd_part*part=PART(mtd);
  85. returnpart->master->get_fact_prot_info(part->master,buf,len);
  86. }
  87. //分区写函数
  88. staticintpart_write(structmtd_info*mtd,loff_tto,size_tlen,
  89. size_t*retlen,constu_char*buf)
  90. {
  91. structmtd_part*part=PART(mtd);
  92. if(!(mtd->flags&MTD_WRITEABLE))
  93. return-EROFS;
  94. if(to>=mtd->size)
  95. len=0;
  96. elseif(to+len>mtd->size)
  97. len=mtd->size-to;
  98. returnpart->master->write(part->master,to+part->offset,
  99. len,retlen,buf);
  100. }
  101. staticintpart_panic_write(structmtd_info*mtd,loff_tto,size_tlen,
  102. size_t*retlen,constu_char*buf)
  103. {
  104. structmtd_part*part=PART(mtd);
  105. if(!(mtd->flags&MTD_WRITEABLE))
  106. return-EROFS;
  107. if(to>=mtd->size)
  108. len=0;
  109. elseif(to+len>mtd->size)
  110. len=mtd->size-to;
  111. returnpart->master->panic_write(part->master,to+part->offset,
  112. len,retlen,buf);
  113. }
  114. staticintpart_write_oob(structmtd_info*mtd,loff_tto,
  115. structmtd_oob_ops*ops)
  116. {
  117. structmtd_part*part=PART(mtd);
  118. if(!(mtd->flags&MTD_WRITEABLE))
  119. return-EROFS;
  120. if(to>=mtd->size)
  121. return-EINVAL;
  122. if(ops->datbuf&&to+ops->len>mtd->size)
  123. return-EINVAL;
  124. returnpart->master->write_oob(part->master,to+part->offset,ops);
  125. }
  126. staticintpart_write_user_prot_reg(structmtd_info*mtd,loff_tfrom,
  127. size_tlen,size_t*retlen,u_char*buf)
  128. {
  129. structmtd_part*part=PART(mtd);
  130. returnpart->master->write_user_prot_reg(part->master,from,
  131. len,retlen,buf);
  132. }
  133. staticintpart_lock_user_prot_reg(structmtd_info*mtd,loff_tfrom,
  134. size_tlen)
  135. {
  136. structmtd_part*part=PART(mtd);
  137. returnpart->master->lock_user_prot_reg(part->master,from,len);
  138. }
  139. staticintpart_writev(structmtd_info*mtd,conststructkvec*vecs,
  140. unsignedlongcount,loff_tto,size_t*retlen)
  141. {
  142. structm

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

网站地图

Top