1. Embedded root file system
Linux supports multiple file systems, including ext2, ext3, vfat, NTFS, iso9660, jffs, romfs, and NFS. to centrally manage various file systems, linux introduces Virtual File System (VFS), which provides a unified operation interface and Application Programming Interface for various file systems.
During Linux Startup, the first file system must be mounted. If the system cannot mount the root file system from a specified device, the system will exit the startup due to an error. You can then automatically or manually Mount other file systems. Therefore, different file systems can exist in a system at the same time. Different file system types have different characteristics, so there are different application scenarios based on the hardware characteristics and system requirements of storage devices. In Embedded Linux applications, the main storage devices are Ram (DRAM, SDRAM) and Rom (Flash memory is often used). Common file system types based on storage devices include: jffs2, yaffs,
Cramfs, romfs, ramdisk, initramfs, ramfs/tmpfs,Ubifs.
Ii. Flash-based File System
As the main storage medium of embedded systems, flash memory has its own characteristics. The Flash write operation can only change 1 of the corresponding position to 0, but not 0 to 1 (flash erased restores the content of the corresponding storage block to 1). Therefore, generally, when writing content to flash, you must first erase the corresponding storage range. This erasure is performed in blocks.
First, flash (flash memory) is the main storage medium for embedded systems, mainly including the nor and NAND technologies. Flash Memory has a limited number of writes. nand flash memory also has special hardware interfaces and read/write time series. Therefore, you must design a file system that meets application requirements based on flash hardware features. Traditional file systems such as ext2 have many drawbacks when used as Flash file systems. Here we will briefly compare the nor flash memory with the nand flash memory:
Nor flash The interface time series is the same as that of SRAM, which is easy to use. Fast Reading Speed The erasure speed is slow. In the unit of 10000-kb, the number of erased data is limited. Write speed is slow (because it usually needs to be erased first) The random access speed is fast and supports xip (execute in place, In-chip execution) and is suitable for code storage. Embedded systems are often used to store boot programs and root file systems. Small Single-Chip capacity, 1-32 MB |
NAND Flash Address/data line multiplexing, narrow data bit Slow reading speed The erasure speed is fast. In 8-32 KB blocks, 100000 words can be erased. Fast write speed Fast sequential reading speed and slow random access speed, suitable for data storage (such as large-capacity multimedia applications ). Embedded systems are often used to store user file systems. Large Single-Chip capacity, 8-128 MB, increased unit density |
In Embedded Linux, MTD (memory technology device, storage technology device) provides a unified abstract interface between the underlying hardware (flash memory) and the upper layer (File System, that is, the Flash file system is based on the MTD driver layer (see the Virtual File System Hierarchy in Linux below ). The main advantage of using the MTD driver is that it is specially designed for a variety of non-volatile memory (mainly flash memory, therefore, it provides better support, management, and sector-based erasure and read/write operations for flash.
By the way, a flash chip can be divided into multiple partitions, and different file systems can be used for each partition. The two flash chips can also be combined into one partition and used in one file system. That is, the file system is for memory partitions, rather than storage chips.
(1) jffs2
Jffs is a file system first developed by Swedish axis communications based on the Linux kernel for embedded systems. Jffs2 is a flash file system developed by RedHat Based on jffs. It was originally an embedded file system developed for the RedHat embedded product ECOs. Therefore, jffs2 can also be used in Linux and uClinux.
Jffs2: log flash File System Version 2 (Journalling flash filesystem V2)
It is mainly used for nor-type flash memory and is based on the MTD driver layer. It features read/write, data compression, and hash-table-based log file systems, it also provides crash/power-down security protection and "Write balance" support. The main drawback is that when the file system is full or near full, jffs2 is greatly slowed down due to the spam relationship.
Jffs3 is currently under development. For more information about how to use the jffsseries file system, see mtd-jffs-howto.txt in the mtdpatch.
Jffsx is not suitable for nand flash memory because the capacity of nand flash memory is generally large, which leads to a rapid increase in the memory space occupied by jffs to maintain log nodes. In addition, when mounting a jffsx file system, you need to scan the entire Flash content to find all log nodes and create a file structure. It takes a lot of time for large-capacity nand flash memory.
(2)Yaffs: yet another flash File System
Yaffs/yaffs2 is a log file system designed for embedded systems to use nand flash memory. Compared with jffs2, jffs2 reduces some features (for example, data compression is not supported), so it is faster, has a short Mount time, and consumes less memory. In addition to Linux and ECOs, it also supports wince, PSOs, and threadx.
Yaffs/yaffs2 comes with a NAND chip driver and provides APIs for direct access to the file system for embedded systems. You can directly operate the file system without using MTD and VFS in Linux. Of course, yaffs can also be used with MTD drivers.
The main difference between yaffs and yaffs2 is that the former only supports small pages (512 bytes) NAND Flash, while the latter supports large pages (2 kb) NAND Flash. In addition, yaffs2 significantly improves the memory space usage, garbage collection speed, and read/write speed.
(3)Cramfs: Compressed ROM file system
Cramfs is a read-only compressed file system developed by Linux founder Linus Torvalds. It is also based on the MTD driver.
In the cramfs file system, each page (4 kb) is compressed separately and can be accessed by random pages. The compression ratio is as high as, saving a lot of flash storage space for the embedded system, this allows the system to store the same file through a lower-capacity FLASH, thus reducing system costs.
The cramfs file system stores data in Compressed Mode and decompress the data during running. Therefore, applications cannot run in xip mode. All applications must be copied to ram for running, however, this does not mean that the ram space required by ramfs is larger, because cramfs uses paging compression to store files. When reading files, it will not consume too much memory at once, only allocate memory for the part currently actually read. No memory space is allocated for the part that has not been read. When the file we read is not in the memory, the cramfs file system automatically calculates the location of the compressed data and decompress it to ram.
In addition, it is fast and efficient. Its read-only feature is conducive to protecting the file system from damages and improving the system reliability.
Thanks to the above features, cramfs is widely used in embedded systems. However, its read-only attribute is also a major defect, making it impossible for users to expand their content pairs. Cramfs images are usually stored in flash, but they can also be stored in other file systems. Using loopback devices, you can install them in other file systems.
(4) romfs
The traditional romfs file system is a simple, compact, and read-only file system. It does not support dynamic erasure and storage, and stores data in sequence, therefore, you can run applications in xip (execute in place, In-chip operation) mode to save Ram space during system operation. Generally, the uClinux system uses the romfs file system.
Other file systems: fat/FAT32 can also be used for extended memory (SD cards for actual embedded systems, such as PDA, smartphone, and digital cameras ), this is mainly for better compatibility with the most popular Windows desktop operating systems. Ext2 can also be used as an embedded Linux File System, but using it in flash memory has many drawbacks.
Iii. Ram-based File System
(1) ramdisk
Ramdisk uses some fixed-size memory as a partition. It is not an actual file system, but a mechanism to load the actual file system into the memory, and can be used as the root file system. By placing some frequently accessed files (such as the read-only root file system) in the memory through ramdisk, the system performance can be significantly improved.
In the Linux Startup phase, initrd provides a mechanism to load the kernel image and the root file system into the memory.
(2) initramfs
The ram-based file system-initramfs appears in the 2.6 kernel. It is similar to tmpfs and is a memory-based file system. It does not need to be used to create memory block devices. Adding a file to ramfs (or increasing the size of the original file) will automatically configure more memory and delete or intercept the file to release the memory. (If the ramdisk is not full, the occupied extra memory cannot be used for other tasks. If the ramdisk is full, there is still idle memory, you must also format it before it can be extended)
(3) ramfs/tmpfs
Ramfs is a memory-based file system developed by Linus Torvalds. It works on the VFS layer and cannot be formatted. Multiple file systems can be created, you can specify the maximum memory size that can be used during creation. (In fact, VFS is essentially a memory file system, which unifies the representation of files in the kernel and caches the disk file system .)
The ramfs/tmpfs file system stores all the files in Ram, so read/write operations occur in Ram. You can use ramfs/tmpfs to store temporary or frequently-modified data, for example, the/tmp and/var directories avoid the read/write loss of flash memory and increase the data read/write speed.
Ramfs/tmpfs differs from the traditional ramdisk in that it cannot be formatted and the file system size can change with the size of the contained file.
One disadvantage of tmpfs is that all data is lost when the system is rebooted.
4. Other File Systems
(1) Network File SystemNFS(Network File System)
NFS is a technology developed and developed by Sun to share files through networks between different machines and operating systems. In the development and debugging phase of an embedded Linux system, you can use this technology to establish an NFS-based root file system on the host and mount it to an embedded device, so that you can easily modify the content of the root file system.
(2)Ubifs
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 ). 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.
All of the above discussions are based on the memory-based file system of storage devices, which can be used as the root file system of Linux. In fact, Linux also supports logical or pseudo file systems, such as procfs (proc file system), for obtaining system information, and devfs (Device File System) and sysfs, used to maintain device files.