利用nandsim挂载ubi文件系统

来源:互联网 发布:minitab 两组数据分析 编辑:程序博客网 时间:2024/05/01 12:46

开发环境:Fedora15

开发工具:mtd-utils-1.4.6

注意:在linux2.6.28后才加入对ubifs的支持,开发环境主机要求至少是在linux2.6.28后的内核,且已经有nandsim,ubi等相关模块。

步骤:

1.虚拟出NANDFLASH

#modprobe mtd

#modprobe mtdblock

#modprobe nandsim first_id_byte=0xec second_id_byte=0xa1 third_id_byte=0x00 fourth_id_byte=0x15

#chmod 660 /dev/mtd0*

#ls -lah /dev/mtd*

crw-------. 1 root root 90, 0 Oct 18 15:07 /dev/mtd0         mtd字符设备

crw-------. 1 root root 90, 1 Oct 18 15:07 /dev/mtd0ro

brw-rw----. 1 root disk 31, 0 Oct 18 15:07 /dev/mtdblock0    mtd块设备,与mtd0对应

# cat /proc/mtd

dev:    size   erasesize  name

mtd0: 08000000 00020000 "NAND simulator partition 0"

大小为128MiB,擦除单元大小(一般即为块大小)128KiB,名字是"NAND simulator partition 0"

NandFlash擦除是以块(block)为单位,读写是以页(page)为单位。

查看nand的基本信息

# ./mtd-utils/ubi-utils/mtdinfo /dev/mtd0

mtd0

Name:                           NAND simulator partition 0

Type:                           nand

Eraseblock size:                131072 bytes, 128.0 KiB      擦除单元大小

Amount of eraseblocks:          1024 (134217728 bytes, 128.0 MiB)  块数*块大小=总容量

Minimum input/output unit size: 2048 bytes    最小输入输出单元

Sub-page size:                  512 bytes  子页大小

OOB size:                       64 bytes  Out-of-bank

Character device major/minor:   90:0        主,次设备号

Bad blocks are allowed:         true

Device is writable:             true

现在的nandflash一般页大小为(512+16)Bytes,(2048+64)Bytes

大小为512Bytes的可用页对应有16BytesOOB信息

大小为2048Byte的可用页对应有64BytesOOB信息

 

 

 

2.制作ubi文件系统

我是参照google到的一个创建ubi.img的脚本来生成ubi image的。

./create_ubifs.sh 页大小 每块的页数 分区大小 分区包含的块数 文件夹

:

#./create_ubifs.sh 2048 64 134217728 1024 ./rootfs

这个是与上面加载的nandsim对应的.

 

3.写入镜像到nandflash

#dd if=ubi.img of=/dev/mtd0 bs=2048

 

4.加载文件系统并attach MTD设备

#modprobe ubi

#./ubiattach /dev/ubi_ctrl -m 0 -O 2048

-m指定挂在在mtd0

-O参数用来指定VID header offset,默认是512

 

5.mount文件系统

#mount -t ubifs ubi0_0 ./mntdir

即可将文件系统挂上.

 

错误处理

mount时出错:

mount: wrong fs type, bad option, bad superblock on ubi0_0,

       missing codepage or helper program, or other error

       (for several filesystems (e.g. nfs, cifs) you might

       need a /sbin/mount. helper program)

       In some cases useful info is found in syslog - try

       dmesg | tail  or so

#dmesg

[40278.359982] UBIFS error (pid 11094): validate_sb: LEB size mismatch: 520192 in superblock, 126976 real

[40278.359987] UBIFS error (pid 11094): validate_sb: bad superblock, error 1

 

很明显能看出是由于LEB size不对造成的,而LED size是我们在mkfs.ubifs时指定的。

重新修改脚本对应命令:

./create_ubifs.sh 2048 64 134217728 1024 ./rootfs

我之前用的命令是

./create_ubifs.sh 2048 256 134217728 1024 ./rootfs

生成新的ubi.img再重新写入nandflash.

注意此时需要重新挂载mtdblock,nandsim模块。

 

:创建分卷命令

ubimkvol /dev/ubi0 -N ubi-vol0 -s 32MiB



http://blog.chinaunix.net/uid-23859284-id-2976498.html

0 0
原创粉丝点击