-rw-r--r--   1 root  root   1098640 Sep 17 22:03 jffs2.bin

drwxr-xr-x  13 root  root      4096 Sep 17 22:02 jffs2-image-dir

#

The directory structure and files from Listing 9-8 are in the jffs2-image-dir directory in our example. We arbitrarily execute the mkfs.jffs2 command from the directory above our file system image. Using the -d flag, we tell the mkfs.jffs2 command where the file system template is located. We use the -o flag to name the output file to which the resulting JFFS2 image is written. The resulting image, jffs2.bin, is used in Chapter 10, 'MTD Subsystem,' when we examine the JFFS2 file together with the MTD subsystem.

It should be pointed out that any Flash-based file system that supports write operations is subject to conditions that can lead to premature failure of the underlying Flash device. For example, enabling system loggers (syslogd and klogd) configured to write their data to Flash-based file systems can easily overwhelm a Flash device with continuous writes. Some categories of program errors can also lead to continuous writes. Care must be taken to limit Flash writes to values within the lifetime of Flash devices.

9.6. cramfs

From the README file in the cramfs project, the goal of cramfs is to 'cram a file system into a small ROM.' The cramfs file system is very useful for embedded systems that contain a small ROM or FLASH memory that holds static data and programs. Borrowing again from the cramfs README file, 'cramfs is designed to be simple and small, and compress things well.'

The cramfs file system is read only. It is created with a command line utility called mkcramfs. If you don't have it on your development workstation, you can download it from the link at the end of this chapter. As with JFFS2, mkcramfs builds a file system image from a directory specified on the command line. Listing 9-10 details the procedure for building a cramfs image. We use the same file system structure from Listing 9-8 that we used to build the JFFS2 image.

Listing 9-10. mkcramfs Command Example

# mkcramfs

usage: mkcramfs [-h] [-v] [-b blksize] [-e edition] [-i file] [-n name]

dirname outfile

-h         print this help

-E         make all warnings errors (non-zero exit status)

-b blksize use this blocksize, must equal page size

-e edition set edition number (part of fsid)

-i file    insert a file image into the filesystem (requires >= 2.4.0)

-n name    set name of cramfs filesystem

-p         pad by 512 bytes for boot code

-s         sort directory entries (old option, ignored)

-v         be more verbose

-z         make explicit holes (requires >= 2.3.39)

dirname    root of the directory tree to be compressed

outfile    output file

#

# mkcramfs . ../cramfs.image

warning: gids truncated to 8 bits (this may be a security concern)

# ls -l ../cramfs.image

-rw-rw-r--  1 chris chris 1019904 Sep 19 18:06 ../cramfs.image

The mkcramfs command was initially issued without any command line parameters to reproduce the usage message. Because there is no man page for this utility, this is the best way to understand its usage. We subsequently issued the command specifying the current directory, ., as the source of the files for the cramfs file system, and a file called cramfs.image as the destination. Finally, we listed the file just created, and we see a new file called cramfs.image.

Note that if your kernel is configured with cramfs support, you can mount this file system image on your Linux development workstation and examine its contents. Of course, because it is a read-only file system, you cannot modify it. Listing 9-11 demonstrates mounting the cramfs file system on a mount point called /mnt/flash.

Listing 9-11. Examining the cramfs File System

# mount -o loop cramfs.image /mnt/flash

# ls -l /mnt/flash

total 6

drwxr-xr-x  1 root  root 704 Dec 31  1969 bin

drwxr-xr-x  1 root  root   0 Dec 31  1969 dev

drwxr-xr-x  1 root  root 416 Dec 31  1969 etc

drwxr-xr-x  1 root  root   0 Dec 31  1969 home

drwxr-xr-x  1 root  root 172 Dec 31  1969 lib

drwxr-xr-x  1 root  root   0 Dec 31  1969 proc

drws------  1 root  root   0 Dec 31  1969 root

drwxr-xr-x  1 root  root 272 Dec 31  1969 sbin

drwxrwxrwt  1 root  root   0 Dec 31  1969 tmp

drwxr-xr-x  1 root  root 124 Dec 31  1969 usr

drwxr-xr-x  1 root  root 212 Dec 31  1969 var

#

You might have noticed the warning message regarding group ID (GID) when the mkcramfs command was executed. The cramfs file system uses very terse metadata to reduce file system size and increase the speed of execution. One of the 'features' of the cramfs file system is that it truncates the group ID field to 8 bits. Linux uses 16-bit group ID field. The result is that files created with group IDs greater than 255 are truncated with the warning issued in Listing 9-10.

Although somewhat limited in terms of maximum file sizes, maximum number of files, and so on, the cramfs file system is ideal for boot ROMS, in which read-only operation and fast compression are ideally suited.

9.7. Network File System

Those of you who have developed in the UNIX environment will undoubtedly be familiar with the Network File System, or simply NFS. Properly configured, NFS enables you to export a directory on an NFS server and mount that directory on a remote client machine as if it were a local file system. This is useful in general for large networks of UNIX/Linux machines, and it can be a panacea to the embedded developer. Using NFS on your target board, an embedded developer can have access to a huge number of files, libraries, tools, and utilities during development and debugging, even if the target embedded system is resource constrained.

As with the other file systems, your kernel must be configured with NFS support, for both the server-side functionality and the client side. NFS server and client functionality is independently configured in the kernel configuration.

Detailed instructions for configuring and tuning NFS are beyond the scope of this book, but a short introduction helps to illustrate how useful NFS can be in the embedded environment. See Section 9.11.1 at the end

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату