1、使用命令前用cat /proc/mtd 查看一下mtdchar字符設備锯蛀;或者用ls -l /dev/mtd*
cat /proc/mtd
2、mtd_debug info /dev/mtdX (不能使用mtdblockX, mtdblockX 只是提供用來 mount 而已)
3炊琉、命令:flash_erase
作用:擦出指定范圍內(nèi)flash的內(nèi)容杰赛,如果不指定,默認擦出起始位置的第一塊兽泄,使相應flash變?yōu)槿?
用法:
flash_erase MTD-device [start] [cnt (# erase blocks)] [lock]
MTD-device:待擦出的分區(qū)漓概,如/dev/mtd0
start:起始位置設置,這里必須設置為0×20000(128K)的整數(shù)倍
cnt: 從start開始計算病梢,要擦出的塊數(shù)
lock: 寫保護
eg: ./flash_erase /dev/mtd0 0×40000 5 //擦出mtd0分區(qū)上從0×40000開始的5塊數(shù)據(jù) 胃珍,128K/塊
4、命令:flash_eraseall
作用:擦出整個分區(qū)的數(shù)據(jù),同時也會作壞塊檢測
用法:
flash_eraseall [OPTION] MTD_DEVICE
-q, –quiet 不顯示打印信息
-j, –jffs2 一jffs2 格式化分區(qū)
eg: ./flash_eraseall -j /dev/mtd0
5蜓陌、命令:flashcp
作用:copy 數(shù)據(jù)到 flash 中
用法:
usage: flashcp [ -v | --verbose ] <filename> <device>
flashcp -h | –help
filename:待寫入的數(shù)據(jù)
device: 寫入的分區(qū)觅彰,如/dev/mtd0
eg:
filename制作:mkfs.jffs2 -e 0×20000 -d cq8401 -o cq8401.img -n //這里的-e 0×20000 必須更你芯片的erasesize 相等
./flashcp cq8401.img /dev/mtd0 // copy cq8401.img文件系統(tǒng)到 /dev/mtd0分區(qū)中
當然這個命令的功能跟 dd if=/tmp/fs.img of=/dev/mtd0差不多
6、命令:nandwrite
作用:向nand flash中寫數(shù)據(jù)
用法:
nandwrite [OPTION] MTD_DEVICE INPUTFILE
-a, –autoplace Use auto oob layout
-j, –jffs2 force jffs2 oob layout (legacy support)
-y, –yaffs force yaffs oob layout (legacy support)
-f, –forcelegacy force legacy support on autoplacement enabled mtd device
-n, –noecc write without ecc
-o, –oob image contains oob data
-s addr, –start=addr set start address (default is 0)
-p, –pad pad to page size
-b, –blockalign=1|2|4 set multiple of eraseblocks to align to
-q, –quiet don’t display progress messages
–help display this help and exit
–version output version information and exit
eg: ./nandwrite -p /dev/mtd0 /tmp/rootfs.jffs2
7钮热、命令:nanddump
作用:dump出nand flash一些信息填抬,如:block size,erasesize,oobblock 大小,oob data ,page data等隧期;同時也會作壞塊檢測
用法:
nanddump [OPTIONS] MTD-device
–help display this help and exit
–version output version information and exit
-f file –file=file dump to file
-i –ignoreerrors ignore errors
-l length –length=length length
-o –omitoob omit oob data
-b –omitbad omit bad blocks from the dump
-p –prettyprint print nice (hexdump)
-s addr –startaddress=addr start address
eg:./nanddump -p -f nandinfo.txt /dev/mtd0 //dump出nand flash /dev/mtd0數(shù)據(jù)并保存到 nandinfo.txt
8飒责、命令:mtd_debug
作用: 對mtd 調(diào)試作用
用法:
usage: mtd_debug info <device>
mtd_debug read <device> <offset> <len> <dest-filename>
mtd_debug write <device> <offset> <len> <source-filename>
mtd_debug erase <device> <offset> <len>
eg:
./mtd_debug info /dev/mtd0 // 輸出/dev/mtd0上的一些信息,這里必須用mtdx
./mtd_debug erase /dev/mtd0 0×0 0×40000 // 擦出/dev/mtd0 分區(qū)上 從0×0開始的 , 128K*2 大小的數(shù)據(jù)
./mtd_debug write /dev/mtdblock0 ox0 0×360810 cq8401.img //向mtdblock0分區(qū)仆潮,寫入 3.6M 大小的文件系統(tǒng)cq8401.img,這里最好用mtdblockx
./mtd_debug read /dev/mtdblock0 ox0 0×360810 read.img //從mtdblock0中讀出 3.6M 數(shù)據(jù)保存到read.img
cmp -l cq8401.img read.img // 驗證write to flash 和 read from flash 中的數(shù)據(jù)是否一致;也可以使用diff命令來比較
另外針對nand flash,mtd_debug這個工具來測試mtd驅(qū)動也不是很好读拆,用nandwrite和nanddump這兩個工具或許更好點。然后可以用cmp這個命令來比較一下nanddump出來的數(shù)據(jù)和nandwrite寫入的數(shù)據(jù)是否一致鸵闪。