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.第一次编译
-
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/zlib-1.2.8$ find /opt/6410/4.3.2/arm-none-linux-gnueabi/ -name "libz*"
-
/opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.a
-
/opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.so.1
-
/opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.so.1.2.8
-
/opt/6410/4.3.2/arm-none-linux-gnueabi/lib/libz.so
-
/opt/6410/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/libz.a
4.第四次编译
-
sun@ubuntu:/work/6410/tools/mtd-utils$ make WITHOUT_XATTR=1
-
In file included from mkfs.ubifs/mkfs.ubifs.c:26:
-
mkfs.ubifs/mkfs.ubifs.h:46:23: error: uuid/uuid.h: No such file or directory
-
mkfs.ubifs/mkfs.ubifs.c: In function 'write_data':
-
mkfs.ubifs/mkfs.ubifs.c:1621: warning: implicit declaration of function 'time'
-
mkfs.ubifs/mkfs.ubifs.c: In function 'write_super':
-
mkfs.ubifs/mkfs.ubifs.c:1934: warning: implicit declaration of function 'uuid_generate_random'
-
mkfs.ubifs/mkfs.ubifs.c:1938: warning: implicit declaration of function 'uuid_unparse_upper'
-
make: *** [/work/6410/tools/mtd-utils/arm-none-linux-gnueabi/mkfs.ubifs/mkfs.ubifs.o] Error 1
原因: 找不到头文件uuid
解决方法:
-
sun@ubuntu:/opt/6410/4.3.2$ grep "uuid_generate_random" * -R
-
arm-none-linux-gnueabi/libc/usr/include/uuid.h:void uuid_generate_random(uuid_t out);
-
//搜索发现uuid.h是在include目录下而不是在uuid这个目录下,所以只需要改一下路径就可以了
-
sun@ubuntu:/work/6410/tools/mtd-utils$ vi mkfs.ubifs/mkfs.ubifs.h
-
46 //#include <uuid/uuid.h>
-
47 #include <uuid.h>
5.第五次编译
-
sun@ubuntu:/work/6410/tools/mtd-utils$ make WITHOUT_XATTR=1
-
CHK include/version.h
-
CC mkfs.ubifs/mkfs.ubifs.o
-
CC mkfs.ubifs/crc16.o
-
CC mkfs.ubifs/lpt.o
-
CC mkfs.ubifs/compr.o
-
CC mkfs.ubifs/devtable.o
-
CC mkfs.ubifs/hashtable/hashtable.o
-
CC mkfs.ubifs/hashtable/hashtable_itr.o
-
CC ubi-utils/libubi.o
-
AR ubi-utils/libubi.a
-
LD mkfs.ubifs/mkfs.ubifs
-
/opt/6410/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -luuid
-
collect2: ld returned 1 exit status
原因: 找不到库libuuid
解决方法:
-
sun@ubuntu:/opt/6410/4.3.2$ find . -name "libuuid*"
-
./arm-none-linux-gnueabi/libc/armv4t/usr/lib/libuuid.so.1
-
./arm-none-linux-gnueabi/libc/armv4t/usr/lib/libuuid.so
-
./arm-none-linux-gnueabi/libc/armv4t/usr/lib/libuuid.so.1.2
-
//搜索发现libuuid是在libc/armv4t/usr/lib目录下,arm-none-linux-gnueabi-ld找不到,所以加个软链接
-
sun@ubuntu:/opt/6410/4.3.2/arm-none-linux-gnueabi/lib$ ln -s ../libc/armv4t/usr/lib/libuuid.so ./libuuid.so
6.第六次编译
OK,可以了,这样就有了一大串命令
-
sun@ubuntu:/work/6410/tools/mtd-utils$ ls /tmp/mtd/sbin/
-
docfdisk flash_eraseall flash_otp_lock ftl_format mkfs.ubifs nandtest recv_image sumtool ubiformat ubirename
-
doc_loadbios flash_lock flash_otp_write jffs2dump mtd_debug nandwrite rfddump ubiattach ubimkvol ubirmvol
-
flashcp flash_otp_dump flash_unlock jffs2reader mtdinfo nftldump rfdformat ubicrc32 ubinfo ubirsvol
-
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的支持
-
Device Drivers --->
-
<*> Memory Technology Device (MTD) support --->
-
<*> Enable UBI - Unsorted block images --->
-
-
File systems --->
-
[*] Miscellaneous filesystems --->
-
<*> UBIFS file system support
2. 查看分区信息
-
root@OK6410:~# mtdinfo -u
-
Count of MTD devices: 3
-
Present MTD devices: mtd0, mtd1, mtd2
-
Sysfs interface supported: yes
或者
-
root@OK6410:~# cat /proc/mtd
-
dev: size erasesize name
-
mtd0: 00100000 00080000 "Bootloader"
-
mtd1: 00500000 00080000 "Kernel"
-
mtd2: 7fa00000 00080000 "File System"
-
root@OK6410:~# mtdinfo /dev/mtd0
-
mtd0
-
Name: Bootloader
-
Type: nand
-
Eraseblock size: 524288 bytes, 512.0 KiB
-
Amount of eraseblocks: 2 (1048576 bytes, 1024.0 KiB)
-
Minimum input/output unit size: 4096 bytes
-
Sub-page size: 4096 bytes
-
OOB size: 218 bytes
-
Character device major/minor: 90:0
-
Bad blocks are allowed: true
-
Device is writable: false
3. 将文件系统格式化为ubifs
ubiformat: a tool to format MTD devices and flash UBI images
-
root@OK6410:~# ubiformat /dev/mtd2
-
ubiformat: mtd2 (nand), size 2141192192 bytes (2.0 GiB), 4084 eraseblocks of 524288 bytes (512.0 KiB), min. I/O size 4096 bytes
-
libscan: scanning eraseblock 4083 -- 100 % complete
-
ubiformat: 4070 eraseblocks are supposedly empty
-
ubiformat: 2 bad eraseblocks found, numbers: 3, 121
-
ubiformat: 12 of 4082 eraseblocks contain non-ubifs data
-
ubiformat: continue? (y/N) y
-
ubiformat: only 0 of 4082 eraseblocks have valid erase counter
-
ubiformat: erase counter 0 will be used for all eraseblocks
-
ubiformat: note, arbitrary erase counter value may be specified using -e option
-
ubiformat: continue? (y/N) y
-
ubiformat: use erase counter 0 for all eraseblocks
-
ubiformat: formatting eraseblock 4083 -- 100 % complete
4. 将文件系统与ubi_ctrl相关联
-
root@OK6410:~# ubiattach /dev/ubi_ctrl -m 2
-
UBI: attaching mtd2 to ubi0
-
UBI: physical eraseblock size: 524288 bytes (512 KiB)
-
UBI: logical eraseblock size: 516096 bytes
-
UBI: smallest flash I/O unit: 4096
-
UBI: VID header offset: 4096 (aligned 4096)
-
UBI: data offset: 8192
-
UBI: max. sequence number: 0
-
UBI: attached mtd2 to ubi0
-
UBI: MTD device name: "File System"
-
UBI: MTD device size: 2042 MiB
-
UBI: number of good PEBs: 4082
-
UBI: number of bad PEBs: 2
-
UBI: number of corrupted PEBs: 0
-
UBI: max. allowed volumes: 128
-
UBI: wear-leveling threshold: 4096
-
UBI: number of internal volumes: 1
-
UBI: number of user volumes: 0
-
UBI: available PEBs: 4038
-
UBI: total number of reserved PEBs: 44
-
UBI: number of PEBs reserved for bad PEB handling: 40
-
UBI: max/mean erase counter: 0/0
-
UBI: image sequence number: 557638241
-
UBI: background thread "ubi_bgt0d" started, PID 96
-
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信息
-
root@OK6410:~# ubinfo -a
-
UBI version: 1
-
Count of UBI devices: 1
-
UBI control device major/minor: 10:63
-
Present UBI devices: ubi0
-
ubi0
-
Volumes count: 0
-
Logical eraseblock size: 516096 bytes, 504.0 KiB
-
Total amount of logical eraseblocks: 4082 (2106703872 bytes, 2.0 GiB)
-
Amount of available logical eraseblocks: 4038 (2083995648 bytes, 1.9 GiB)
-
Maximum count of volumes 128
-
Count of bad physical eraseblocks: 2
-
Count of reserved physical eraseblocks: 40
-
Current maximum erase counter value: 0
-
Minimum input/output unit size: 4096 bytes
-
Character device major/minor: 252:0
5. 创建volume
-
root@OK6410:~# ubimkvol /dev/ubi0 -N ubifs -m
-
Set volume size to 2083995648
-
Volume ID 0, size 4038 LEBs (2083995648 bytes, 1.9 GiB), LEB size 516096 bytes (504.0 KiB), dynamic, name "ubifs", alignment 1
-
root@OK6410:~# ubinfo -a
-
UBI version: 1
-
Count of UBI devices: 1
-
UBI control device major/minor: 10:63
-
Present UBI devices: ubi0
-
ubi0
-
Volumes count: 1
-
Logical eraseblock size: 516096 bytes, 504.0 KiB
-
Total amount of logical eraseblocks: 4082 (2106703872 bytes, 2.0 GiB)
-
Amount of available logical eraseblocks: 0 (0 bytes)
-
Maximum count of volumes 128
-
Count of bad physical eraseblocks: 2
-
Count of reserved physical eraseblocks: 40
-
Current maximum erase counter value: 1
-
Minimum input/output unit size: 4096 bytes
-
Character device major/minor: 252:0
-
Present volumes: 0
-
Volume ID: 0 (on ubi0)
-
Type: dynamic
-
Alignment: 1
-
Size: 4038 LEBs (2083995648 bytes, 1.9 GiB)
-
State: OK
-
Name: ubifs
-
Character device major/minor: 252:1
-
root@OK6410:~# mount -t ubifs ubi0_0 /mnt/ubi/
-
UBIFS: default file-system created
-
UBIFS: mounted UBI device 0, volume 0, name "ubifs"
-
UBIFS: file system size: 2078834688 bytes (2030112 KiB, 1982 MiB, 4028 LEBs)
-
UBIFS: journal size: 33546240 bytes (32760 KiB, 31 MiB, 65 LEBs)
-
UBIFS: media format: w4/r0 (latest is w4/r0)
-
UBIFS: default compressor: lzo
-
UBIFS: reserved for root: 4952683 bytes (4836 KiB)
6. 挂载ubifs
-
//创建挂载目录
-
root@OK6410:~# mkdir -p /mnt/ubi
-
//挂载
-
root@OK6410:~# mount -t ubifs ubi0_0 /mnt/ubi/
-
UBIFS: default file-system created
-
UBIFS: mounted UBI device 0, volume 0, name "ubifs"
-
UBIFS: file system size: 2078834688 bytes (2030112 KiB, 1982 MiB, 4028 LEBs)
-
UBIFS: journal size: 33546240 bytes (32760 KiB, 31 MiB, 65 LEBs)
-
UBIFS: media format: w4/r0 (latest is w4/r0)
-
UBIFS: default compressor: lzo
-
UBIFS: reserved for root: 4952683 bytes (4836 KiB)
-
-
//查看
-
root@OK6410:~# df -h
-
Filesystem Size Used Available Use% Mounted on
-
192.168.6.220:/work/6410/yaffs2/
-
147.6G 93.4G 46.8G 67% /
-
tmpfs 37.8M 0 37.8M 0% /dev/shm
-
ubi0_0 1.8G 28.0K 1.8G 0% /mnt/ubi
三. 在PC上制作ubifs镜像
1. 编译mtd-util的pc版
需要先安装uuid-dev,要不会报以下错误:
-
sun@ubuntu:/work/6410/pctools/mtd-utils$ make WITHOUT_XATTR=1
-
In file included from mkfs.ubifs/mkfs.ubifs.c:26:0:
-
mkfs.ubifs/mkfs.ubifs.h:47:18: fatal error: uuid.h: No such file or directory
-
compilation terminated.
-
make: *** [/work/6410/pctools/mtd-utils/mkfs.ubifs/mkfs.ubifs.o] Error 1
-
-
sun@ubuntu:/work/6410/pctools/mtd-utils$ sudo apt-get install uuid-dev
2.在PC机上制作ubi的镜像
-
sun@ubuntu:/work/6410/test$ sudo /tmp/mtdpc/sbin/mkfs.ubifs -r rootfs -m 4096 -e 516096 -c 4038 -o ubifs.img
-
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启动的
-
root@OK6410:~# cat /proc/mtd
-
dev: size erasesize name
-
mtd0: 00100000 00080000 "Bootloader"
-
mtd1: 00500000 00080000 "Kernel"
-
mtd2: 7fa00000 00080000 "File System"
b.格式化为ubifs
从上面可以看出mtd2是nand flash的文件系统,所以要将mtd2格式化成ubifs
-
root@OK6410:/work# ubiformat /dev/mtd2 -s 4096 -f /work/ubi.img
这儿用到了ubiformat的-f指令:把ubifs的镜像文件/work/ubi.img烧到/dev/mtd2中
c.下面检查一下是否挂载成功
root@OK6410:/work# ubiattach /dev/ubi_ctrl -m 2
-
root@OK6410:/work# mount -t ubifs ubi0:ubifs /mnt/ubi/
-
UBIFS: mounted UBI device 0, volume 0, name "ubifs"
-
UBIFS: file system size: 2078834688 bytes (2030112 KiB, 1982 MiB, 4028 LEBs)
-
UBIFS: journal size: 10452992 bytes (10208 KiB, 9 MiB, 21 LEBs)
-
UBIFS: media format: w4/r0 (latest is w4/r0)
-
UBIFS: default compressor: lzo
-
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
-
setenv bootargs "console=ttySAC0,115200 ubi.mtd=2 root=ubi0:ubifs rootfstype=ubifs"
注意: 我试过下面这个就是多加了init=linuxrc
-
setenv bootargs "console=ttySAC0,115200 ubi.mtd=2 root=ubi0:ubifs rootfstype=ubifs init=/linuxrc"
但是出现下面这个错误,所以不用加init=/linuxrc
-
VFS: Unable to mount root fs via NFS, trying floppy.
-
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
-
[<c003acac>] (unwind_backtrace+0x0/0xfc) from [<c0494430>] (dump_stack+0x18/0x1c)
-
[<c0494430>] (dump_stack+0x18/0x1c) from [<c0494494>] (panic+0x60/0x1ac)
-
[<c0494494>] (panic+0x60/0x1ac) from [<c0008fb4>] (mount_block_root+0x1bc/0x25c)
-
[<c0008fb4>] (mount_block_root+0x1bc/0x25c) from [<c00090dc>] (mount_root+0x88/0xd0)
-
[<c00090dc>] (mount_root+0x88/0xd0) from [<c0009230>] (prepare_namespace+0x10c/0x1a8)
-
[<c0009230>] (prepare_namespace+0x10c/0x1a8) from [<c00084c4>] (kernel_init+0xf0/0x130)
-
[<c00084c4>] (kernel_init+0xf0/0x130) from [<c0035a34>] (kernel_thread_exit+0x0/0x8
下面是成功的mount
-
root@OK6410:~# mount
-
rootfs on / type rootfs (rw)
-
ubi0:ubifs on / type ubifs (rw,relatime)
阅读(2428) | 评论(0) | 转发(0) |