现在的位置: 首页 > 综合 > 正文

mtd———-嵌入式——————-

2014年02月02日 ⁄ 综合 ⁄ 共 6507字 ⁄ 字号 评论关闭

 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
 


-------------------------------------------------------------------------------------------

 OKC6410使用---30让ubifs作rootfs 2013-08-23
12:29:35

分类: LINUX

                   by wangcong02345
                               欢迎转载,但请注明出处
                               http://blog.chinaunix.net/blog/post/id/3862627.html

一.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.第一次编译

  1. sun@ubuntu:/work/6410/tools/mtd-utils$
    make
  2.   CHK include/version.h
  3.   LD ftl_format
  4.   CC flash_erase.o
  5.   LD flash_erase
  6.   CC nanddump.o
  7.   LD nanddump
  8.   CC doc_loadbios.o
  9.   LD doc_loadbios
  10.   CC ftl_check.o
  11.   LD ftl_check
  12.   CC mkfs.jffs2.o
  13. mkfs.jffs2.c:70:21: error: sys/acl.h: No
    such file or directory
  14. mkfs.jffs2.c: In function 'formalize_posix_acl':
  15. mkfs.jffs2.c:1024: error: 'ACL_USER_OBJ' undeclared (first
    use in this function)
  16. mkfs.jffs2.c:1024: error: (Each undeclared
    identifier is reported only once
  17. mkfs.jffs2.c:1024: error: for each function it
    appears in.)
  18. mkfs.jffs2.c:1025: error: 'ACL_GROUP_OBJ' undeclared (first
    use in this function)
  19. mkfs.jffs2.c:1026: error: 'ACL_MASK' undeclared (first
    use in this function)
  20. mkfs.jffs2.c:1027: error: 'ACL_OTHER' undeclared (first
    use in this function)
  21. mkfs.jffs2.c:1033: error: 'ACL_USER' undeclared (first
    use in this function)
  22. mkfs.jffs2.c:1034: error: 'ACL_GROUP' undeclared (first
    use in this function)
  23. make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/mkfs.jffs2.o] Error 1

原因:  编译时调用acl.h了而没有调用zlib库
解决方法:指定WITHOUT_XATTR=1 指定编译时要调用zlib库

2.第二次编译

  1. sun@ubuntu:/work/6410/tools/mtd-utils$
    make WITHOUT_XATTR=1
  2.   CHK include/version.h
  3.   CC mkfs.jffs2.o
  4.   CC compr_rtime.o
  5.   CC compr_zlib.o
  6.   CC compr_lzo.o
  7. compr_lzo.c:31:23: error: lzo/lzo1x.h: No
    such file or directory
  8. compr_lzo.c: In function 'jffs2_lzo_cmpr':
  9. compr_lzo.c:53: error: 'lzo_uint' undeclared (first
    use in this function)
  10. compr_lzo.c:53: error: (Each undeclared
    identifier is reported only once
  11. compr_lzo.c:53: error: for each function it
    appears in.)
  12. compr_lzo.c:53: error: expected ';' before 'compress_size'
  13. compr_lzo.c:56: warning: implicit
    declaration of function 'lzo1x_999_compress'
  14. compr_lzo.c:56: error: 'compress_size' undeclared (first
    use in this function)
  15. compr_lzo.c:58: error: 'LZO_E_OK' undeclared (first
    use in this function)
  16. compr_lzo.c: In function 'jffs2_lzo_decompress':
  17. compr_lzo.c:74: error: 'lzo_uint' undeclared (first
    use in this function)
  18. compr_lzo.c:74: error: expected ';' before 'dl'
  19. compr_lzo.c:76: warning: implicit
    declaration of function 'lzo1x_decompress_safe'
  20. compr_lzo.c:76: error: 'dl' undeclared (first
    use in this function)
  21. compr_lzo.c:78: error: 'LZO_E_OK' undeclared (first
    use in this function)
  22. compr_lzo.c: In function 'jffs2_lzo_init':
  23. compr_lzo.c:97: error: 'LZO1X_999_MEM_COMPRESS' undeclared (first
    use in this function)
  24. make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/compr_lzo.o] Error 1

原因: 没有lzo库
解决方法:编译lzo库,并添加到交叉编译工具链中

  1. sun@ubuntu:/work/6410/tools/mtd-utils$
    cd ..
  2. sun@ubuntu:/work/6410/tools$
    wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz   //下载lzo库
  3. sun@ubuntu:/work/6410/tools$
    ls
  4. lzo-2.06.tar.gz
    mtd-utils
  5. //下面的config指定交叉编译器
  6. 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/
  7. //编译
  8. sun@ubuntu:/work/6410/tools/lzo-2.06$
    make && make install
  9. //确认在工具链目录中是否己经有头文件了
  10. sun@ubuntu:/work/6410/tools/lzo-2.06$
    find /opt/6410/4.3.2/ -name "lzo1x.h"
  11. /opt/6410/4.3.2/arm-none-linux-gnueabi/include/lzo/lzo1x.h

3.第三次编译

  1. sun@ubuntu:/work/6410/tools/mtd-utils$
    make WITHOUT_XATTR=1
  2.   CHK include/version.h
  3.   LD mkfs.jffs2
  4. /opt/6410/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: cannot
    find -lz
  5. collect2: ld returned 1 exit status
  6. make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/mkfs.jffs2] Error 1

原因: 没有libz库
解决方法:编译libz库,并添加到交叉编译工具链中

  1. sun@ubuntu:/work/6410/tools$
    wget http://zlib.net/zlib-1.2.8.tar.gz   //下载lzo库
  2. sun@ubuntu:/work/6410/tools$
    ls
  3. lzo-2.06 lzo-2.06.tar.gz
    lzo-2.06.tar.gz.1
    mtd-utils zlib-1.2.8.tar.gz
  4. sun@ubuntu:/work/6410/tools$
    tar xf zlib-1.2.8.tar.gz 
  5. sun@ubuntu:/work/6410/tools$
    cd zlib-1.2.8/
  6. //下面的config指定交叉编译器
  7. 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/
  8. //编译并安装到工具链目录中
  9. sun@ubuntu:/work/6410/tools/zlib-1.2.8$
    make && make install
  10. //确认在工具链目录中是否己经有库了
  11. sun@ubuntu:/work/6410/tools

抱歉!评论已关闭.