目录
ubinfo
ubiformat
ubiattach
ubidetach
ubimkvol
ubirmvol
ubinize
ubiblock
ubirename
ubiupdatevol
操作示例
第一次操作
非第一次操作
内核启动后,会自动创建/dev/ubi_ctrl、/sys/class/misc/ubi_ctrl、/sys/class/ubi/version。
本部分命令所在软件包:ubi-utils
作用 |
提供从系统中找到的UBI设备、UBI卷的相关信息 |
格式 |
|
参数 |
|
-d, --devn= |
UBI device number to get information about |
-n, --vol_id= |
ID of UBI volume to print information about |
-N, --name= |
name of UBI volume to print information about |
-a, --all |
print information about all devices and volumes,or specified |
-h, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubinfo - (no arguments) print general UBI information ubinfo -d 1 - print information about UBI device number 1 ubinfo /dev/ubi0 -a - print information about all volumes of UBI device /dev/ubi0 ubinfo /dev/ubi1_0 - print information about UBI volume /dev/ubi1_0 ubinfo -a - print all information |
作用 |
格式化MTD设备,擦除Flash,保存擦除计数,写入UBI镜像到Flash; flash_erase命令有类似的效果。 详细操作: 1.从/sys/class/mtd/mtdN下的节点中读数据 3. 扫描所有块: 检查坏块、读出EC header、检查是否为ubi块、记录擦除次数
EC header是在一个擦除块的开头,而VID header的位置有几个情况: 若是nor flash有1字节操作单元,通常VID header的位置在偏移64字节处 |
格式 |
ubiformat [-Q [--vid-hdr-offset= [--no-volume-table][--flash-image= [--image-seq= [--verbose] [--help] [--version]
|
参数 |
|
-s, --sub-page-size=
|
minimum input/output unit used for UBI headers, e.g. sub-page size in case of NAND flash (equivalent to the minimum input/output unit size by default) |
-O, --vid-hdr-offset= |
offset if the VID header from start of the physical eraseblock (default is the next minimum I/O unit or sub-page after the EC header) |
-n, --no-volume-table |
only erase all eraseblock and preserve erase counters, do not write empty volume table |
-f, --flash-image= |
flash image file, or '-' for stdin |
-S, --image-size= |
bytes in input, if not reading from file |
-e, --erase-counter= |
use |
-x, --ubi-ver= |
UBI version number to put to EC headers (default is 1) |
-Q, --image-seq= |
32-bit UBI image sequence number to use (by default a random number is picked) |
-y, --yes |
assume the answer is "yes" for all question this program would otherwise ask |
-q, --quiet |
suppress progress percentage information |
-v, --verbose |
be verbose |
-h, -?, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubiformat /dev/mtd0 -y - format MTD device number 0 and do not ask questions. ubiformat /dev/mtd0 -q -e 0 - format MTD device number 0, be quiet and force erase counter value 0.
ubiformat /dev/mtd8 -s 2048 -O 2048 ubiformat: mtd8 (nand), size 41943040 bytes (40.0 MiB), 320 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes nanddump -p -c -s 0 -l 4096 /dev/mtd8 |
作用 |
链接MTD设备(MTD设备描述原始Flash设备)到UBI并且创建相应的UBI设备。 attach通过ioctl系统调用,执行内核的UBI_IOCATT操作,内核中执行attach的主要函数是ubi_attach_mtd_dev。 详细操作: 5. 创建一个ubi设备(struct ubi_device),设备节点为/dev/ubiN
会创建/dev/ubiN节点 以及 /sys/class/ubi/ubiN目录 |
格式 |
ubiattach [ [-m [-d [-p [--mtdn= [--devn= [--dev-path= [--max-beb-per1024= UBI control device defaults to /dev/ubi_ctrl if not supplied. |
参数 |
|
-d, --devn= |
the number to assign to the newly created UBI device (assigned automatically if this is not specified) |
-p, --dev-path= |
path to MTD device node to attach |
-m, --mtdn= 此选项是必须的 |
MTD device number to attach (alternative method, e.g if the character device node does not exist) 。 |
-O, --vid-hdr-offset |
VID header offset (do not specify this unless you really know what you are doing, the default should be optimal) |
-b, --max-beb-per1024 |
maximum expected bad block number per 1024 eraseblock. Allowed range is 0-768, 0 means the default kernel value. |
-h, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubiattach -p /dev/mtd0 - attach /dev/mtd0 to UBI //等价于 ubiattach -m 0 ubiattach -m 0 - attach MTD device 0 (mtd0) to UBI ubiattach -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI and create UBI device number 3 (ubi3) ubiattach -m 1 -b 25 - attach /dev/mtd1 to UBI and reserve 25*C/1024 eraseblocks for bad block handling, where C is the flash is total flash chip eraseblocks count, that is flash chip size in eraseblocks (including bad eraseblocks). E.g., if the flash chip has 4096 PEBs, 100 will be reserved.
实例: ubiattach -m 8 -d 1 执行结果: [ 366.634630] ubi1: attaching mtd8
flash physical eraseblock size:从flash芯片手册中可以得到FLASH物理擦除块大小,或cat /proc/mtd sub-page size: 通过flash手册获得 logical eraseblock size: 对于没有子页的NAND FLASH来说:等于peb(物理擦除块大小) 对于有子页的NAND FLASH来说,等于“物理擦除块大小-1页的大小” |
作用 |
ubiattach相反的操作,将MTD设备从UBI设备上去链接。 注意,在使用此命令之前,先要umount掉。 |
格式 |
ubidetach [ [-d [-m [-p [--devn= [--mtdn= [--dev-path= UBI control device defaults to /dev/ubi_ctrl if not supplied. |
参数 |
|
-d, --devn= |
the number to assign to the newly created UBI device (assigned automatically if this is not specified) |
-p, --dev-path= |
path to MTD device node to attach |
-m, --mtdn= |
MTD device number to attach (alternative method, e.g if the character device node does not exist) |
-O, --vid-hdr-offset |
VID header offset (do not specify this unless you really know what you are doing, the default should be optimal) |
-b, --max-beb-per1024 |
maximum expected bad block number per 1024 eraseblock. The default value is correct for most NAND devices. Allowed range is 0-768, 0 means the default kernel value. |
-h, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubidetach -p /dev/mtd0 - detach MTD device /dev/mtd0 ubidetach -d 2 - delete UBI device 2 (ubi2) ubidetach -m 0 - detach MTD device 0 (mtd0) |
作用 |
从UBI设备上创建UBI卷。 详细操作: 其实ubiattach要分两种情况:mtd设备已经有制作卷了,或者是没有制作卷。判断依据就是VIDheader里面的卷ID。 |
格式 |
ubimkvol [-h] [-a [-s [--alignment= [--version] [--maxavsize] |
参数 |
|
-a, --alignment= |
volume alignment (default is 1) |
-n, --vol_id= |
UBI volume ID, if not specified, the volume ID will be assigned automatically |
-N, --name= |
volume name |
-s, --size= |
volume size volume size in bytes, kilobytes (KiB) or megabytes (MiB) |
-S, --lebs= |
alternative way to give volume size in logical eraseblocks |
-m, --maxavsize |
set volume size to maximum available size |
-t, --type= |
volume type (dynamic, static), default is dynamic |
-h, -?, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubimkvol /dev/ubi0 -s 20MiB -N config_data - create a 20 Megabytes volume named "config_data" on UBI device /dev/ubi0.
ubimkvol /dev/ubi1 -N app_pri -m Set volume size to 37584896 |
作用 |
从UBI设备上删除UBI卷 |
格式 |
ubirmvol |
参数 |
|
-a, --alignment= |
volume alignment (default is 1) |
-m, --maxavsize |
set volume size to maximum available size |
-n, --vol_id= |
volume ID to remove |
-N, --name= |
volume name to remove |
-h, -?, --help |
print help message |
-s, --size= |
volume size volume size in bytes, kilobytes (KiB) or megabytes (MiB) |
-S, --lebs= |
alternative way to give volume size in logical eraseblocks |
-t, --type= |
volume type (dynamic, static), default is dynamic |
-h, -?, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubirmvol /dev/ubi0 -n 1 - remove UBI volume 1 from UBI device corresponding to /dev/ubi0 ubirmvol /dev/ubi0 -N my_vol - remove UBI named "my_vol" from UBI device corresponding to /dev/ubi0 |
作用 |
制作UBI镜像 |
格式 |
ubinize [-o filename] [-p [-e [--output= [--min-io-size= [--vid-hdr-offset= [--ubi-ver= [--help] [--version] ini-file |
参数 |
|
-o, --output= |
output file name |
-p, --peb-size=
|
size of the physical eraseblock of the flash this UBI image is created for in bytes, kilobytes (KiB), or megabytes (MiB) (mandatory parameter) |
-m, --min-io-size= |
minimum input/output unit size of the flash in bytes |
-s, --sub-page-size= |
minimum input/output unit used for UBI headers, e.g. sub-page size in case of NAND flash (equivalent to the minimum input/output unit size by default) |
-O, --vid-hdr-offset= |
offset if the VID header from start of the physical eraseblock (default is the next minimum I/O unit or sub-page after the EC header) |
-e, --erase-counter= |
the erase counter value to put to EC headers (default is 0) |
-x, --ubi-ver= |
UBI version number to put to EC headers (default is 1) |
-Q, --image-seq= |
32-bit UBI image sequence number to use (by default a random number is picked) |
-v, --verbose |
be verbose |
-h, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubinize -o ubi.img -p 16KiB -m 512 -s 256 cfg.ini - create UBI image 'ubi.img' as described by configuration file 'cfg.ini' |
作用 |
管理UBI卷上的block(创建/删除) |
格式 |
ubiblock [-c,-r] |
参数 |
|
-c, --create |
create block on top of a volume |
-r, --remove |
remove block from volume |
-h, --help |
print help message |
-V, --version |
print program version |
示例 |
|
ubiblock --create /dev/ubi0_0 |
作用 |
更改ubi某个olume的名字,或者完成两个volume的互换 |
格式 |
ubirename |
示例 |
|
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 3. 把volume A的名字改为B,把volume C的名字改为D ubirename/dev/ubi0 A B C D |
作用 |
向UBI volume里边写数据 |
格式 |
ubiupdatevol [--truncate] [--size= |
参数 |
|
-t, --truncate |
truncate volume (wipe it out) |
-s, --size= |
bytes to read from input |
--skip= |
leading bytes to skip from input |
-h, --help |
print help message |
-V, --version |
print program version |
示例 |
|
1. write file "fs.img" to UBI volume /dev/ubi0_1 ubiupdatevol /dev/ubi0_1 fs.img 2. wipe out UBI volume /dev/ubi0_1 ubiupdatevol /dev/ubi0_1 -t |
ubiformat /dev/mtd8 -s 0x800 -O 0x800
ubiattach -m 8 -d 1 /dev/ubi_ctrl //会出现/dev/ubi1节点
ubimkvol /dev/ubi1 -N app_pri -m //会出现/dev/ubi1_0节点
mount -t ubifs /dev/ubi1_0 /mnt
//注意:ubiattach 生成/dev/ubiM和ubimkvol生成/dev/ubiM_N需要时间,要等待其生成节点之后再mount
示例等待命令(shell):
/usr/sbin/ubiattach -m 8 -d 1 /dev/ubi_ctrl
if [ $? == 0 ]; then
loop=0
while [ "$((loop++))" -lt "6" ]
do
echo "waiting for /dev/ubi1."
if [ -e /dev/mtd1 ]; then
echo "/dev/ubi1 appear"
break
fi
/bin/sleep 1
done
else
echo "ubiattach -m 8 -d 1failed!"
exit 1
fi
// umount /dav
// ubidetach /dev/ubi_ctrl -d 1
ubiattach -m 8 -d 1 /dev/ubi_ctrl //会出现/dev/ubi1节点
mount -t ubifs /dev/ubi1_0 /mnt
mount打印:
# mount -t ubifs /dev/ubi1_0 /mnt/
[ 52.943452] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 274
[ 53.387663] UBIFS (ubi1:0): recovery needed
[ 54.160605] UBIFS (ubi1:0): recovery completed
[ 54.169441] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "app_pri"
[ 54.181077] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 54.195172] UBIFS (ubi1:0): FS size: 36315136 bytes (34 MiB, 286 LEBs), journal size 1777664 bytes (1 MiB, 14 LEBs)
[ 54.209642] UBIFS (ubi1:0): reserved for root: 1715252 bytes (1675 KiB)
[ 54.219050] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID 0C991C90-92CF-4740-A810-7114851BC829, small LPT model