Using CompactFlash Cards in Your Embedded Linux System

Use a CompactFlash card as a nonmechanical alternative to a disk drive.

When designing embedded systems, the designer has many choices to make. If you sell thousands of units, you spend lots of time designing around the most inexpensive parts you can find. You design custom circuit boards and search high and low for the best components that you can get for the cheapest price.

If you build only one or two units, the time and cost needed to design the perfect circuit board and find the best parts can eat up the entire budget for your product. In this case, off-the-shelf parts are the best choice.

Most of my projects are for one or two units, so I'm always looking for inexpensive items I can use. The 25¢ MP3 playing chip that can only be bought in lots of 10,000 doesn't help me at all. If there was a $25 chip that I could get in single quantities, I might be interested.

I am an amateur radio operator and a member of the Tucson Amateur Packet Radio organization (TAPR). This organization is dedicated to the support and advancement of amateur radio digital communications by providing publications, meetings and electronic kits. I recently purchased a couple of IDE CompactFlash adapters from them (see Figure 1). This product is a circuit board that allows you to use standard CompactFlash memory cards as an IDE device in a PC.

Figure 1. IDE CompactFlash Card Adapter

If you have a digital camera or a portable MP3 player, you might have seen a CompactFlash card (see Figure 2). My Nikon digital camera uses these cards to store images. The cards contain between 2MB and 192MB of Flash memory. Flash memory is read/write memory that does not lose its contents when the power is disconnected.

Figure 2. A Dimensionally Indicative Photo of a CompactFlash Card

When building an embedded system based on the Linux operating system, the first problem to solve is how to boot the operating system. It might be possible to purchase an ISA or PCI card that has ROM on it and place your code in these ROMs. I haven't tried this because I haven't found affordable boards to do this.

You could use a floppy drive or hard drive in your embedded device, but I've found that anytime you can reduce the number of moving parts, you increase reliability. These drives also draw a lot of current and generate heat, so they could cause other problems.

Using the TAPR CompactFlash adapter would let you boot the operating system off of a CompactFlash card. These cards aren't terribly expensive, and they are very small. They have no moving parts, so they could be a good solution for embedded projects.

For this article, I show how to build a Linux system on the CompactFlash card. When you boot this system, it starts up a web server. Of course, I have bigger plans for the future, but there just isn't enough room in this article.

Installing the Hardware

The CompactFlash adapter has three connectors and one jumper. It has an IDE connector, a CompactFlash card connector and a power connector. The jumper is used to make this device the master or slave IDE device. It is very easy to install in a system. I used a development system to build the software and a target system to test and run the software. I installed the CompactFlash adapter on the secondary IDE connector of my development box. It is configured as the master device on this controller, so Linux will see the CompactFlash adapter as /dev/hdc on my development box. My development box has a hard drive for the /dev/hda device that has Mandrake Linux 7.2 on it. Almost any Linux distribution should work, though. I also have an IDE CD-ROM on my development system that is the /dev/hdb device on the primary IDE controller.

I am using a 32MB CompactFlash card for my device, but if you want to duplicate my results from this article, an 8MB card will work. The CompactFlash will be used when the target system boots, so it would need to be device /dev/hda on the target. It should be connected to the primary IDE controller and configured as a master device. In this application, it is the only IDE device in the target system. You could connect other needed devices.

If your BIOS supports autodetection of drive parameters, it should detect the card. If it doesn't, you'll have to enter parameters for the cylinders, heads and sectors. Check the TAPR web site for some example parameters you can use. Make sure that you do not install or remove a CompactFlash card while the system is powered on. This could cause data corruption. At the very least, it will confuse the operating system if a device disappears or appears with no warning.

My target system will have an NE2000-compatible Ethernet card in it. Make sure you have the proper drivers for the network card you have in your target system. If you installed the driver as a module, you'll need to modify the /etc/init.d/rcS file also.

______________________

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState