Setting up RedHat 9 for PCMCIA memory card reading

file: redhat-pcmcia-setup.html
date: 20 Aug 2004


Beginning with RedHat 7, Linux kernel version 2.4 became the standard kernel in the RedHat distribution. Unfortunately, some of the lesser-used memory card drivers have not been ported to the Linux 2.4 kernel drivers (see comments by David Hinds on 2.4 kernel issues with PCMCIA). Thus the default kernels from RedHat (and others) will not handle "raw" memory cards directly. Support is still available as part of the standalone PCMCIA package. This requires "tweaking" the kernel and rebuilding it, installing the latest pcmcia-cs package from sourceforge.net, then a couple of minor setup changes to RedHat startup files. This document will outline that process.


Getting the new kernel and pcmcia-cs sources

The first step is to get the latest kernel sources for your machine as well as the pcmcia-cs source. Go to redhat.com and look for the most recent kernel RPM's in the support/errata section of the site (Errata: Security Alerts, Bugfixes, and Enhancements). Download the pre-built kernel for your machine, plus the kernel-source package (NOT the kernel-version.src.rpm - you want the kernel-source-version.i386.rpm; for example, on my Dell Inspiron 8100 notebook with RedHat 9 running (in July 2003), it's kernel source kernel-source-2.4.20-18.9.i386.rpm and pre-compiled kernel kernel-2.4.20-18.9.i686.rpm

Follow RedHat's instructions for upgrading your running kernel - get this working before proceeding! Once you are happy that everything is running normally with the new kernel, you can update the kernel source package on your PC as well. If you have rebuilt your kernel before for any reason, backup any .config files you want to keep (the /usr/src/linux-2.4/ source tree will normally be replaced when you upgrade). Once you're happy about your backups, upgrade the kernel source.

Now that you have the latest kernel running, and the matching kernel source is on your machine, get the latest pcmcia-cs source package from pcmcia-cs.sourceforge.net at the downloads page. As of July 2003, the package is pcmcia-cs-3.2.4.tar.gz. Untar this in the /usr/src/ directory. An ls in the /usr/src/ directory (current as of July 2003) shows the following directories:

aragorn: /usr/src#  ls
debug/    kernelconfigs/    linux-2.4@    linux-2.4.20-18.9/    pcmcia-cs-3.2.4/    redhat/

kernelconfigs/ is where I backed up a couple of older .config files for the linux kernel, linux-2.4@ is the symlink to linux-2.4.20-18.9, and pcmcia-cs-3.2.4 is the new pcmcia-cs source tree.


Rebuilding the kernel for standalone PCMCIA support

To rebuild the kernel for use with standalone PCMCIA support, you need to turn off PCMCIA support in the kernel then recompile everything. Here's how:

  1. cd to the /usr/src/linux-2.4/ directory (everything that follows is done in this directory)
  2. make clean
  3. make mrproper
  4. copy the config file for your installed kernel from /usr/src/linux-2.4/configs/ (or from the backup of a special build you kept in /usr/src/kernelconfigs/ ) to .config in the current directory. In my case, kernel-2.4.20-i686.config is the config file that was originally used to build the stock kernel.
  5. make xconfig
    1. The "Linux Kernel Configuration" window will pop up
    2. Go to "General setup" and select "PCMCIA/CardBus Support" to pop up the next window
    3. The first choice in the "PCMCIA/CardBus Support" window can Enable, Modularize, or Disable PCMCIA support in the kernel - select "N" to disable kernel support
    4. Click on "OK" to leave this window, and "Main Menu" to go back to the main window.
    5. Go to "File systems" and scrol down to "Ext3 journalling file system support" - select "Y" to build ext3 support directly into the kernel
    6. Click on "Main Menu" to leave this window and go back to the main window.
    7. Click on "Save and Exit" to finish configuration.
  6. The top-level Makefile includes the variable name EXTRAVERSION; typically it is set to the extra version number of the source tree with the word custom appended ( -18.9custom in my case). If it DOESN'T have that extension, be sure to add it so you don't overwrite all your current kernel and module directories in the following steps.
  7. make dep
  8. make bzImage
  9. make modules
  10. make modules_install
  11. cd to /usr/src/linux-2.4/arch/i386/boot/ and copy the new kernel, bzImage, to the /boot directory on your system.

Now that the kernel and modules have been rebuilt, it might be a good idea to be sure you have a boot floppy available to reboot your current system if anything goes wrong in the next several steps. If you don't have a working boot floppy, make one now. See the man page for mkbootdisk for a handy way to make a boot floppy (example: if your current kernel is version 2.4.20-18.9, put a 1.4MB floppy in your drive and enter mkbootdisk 2.4.20-18.9 to create a boot disk for the running kernel).

Next update your bootloader configuration file (lilo.conf or grub.conf) to add the new kernel - DON'T remove the references to the current kernel. Add the lines for the new kernel so that you still default to the current kernel, and can choose the new kernel at boot time. Here's a typical example for grub.conf:

title Red Hat Linux (2.4.20-18.9)
        root (hd0,1)
        kernel /vmlinuz-2.4.20-18.9 ro root=/dev/hda11 hdb=ide-scsi
        initrd /initrd-2.4.20-18.9.img
title Red Hat 9 custom (2.4.20-18.9custom)
        root (hd0,1)
        kernel /bzImage ro root=/dev/hda11 hdb=ide-scsi

If you use lilo.conf, the syntax is similar, but different; and don't forget to run /sbin/lilo after you save the new lilo.conf to actually update the boot record (there is no equivalent step for grub).

Now try rebooting to make sure everything is still working; if you kept your old kernel as default, everything should start up like always. Reboot again, and at the grub (or lilo) prompt, select the new kernel. Again, everything (except PCMCIA) should start up normally. Fix any problems BEFORE proceeding. When you are sure everything is OK, make a boot floppy for the new kernel as described earlier, then modify your bootloader configuration file to make the new kernel the default.


Building the standalone PCMCIA support package

Now build the standalone PCMCIA support package as follows (you must now be running the new kernel):

  1. cd to the /usr/src/pcmcia-cs-3.2.4/ directory (everything that follows is done in this directory)
  2. .Configure
  3. make all
  4. make install

Testing the standalone PCMCIA support package

Now test the new PCMCIA support; you should have a memory card with some data on it available for testing. First manually install the PCMCIA modules and restart PCMCIA services as follows:

  1. service pcmcia stop
  2. modprobe pcmcia_core
  3. modprobe i82365
  4. modprobe ds
  5. service pcmcia start
The first command may fail or give some message; that's OK for now. If you get any other errors, you probably missed a step somewhere.

If these commands worked, an lsmod command should show the three modules in the list. You should now be able to plug in a memory card and get two "happy" beeps. Another lsmod command should show that memory_cs and a couple of other memory related modules are now present; doing ls /dev/mem* should show several memory devices present, as follows:

/dev/mem /dev/mem0a /dev/mem0a0c /dev/mem0c /dev/mem0c0b /dev/mem0c0c

Copy the card contents to a file as follows:

cp /dev/mem0c0c test-file

then look at the file with:

od -t x1 -A x test-file | less

See Linux FLASH Card Reading for more info.


Modifying the system startup files to use standalone PCMCIA support

The final steps to reconfiguring your notebook PC to use standalone PCMCIA support require modifying a couple of system files. Keep old copies to use if you want to go back to your old kernel for any reason.

  1. save /etc/sysconfig/pcmcia to /etc/sysconfig/pcmcia.old
  2. Edit /etc/sysconfig/pcmcia to change PCIC=i82365
  3. save the edited /etc/sysconfig/pcmcia to /etc/sysconfig/pcmcia.new
  4. This should do it on most new installs. If it doesn't, make sure the pcmcia script in /etc/rc.d/init.d/ is handling the PCIC variable correctly. If not, you may need to go on to the next few steps and clean up old references to yenta_socket and the .o extensions mentioned below. Otherwise, skip to the last step:

    1. save /etc/rc.d/init.d/pcmcia to /etc/rc.d/init.d/pcmcia.old
    2. Edit /etc/rc.d/init.d/pcmcia as follows:
      1. Find the reference to PCIC=yenta_socket and change it to PCIC=i82365
      2. Find the references to pcmcia_core.o and ds.o and change these to pcmcia_core and ds (no .o extension)
    3. save the edited /etc/rc.d/init.d/pcmcia to /etc/rc.d/init.d/pcmcia.new

  5. Reboot should now load all the base pcmcia modules automatically on startup - test by inserting a memory card as above.

Document any extra or special steps you took....NOW!!