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

来源:互联网 发布:乐视电视软件 编辑:程序博客网 时间:2024/06/05 00:32

 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/zlib-1.2.8$ find /opt/6410/4.3.2/arm-none-linux-gnueabi/ -name "libz*"
  12. /opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.a
  13. /opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.so.1
  14. /opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.so.1.2.8
  15. /opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.so
  16. /opt/6410/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/libz.a
4.第四次编译
  1. sun@ubuntu:/work/6410/tools/mtd-utils$ make WITHOUT_XATTR=1
  2. In file included from mkfs.ubifs/mkfs.ubifs.c:26:
  3. mkfs.ubifs/mkfs.ubifs.h:46:23: error: uuid/uuid.h: No such file or directory
  4. mkfs.ubifs/mkfs.ubifs.c: In function 'write_data':
  5. mkfs.ubifs/mkfs.ubifs.c:1621: warning: implicit declaration of function 'time'
  6. mkfs.ubifs/mkfs.ubifs.c: In function 'write_super':
  7. mkfs.ubifs/mkfs.ubifs.c:1934: warning: implicit declaration of function 'uuid_generate_random'
  8. mkfs.ubifs/mkfs.ubifs.c:1938: warning: implicit declaration of function 'uuid_unparse_upper'
  9. make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/mkfs.ubifs/mkfs.ubifs.o] Error 1
原因: 找不到头文件uuid
解决方法:
  1. sun@ubuntu:/opt/6410/4.3.2$ grep "uuid_generate_random" * -
  2.       arm-none-linux-gnueabi/libc/usr/include/uuid.h:void uuid_generate_random(uuid_t out);
  3. //搜索发现uuid.h是在include目录下而不是在uuid这个目录下,所以只需要改一下路径就可以了
  4. sun@ubuntu:/work/6410/tools/mtd-utils$ vi mkfs.ubifs/mkfs.ubifs.h
  5.  46 //#include <uuid/uuid.h>
  6.  47 #include <uuid.h>
5.第五次编译
  1. sun@ubuntu:/work/6410/tools/mtd-utils$ make WITHOUT_XATTR=1
  2.   CHK include/version.h
  3.   CC mkfs.ubifs/mkfs.ubifs.o
  4.   CC mkfs.ubifs/crc16.o
  5.   CC mkfs.ubifs/lpt.o
  6.   CC mkfs.ubifs/compr.o
  7.   CC mkfs.ubifs/devtable.o
  8.   CC mkfs.ubifs/hashtable/hashtable.o
  9.   CC mkfs.ubifs/hashtable/hashtable_itr.o
  10.   CC ubi-utils/libubi.o
  11.   AR ubi-utils/libubi.a
  12.   LD mkfs.ubifs/mkfs.ubifs
  13. /opt/6410/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -luuid
  14. collect2: ld returned 1 exit status
原因: 找不到库libuuid
解决方法:
  1. sun@ubuntu:/opt/6410/4.3.2$ find . -name "libuuid*"
  2. ./arm-none-linux-gnueabi/libc/armv4t/usr/lib/libuuid.so.1
  3. ./arm-none-linux-gnueabi/libc/armv4t/usr/lib/libuuid.so
  4. ./arm-none-linux-gnueabi/libc/armv4t/usr/lib/libuuid.so.1.2
  5. //搜索发现libuuid是在libc/armv4t/usr/lib目录下,arm-none-linux-gnueabi-ld找不到,所以加个软链接
  6. sun@ubuntu:/opt/6410/4.3.2/arm-none-linux-gnueabi/lib$ ln -../libc/armv4t/usr/lib/libuuid.so ./libuuid.so
6.第六次编译
OK,可以了,这样就有了一大串命令
  1. sun@ubuntu:/work/6410/tools/mtd-utils$ ls /tmp/mtd/sbin/
  2. docfdisk flash_eraseall flash_otp_lock ftl_format mkfs.ubifs nandtest recv_image sumtool ubiformat ubirename
  3. doc_loadbios flash_lock flash_otp_write jffs2dump mtd_debug nandwrite rfddump ubiattach ubimkvol ubirmvol
  4. flashcp flash_otp_dump flash_unlock jffs2reader mtdinfo nftldump rfdformat ubicrc32 ubinfo ubirsvol
  5. flash_erase flash_otp_info ftl_check mkfs.jffs2 nanddump nftl_format serve_image ubidetach ubinize ubiupdatevol

二. linux中ubifs的使用
NFS动系统将编译好的mtd-util复制到nfs系统中的/sbin/目录
1. 重新编译内核添加ubi与ubifs的支持
  1. Device Drivers ---> 
  2.  <*> Memory Technology Device (MTD) support ---> 
  3.      <*> Enable UBI - Unsorted block images --->     
  4.     
  5. File systems --->    
  6.  [*] Miscellaneous filesystems --->
  7.      <*> UBIFS file system support
2. 查看分区信息
  1. root@OK6410:~# mtdinfo -u
  2. Count of MTD devices: 3
  3. Present MTD devices: mtd0, mtd1, mtd2
  4. Sysfs interface supported: yes
或者
  1. root@OK6410:~# cat /proc/mtd
  2. dev: size erasesize name
  3. mtd0: 00100000 00080000 "Bootloader"
  4. mtd1: 00500000 00080000 "Kernel"
  5. mtd2: 7fa00000 00080000 "File System"
  6. root@OK6410:~# mtdinfo /dev/mtd0
  7. mtd0
  8. Name: Bootloader
  9. Type: nand
  10. Eraseblock size: 524288 bytes, 512.0 KiB
  11. Amount of eraseblocks: 2 (1048576 bytes, 1024.0 KiB)
  12. Minimum input/output unit size: 4096 bytes
  13. Sub-page size: 4096 bytes
  14. OOB size: 218 bytes
  15. Character device major/minor: 90:0
  16. Bad blocks are allowed: true
  17. Device is writable: false
3. 将文件系统格式化为ubifs
ubiformat: a tool to format MTD devices and flash UBI images
  1. root@OK6410:~# ubiformat /dev/mtd2
  2. ubiformat: mtd2 (nand), size 2141192192 bytes (2.0 GiB), 4084 eraseblocks of 524288 bytes (512.0 KiB), min. I/O size 4096 bytes
  3. libscan: scanning eraseblock 4083 -- 100 % complete 
  4. ubiformat: 4070 eraseblocks are supposedly empty
  5. ubiformat: 2 bad eraseblocks found, numbers: 3, 121
  6. ubiformat: 12 of 4082 eraseblocks contain non-ubifs data
  7. ubiformat: continue? (y/N) y
  8. ubiformat: only 0 of 4082 eraseblocks have valid erase counter
  9. ubiformat: erase counter 0 will be used for all eraseblocks
  10. ubiformat: note, arbitrary erase counter value may be specified using -option
  11. ubiformat: continue? (y/N) y
  12. ubiformat: use erase counter 0 for all eraseblocks
  13. ubiformat: formatting eraseblock 4083 -- 100 % complete
4. 将文件系统与ubi_ctrl相关联
  1. root@OK6410:~# ubiattach /dev/ubi_ctrl -m 2
  2. UBI: attaching mtd2 to ubi0
  3. UBI: physical eraseblock size: 524288 bytes (512 KiB)
  4. UBI: logical eraseblock size: 516096 bytes
  5. UBI: smallest flash I/O unit: 4096
  6. UBI: VID header offset: 4096 (aligned 4096)
  7. UBI: data offset: 8192
  8. UBI: max. sequence number: 0
  9. UBI: attached mtd2 to ubi0
  10. UBI: MTD device name: "File System"
  11. UBI: MTD device size: 2042 MiB
  12. UBI: number of good PEBs: 4082
  13. UBI: number of bad PEBs: 2
  14. UBI: number of corrupted PEBs: 0
  15. UBI: max. allowed volumes: 128
  16. UBI: wear-leveling threshold: 4096
  17. UBI: number of internal volumes: 1
  18. UBI: number of user volumes: 0
  19. UBI: available PEBs: 4038
  20. UBI: total number of reserved PEBs: 44
  21. UBI: number of PEBs reserved for bad PEB handling: 40
  22. UBI: max/mean erase counter: 0/0
  23. UBI: image sequence number: 557638241
  24. UBI: background thread "ubi_bgt0d" started, PID 96
  25. UBI device number 0, total 4082 LEBs (2106703872 bytes, 2.0 GiB), available 4038 LEBs (2083995648 bytes, 1.9 GiB), LEB size 516096 bytes (504.0 KiB)
查看ubi信息
  1. root@OK6410:~# ubinfo -a
  2. UBI version: 1
  3. Count of UBI devices: 1
  4. UBI control device major/minor: 10:63
  5. Present UBI devices: ubi0
  6. ubi0
  7. Volumes count: 0
  8. Logical eraseblock size: 516096 bytes, 504.0 KiB
  9. Total amount of logical eraseblocks: 4082 (2106703872 bytes, 2.0 GiB)
  10. Amount of available logical eraseblocks: 4038 (2083995648 bytes, 1.9 GiB)
  11. Maximum count of volumes 128
  12. Count of bad physical eraseblocks: 2
  13. Count of reserved physical eraseblocks: 40
  14. Current maximum erase counter value: 0
  15. Minimum input/output unit size: 4096 bytes
  16. Character device major/minor: 252:0
5. 创建volume
  1. root@OK6410:~# ubimkvol /dev/ubi0 -N ubifs -m
  2. Set volume size to 2083995648
  3. Volume ID 0, size 4038 LEBs (2083995648 bytes, 1.9 GiB), LEB size 516096 bytes (504.0 KiB), dynamic, name "ubifs", alignment 1
  4. root@OK6410:~# ubinfo -a
  5. UBI version: 1
  6. Count of UBI devices: 1
  7. UBI control device major/minor: 10:63
  8. Present UBI devices: ubi0
  9. ubi0
  10. Volumes count: 1
  11. Logical eraseblock size: 516096 bytes, 504.0 KiB
  12. Total amount of logical eraseblocks: 4082 (2106703872 bytes, 2.0 GiB)
  13. Amount of available logical eraseblocks: 0 (0 bytes)
  14. Maximum count of volumes 128
  15. Count of bad physical eraseblocks: 2
  16. Count of reserved physical eraseblocks: 40
  17. Current maximum erase counter value: 1
  18. Minimum input/output unit size: 4096 bytes
  19. Character device major/minor: 252:0
  20. Present volumes: 0
  21. Volume ID: 0 (on ubi0)
  22. Type: dynamic
  23. Alignment: 1
  24. Size: 4038 LEBs (2083995648 bytes, 1.9 GiB)
  25. State: OK
  26. Name: ubifs
  27. Character device major/minor: 252:1
  28. root@OK6410:~# mount -t ubifs ubi0_/mnt/ubi/
  29. UBIFS: default file-system created
  30. UBIFS: mounted UBI device 0, volume 0, name "ubifs"
  31. UBIFS: file system size: 2078834688 bytes (2030112 KiB, 1982 MiB, 4028 LEBs)
  32. UBIFS: journal size: 33546240 bytes (32760 KiB, 31 MiB, 65 LEBs)
  33. UBIFS: media format: w4/r0 (latest is w4/r0)
  34. UBIFS: default compressor: lzo
  35. UBIFS: reserved for root: 4952683 bytes (4836 KiB)
6. 挂载ubifs
  1. //创建挂载目录
  2. root@OK6410:~# mkdir -/mnt/ubi
  3. //挂载
  4. root@OK6410:~# mount -t ubifs ubi0_0 /mnt/ubi/
  5. UBIFS: default file-system created
  6. UBIFS: mounted UBI device 0, volume 0, name "ubifs"
  7. UBIFS: file system size: 2078834688 bytes (2030112 KiB, 1982 MiB, 4028 LEBs)
  8. UBIFS: journal size: 33546240 bytes (32760 KiB, 31 MiB, 65 LEBs)
  9. UBIFS: media format: w4/r0 (latest is w4/r0)
  10. UBIFS: default compressor: lzo
  11. UBIFS: reserved for root: 4952683 bytes (4836 KiB)

  12. //查看
  13. root@OK6410:~# df -h
  14. Filesystem Size Used Available Use% Mounted on
  15. 192.168.6.220:/work/6410/yaffs2/
  16.                         147.6G 93.4G 46.8G 67% /
  17. tmpfs 37.8M 0 37.8M 0% /dev/shm
  18. ubi0_0 1.8G 28.0K 1.8G 0% /mnt/ubi
三. 在PC上制作ubifs镜
1. 编译mtd-util的pc版
需要先安装uuid-dev,要不会报以下错误:
  1. sun@ubuntu:/work/6410/pctools/mtd-utils$ make WITHOUT_XATTR=1
  2. In file included from mkfs.ubifs/mkfs.ubifs.c:26:0:
  3. mkfs.ubifs/mkfs.ubifs.h:47:18: fatal error: uuid.h: No such file or directory
  4. compilation terminated.
  5. make: *** [/work/6410/pctools/mtd-utils/mkfs.ubifs/mkfs.ubifs.o] Error 1

  6. sun@ubuntu:/work/6410/pctools/mtd-utils$ sudo apt-get install uuid-dev
2.在PC机上制作ubi的镜像
  1. sun@ubuntu:/work/6410/test$ sudo /tmp/mtdpc/sbin/mkfs.ubifs -r rootfs -m 4096 -e 516096 -c 4038 -o ubifs.img
  2. sun@ubuntu:/work/6410/test$ sudo /tmp/mtdpc/sbin/ubinize -o ubi.img -m 4096 -s 4096 -p 512KiB ubifs.conf
参数解析:
-r:制定文件内容的位置                   /work/6410/test/rootfs目录下
-m:页面大小                                4096
-e:逻辑擦除块大小                        516096:Logical eraseblock size: 516096 bytes--> ubinfo -a
-p:物理擦除块大小                        512K, 这个参数是datasheet中一个block的大小
-c:最大的逻辑擦除块数量               4038:  Amount of available logical eraseblocks --> ubinfo -a
-s:最小的硬件输入输出页面大小,   Minimum input/output unit size: 4096 bytes

四. 在6410上烧写ubifs镜像,并启动
1. 在6410中将ubi.img写入到nand flash上去

a.查看文件系统的路径,注意这儿是nfs启动的
  1. root@OK6410:~# cat /proc/mtd
  2. dev: size erasesize name
  3. mtd0: 00100000 00080000 "Bootloader"
  4. mtd1: 00500000 00080000 "Kernel"
  5. mtd2: 7fa00000 00080000 "File System"
b.格式化为ubifs
从上面可以看出mtd2是nand flash的文件系统,所以要将mtd2格式化成ubifs
  1. root@OK6410:/work# ubiformat /dev/mtd2 -s 4096 -/work/ubi.img
这儿用到了ubiformat的-f指令:把ubifs的镜像文件/work/ubi.img烧到/dev/mtd2中
c.下面检查一下是否挂载成功
  root@OK6410:/work# ubiattach /dev/ubi_ctrl -m 2
  1. root@OK6410:/work# mount -t ubifs ubi0:ubifs /mnt/ubi/
  2. UBIFS: mounted UBI device 0, volume 0, name "ubifs"
  3. UBIFS: file system size: 2078834688 bytes (2030112 KiB, 1982 MiB, 4028 LEBs)
  4. UBIFS: journal size: 10452992 bytes (10208 KiB, 9 MiB, 21 LEBs)
  5. UBIFS: media format: w4/r0 (latest is w4/r0)
  6. UBIFS: default compressor: lzo
  7. UBIFS: reserved for root: 0 bytes (0 KiB)
特别注意: ubi0:ubifs 中后面这个ubifs是分区name,可以在ubimkvol中设定,我这儿设定的name=ubifs 
ubimkvol /dev/ubi0 -N ubifs -m
d. 设定u-boot中的bootargs
  1. setenv bootargs "console=ttySAC0,115200 ubi.mtd=2 root=ubi0:ubifs rootfstype=ubifs"
注意:  我试过下面这个就是多加了init=linuxrc
  1. setenv bootargs "console=ttySAC0,115200 ubi.mtd=2 root=ubi0:ubifs rootfstype=ubifs init=/linuxrc"
但是出现下面这个错误,所以不用加init=/linuxrc
  1. VFS: Unable to mount root fs via NFS, trying floppy.
  2. Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
  3. [<c003acac>] (unwind_backtrace+0x0/0xfc) from [<c0494430>] (dump_stack+0x18/0x1c)
  4. [<c0494430>] (dump_stack+0x18/0x1c) from [<c0494494>] (panic+0x60/0x1ac)
  5. [<c0494494>] (panic+0x60/0x1ac) from [<c0008fb4>] (mount_block_root+0x1bc/0x25c)
  6. [<c0008fb4>] (mount_block_root+0x1bc/0x25c) from [<c00090dc>] (mount_root+0x88/0xd0)
  7. [<c00090dc>] (mount_root+0x88/0xd0) from [<c0009230>] (prepare_namespace+0x10c/0x1a8)
  8. [<c0009230>] (prepare_namespace+0x10c/0x1a8) from [<c00084c4>] (kernel_init+0xf0/0x130)
  9. [<c00084c4>] (kernel_init+0xf0/0x130) from [<c0035a34>] (kernel_thread_exit+0x0/0x8
下面是成功的mount
  1. root@OK6410:~# mount
  2. rootfs on / type rootfs (rw)
  3. ubi0:ubifs on / type ubifs (rw,relatime)

 

原创粉丝点击