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

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

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

  1. sanddelaytoensurethewrite
  2. succeeds(butnotsleep).*/
  3. int(*panic_write)(structmtd_info*mtd,loff_tto,size_tlen,size_t*retlen,constu_char*buf);
  4. //用于MTD设备的OBB数据读写
  5. int(*read_oob)(structmtd_info*mtd,loff_tfrom,
  6. structmtd_oob_ops*ops);
  7. int(*write_oob)(structmtd_info*mtd,loff_tto,
  8. structmtd_oob_ops*ops);
  9. /*
  10. *Methodstoaccesstheprotectionregisterarea,presentinsome
  11. *flashdevices.Theuserdataisonetimeprogrammablebutthe
  12. *factorydataisreadonly.
  13. */
  14. int(*get_fact_prot_info)(structmtd_info*mtd,structotp_info*buf,size_tlen);
  15. int(*read_fact_prot_reg)(structmtd_info*mtd,loff_tfrom,size_tlen,size_t*retlen,u_char*buf);
  16. int(*get_user_prot_info)(structmtd_info*mtd,structotp_info*buf,size_tlen);
  17. int(*read_user_prot_reg)(structmtd_info*mtd,loff_tfrom,size_tlen,size_t*retlen,u_char*buf);
  18. int(*write_user_prot_reg)(structmtd_info*mtd,loff_tfrom,size_tlen,size_t*retlen,u_char*buf);
  19. int(*lock_user_prot_reg)(structmtd_info*mtd,loff_tfrom,size_tlen);
  20. /*kvec-basedread/writemethods.
  21. NB:Thecountparameteristhenumberof_vectors_,eachof
  22. whichcontainsan(ofs,len)tuple.
  23. */
  24. int(*writev)(structmtd_info*mtd,conststructkvec*vecs,unsignedlongcount,loff_tto,size_t*retlen);
  25. /*Sync*/
  26. //MTD设备的同步函数
  27. void(*sync)(structmtd_info*mtd);
  28. /*Chip-supporteddevicelocking*/
  29. //芯片的加锁和解锁
  30. int(*lock)(structmtd_info*mtd,loff_tofs,uint64_tlen);
  31. int(*unlock)(structmtd_info*mtd,loff_tofs,uint64_tlen);
  32. /*PowerManagementfunctions*/
  33. //支持电源管理函数
  34. int(*suspend)(structmtd_info*mtd);
  35. void(*resume)(structmtd_info*mtd);
  36. /*Badblockmanagementfunctions*/
  37. //坏块管理函数
  38. int(*block_isbad)(structmtd_info*mtd,loff_tofs);
  39. int(*block_markbad)(structmtd_info*mtd,loff_tofs);
  40. structnotifier_blockreboot_notifier;/*defaultmodebeforereboot*/
  41. /*ECCstatusinformation*/
  42. structmtd_ecc_statsecc_stats;//ECC状态信息
  43. /*Subpageshift(NAND)*/
  44. intsubpage_sft;
  45. void*priv;//私有数据指针
  46. structmodule*owner;
  47. structdevicedev;
  48. intusecount;//记录用户的个数
  49. /*Ifthedriverissomethingsmart,likeUBI,itmayneedtomaintain
  50. *itsownreferencecounting.Thebelowfunctionsareonlyfordriver.
  51. *Thedrivermayregisteritscallbacks.Thesecallbacksarenot
  52. *supposedtobecalledbyMTDusers*/
  53. //驱动回调函数
  54. int(*get_device)(structmtd_info*mtd);
  55. void(*put_device)(structmtd_info*mtd);
  56. };


2、mtd_part结构体信息

  1. /*Ourpartitionlinkedlist*/
  2. staticLIST_HEAD(mtd_partitions);//分区链表

  1. /*Ourpartitionnodestructure*/
  2. //分区结构信息
  3. structmtd_part{
  4. structmtd_infomtd;//mtd_info数据结构,会被加入mtd_table中
  5. structmtd_info*master;//该分区的主分区
  6. uint64_toffset;//该分区的偏移地址
  7. structlist_headlist;//分区链表
  8. };


3、mtd_partition描述mtd具体分区结构

  1. /*
  2. *Partitiondefinitionstructure:
  3. *
  4. *AnarrayofstructpartitionispassedalongwithaMTDobjectto
  5. *add_mtd_partitions()tocreatethem.
  6. *
  7. *Foreachpartition,thesefieldsareavailable:
  8. *name:stringthatwillbeusedtolabelthepartitionsMTDdevice.
  9. *size:thepartitionsize;ifdefinedasMTDPART_SIZ_FULL,thepartition
  10. *willextendtotheendofthemasterMTDdevice.
  11. *offset:absolutestartingpositionwithinthemasterMTDdevice;if
  12. *definedasMTDPART_OFS_APPEND,thepartitionwillstartwherethe
  13. *previousoneended;ifMTDPART_OFS_NXTBLK,atthenexteraseblock.
  14. *mask_flags:containsflagsthathavetobemasked(removed)fromthe
  15. *masterMTDflagsetforthecorrespondingMTDpartition.
  16. *Forexample,toforcearead-onlypartition,simplyadding
  17. *MTD_WRITEABLEtothemask_flagswilldothetrick.
  18. *
  19. *Note:writeablepartitionsrequiretheirsizeandoffsetbe
  20. *erasesizealigned(e.g.useMTDPART_OFS_NEXTBLK).
  21. */
  22. structmtd_partition{
  23. char*name;/*identifierstring分区名*/
  24. uint64_tsize;/*partitionsize分区大小*/
  25. uint64_toffset;/*offsetwithinthemasterMTDspace偏移地址*/
  26. uint32_tmask_flags;/*masterMTDflagstomaskoutforthispartition*/
  27. structnand_ecclayout*ecclayout;/*outofbandlayoutforthispartition(NANDonly)*/
  28. };


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

网站地图

Top