54 CIRCUIT CELLAR • APRIL 2014 #285 EMBEDDED IN THIN SLICES Embedded File Systems (Part 4) COLUMNS Specialized Linux Tools Several types of file systems are available for Linux. This article discusses compressed read- only file systems (CRAMFS), RAM file systems, network file systems (NFS), and the Samba networking protocol. By Bob Japenga (US) o help embedded systems designers using the built-in zlib compression to enable Tachieve their design goals, Linux offers random access of all of the files. This makes a variety of file systems that require only a CRAMFS relatively fast. The file metadata moderate amount of effort to implement. This (e.g., information about when the file was article introduces several file systems and a created, read and write privileges, etc.) is networking protocol and describes how and not compressed but uses a more compact when to use each one. notation than is present in most file systems. WHAT IS A CRAMFS? WHEN TO USE A CRAMFS While pursuing my Master’s degree in The primary reason my company has used 1973, a professor made a statement I will a CRAMFS is to cut down on the flash memory never forget: “Memory prices are plunging used by the file system. The first embedded so fast you will never have to worry about Linux system we worked on had 16 MB of RAM how much memory your designs use from and 32 MB of flash. There was a systems- now on.” Obviously, this professor did not level requirement to provide a means for have a crystal ball and missed something the system to recover should the primary that has been a design challenge in virtually partition become corrupt or fail to boot every embedded system I have designed. Our in any way (see Part 3 of this article series systems demand more and more memory (or “Designing Robust Flash Memory Systems,” file space) and a compressed read-only file Circuit Cellar 283, 2014, for more detail). We system (CRAMFS) can be a useful solution in met this requirement by creating a backup some instances. partition that used a CRAMFS. A CRAMFS is an open-source file system The backup partition’s only function was to available for Linux. I am not sure where the enable the box to recover from the corrupted CRAMFS gets its name. Perhaps it gets its primary partition. How we accomplished that name because a CRAMFS is one way to cram is a discussion for another day, but we had your file system into a smaller footprint. very little flash memory to hold the Linux The files are compressed one page at a time kernel, the file system, the boot-loader, and circuitcellar.com 55 the application. We were able to have the two mount command, you specify the ramfs size. file systems identical in file content, which However, it can grow in size to exceed that made it easy to maintain. Using a CRAMFS amount of RAM. Thus ramfs will enable you enabled us to cut our backup file system to use your entire RAM and not provide you space requirements in half. any with warning that it is doing it. tmpfs A second feature of a CRAMFS is its read- does not enable you to write more than the only nature. Given that it is read-only, it space allocated at mount time. An error is does not require wear leveling. This keeps returned when you try to use more than you the overhead for using CRAMFS files very have allocated. Another difference is that low. Due to the typical data retention of flash tmpfs uses swap space and can swap seldom memory, this also means that for products used files out to a flash drive. ramfs does that will be deployed for more than 10 years, not use swapping. This difference is of little you will need to rewrite the CRAMFS partition value to us since we disable swapping in our COLUMNS every three to five years. embedded systems. The fact that the file system is read-only can make it difficult to deploy in all situations. WHEN TO USE RAM FILE SYSTEMS For example, once our CRAMFS began using In 1987, the Department of Defense began encryption keys that were uniquely calculated requiring the use of Ada in new embedded for each system one time at start-up (this systems. Shortly thereafter I bought an Ada took several minutes on a 200-mHz ARM9 compiler for my IBM PC at work. Much to my processor) the CRAMFS became a problem. surprise, the compiler came with a board We could not store the calculated keys on to plug into the PC. The board added a RAM the CRAMFS and the start-up delay was file system to my PC. To improve the speed unacceptable. This forced us to come up with of compiling from glacial to turtle-like, the an alternate backup file system. compiler designers used a RAM file system to store all intermediate results. HOW TO MAKE A CRAMFS Speed is one of the primary reasons to use As with the other file systems I have a RAM file system. Disk writes are lightning discussed, implementing a CRAMFS with fast when you have a RAM disk. We have used Linux is simple and relatively painless. Linux a RAM file system when we are recording a provides a tool (mkfs) you can use to take any burst of high-speed data. In the background, group of directories and files and create a we write the data out to flash. CRAMFS image. Actually, mkfs is a wrapper A second reason to use a RAM file system for a variety of file system building tools. is that it reduces the wear and tear on the mkfs.cramfs is the tool used to create the flash file system, which has a limited write CRAMFS image. Once written, the image is life. We make it a rule that all temporary files placed in its own partition. should be kept on the RAM disk. We also use it for temporary variables that are needed WHAT ARE RAM FILE SYSTEMS? across threads/processes. Linux provides two types of RAM file systems: ramfs and tmpfs. Both are full- HOW TO MAKE A RAM FILE SYSTEM featured file systems that reside in RAM and Since tmpfs is built into Linux, you can are thus very fast and volatile (i.e., the data simply mount a RAM drive with a command is not retained across power outages and such as: system restarts). When the systems are created with the mount – o size=16G –t tmpfs my_ Hard drive CRC PLC PLC Embedded Embedded Embedded Embedded PLC Embedded Embedded Embedded Embedded controller controller controller controller controller controller controller controller FIGURE 1 This layout shows the memory regions Embedded Embedded Embedded Embedded required to bring up one of my controller controller controller controller company’s embedded Linux designs with no redundancy. 56 CIRCUIT CELLAR • APRIL 2014 #285 tmpfs /mnt/tmpfs The major area in which we use NFS today is during software development. Even though where the maximum size is 16 GB, the type flash file systems are fast and new versions of of file system is tmpfs, the name is my_ your code can be seamlessly written to flash, tmpfs, and the access point (device name) is it can be time consuming. For example, you /mnt/tmpfs. The size can also be specified can use a flash memory stick over USB to in terms of percentage of your total physical update the flash file system on several of our RAM. tmpfs will only use the RAM that it designs. This is simple but can take anywhere needs up to the maximum specified. If you from several seconds to minutes. don’t specify a maximum, it defaults to 50% With an NFS, all of your development tools of your total physical RAM. can be on a PC and you never have to transfer ramfs is also built into Linux and is created the target code to the target system. You use with a command such as: all of your PC tools to change the file on your ABOUT THE AUTHOR PC, and when the embedded device boots up mount –o size=20m –t ramfs my_ Bob Japenga has been or the application is restarted, those changed COLUMNS ramfs /mnt/ramfs files will be used on the device. designing embedded systems since 1973. In where the type is ramfs, the name is my_ HOW TO MAKE AN NFS 1988, along with his ramfs and the access point (device name) is An NFS is built into Linux and thus is pretty best friend, he start- /mnt/ramfs. trivial to set up. The embedded system can ed MicroTools, which mount an external drive using a combination specializes in creating WHAT ARE NETWORK FILE of the Mount command and an entry in the file a variety of real-time SYSTEMS? system table file (usually in /etc/fstab). The embedded systems. In the early 1990s I started working with a external drive requires an NFS driver that is With a combined em- company that developed embedded controllers easily available for Windows and is built into bedded systems experi- for machine control. These controllers had a all Linux distributions. ence base of more than user interface that consisted of a PC located 200 years, they love to on the factory floor. The company called WHAT IS SAMBA? tackle impossible prob- this the production line console (PLC). The Although we don’t like to admit it, many lems together.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages4 Page
-
File Size-