Embedded storage and File System

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 Systems

 

 


Building 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 nor,
Two types of 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. Nand
The unit size of rash is almost half the size of the nor device. Because the production process is simpler, the NAND structure can provide a 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, which also shows that nor is mainly used in code storage media, and 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.

 

 

● Blkmem driver layer

 


The blkmem driver is specially designed for uClinux and one of the earliest block drivers. Many embedded Linux operating systems still use it as a 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.
When the disk is started, it virtualizes some 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.

 

 

● MTD driver layer

 

To avoid using different tools for different technologies and provide the same capabilities for different technologies, the Linux kernel incorporates the MTD subsystem (memory)
Technology device ). It provides consistent and unified interfaces, allowing the underlying MTD chip driver to be seamlessly combined with higher-level interfaces. Jffs2, cramfs,
File systems such as yaffs can be installed as MTD Block 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 then provides MTD to the user layer.
Char and MTD Block devices. 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, and MTD.
Block devices simulate flash into Block devices, so that you can create file systems in formats such as cramfs and jffs2 on these simulated Block devices.

 

 

The MTD driver layer also supports creating multiple flash partitions in one flash. Each partition acts as an MTD.
Block device, which can distribute system software and data to different partitions. At the same time, different partitions can adopt different file system formats. This is very important because it provides flexibility for the establishment of multiple file systems in embedded systems.

 

2. Flash-based File System

 


In 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

 


The traditional romfs file system is the most commonly used file system. It is a simple, compact, and read-only file system and 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

 

Cramfs is the founder of Linux, Linus
Torvalds develops a compressed read-only file system. In the cramfs file system, each page is individually compressed and can be accessed by random pages. The compression ratio is as high, saves 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, but this does not mean that ram than ramfs needs
The space needs to be larger, because cramfs uses paging compression to store files. When reading files, it does not consume too much memory space at once, and only allocates memory for the actually read parts, the unread part does not allocate memory space. When the file we read is not in 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 Linus
Developed by Torvalds, The ramfs file system stores all the files in Ram and usually uses flash systems 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 reside in Ram
So the 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

 


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. Jffs file system was first created by axis, Sweden
Communications is a file system developed for embedded systems based on the Linux kernel. 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

 


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.

 

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.