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