1.ubiattach version 1.0 - a tool to attach MTD device to UBI.
Usage: ubiattach <UBI control device node file name> [-m <MTD device number>] [-d <UBI device number>] [--mtdn=<MTD device number>] [--devn <UBI device number>]
Example 1: ubiattach /dev/ubi_ctrl -m 0 (attach MTD device 0 (mtd0) to UBI)
Example 2: ubiattach /dev/ubi_ctrl -m 0 -d 3(attach MTD device 0 (mtd0) to UBI and create UBI device number 3 (ubi3))
2.ubimkvol version 1.0 - a tool to create UBI volumes.
Usage: ubimkvol <UBI device node file name> [-h] [-a <alignment>] [-n <volume ID>] [-N <name>] [-s <bytes>] [-S <LEBs>] [-t <static|dynamic>] [-V] [-m]
[--alignment=<alignment>][--vol_id=<volume ID>] [--name=<name>] [--size=<bytes>] [--lebs=<LEBs>] [--type=<static|dynamic>] [--help] [--version]
[--maxavsize]
Example:
ubimkvol /dev/ubi0 -s 20MiB -N config_data (reate a 20 Megabytes volume named "config_data" on UBI device /dev/ubi0.)
3.ubidetach version 1.0 - a tool to remove UBI devices (detach MTD devices from UBI)
Usage: ubidetach<UBI control device node file name> [-d <UBI device number>] [-m <MTD device number>] [--devn <UBI device number>]
[--mtdn=<MTD device number>]
Example 1: ubidetach /dev/ubi_ctrl -d 2 (delete UBI device 2 (ubi2))
Example 2: ubidetach /dev/ubi_ctrl -m 0 (detach MTD device 0 (mtd0))
4.ubiformat version 1.0 - a tool to format MTD devices and flash UBI images
Usage: ubiformat <MTD device node file name> [-h] [-V] [-y] [-q] [-v][-x <num>] [-E <value>] [-s <bytes>] [-O <offs>] [-n]
[--help] [--version] [--yes] [--verbose] [--quiet][--ec=<value>] [--vid-hdr-offset=<offs>][--ubi-ver=<num>] [--no-volume-table]
Example 1: ubiformat /dev/mtd0 -y format MTD device number 0 and do not ask questions.
Example 2: ubiformat /dev/mtd0 -q -e 0format MTD device number 0,be quiet and force erase counter value 0.
使用实例
1.分区制作:将一个MTD分区挂载为UBIFS格式
● flash_eraseall /dev/mtd5 //擦除mtd5
● ubiattach /dev/ubi_ctrl -m 5 -d 0 //UBI和mtd5关联 ->ubi0
● ubimkvol /dev/ubi0 -n 0 -N rootfs0 -s 256MiB //创建分区ubi0_0设定volume 大小
● mount -t ubifs ubi0_0 /mnt/ubi或mount -t ubifs ubi0:rootfs0 /mnt/ubi //挂载
2.烧写:烧写UBIFS文件系统映像
方法一:U-Boot烧写ubifs:(mmc)
#mmcinit
#fatload mmc 0:1 81000000 ubi.img
#nand unlock
#nand ecc sw
#nand erase 680000 7980000
#nand write.i 81000000 680000 $(filesize) (或nand write.e)
方法二:在u-boot下通过nand write命令烧写
使用ubinize命令制作的带有卷标的UBIFS文件系统镜像可以直接使用nand flash的烧写命令烧写到NAND FLASH上,具体命令为:
tftp 0xc1180000 ubi.img
nand erase 0x400000 0x7c00000
nand write.e 0xc1180000 0x400000 0x3660000
关于tftp,nand 等命令使用格式请参见u-boot的help。
方法三:在u-boot下通过ubi write命令烧写
使用mkfs.ubifs命令制作的UBIFS文件系统镜像可以使用命令ubi write烧写到NAND FLASH上,具体命令为:
1. 设置FLASH的分区,此处以128M NAND FLASH为例,分为5个区:
setenv mtdids nand0=nand0
setenv mtdparts mtdparts=nand0:0x20000(u-boot env),0x20000(UBL),0x1c0000(u-boot),0x200000(kernel),0x7c00000(filesystem)
设置完后,使用mtdparts命令可以看到分区信息:
device nand0 <nand0>, # parts = 5
#: name size offset mask_flags
0: u-boot env 0x00020000 0x00000000 0
1: UBL 0x00020000 0x00020000 0
2: u-boot 0x001c0000 0x00040000 0
3: kernel 0x00200000 0x00200000 0
4: filesystem 0x07c00000 0x00400000 0
active partition: nand0,0 - (u-boot env) 0x00020000 @ 0x00000000
2. 烧写文件系统:
nand erase 0x400000 0x7c00000
tftp 0xc1180000 ubifs.img
ubi create rootfs
ubi part nand filesystem
ubi write 0xc1180000 rootfs 0x1d1000
通过以上命令,可以将文件系统烧写到第4个分区上,UBIFS文件系统卷标为rootfs。
3. 设置内核启动参数:
setenv bootargs 'console=ttyS2,115200n8 ubi.mtd=4,2048 root=ubi0:rootfs rootwait rootfstype=ubifs rw ip=off'
这样就可以将烧写的UBIFS文件系统用作根分区了。
方法四:NFS文件系统上烧写
(1)使用ubiformat工具
./ubiformat -q /dev/mtd5 -f ubi.img (ubiformat /dev/mtd4 -s 2048 -f ubi.img > /dev/null 2>&1)
我们在uboot中用nand markbad 试过mark bad block(一块在mtd device的首块,一块在中间,一块在最后),测试表面ubi在attach时的scan能认出
bad block nand skip bad block.同时用ubiformat烧写ubi.img时也会自动跳过bad block.
(2)不必烧写映像,将ROOTFS打包,解压到UBIFS
ubiattach /dev/ubi_ctrl -m 5 -d 0
ubimkvol /dev/ubi0 -n 0 -N rootfs -s 128MiB
mount -t ubifs ubi0_0 /mnt/ubi0
tar -jxv -C /mnt/ubi0 rootfs.tar.bz2
umount /mnt/ubi0
3.启动:UBI文件系统启动
设置UBIFS文件系统作为根文件系统启动的参数
#setenv bootargs console=ttyAM0,115200n8 ubi.mtd=5 root=ubi0:rootfs rootfstype=ubifs init=linuxrc
# setenv bootcmd nand read.i 80300000 280000 200000\;bootm 80300000
参考文献:
1.UBIFS分区制作及UBIFS烧写和启动 (转载)http://hi.baidu.com/dreammerge/item/57055f299e561dc9a5275a95
2.ubifs烧写到nand flash中的几种方法 http://blog.163.com/shaohj_1999@126/blog/static/63406851201212305156639/