1. mkfs.ubifs
mkfs.ubifs生成的image可以用来在linux kernnel里面更新ubi volume。
其使用方法如下:
mkfs.ubifs -r root-tree -F -m 4096 -e 258048 -c 362 -o ti.ubifs
-r 后面跟文件系统的tree
-F --space-fixup, 如果要基于ti.ubifs来制作使用u-boot来烧写的ubi.img,这个flag一定要选啊
-m min i/o size
-e logical 擦除块的大小
-c 逻辑擦除块的数目
-o 目标生成文件
下面是使用ti.ubifs更新ubi vlomue的例子:
flash_eraseall /dev/mt7
ubiattach /dev/ubi_ctrl -m 7
ubimkvol /dev/ubi0 -N rootfs -s 85MiB
ubiupdatevol /dev/ubi0_0 ti.ubifs
mount /dev/ubi0_0 /mnt/ubi0
就可以看到ubifs的内容了
2. ubinize
ubinize用来制作u-boot下烧写用的ubifs的image。
其使用方法如下:
ubinize -o ubi.img -m 4096 -p 256KiB -s 1024 ubinize.cfg
-o 后跟目标image文件名,这个ubi.img可以在u-boot里面进行烧写
-m minimum io size
-p 物理擦除块的大小
-s subpage的大小
ubinize.cfg 是生成ubi.img的配置文件,内容如下。
#cat ubinize.cfg
[ubifs]
mode=ubi
image=ti.ubifs
vol_id=0
vol_size=80MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
其中
"image=ti.ubifs"指明使用上文所述的ti.ubifs作为输入。
"vol_name=rootfs"指明volume的name.
"vol_size=80MiB"指明fs的总大小。
下面是u-boot烧写ubi.img的方法
当前是写48MB, 需要根据实际调整.
U-Boot# mw.b 0x82000000 0xFF 0x3000000
U-Boot# tftp 0x82000000 ubi.img
U-Boot# nand erase 0x1000000 0x7000000 /* 将整个mtd都擦掉了 */
U-Boot# nand write 0x82000000 0x1000000 0x3000000
在kernel里面也可以将ubi.img烧写到mtd分区里。
#ubiformat /dev/mtd7 -f ubi.img -s 4096
3. 如何知道min i/o size,logical 擦除块的大小呢?
ubinfo /dev/ubi0 可以看到i/o size, 实际上也是page size,这里的page大小是4096字节
logical 擦除块的大小,通常比物理擦除块的小一点。比如东芝的"TC58NVG3S0H 8G 3.3V 8 bit"的物理擦除块是256KiB, 而逻辑擦除块的大小只有252KiB
逻辑擦除块的数目实际是文件系统最大将会使用的擦除块的数目。比如说,我准备使用50M的空间,而擦除块的大小是252KiB,那么大约200个逻辑擦除块就够了
root@localhost:/mnt# ubinfo /dev/ubi0
ubi0
Volumes count: 1
Logical eraseblock size: 258048 bytes, 252.0 KiB
Total amount of logical eraseblocks: 448 (115605504 bytes, 110.2 MiB)
Amount of available logical eraseblocks: 18 (4644864 bytes, 4.4 MiB)
Maximum count of volumes 128
Count of bad physical eraseblocks: 0
Count of reserved physical eraseblocks: 80
Current maximum erase counter value: 2
Minimum input/output unit size: 4096 bytes
Character device major/minor: 247:0
Present volumes: 0
root@localhost:/mnt# ubinfo /dev/ubi0_0
Volume ID: 0 (on ubi0)
Type: dynamic
Alignment: 1
Size: 346 LEBs (89284608 bytes, 85.1 MiB)
State: OK
Name: rootfs
Character device major/minor: 247:1
mtd7
Name: NAND.file-system
Type: nand
Eraseblock size: 262144 bytes, 256.0 KiB
Amount of eraseblocks: 448 (117440512 bytes, 112.0 MiB)
Minimum input/output unit size: 4096 bytes
Sub-page size: 1024 bytes
OOB size: 256 bytes
Character device major/minor: 90:14
Bad blocks are allowed: true
Device is writable: true
4. linux kernel使用ubifs启动时需要的bootargs
root@localhost:/mnt# cat /proc/mtd
dev: size erasesize name
mtd0: 00040000 00040000 "NAND.dt"
mtd1: 00040000 00040000 "NAND.dt.backup"
mtd2: 00080000 00040000 "NAND.hardinfo"
mtd3: 000c0000 00040000 "NAND.u-boot"
mtd4: 00040000 00040000 "NAND.u-boot-env"
mtd5: 00800000 00040000 "NAND.userdata"
mtd6: 00600000 00040000 "NAND.kernel"
mtd7: 07000000 00040000 "NAND.file-system"
mtd8: 08000000 00040000 "NAND.hmidata"
mtd9: 10000000 00040000 "NAND.prjdata"
需要在bootargs中指出使用的内核ubiattach使用哪一个mtd
如:ubi.mtd=NAND.file-system,1024 其中“NAND.file-system”是mtd7的名字, “1024”是vid header的偏移。
也可以不用mtd的名字,而是使用mtd的编号,如:ubi.mtd=7,1024 其中7是mtd的编号
或者不指定header的偏移,如:ubi.mtd=7
需要在bootargs中指出使用的内核使用的ubi volume name,如root=ubi0:rootfs, 这个rootfs是在ubinize.cfg中指明的。ubimkvol中也会指明volume的name。也可以写成root=ubi0_0
例1:
"setenv bootargs console=ttyS0,115200n8 root=ubi0:rootfs
rw ubi.mtd=NAND.file-system,1024 rootfstype=ubifs rootwait=1;tftp
0x82000000 zImage; tftp 0x88000000 snd.dtb; bootz 0x82000000 -
0x88000000"
例2:
"setenv bootargs console=ttyS0,115200n8 root=ubi0:rootfs
rw ubi.mtd=7,1024 rootfstype=ubifs rootwait=1;tftp
0x82000000 zImage; tftp 0x88000000 snd.dtb; bootz 0x82000000 -
0x88000000"
例3:
"setenv bootargs console=ttyS0,115200n8 root=ubi0:rootfs
rw ubi.mtd=7 rootfstype=ubifs rootwait=1;tftp
0x82000000 zImage; tftp 0x88000000 snd.dtb; bootz 0x82000000 -
0x88000000"
5.What is the the purpose of the -F (--space-fixup) mkfs.ubifs option?
Because of subtle ECC errors that can arise when programming NAND flash
(see ), ubiformat is the recommended way of flashing a UBI image which contains a UBIFS file
system. However, this is not always possible - for example, some embedded
devices are manufactured using an industrial NAND flash programmer which has
no knowledge of UBI or UBIFS.
The -F option causes mkfs.ubifs to set a special
flag in the superblock, which triggers a "free space fixup" procedure in the
kernel the very first time the filesystem is mounted. This fixup procedure
involves finding all empty pages in the UBIFS file system and re-erasing them.
This ensures that NAND pages which contain all 0xFF data get
fully erased, which removes any problematic non-0xFF data from
their OOB areas.
Of course it is not possible to re-erase individual NAND pages, and entire
PEBs are erased. UBIFS performs this procedure by reading the useful
(non 0xFF'ed) contents of LEBs and then invoking the UBI operation. Obviously,
this means that UBIFS has to read and write a lot of LEBs which takes
time. But this happens only once, and the "free space fixup" procedure then
unsets the "fixup" UBIFS superblock flag.
This option is supported if you are running a kernel version 3.0 or higher, or if you have pulled the changes from a UBIFS . Note that ubiformat is still the preferred flashing method if the image is
not being flashed for the first time, since it preserves existing erase
counters (while using nandwrite or its equivalent does not).
6.