Analysis of Embedded Linux File System and its storage mechanism

Source: Internet
Author: User
  • Embedded systems are different from general-purpose PCs. Generally, they do not have storage devices such as hard disks. Instead, they use flash chips, small flash cards, and other storage devices designed for embedded systems, this article analyzes the commonly used storage devices in embedded systems and their management mechanisms, and introduces the commonly used file system types based on flash.1. Analysis of storage devices and management mechanisms of Embedded SystemsBuilding a Linux file system suitable for embedded systems involves two key points. One is the selection of file system types, which is related to the read/write performance and size of the file system; the other is the choice of the content of the root file system, which is related to the functions and sizes provided by the root file system. Memory Used in embedded devices is a storage device designed for embedded systems, such as flash memory chips and small flash cards. Flash is a mainstream memory widely used in embedded systems. Its main features are full/sector erasure and byte programming. It has the advantages of low power consumption, high density, and small size. Currently, Flash is classified into either nor or NAND. Nor flash memory can directly read the data stored in the chip, so the speed is relatively fast, but the price is relatively high. The address line of the nor chip is separated from the data line. Therefore, the nor chip can be connected to the data line like the SRAM, And the nor chip can be operated as the basic unit. Therefore, the transmission efficiency is very high, applications can run directly in Flash without having to read the code to the system Ram. The biggest difference between it and SRAM is that write operations need to be erased and written. The nand flash memory chip shares the address line and data line, and internal data is stored in blocks. It is difficult to directly start the NAND chip. Nand flash memory is a continuous storage medium and is suitable for file amplification. The nor device is erased in blocks of-kb, And the write/erase operation is performed in 5 S. The NAND device is erased in blocks of 8-kb, it takes up to 4 ms to perform the same operation. The unit size of NAND rash is almost half the size of the nor device. Due to the simpler production process, the NAND structure can provide higher capacity within the given mold size, thus reducing the price accordingly. Nor flash occupies most of the 1-16 MB flash memory market, while NAND Flash is only used in 8-MB products. This also shows that nor is mainly used in code storage media, nand is suitable for data storage. Lifetime (durability): In nand flash memory, the maximum number of writes to each block is 1 million, and the number of writes to nor is 100,000. In addition to having a block erasure cycle of 10 to 1, the typical NAND block size is eight times smaller than that of the nor device, each NAND memory block is deleted less frequently within a given period of time. All embedded systems must start with at least some form of permanent storage devices. They need appropriate drivers. Currently, there are three common block drivers available in embedded Linux. ● The blkmem driver layer blkmem driver is specially designed for uClinux and is one of the earliest block drivers. Currently, many embedded Linux operating systems still choose it as the block driver, especially in uClinux. It is relatively simple, and only supports the root file system established in the nor flash and ram. Using the blkmem driver makes it difficult to create a flash partition configuration. This type of Driver provides some basic erasure/write operations for flash. ● Ramdisk driver layer the ramdisk driver layer is usually used to start a non-disk workstation in standard Linux and does not provide any direct support for flash memory. The RAM disk is used when it is started up, virtualize some of the memory into a block device, and decompress the prepared file system image to the RAM disk environment. When a compressed file system is placed in flash, you can extract the file system to ram, and use the RAM disk driver layer to support a file system that is kept in Ram. ● The MTD driver layer is incorporated into the MTD subsystem (memory technology device) to avoid using different tools for different technologies and provide common capabilities for different technologies as much as possible ). It provides consistent and unified interfaces, allowing the underlying MTD chip driver to be seamlessly combined with higher-level interfaces. Jffs2, cramfs, yaffs and other file systems can be installed as MTD devices. The MTD driver can also support the nor flash that supports the CFI interface. Although MTD can be built on Ram, it is designed for flash-based devices. MTD contains drivers for specific flash chips. Developers should choose flash chip drivers suitable for their systems. The flash chip Driver provides read, write, erase, and other basic operations to the upstream layer. MTD encapsulates these operations and provides MTD char and MTD Block devices to the user layer. Devices of The MTD char type include/dev/mtd0,/dev/mtdl, and they provide access to the original flash characters. MTD Block devices include/dev/mtdblock0,/dev/mtdblock1, etc. MTD Block devices simulate flash into Block devices, so that they can create Block devices like cramfs on these simulated Block devices, jffs2 and other format file systems. The MTD driver layer also allows you to create multiple flash partitions in one flash. Each partition is used as an MTD block device and system software and data can be allocated to different partitions, at the same time, you can use a file system format that is not used in different partitions. This is very important because it provides flexibility for the establishment of multiple file systems in embedded systems.2. Flash-based File SystemIn view of the read and write features of flash storage media, traditional Linux file systems are not suitable for embedded systems. The ext2fs file system is designed for Block devices like IDE, the logical blocks of these devices are 512 bytes and 1024 bytes. They do not provide good sector erasure support, do not support loss balancing, do not have power loss protection, and do not have perfect sector management, this is not suitable for flash devices with sector sizes divided by device types. For this reason, many file systems have been designed for flash devices. Common file systems dedicated to flash devices are as follows: ● romfs's traditional romfs file system is the most commonly used file system. It is a simple, compact, and read-only file system that does not support dynamic erasure and storage; it stores all the file data in sequence. Therefore, this file system format allows applications to run in xip mode, allowing considerable Ram space savings during system operation. Generally, the uClinux system uses the romfs file system. ● Cramfs is a compress read-only file system developed by Linux founder Linus Torvalds. In the cramfs file system, each page is compressed and can be accessed on random pages, the compression ratio is as high as, saving a lot of flash storage space for embedded systems. 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 reliability of the system. However, its read-only attribute is also a major defect of it, this makes 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. You can use the mkcramfs tool to create a cramfs image. ● Ramfs/tmpfs ramfs is also developed by Linus Torvalds. The ramfs file system runs all the files in Ram, which is usually used by the flash system to store temporary or frequently-modified data, compared with ramdisk, the size of ramfs can change with the size of the contained file, unlike the size of ramdisk. Tmpfs is a memory-based file system. Because tmpfs resides in Ram, write/read operations occur in Ram. The size of the tmpfs file system varies with the size of the contained files, making it ideal to use the memory. tmpfs stays in Ram, so reading and writing are almost instantaneous. One disadvantage of tmpfs is that all data is lost when the system is rebooted. ● 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. Therefore, jffs2 can also be used in Linux and uClinux. Jffs is a file system first developed by Swedish axis communications based on the Linux kernel for embedded systems. Jffs2 is a read/write, compressed, and log-type file system. It provides crash/power-down security protection and overcomes some shortcomings of jffs: the hash table-based Log node structure is used to greatly speed up node operations; data compression is supported; write balancing is supported; multiple node types are supported; improves the utilization of flash memory and reduces memory consumption. These features make jffs2 the most popular file system format on flash devices. Its disadvantage is that when the file system is full or near full, jffs2 runs slowly, this is mainly because of fragment collection issues. ● Yaffs/yaffs2 is a kind of FLASH file system similar to jffsx. It is a kind of log file system designed for embedded systems to use nand flash memory. Compared with jffs2, jffs2 reduces some functions, so the speed is faster and the memory usage is relatively small. In addition, the yaffs comes with a NAND chip driver and provides an API for the embedded system to directly access the file system. You can directly operate the file system without using MTD and VFS in Linux. Yaffs2 supports large-page NAND devices and optimizes large-page NAND devices. Jffs2 is not stable in nand flash memory and is more suitable for nor flash memory. Therefore, yaffs is a better choice for relatively large-capacity nand flash memory. In the specific embedded system design, you can determine the file system to be used based on the different contents stored in different directories and the stored file attributes.

  •  

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.