UBI/UBIFS無法使用loop-back方式mount, 不過我們可以使用NAND simulator將UBI燒入到nandsim中.
root@vista:~# mkfs.ubifs -m 2KiB -e 129024 -c 2048 -r ubifs-root -x zlib ubifs.img root@vista:~# cat ubi.ini [ubi_rfs] mode=ubi image=ubifs.img vol_id=0 vol_type=dynamic vol_name=ubi_rfs vol_alignment=1 vol_flags=autoresize root@vista:~# ubinize -o my.ubi -p 128KiB -m 2KiB -O 512 ubi.ini ubinize: volume size was not specified in section "ubi_rfs", assume minimum to fit image "ubifs.img"1806336 bytes (1.7 MiB) root@vista:~# modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15 root@vista:~# ubiformat /dev/mtd0 -f my.ubi ubiformat: mtd0 (nand), size 268435456 bytes (256.0 MiB), 2048 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes libscan: scanning eraseblock 2047 -- 100 % complete ubiformat: 2048 eraseblocks have valid erase counter, mean value is 3 ubiformat: flashing eraseblock 15 -- 100 % complete ubiformat: formatting eraseblock 2047 -- 100 % complete ubiformat: formatting eraseblock 2047 -- 100 % complete root@vista:~# ubiattach -m 0 UBI device number 0, total 2048 LEBs (264241152 bytes, 252.0 MiB), available 0 LEBs (0 bytes), LEB size 129024 bytes (126.0 KiB) root@vista:~# ubinfo -a UBI version: 1 Count of UBI devices: 1 UBI control device major/minor: 10:55 Present UBI devices: ubi0 ubi0 Volumes count: 1 Logical eraseblock size: 129024 bytes, 126.0 KiB Total amount of logical eraseblocks: 2048 (264241152 bytes, 252.0 MiB) Amount of available logical eraseblocks: 0 (0 bytes) Maximum count of volumes 128 Count of bad physical eraseblocks: 0 Count of reserved physical eraseblocks: 40 Current maximum erase counter value: 9 Minimum input/output unit size: 2048 bytes Character device major/minor: 245:0 Present volumes: 0 Volume ID: 0 (on ubi0) Type: dynamic Alignment: 1 Size: 2002 LEBs (258306048 bytes, 246.3 MiB) State: OK Name: ubi_rfs Character device major/minor: 245:1 root@vista:~# mount -t ubifs /dev/ubi0_0 www
Usage: mkfs.ubifs [OPTIONS] target Make a UBIFS file system image from an existing directory tree Options: -r, -d, --root=DIR build file system from directory DIR -m, --min-io-size=SIZE minimum I/O unit size -e, --leb-size=SIZE logical erase block size -c, --max-leb-cnt=COUNT maximum logical erase block count -x, --compr=TYPE compression type - "lzo", "favor_lzo", "zlib" or "none" (default: "lzo") # mkfs.ubifs -F -r </path/to/your/rootfs/tree> -m <min io size> -e <LEB size> -c <Erase Blocks count> -o </path/to/output/Image.ubifs> <min io size> Equals the page-size of the used NAND-Flash <LEB size> Logical Erase Block size <Erase Blocks count> maximum logical erase block countmkfs.ubifs -m 2KiB -e 129024 -c 2048 -r ubifs-root -x zlib ubifs.img這些相關參數是先用ubiformat確認的, 不過-e是在mount failed的時候看dmesg的
Usage: ubinize [-o filename] [-pubinize -o my.ubi -p 128KiB -m 2KiB -O 512 ubi.ini這些參數也是在ubiformat修正的, 如-O 512] [-m ] [-s ] [-O ] [-e ] [-x ] [-Q ] [-v] [-h] [-V] [--output= ] [--peb-size= ] [--min-io-size= ] [--sub-page-size= ] [--vid-hdr-offset= ] [--erase-counter= ] [--ubi-ver= ] [--image-seq= ] [--verbose] [--help] [--version] ini-file -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 -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) # ubinize -vv -o <output image> -m <min io size> -p <PEB size>KiB -s <subpage-size> -O <VID-hdr-offset> <configuration file> <min io size> Equals the page-size of the used NAND-Flash <PEB size> Physical Erase Block size (in KiB) - Equals the block size of the NAND-Flash <Erase Blocks count> Count of the available Erase Blocks <subpage-size> Subpage size in bytes. Default value is the minimum input/output size (page-size) <VID-hdr-offset> offset if the VID header from start of the PEB (default is the next min I/O unit or sub-page after the EC header) <configuration file> Path to a configuration file.
-
參考資料:
- http://www.linux-mtd.infradead.org/faq/ubifs.html#L_loop_mount, Can UBIFS mount loop-back devices?
- https://elinux.org/UBIFS, UBIFS
- http://www.linux-mtd.infradead.org/faq/nand.html#L_nand_nandsim, How do I use NAND simulator?