相關命令工具
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/