mtd-utils 的 使用

摘要:
有关编译信息,请参阅文章“Arm Linux Migration mtd utils 1.x”。在使用命令之前,使用cat/proc/mtd检查mtdchar字符设备;或者使用ls-l/dev/mtd*cat/proc/mtddev:sizeerassesizenamemtd0:00c0000000020000“ROOTFS”mtd1:002000000000000“BOOTLOADER”mtd2:0020000000

关于编译可以查看文章:《Arm-Linux 移植 mtd-utils 1.x

查看信息

使用命令前用cat /proc/mtd 查看一下mtdchar字符设备;或者用ls -l /dev/mtd*

cat /proc/mtd
dev: size erasesize name mtd0: 00c00000
00020000 "ROOTFS"mtd1: 00200000 00020000 "BOOTLOADER"mtd2: 00200000 00020000 "KERNEL"mtd3: 03200000 00020000 "NAND ROOTFS partition"mtd4: 04b00000 00020000 "NAND DATAFS partition"

为了更详细了解分区信息用mtd_debug命令

mtd_debug info /dev/mtdX #(不能使用mtdblockX, mtdblockX 只是提供用來 mount而已)
mtd.type
=MTD_NORFLASH mtd.flags =mtd.size = 12582912(12M) mtd.erasesize = 131072(128K) mtd.oobblock = 1mtd.oobsize = 0mtd.ecctype = (unknown ECC type - new MTD API maybe?) regions = 0

mtd 有关命令

命令:flash_erase
擦除指定范围内flash的内容;如果不指定,默认擦出起始位置的第一块,使相应flash变为全1
用法:

flash_erase MTD-device [start] [cnt (# erase blocks)] [lock]
MTD-device:待擦出的分区,如/dev/mtd0
start:起始位置设置,这里必须设置为0x20000(128K)的整数倍
cnt: 从start开始计算,要擦出的块数
lock: 写保护                             
eg:  

./flash_erase /dev/mtd0 0x40000 5   //擦出mtd0分区上从0x40000开始的5块数据 ,128K/块

命令:flash_eraseall
擦除整个分区的数据,同时也会作坏块检测
用法:

flash_eraseall [OPTION] MTD_DEVICE
-q, --quiet    不显示打印信息
-j, --jffs2    一jffs2 格式化分区

eg:

./flash_eraseall -j /dev/mtd0

命令:flashcp
copy 数据到 flash 中
用法:

usage: flashcp [ -v | --verbose ] <filename> <device>flashcp -h | --help
filename:待写入的数据
device: 写入的分区,如/dev/mtd0

eg:  
filename制作:

mkfs.jffs2 -e 0x20000 -d cq8401 -o cq8401.img  -n  //这里的-e 0x20000 必须更你芯片的erasesize 相等
./flashcp cq8401.img /dev/mtd0  //copy cq8401.img文件系统到  /dev/mtd0分区中
这个命令的功能跟 dd if=/tmp/fs.img of=/dev/mtd0差不多

命令:nandwrite
向nand flash中写数据
用法:

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           writewithout 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|4set 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 /dev/mtd0  /tmp/rootfs.jffs2

命令: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数据并保存到 nandinfo.txt

命令:mtd_debug
对mtd 调试作用
用法:

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 0x0 0x40000  //擦出/dev/mtd0 分区上 从0x0开始的  , 128K*2 大小的数据
./mtd_debug write /dev/mtdblock0 ox0 0x360810 cq8401.img //向mtdblock0分区,写入 3.6M 大小的文件系统cq8401.img,这里最好用mtdblockx
./mtd_debug read  /dev/mtdblock0 ox0 0x360810 read.img  //从mtdblock0中读出 3.6M 数据保存到read.img
cmp -l cq8401.img read.img  //验证write to flash 和 read from flash 中的数据是否一致;也可以使用diff命令来比较
另外针对nand flash,mtd_debug这个工具来测试mtd驱动也不是很好,用nandwrite和nanddump这两个工具或许更好点。

然后可以用cmp这个命令来比较一下nanddump出来的数据和nandwrite写入的数据是否一致。

命令:ftl_format
解释:

In order to use one of conventional file systems (Ext2, ext3, XFS, JFS, FAT) over an MTD device,you
need a software layer which emulates a block device over the MTD device. These layers are often called
Flash Translation Layers (FTLs).

参考文章
http://blog.csdn.net/yinkaizhong/archive/2008/12/25/3604794.aspx
http://hi.baidu.com/qwetiop/blog/item/f2acb50f03e800eaab64577a.html
http://blog.chinaunix.net/u1/53103/showart_1101011.html

参考地址(节选)

http://blog.csdn.net/gzshun/article/details/7051425

免责声明:文章转载自《mtd-utils 的 使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇分享整理的免费API接口从 C++ 到 Qt(命令行编译)good下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

【转】shell命令中&amp;gt;/dev/null 2&amp;gt;&amp;amp;1的实现原理

异步执行 exec("/alidata/server/php/bin/php /nas/wxdoctor/index.php App/Common/WordsPic/user_id/".$user_info['user_id']."/goods_id/".$goods_id."."/open_id/".$user_info['open_id']." &...

webpack的使用方法

我常用的webpack版本是3.8.1版本 https://www.cnblogs.com/QxQstar/p/5961387.html    这个是他的网址 那么我们说一下webpack,他是一个前端资源加载或打包的工具,他可以打包:img,css,js,json等 第一步:下载   npm  install  -g  webpack@3.8.1    ...

1.1 关于LVM的创建、删除、扩容和缩减

一、新建LVM的过程 1.使用fdisk 新建分区 修改ID为8e 3.使用 pvcreate 创建 PV  4.使用 vgcreate 创建 VG  5.使用 lvcreate 创建 LV  6.格式化LV 7.挂载 示例过程: 1. 查看磁盘情况 # fdisk -l # lsblk 2.使用fdisk 新建分区 修改ID为8e 并更新 # fdisk...

centos7扩展根分区

参考网站:http://www.360doc.com/content/18/0128/11/52410512_725728162.shtml VirtualBox中安装了CentOS 7,给同事用来做kafka和zookeeper测试服务器。昨晚kafka意外终止,看了日志发现是/root只分配了1GiB大小,已接近饱和。开始bing,总结一下步骤: 列...

多个yml文件的读取方式

1配置pom.xml文件,以下配置将默认激活-dev.yml配置文件<profiles><profile><id>dev</id><activation><!--默认激活--><activeByDefault>true</activeByDefault><...

GIT 保存日志并建立自己的分支

以下是我个人在工作中对git的愚见全是大白话说明。也是我踩坑记录吧,防止下次再次踩坑。 再已有的dev(开发分支)新建自己的分支 (featuer)在更新到gitlab 仓库中的过程。 首先要有大致的概念 本地 git init 是创建本地并初始化本地的git仓库,本地的仓库现在和线上的仓库是两个并行的仓库(也就是现在本地和线上没毛关系) 我先假定你已经安...