|
Selecting a file systemWhen building an embedded system, one of the important decisions which has to be made is which file system to use. Linux provides a number of file systems, some of which are more suitable to embedded products than others. There are several questions which will influence the decision. For example:
The types of file system which can be considered for ST systems are disk based, memory based and Flash based (as well as network based for development), and combinations of these. Disk oriented file systemsAlthough only a minority of embedded systems use a rotating disk for storage, these are the normal file systems with which people will be familiar from desktop systems, and so can provide a useful point of comparison.
Memory oriented file system
In embedded systems, it is common to present a file system interface to an area of memory. Linux provides several ways to do this. The most common is to treat an area of memory as a block device, and mount a normal file system (for example ext2) on top of this device. This is done by enabling RAM disk support (
A feature of this is that the RAM disk contents can be initialized from a compressed file system image when the system boots. To do this, enable initial read support (
Although it is normal to use ext2 or minix file systems on a RAM disk, if it is not necessary to write to the file system it can be more efficient to use the Compressed ROM file system (
As it is read-only, and applies some restrictions to the file size and file system size, CramFs uses very little extra memory for file meta data. It can also compress the data effectively, saving even more space.
Another way to hold a file system completely in memory is to use TmpFs by setting
This has the advantage that the file system shrinks and expands to contain the contents, whereas a RAM disk size must be decided when the disk is created, and the full memory contents are allocated at that point. Flash file systemsFlash memory is common in embedded systems to allow field upgrades. It can be used to store a file system, but with some restrictions. Flash devices are characterized by being fairly fast to write to, but data cannot be overwritten unless it is first erased, and most devices only allow erasing of large blocks, which can be time-consuming. The easiest way to use Flash as a file system is to use it to store a file system image, which can be accessed directly (using the MTD pseudo block device), or copied to a RAM disk. The disadvantage of this is that the file system is either read-only (in the first case) or read/write but volatile (in the RAM disk case). In many applications this is adequate, and has the advantage that if the file system is corrupted for any reason a system reset restores it to its previous state). However, if the file system needs to be updated in place, then other techniques must be used. The most common way to put a writable file system into Flash in a modern Linux system is to use the Journalling Flash File System JFFS2. This uses Journalling techniques similar to those used by high performance file systems such as ext3, but for very different reasons. As Journalling appends all changes to a file system log, it is not necessary to update data in place, which makes it ideal for Flash. JFFS2 can also compress the data, making very effective use of available space. For more details on JFFS2 see the project's home page. Rather than being built on top of the standard block device interface, JFFS2 uses the MTD Flash interface. This gives it visibility of the Flash characteristics, allowing more intelligent support of Flash devices, for example by being able to write at a finer granularity than the full block, and by performing `wear leveling', this improves performance when writing to the Flash and extends its life. The main disadvantages of using JFFS2 are timing related. At boot time it has to scan the Flash, building up tables of its state, which can take some time. Periodically it needs to erase Flash sectors, which can take several seconds, during which time file system access is denied. However this can usually be overcome by using a buffer process or thread which is decoupled from the real-time parts of the system. Another system is the Flash Translation Layer (FTL). This is a technique for mapping a normal block oriented file system onto Flash devices. It has the disadvantage that it does not provide wear leveling, and as it only presents the normal block device interface it performs more erase cycles trying to emulate the behavior of a magnetic disk. FTL may be subject to patents in some countries. A brief description of how to use it is given in Using the Flash Translation Layer (FTL), but in practice there is little to recommend FTL over JFFS2. Mix and matchAs described above, there are a number of options for file systems, all of which have advantages and disadvantages. However, since it is possible to mount multiple file systems anywhere in the file hierarchy, it is possible to construct a custom file system to meet any requirement.
A typical example would be a system with no need for a writable file system, except for some configuration files which need to be updated and non-volatile, and some temporary data which can be regenerated each time the system boots. In this case, the root file system could be a CramFs file system (compressed and read-only), with a small JFFS2 file system mounted on
Some problems may be seen when booting. These can be overcome using alternative mechanisms. For example, a kernel module may be needed to access the main file system (which has to be mounted on
|
|||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||