Linux
Supports multiple file systems, including ext2, ext3, vfat, NTFS, iso9660, jffs, romfs, and NFS. to centrally manage various file systems, linux introduces the Virtual File System VFS (Virtual File
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 device is Ram (DRAM,
SDRAM and Rom (usually flash memory). Common file system types based on storage devices include jffs2, yaffs, cramfs, romfs,
Ramdisk, ramfs/tmpfs, etc.
1. 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 (
In addition to flash, the content of the corresponding storage block is restored to 1). Therefore, when writing content to flash, you must first erase the corresponding storage range, this erasure is based on blocks.
Unit.
There are two types of flash memory: nor and NAND.
Technology (for a simple comparison, see the appendix ). Flash Memory has a limited number of writes. nand flash memory also has special hardware interfaces and read/write time series. Because
Therefore, a file system that meets the application requirements must be designed for flash hardware features. Traditional file systems such as ext2 have many drawbacks when used as Flash file systems.
In Embedded Linux
Next, 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
In Linux ). The main advantage of using the MTD driver is that it is specially designed for a variety of non-volatile memory (mainly flash memory), so it has
Better support, management, and sector-based erasure, read/write operations.
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 file system was first developed by Sweden
Axis
Communications is a file system developed for embedded systems based on the Linux kernel. Jffs2 is a flash file system developed by RedHat Based on jffs.
Originally, jffs2 is 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 is mainly because the memory size of the nand flash memory is generally large, which leads to the rapid increase of memory space occupied by jffs to maintain log nodes.
In addition, the jffsx file system needs to scan the entire Flash Content During mounting to find all log nodes and create a file structure. It will take 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, it reduces some features (for example, the number of unsupported
Data Compression), so the speed is faster, the mounting time is short, and the memory usage is small. 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.
Cramfs file system is compressed
Storage, decompress during running, so it does not support running applications in xip mode. All applications must be copied to ram for running.
It does not mean that the ram space required by ramfs is larger, because cramfs uses paging compression to store files. When reading files, it does not consume too much memory space at once.
Memory is allocated for the part actually read before, and no memory space is allocated for the part not read. When the file we read is not in the memory, the cramfs file system automatically calculates the location of the compressed data, instant again
Decompress the package 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 Data erasure and storage, and stores data in order. Therefore, it supports the use of xip (execute in
Place, In-chip running) to save Ram space when the system is running. Generally, the uClinux system uses the romfs file system.
Other file systems: fat/FAT32 can also be used for extended memory (such as PDA, smartphone,
Digital cameras and other SD cards), mainly to better be compatible with the most popular Windows desktop operating system. Ext2 can also be used as an embedded Linux File System.
Flash flash memory has many drawbacks.
2. 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) ramfs/tmpfs
Ramfs is Linus
A memory-based file system developed by Torvalds, which works on the VFS layer and cannot be formatted. You can create multiple file systems, you can specify the maximum memory size that can be used during creation.
Small. (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.
3. Network File System (NFS)
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.
The above discussions are based on the storage device text
File System (memory-based file)
And can be used as the linux root file system. In fact, Linux also supports logical or pseudo file systems (
System), such as procfs (proc file system), used to obtain system information, as well as devfs (Device File System) and sysfs, used to maintain device files.
Appendix: Comparison between nor flash and NAND Flash
Nor flash
NAND Flash
The interface time series is the same as that of SRAM, which is easy to use.
Address/data line multiplexing, narrow data bit
Fast Reading Speed
Slow reading speed
The erasure speed is slow. The unit is 64-128kb.
Fast erasure, measured in 8-32 KB Blocks
Write speed is slow (because it usually needs to be erased first)
Fast write speed
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.
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.
Small Single-Chip capacity, 1-32 MB
Large Single-Chip capacity, 8-128 MB, increased unit density