UBI File System Overview
Before linux-2.6.27, talking about flash file system, we often think of cramfs, jffs2, yaffs2 and other file systems. They are also based on the file system + MTD + flash device architecture. After the linux-2.6.27, the kernel added a new type of FLASH file system ubi (unsorted block images ). Here we will briefly introduce the reasons for adding the ubi file system and how to use it. I have just got in touch with this file system. I may not understand it. please correct me.
I. background
Flash has the following features: "First erase and then write", "Bad Block", and "limited read/write count". Currently, the main methods for flash management are as follows:
1. MTD + FTL/nftl (flash Conversion Layer/NAND Flash Conversion Layer) + traditional file systems, such as fat and ext2. FTL/nftl is a unique feature of flash. It implements log management, bad block management, profit and loss balancing, and other technologies through software. However, practice has proved that this scheme has certain limitations due to factors such as intellectual property rights and efficiency.
2. Hardware Translation Layer + traditional file system solution. This method is used by many storage card products, such as SD card and USB flash disk. This solution is costly for some products.
3. Use MTD + flash dedicated file systems, such as jffs1/2 and yaffs1/2. They greatly improve flash management capabilities and are widely used.
Specialized file systems such as jffs2 and yaffs2 also have some technical bottlenecks, such as high memory consumption and linear dependency on flash capacity, file system size, content, and access mode, poor Profit and Loss balancing capacity or transitional profit and loss. In this context, the kernel is supported by the ubi file system.
Ii. Usage
Environment: omap3530 processor, (128 Mbyte 16-bit nand flash), linnux-2.6.28 Kernel
1. Configure the kernel to support ubifs
Device Drivers ---> memory technology device (MTD) support ---> ubi-unsorted block images ---> enable ubi
Configure MTD to support the ubi Interface
File systems ---> miscellaneous filesystems ---> ubifs File System Support
Configure the kernel to support the ubifs File System
2. Mount MTD partition 4 to ubifs format
● Flash_eraseall/dev/mtd4 // erase mtd4
● Ubiattach/dev/ubi_ctrl-M 4 // associate with mtd4
● Ubimkvol/dev/ubi0-N rootfs-s 100mib // set the volume size (not a fixed value, which can be changed using tools) and name
● Mount-T ubifs ubi0_0/mnt/ubi or mount-T ubifs ubi0: rootfs/mnt/ubi
3. Create an ubifs File System
When creating an ubi image, you must first determine the following parameters:
MTD partition size; // the size of the flash partition.
Flash physical eraseblock size; // flash physical erasure block size
Minimum Flash Input/output unit size; // minimum Flash Input/output unit size
For NAND flashes-Sub-page size; // For NAND Flash, the size of the sub-page
Logical eraseblock size. // the size of the logically erased Block
Parameters can be obtained in several ways
1) if the kernel is later than 2.6.30, the information can be obtained from the kernel through tools, such as mtdinfo-U.
2) The previous kernel can be implemented through the following methods:
● MTD partition size: obtained from the kernel partition table or CAT/proc/MTD
● Flash physical eraseblock size: the size of the flash physical erased block can be obtained from the flash chip manual, or CAT/proc/MTD
● Minimum Flash Input/output unit size:
1) nor FLASH: usually 1 byte
2) nand falsh: a page
● Sub-page size: obtained through the flash Manual
● Logical eraseblock size: For NAND Flash with sub-pages, it is equal to "physical erased block size-1 page size"
3) You can also obtain the information generated during the connection between ubi and MTD, for example:
# Modprobe ubi MTD = 4 // ubi loaded as a module
Or
# Ubiattach/dev/ubi_ctrl-M 4 // associate MTD with ubiattach
UBI: attaching mtd4 to ubi0
UBI: Physical eraseblock size: 131072 bytes (128 kib)
UBI: Logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: Sub-page size: 512
UBI: vid header offset: 512 (aligned 512)
UBI: Data offset: 2048
UBI: attached mtd4 to ubi0
For more detailed explanations, see http://www.linux-mtd.infradead.org/doc/ubi.html#L_overhead
# Mkfs. ubifs-r rootfs-M 2048-e 129024-C 812-O ubifs. img
# Ubinize-O ubi. IMG-M 2048-P 128kib-s 512/home/LHT/omap3530/tools/ubinize. cfg
-R: Specifies the location of the file content.
-M: page size
-E: size of the logically erased Block
-P: Physical erased block size
-C: Maximum number of logical erased Blocks
In this case, the file system can access a maximum of 129024*812 = MB of space on the volume.
-S: the minimum size of the hardware input/output page. For example, the value of k9f1208 is 256 (the upper and lower half pages are accessed)
The content of ubinize. cfg is:
[Ubifs]
Mode = ubi
Image = ubifs. img
Vol_id = 0
Vol_size = 100mib
Vol_type = dynamic
Vol_name = rootfs
Vol_flags = autoresize
4. Use uboot to write and start the ubifs Image
1) Burn the ubifs Image
Omap3 devkit8000 # mmcinit
Omap3 devkit8000 # fatload MMC 81000000 ubi. img
Reading ubi. img
12845056 bytes read
Omap3 devkit8000 # NAND unlock
Device 0 whole Chip
Nand_unlock: Start: 00000000, Length: 268435456!
NAND Flash successfully unlocked
Omap3 devkit8000 # NAND ECC SW
Omap3 devkit8000 # NAND erase 680000 7980000
Nand erase: device 0 offset 0x680000, size 0x7980000
Erasing at 0x7fe0000 -- 100% complete.
OK
Omap3 devkit8000 # NAND write. I 81000000 $680000 (filesize)
Nand write: device 0 offset 0x680000, size 0xc40000
Writing data at 0x12bf800 -- 100% complete.
12845056 bytes written: OK
The write and write processes are the same as those of kernel images. Therefore, the ubi file system should not use the OOB area of NAND as the yaffs file system does.
2) set the ubifs file system as the parameter for starting the root file system.
Omap3 devkit8000 # setenv bootargs console = ttys2, 115200n8 ubi. MTD = 4 root = ubi0: rootfs
Rootfstype = ubifs Video = omapfb: Mode: 4. 3inch _ LCD
Omap3 devkit8000 # setenv bootcmd NAND read. I 80300000 280000 200000/; bootm 80300000
The root file system is located on mtd4.
When the system starts, the following ubi-related information is printed:
Creating 5 MTD partitions on "omap2-nand ":
0x00000000-0x00080000: "X-loader"
0x00080000-0x00260000: "U-Boot"
0x00260000-0x00280000: "U-boot env"
0x00280000-0x00680000: "kernel"
0x00680000-0x08000000: "File System"
UBI: attaching mtd4 to ubi0
UBI: Physical eraseblock size: 131072 bytes (128 kib)
UBI: Logical eraseblock size: 129024 bytes
UBI: smallest flash I/O unit: 2048
UBI: Sub-page size: 512
UBI: vid header offset: 512 (aligned 512)
UBI: Data offset: 2048
UBI: attached mtd4 to ubi0
UBI: MTD device name: "File System"
UBI: MTD device size: 121 MIB
UBI: Number of good pebs: 970
UBI: Number of bad pebs: 2
UBI: Max. allowed volume: 128
UBI: Wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 1
UBI: available pebs: 0
UBI: Total number of FIG: 970
UBI: Number of pebs reserved for bad peb handling: 9
UBI: Max/mean erase counter: 2/0
The above is the ubifs operation method downloaded from the network, which has some reference value.
The following is an operation document obtained from Marvell.
Building the MTD-utils
======================================
For Debian distribution, you need the following packages installed
Building the head snapshot of MTD-utils,
UUID-Dev
Liblzo2-dev
Libz-Dev
Extract the latest snapshot of MTD-utils and go into the sub directory
'Mkfs. ubifs 'and then type 'make' to build the mkfs. ubifs utility. Once it
Is done, go up one directory and then go into the sub directory 'ubi-tuils '.
Inside that directory, type 'make' again to make the rest of ubi utilities
(Ubinfo, ubinize, ubiformat, etc .).
How to find out Min. I/O unit size, sub-page size, etc
========================================================== ====================
The easiest way to find this out is to attach your MTD device to ubi and
Glance to the syslog/dmesg output (erase the MTD device before doing this ).
The newest ubi prints something like this:
UBI: attaching mtd0 to ubi0
UBI: Physical eraseblock size: 262144 bytes (256 kib)
UBI: Logical eraseblock size: 258048 bytes
UBI: smallest flash I/O unit: 2048
UBI: vid header offset: 2048 (aligned 2048)
UBI: Data offset: 4096
UBI: Empty MTD device detected
UBI: Create volume table (copy #1)
UBI: Create volume table (copy #2)
UBI: attached mtd0 to ubi0
UBI: MTD device name: "rootfs"
UBI: MTD device size: 2048 MIB
UBI: Number of good pebs: 8183
UBI: Number of bad pebs: 9
UBI: Max. allowed volume: 128
UBI: Wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 0
UBI: available pebs: 8098
UBI: Total number of reserved pebs: 85
UBI: Number of pebs reserved for bad peb handling: 81
UBI: Max/mean erase counter: 0/0
UBI: Background thread "ubi_bgt0d" started, PID 254
How to attach an MTD Device
======================================
If ubi is compiled into the kernel, The MTD device to attach may be specified
In the ubi. MTD = kernel boot parameter, e.g .,
UBI. MTD = 0
(For attaching the first MTD device)
How to mount a ubi Device
======================================
First, you need to create a user volume on the ubi device.
Ubimkvol/dev/ubi0-N 0-N rootfs-s 4096mib
The above commands will only work after the correct kernel boot parameter is
Specified. Once the user volume is created, you may use the following command
To mount it,
Mount-T ubifs ubi0: rootfs/mnt
If there is no need to keep the user volume, you may use the following command
To delete it,
Ubirmvol/dev/ubi0-N 0
How to Create ubi Images
======================================
First, you need to use the mkfs. ubifs utility to create a volume for your root
File System,
Mkfs. ubifs-M 2kib-e 258048-x lzo-C 8000-D foxes-rootfs-20081128/-O system_ubifs.img
(The above command must have root previledge)
Then use the ubinize utility to combine all the volumes you need into a ubi
Image,
Ubinize-O system_ubi.img-M 2kib-P 256kib-s 2kib ubinize. cfg
In the ubinize. cfg, the following items are specified,
# Section header
[Rootfs]
# Volume mode (other option is static)
Mode = ubi
# Source Image
Image = system_ubifs.img
# Volume ID in ubi Image
Vol_id = 0
# Volume size
Vol_size = 1900mib
# Allow for dynamic resize
Vol_type = dynamic
# Volume name
Vol_name = rootfs
# Autoresize volume at first Mount
Vol_flags = autoresize
How to flash ubi images (and preserve erase counters)
========================================================== ==================
First, you need to detach the ubi device by using the follwing command if
UBI device is attached,
Ubidetach/dev/ubi_ctrl-D 0
The, use the ubiformat utility.
Ubiformat/dev/mtd0-F system_ubi.img
How to Use ubifs as the root file system
==========================================================
You must specify the following text in the kernel boot parameter,
UBI. MTD = 0 root = ubi0: rootfs rootfstype = ubifs RW mtdparts = cafe_nand: 2G (rootfs)
More infromation
======================
You may obtain more information at the following web sites,
(1) ubi FAQ and HOWTO (memory technology device (MTD) subsystem for Linux)
Http://www.linux-mtd.infradead.org/faq/ubi.html
(2) ubifs Initial experiments (OLPC)
Http://wiki.laptop.org/go/UBIFS_initial_experiments
Although there are duplicates between the two, they are complementary.
The above Guidance can cope with most of the application layer operations.