Basic knowledge of embedded development, how much do you know?
Linux supports a variety of file system types, commonly used in embedded development: ROMFS, JFFS2, NFS, CRAMFS, YAFFS, UBIFS.
JFFS file system
The JFFS file system was originally developed by Axis Communications of Sweden based on the Linux 2.0 kernel for file systems developed for embedded systems. JFFS2 is a flash file system developed by RedHat based on JFFS. It was originally an embedded file system developed for RedHat's embedded product eCos, so JFFS2 can also be used in Linux, uCLinux.
Jffs2: Log Flash File System Version 2 (Journalling Flash FileSystem v2)
Mainly used for NOR flash memory, based on MTD driver layer, featuring: readable and writable, hash-based log file system supporting data compression, and providing crash/power-down security protection, providing "write balance" Support and so on. The disadvantage is that when the file system is full or nearly full, the jffs2 runs much slower because of garbage collection.
Currently jffs3 is under development. For detailed documentation on the use of the jffs series file system, refer to the mtd-jffs-HOWTO.txt in the MTD patch package.
Jffsx is not suitable for NAND flash memory mainly because the capacity of NAND flash memory is generally large, which causes jffs to rapidly increase the memory space occupied by the maintenance log node. In addition, the jffsx file system needs to scan the entire FLASH content when it is mounted. To find out all the log nodes and establish a file structure, it takes a lot of time for large-capacity NAND flash.
Yaffs:Yet Another Flash File System
Yaffs/yaffs2 is a log file system designed for embedded systems using NAND flash memory. Compared to jffs2, it reduces some features (such as not supporting data compression), so it is faster, has a shorter mount time, and consumes less memory. In addition, it is a cross-platform file system, in addition to Linux and eCos, it also supports WinCE, pSOS and ThreadX.
Yaffs/yaffs2 comes with a NAND chip driver and provides an API for direct access to the file system for embedded systems. Users can directly operate on the file system without using MTD and VFS in Linux. Of course, yaffs can also be used with the MTD driver.
The main difference between yaffs and yaffs2 is that the former only supports small page (512 Bytes) NAND flash, while the latter supports large page (2KB) NAND flash. At the same time, yaffs2 has greatly improved in terms of memory space usage, garbage collection speed, and read/write speed.
Cramfs: Compressed ROM File System
Cramfs is a read-only compressed file system developed by Linus Torvalds, the founder of Linux. It is also based on the MTD driver.
In the cramfs file system, each page (4KB) is compressed separately and can be accessed randomly. Its compression ratio is up to 2:1, which saves a lot of Flash storage space for embedded systems, enabling the system to store through lower capacity FLASH. The same file, which reduces system costs.
The Cramfs file system is stored in a compressed manner and decompressed at runtime, so the application is not supported to run in XIP mode. All applications are required to be copied to RAM to run, but this does not mean that the RAM space is larger than Ramfs needs. One point, because Cramfs uses paging compression to store files, when reading files, it will not use too much memory space at once, only allocate memory for the part that is actually read, and there is still no read part. Allocating memory space, when the file we read is not in memory, Cramfs file system automatically calculates the location of the compressed data, and then decompresses it into RAM.
In addition, it is fast and efficient, and its read-only feature helps protect the file system from damage and improves system reliability.
Due to the above characteristics, Cramfs is widely used in embedded systems.
But its read-only property is also a major flaw in it, making it impossible for users to expand their content.
Cramfs images are usually placed in Flash, but can also be placed in other file systems. They can be installed in other file systems using loopback devices.
The traditional Romfs file system is a simple, compact, read-only file system that does not support dynamic erasing and saving, storing data in order, thus supporting applications running in XIP (eXecute In Place) mode. Save RAM space while the system is running. The uClinux system usually uses the Romfs file system.
Other file systems: fat/fat32 can also be used for expansion memory of real embedded systems (such as SD cards for PDAs, Smartphones, digital cameras, etc.), mainly for better compatibility with the most popular Windows desktop operating systems. Ext2 can also be used as a file system for embedded Linux, but there are many drawbacks to using it for FLASH flash.
2. RAM-based file system
Ramdisk uses a portion of fixed-size memory as a partition. It is not an actual file system, but a mechanism for loading the actual file system into memory and can be used as a root file system. Putting files that are frequently accessed without changing (such as a read-only root file system) in memory through Ramdisk can significantly improve system performance.
In the Linux boot phase, initrd provides a mechanism for loading kernel images into the memory along with the root file system.
Ramfs is a memory-based file system developed by Linus Torvalds that works in the Virtual File System (VFS) layer and cannot be formatted. It can be created multiple times, and can be specified to maximize its available memory size. (Actually, VFS can essentially be thought of as a memory file system that unifies the way files are represented in the kernel and buffers the disk file system.)
The Ramfs/tmpfs file system puts all the files in RAM, so the read/write operations take place in RAM. Ramfs/tmpfs can be used to store temporary or frequently modified data, such as the /tmp and /var directories. This not only avoids the read and write loss of the flash memory, but also improves the data read and write speed.
The main difference between Ramfs/tmpfs and the traditional Ramdisk is that it cannot be formatted, and the file system size can vary with the size of the file content.
One disadvantage of Tmpfs is that it loses all data when the system reboots.
3. Network File System (NFS)
NFS is a technology developed and developed by Sun to share files over a network between different machines and different operating systems. In the development and debugging phase of the embedded Linux system, this technology can be used to build an NFS-based root file system on the host, and mount it to the embedded device, which can easily modify the content of the root file system.
The above discussion is based on the memory-based file system, 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, as well as devfs (device file system) and sysfs for maintaining device files.