The UBI and UBIFS images depend on parameters of the flash they are going to be used on. Namely, you have to know the following characteristics of the flash before creating images:
- MTD partition size;
- flash physical eraseblock size;
- minimum flash input/output unit size;
- for NAND flashes - sub-page size;
- logical eraseblock size.
UBI文件头部信息 *.cfg文件
Volume table is an on-flash data structure which contains information about each volume on this UBI device. The volume table is an array of volume table records. Each record contains the following information:
- volume size;
- volume name;
- volume type (dynamic or static);
- volume alignment;
- update marker (set for volumes which had interrupted updates;
- auto-resize flag
The below example demonstrates how to create an UBI/UBIFS image for a 256MiB SLC OneNAND flash chip with 128KiB physical eraseblocks, 2048-byte NAND pages, and 512-byte sub-pages (this means that it allows to do 4x512 bytes writes to the same NAND page, which is quite typical for SLC flashes). The resulting image will have only one UBI volume storing UBIFS file-system.
$ mkfs.ubifs -q -r root-fs -m 2048 -e 129024 -c 2047 -o ubifs.img
$ ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg
where ubinize.cfg
contains:
$ cat ubinize.cfg [ubifs] mode=ubi image=ubifs.img vol_id=0 vol_size=200MiB vol_type=dynamic vol_name=rootfs vol_flags=autoresize
Some comments about what the options mean:
-r root-fs
: tellsmkfs.ubifs
to create an UBIFS image which would have identical contents as the localroot-fs
directory;-m 2048
: tellsmkfs.ubifs
that the minimum input/output unit size of the flash this UBIFS image is created for is 2048 bytes (NAND page in this case);-e 129024
: logical eraseblock size of the UBI volume this image is created for;-c 2047
: specifies maximum file-system size in logical eraseblocks; this means that it will be possible to use the resulting file-system on volumes up to this size (less or equivalent); so in this particular case, the resulting FS may be put on volumes up to about 251MiB (129024 multiplied by 2047); See this section for more details.-p 128KiB
: tellsubinize
that physical eraseblock size of the flash chip the UBI image is created for is 128KiB (128 * 1024 bytes);-s 512
: tellsubinize
that the flash supports sub-pages and sub-page size is 512 bytes;ubinize
will take this into account and put the VID header to the same NAND page as the EC header.
注意:
1、-m -e 根据具体的NANDFLASH来定。 -C根据卷大小来制定 x*1024k/128k = y 块
2、UBI头部中的vol_size 和 vol_flags,实践中:vol_size可以理解为静态编译的大小,也即是说,如果文件系统的源码 > 卷 大小,则编译不过,同时,如果没有配置autoresize,机器启动后,文件系统的大小会根据vol_size来定,在此基础上。如果加上了autoresize标志,则在机器启动后第一次会根据mtd大小重新配置vol_size大小,体现在文件系统的大小会变化。
http://www.linux-mtd.infradead.org/faq/ubifs.html