一下载源码包并解压wgetftpftpinfradeadorgpubmtdutilsmtdutils151tarbz2wgethttpwwwzlibnetzlib128targzhttpwwwoberhumercomopensourcelzodownloadlzo203targzwgethttpwwwoberhumercomopensourcelzodownloadlzo203targzwgethttpswwwkernelorgpublinuxutilsutillinuxv221utillinux2211targztarzxvfzlib128targztarzxvflzo203targztarjxvfmtdutils151tarbz2tarzxvfutillinux2211targz二编译安装zlib1cdzlib128CCarmnonelinuxgnueabigccconfigure45prefixusrlocalarm2007q1armnonelinuxgnueabi45shared注意这里的usrlocalarm2007q1armnonelinuxgnueabi是交叉编译工具默认目录2makemakeinstallcd3安装完成后会在usrlocalarm2007q1armnonelinuxgnueabi目录下生成三个目录includelibshare安装完后检查一下目录usrlocalarm2007q1zlib假如include中没有zlibh之类的头文件lib中没有libzso123那就自己手动拷到这些目录下去记着拷的时候把所有的h都需要拷过去在拷库的时候用cpCalibzlib就行要用上Ca选项三编译安装lzo1cdlzo203CCarmnonelinuxgnueabigccconfigure45hostarmnonelinuxgnueabi45prefixusrlocalarm2007q1armnonelinuxgnueabi2makemakeinstallcd3同上四编译安装uuid1cdutillinux2211configure45prefixusrlocalarm2007q1armnonelinuxgnueabi45hostarmnonelinuxgnueabi45disablemount45disablemakeinstallsetuid45disablemakeinstallchown45disableusettygroup45disablechshonlylisted45disableschedutils45disablewall45disablekill45disablepivotroot45disableswitchroot45disablecramfs45disableagetty45disableunshare45disablefallocate45disablemountpoint45disableuuidd45disablepartx45disablefsck45disablelosetup45disablemount45disablelibmount45disabletls45withoutncurses2makemakeinstallcd3同上五交叉编译mtdutils1cdmtdutils1512makeCROSSarmnonelinuxgnueabiWITHOUTXATTR1查看下mtdutils100目录下是否生成了咱们所需要大工具flashcpnandwrite等有工具生成了OK交叉编译成功4将生成大工具拷贝到文件系统开发板的根文件系统放在bin或sbin都行再编译内核就OK拉五补充如果交叉编译器为43x以上编译不通过请参考httpwwwmailarchivecomptxdistpengutronixdemsg01067htmlhttppatchworkozlabsorgpatch12689打补丁六mtdutils工具命令的使用1使用命令前用catprocmtd查看一下mtdchar字符设备或者用lsldevmtdcatprocmtddevsizeerasesizenamemtd000c0000000020000ROOTFSmtd10020000000020000BOOTLOADERmtd20020000000020000KERNELmtd30320000000020000NANDROOTFSpartitionmtd404b0000000020000NANDDATAFSpartition为了更详细了解分区信息用mtddebug命令mtddebuginfodevmtdX不能使用mtdblockXmtdblockX只是提供用來mount而已mtdtypeMTDNORFLASHmtdflagsmtdsize1258291212Mmtderasesize131072128Kmtdoobblock1mtdoobsize0mtdecctypeunknownECCtypenewMTDAPImayberegions02命令flasherase作用擦出指定范围内flash的内容如果不指定默认擦出起始位置的第一块使相应flash变为全1用法flasheraseMTDdevicestartcnteraseblockslockMTDdevice待擦出的分区如devmtd0start起始位置设置这里必须设置为0x20000128K的整数倍cnt从start开始计算要擦出的块数lock写保护egflasherasedevmtd00x400005擦出mtd0分区上从0x40000开始的5块数据128K块命令flasheraseall作用擦出整个分区的数据同时也会作坏块检测用法flasheraseallOPTIONMTDDEVICEq45quiet不显示打印信息j45jffs2一jffs2格式化分区egflasherasealljdevmtd0命令flashcp作用copy数据到flash中用法usageflashcpv45verboseflashcph45helpfilename待写入的数据device写入的分区如devmtd0egfilename制作mkfsjffs2e0x20000dcq8401ocq8401imgn这里的e0x20000必须更你芯片的erasesize相等flashcpcq8401imgdevmtd0copycq8401img文件系统到devmtd0分区中当然这个命令的功能跟ddiftmpfsimgofdevmtd0差不多命令nandwrite作用向nandflash中写数据用法nandwriteOPTIONMTDDEVICEINPUTFILEa45autoplaceUseautoooblayoutj45jffs2forcejffs2ooblayoutlegacysupporty45yaffsforceyaffsooblayoutlegacysupportf45forcelegacyforcelegacysupportonautoplacementenabledmtddevicen45noeccwritewithoutecco45oobimagecontainsoobdatasaddr45startaddrsetstartaddressdefaultis0p45padpadtopagesizeb45blockalign124setmultipleoferaseblockstoaligntoq45quietdontdisplayprogressmessages45helpdisplaythishelpandexit45versionoutputversioninformationandexitegnandwritepdevmtd0tmprootfsjffs2命令nanddump作用dump出nandflash一些信息如blocksizeerasesizeoobblock大小oobdatapagedata等同时也会作坏块检测用法nanddumpOPTIONSMTDdevice45helpdisplaythishelpandexit45versionoutputversioninformationandexitffile45filefiledumptofilei45ignoreerrorsignoreerrorsllength45lengthlengthlengtho45omitoobomitoobdatab45omitbadomitbadblocksfromthedumpp45prettyprintprintnicehexdumpsaddr45startaddressaddrstartaddressegnanddumppfnandinfotxtdevmtd0dump出nandflashdevmtd0数据并保存到nandinfotxt命令mtddebug作用对mtd调试作用用法usagemtddebuginfomtddebugreadmtddebugwritemtddebugeraseegmtddebuginfodevmtd0输出devmtd0上的一些信息这里必须用mtdxmtddebugerasedevmtd00x00x40000擦出devmtd0分区上从0x0开始的128K2大小的数据mtddebugwritedevmtdblock0ox00x360810cq8401img向mtdblock0分区写入36M大小的文件系统cq8401img这里最好用mtdblockxmtddebugreaddevmtdblock0ox00x360810readimg从mtdblock0中读出36M数据保存到readimgcmplcq8401imgreadimg验证writetoflash和readfromflash中的数据是否一致也可以使用diff命令来比较另外针对nandflashmtddebug这个工具来测试mtd驱动也不是很好用nandwrite和nanddump这两个工具或许更好点然后可以用cmp这个命令来比较一下nanddump出来的数据和nandwrite写入的数据是否一致命令ftlformat解释InordertouseoneofconventionalfilesystemsExt2ext3XFSJFSFAToveranMTDdeviceyouneedasoftwarelayerwhichemulatesablockdeviceovertheMTDdeviceTheselayersareoftencalledFlashTranslationLayersFTLs七参考文章httpblogcsdnnetyinkaizhongarchive200812253604794aspxhttphibaiducomqwetiopblogitemf2acb50f03e800eaab64577ahtmlhttpblogchinaunixnetu153103showart1101011html