http://blog.sina.com.cn/s/blog_5d9051c00100ek1j.html
NAND是嵌入式系统一个很重要的部件,而mtd-utilts中包含了很多针对NAND的调试和测试的工具。
1. 在http://git.infradead.org/mtd-utils.git上下载最新的mtd-utils代码, 下面是以2009-07-03的代码为例。
2. 解压缩mtd-utils.tgz
3. cd mtd-utils,编辑common.mk: 增加CROSS=arm-linux-
4. 执行make即可。
在mtd-utils中生成的主要工具有:
(1) flash_eraseall, 用于擦除指定的MTD分区, 用法如下:
./flash_eraseall /dev/mtd1 擦除MTD1
./flash_eraseall -j /dev/mtd1 擦除MTD1并将其格式化为JFFS2
(2) nanddump, 打印(或保存)NAND中的内容,用法如下:
./nanddump -s 0 -l 8024 -f result.dat /dev/mtd1 将mtd1中从地址0开始的8024长度的内容保存到result.dat中,(缺省的,包含OOB的内容)
注意,用vi或vim查看result.dat的内容时是2进制,在命令模式下,输入%!xxd即可转换为十六进制的可读内容。
(3) 其他的还有nandwrite, nandtest等。
在mtd-utils/ubi-utils中生成的工具是针对UBIFS的,包含:
(1)mtdinfo: 输出指定的mtd分区的信息, 该命令只对可读的设备分区有效。
用法: ./mtdinfo /dev/mtd1
(2)ubinfo: 输出指定的ubi设备的信息,不带参数时,输出系统所有的ubi设备以及ubi控制设备信息。ubi控制设备即/dev/ubi_ctrl是一个字符设备,在后面还将用到。
用法:./ubinfo
./ubinfo /dev/ubi0
(3)ubiformat:格式化指定的mtd分区, 参数使用的是mtd的字符设备
用法:./ubiformat /dev/mtd1
(4)ubiattach:将指定的mtd分区关联到ubi上
用法:./ubiattach /dev/ubi_ctrl -m 1, 将mtd1关连ubi
(5)ubidetach:解除mtd与ubi的关联
用法:./ubidetach /dev/ubi_ctrl -m 1
(6)ubimkvol:创建一个voluem,volume才是最终用户挂载文件系统的地方。
用法:在ubi2上创建4个olume,每个大小是20M, 名字分别为my_vol_a, my_vol_b, my_vol_c, my_vol_d.
./ubimkvol /dev/ubi2 -s 20Mib -N my_vol_a
./ubimkvol /dev/ubi2 -s 20Mib -N my_vol_b
./ubimkvol /dev/ubi2 -s 20Mib -N my_vol_c
./ubimkvol /dev/ubi2 -s 20Mib -N my_vol_d
(7)ubirename: 更改ubi某个olume的名字,或者完成两个volume的互换
用法:
(1)将ubi2上名字为my_vol_a的volume名字改为my_vol_newname
./ubirename /dev/ubi2 my_vol_a my_vol_newname
(2)将ubi2上名字为my_vol_b和my_vol_c的两个volume互换,
./ubirename /dev/ubi2 my_vol_b my_vol_c my_vol_c my_vol_b
(8)ubirmvol: 删除某个volume,可以通过名字或id指定具体的volume
用法: ./ubirmvol /dev/ubi2 -n 1
或./ubirmvol /dev/ubi2 -N my_vol_d
(9)ubinize: 创建ubi image。
用法: ./ubinize -o myubi.img -p 126976 -m 2048 my.ini
其中, -p, 指定的是目标flash的physical eraseblock的大小
-s, 指定的是目标flash的minimum input/output unit 的大小, 这两个参数的值可以通过“cat /sys/class/ubi/ubi2/*”得到
my.ini是配置文件,其中指定了原文件,目标volume的大小、名字等。其格式如小:
[jffs2-volume]
mode=ubi
image=../jffs2.img
vol_id=1
vol_size=30MiB
vol_type=dynamic
vol_name=jffs2_volume
vol_flags=autoresize
vol_alignment=1
(10)ubiupdatevol: 向指定的volume上写数据
用法:./ubiupdatevol /dev/ubi2_0 myubi.img
-------------------------------------------------------------------------------------------
12:29:35
分类: LINUX
一.mtd-utils编译过程
下载:
sun@ubuntu:/work/6410/tools$ git clone git://git.infradead.org/mtd-utils.git
修改Makefile
sun@ubuntu:/work/6410/tools/mtd-utils$ vi common.mk
1 CROSS=arm-none-linux-gnueabi- ;指定交叉编译器
25 PREFIX=/tmp/mtd
1.第一次编译
-
sun@ubuntu:/work/6410/tools/mtd-utils$
make -
CHK include/version.h
-
LD ftl_format
-
CC flash_erase.o
-
LD flash_erase
-
CC nanddump.o
-
LD nanddump
-
CC doc_loadbios.o
-
LD doc_loadbios
-
CC ftl_check.o
-
LD ftl_check
-
CC mkfs.jffs2.o
-
mkfs.jffs2.c:70:21: error: sys/acl.h: No
such file or directory -
mkfs.jffs2.c: In function 'formalize_posix_acl':
-
mkfs.jffs2.c:1024: error: 'ACL_USER_OBJ' undeclared (first
use in this function) -
mkfs.jffs2.c:1024: error: (Each undeclared
identifier is reported only once -
mkfs.jffs2.c:1024: error: for each function it
appears in.) -
mkfs.jffs2.c:1025: error: 'ACL_GROUP_OBJ' undeclared (first
use in this function) -
mkfs.jffs2.c:1026: error: 'ACL_MASK' undeclared (first
use in this function) -
mkfs.jffs2.c:1027: error: 'ACL_OTHER' undeclared (first
use in this function) -
mkfs.jffs2.c:1033: error: 'ACL_USER' undeclared (first
use in this function) -
mkfs.jffs2.c:1034: error: 'ACL_GROUP' undeclared (first
use in this function) - make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/mkfs.jffs2.o] Error 1
原因: 编译时调用acl.h了而没有调用zlib库
解决方法:指定WITHOUT_XATTR=1 指定编译时要调用zlib库
2.第二次编译
-
sun@ubuntu:/work/6410/tools/mtd-utils$
make WITHOUT_XATTR=1 -
CHK include/version.h
-
CC mkfs.jffs2.o
-
CC compr_rtime.o
-
CC compr_zlib.o
-
CC compr_lzo.o
-
compr_lzo.c:31:23: error: lzo/lzo1x.h: No
such file or directory -
compr_lzo.c: In function 'jffs2_lzo_cmpr':
-
compr_lzo.c:53: error: 'lzo_uint' undeclared (first
use in this function) -
compr_lzo.c:53: error: (Each undeclared
identifier is reported only once -
compr_lzo.c:53: error: for each function it
appears in.) -
compr_lzo.c:53: error: expected ';' before 'compress_size'
-
compr_lzo.c:56: warning: implicit
declaration of function 'lzo1x_999_compress' -
compr_lzo.c:56: error: 'compress_size' undeclared (first
use in this function) -
compr_lzo.c:58: error: 'LZO_E_OK' undeclared (first
use in this function) -
compr_lzo.c: In function 'jffs2_lzo_decompress':
-
compr_lzo.c:74: error: 'lzo_uint' undeclared (first
use in this function) -
compr_lzo.c:74: error: expected ';' before 'dl'
-
compr_lzo.c:76: warning: implicit
declaration of function 'lzo1x_decompress_safe' -
compr_lzo.c:76: error: 'dl' undeclared (first
use in this function) -
compr_lzo.c:78: error: 'LZO_E_OK' undeclared (first
use in this function) -
compr_lzo.c: In function 'jffs2_lzo_init':
-
compr_lzo.c:97: error: 'LZO1X_999_MEM_COMPRESS' undeclared (first
use in this function) - make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/compr_lzo.o] Error 1
原因: 没有lzo库
解决方法:编译lzo库,并添加到交叉编译工具链中
-
sun@ubuntu:/work/6410/tools/mtd-utils$
cd .. -
sun@ubuntu:/work/6410/tools$
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz //下载lzo库 -
sun@ubuntu:/work/6410/tools$
ls -
lzo-2.06.tar.gz
mtd-utils -
//下面的config指定交叉编译器
-
sun@ubuntu:/work/6410/tools/lzo-2.06$
CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-linux --prefix=/opt/6410/4.3.2/arm-none-linux-gnueabi/ - //编译
-
sun@ubuntu:/work/6410/tools/lzo-2.06$
make && make install -
//确认在工具链目录中是否己经有头文件了
-
sun@ubuntu:/work/6410/tools/lzo-2.06$
find /opt/6410/4.3.2/ -name "lzo1x.h" - /opt/6410/4.3.2/arm-none-linux-gnueabi/include/lzo/lzo1x.h
3.第三次编译
-
sun@ubuntu:/work/6410/tools/mtd-utils$
make WITHOUT_XATTR=1 -
CHK include/version.h
-
LD mkfs.jffs2
-
/opt/6410/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: cannot
find -lz -
collect2: ld returned 1 exit status
- make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/mkfs.jffs2] Error 1
原因: 没有libz库
解决方法:编译libz库,并添加到交叉编译工具链中
-
sun@ubuntu:/work/6410/tools$
wget http://zlib.net/zlib-1.2.8.tar.gz //下载lzo库 -
sun@ubuntu:/work/6410/tools$
ls -
lzo-2.06 lzo-2.06.tar.gz
lzo-2.06.tar.gz.1
mtd-utils zlib-1.2.8.tar.gz -
sun@ubuntu:/work/6410/tools$
tar xf zlib-1.2.8.tar.gz -
sun@ubuntu:/work/6410/tools$
cd zlib-1.2.8/ -
//下面的config指定交叉编译器
-
sun@ubuntu:/work/6410/tools/zlib-1.2.8$
CC=arm-none-linux-gnueabi-gcc ./configure --shared --prefix=/opt/6410/4.3.2/arm-none-linux-gnueabi/ -
//编译并安装到工具链目录中
-
sun@ubuntu:/work/6410/tools/zlib-1.2.8$
make && make install - //确认在工具链目录中是否己经有库了
- sun@ubuntu:/work/6410/tools