Rob KnopCompact Flash Digital Camera
|
Linux, Compact Flash Readers, and Digital Camreas
This page is general advice for getting Compact Flash readers working with Linux. It should apply for any digital camera which uses removable compact flash cards. The camera I use myself is an HP215. It's a low-end 1Mpix camera, and I wouldn't recommend it. It was better once, in full defiance of the manual, I started using rechargeable batteries (of the NiMH variety); before that, I was horrified by the rate at which I was going through AAs. Even now, though, the quality of the camera isn't great. Sometimes it takes very good pictures; sometimes things look flat and washed out, and noisy in sections. It never bothered me, until I borrowed a friend's relatively low-end 2Mpix Canon digital camera, and realized just how much better I could have been doing. Still, as the most casual of camera users, the quality is fine for what I want to do. Interfaces Which Won't WorkI purchased my HP215 camera under the impression that it would work with gphoto2. After I got it, I discovered that the HP 215 and 315 had been mistakenly listed in the list of supported cameras, and that in fact it is not supported by gphoto2. Oops. Digging through the Linux USB resources, I found some people who claimed that the HP PhotoSmart 315 worked with the usb-storage module. I had no luck trying that route with the 215. In other words, for the time being, this camera is not directly supported by Linux. (Note: I wrote this a long time ago. It may well now be supported. However, I'm so happy with the alternate solution I came up with that I've never tried gphoto again.)x Fortunatly, the camera uses CompactFlash cards, and there are ways to read and write those cards with Linux. CompactFlash CardsCompactFlash cards are standard memory cards for embedded devices such as, say, digital cameras. The HP PhotoSmart 215 uses Type I cards, which are (approximately) 44mm x 37mm x 4mm in size. The memory in the card maintains its contents even when the card is not powered. With the HP Photosmart 215 (and, I believe, most devices), the card is configured to have a fat filesystem. Images are saved to the card as normal files in JPEG format. The HP PhotoSmart 215 comes with a 4MB CompactFlash card. This is enough to store about 36 images at Basic (640x480) resolution, about 10 images at Fine (1280x960) resolution, or about 5 images at SuperFine (1280x960) resoluition. Because the exact compression you get in a JPEG image depends on its contents, these numbers are approximate. In my (very limited) experience, the estimates are conservative ones. You can use any standard CompactFlash card with the camera, if you want to be able to store more pictures at once. I got a 16MB card for $30, but nowadays you can probably get a 64MB or even 128MB card for that same price. It is very difficult to get the CompactFlash card out of the HP 215 with your fingers. It is very easy with the supplied plastic "memory extractor tool". Reading/Writing CompactFlash on LinuxSince no Linux tool seems to directly support the HP PhotoSmart 215, using the camera with Linux is reduced to the problem of reading and writing Compcat Flash cards. Fortunately, this turns out not to be very difficult. There are at least two possible solutions. USB CompactFlash Readers
You can buy USB CompactFlash adapters. These typically have a cord which plugs into the USB port, and a slot for inserting a CompactFlash card. The only one I have tried is the SanDisk ImageMate (model SDDR-31) (which sells for $30 or $40). Whichever one you get, make sure that it is supported by the usb-storage kernel module, since not all of them are! In order to use this device, you have to configure your kernel appropriately. It needs the usb-storage driver, which only works with Linux >2.4. The documentation for usb-storage states that it will not work with Linux 2.2. However, I have been told that it does in fact work with Linux 2.2.19. USB and usb-storage are standard in the Linux 2.4 kernel, so you don't have to download any additional drivers. If your kernel doesn't already include support for these drivers (they may be if you use a distribution's kernel), then build a kernel which includes the following drivers (built-in, or as modules):
When you reboot, use modprobe to load any of these drivers which you built as modules. (If you are clever, you can figure out how to do this with modules.conf; or, if you are less clever like me, you can do it in your startup script.) NOTE: I found that with Linux 2.4.19 and the SDDR-31, access to the memory on a card in the device was much slower when the usb-storage module was compiled as a module than when the usb-storage module was compiled directly into the kernel. Why this would be, I have no idea, but once I figured this out I started compiling usb-storage into the kernel. This is probably only an issue if you use a custom kernel (as I do). The stock 2.4.9 kernel that comes with RedHat 7.2 seemed to have reasonably speedy access to the memory on a card in the reader. To get USB working, you should add the following line to your /etc/fstab file:Then issue the command "mount /proc/bus/usb". At this point, you ought to be able to do "cat /proc/bus/usb/devices" and see a listing for your USB reader- assuming it's plugged in! For example, this is an excerpt from my system:none /proc/bus/usb usbdevfs noauto 0 0 T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 4 Spd=12 MxCh= 0 D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=0781 ProdID=0002 Rev= 0.09 S: Manufacturer=SanDisk Corporation S: Product=ImageMate CompactFlash USB S: SerialNumber=000000000004 C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr=100mA I: If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl= 0ms E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl= 0ms Notice that the Driver is listed as usb-storage for this device. If the driver is listed as none, then you have a problem. Finally, we get to actually reading the card. Insert the card into the USB CompactFlash adapter. Assuming you have no other SCSI disks on your system, issue these commands as root: mkdir /mnt/flash If everything is working, then at this point you should have a filesystem at /mnt/flash which is the contents of your card. For the HP PhotoSmart 215, the images show up in subdirctories underneath the /mnt/flash/dcim directory. (Which subdirectories are there seems to have to do with whether or not the camera has felt the need to shut itself off due to weak batteries.) Note that you may or may not want to add "-ofat=12" (or perhaps some other form of "-ofat=xx" argument) between the "-tmsdos" and the "/dev/sda1" above. I am not sure if all CompactFlash cards come formatted with a FAT12 filesystem. You can find out by inserting the card in the reader, and then running (as root) "fdisk /dev/sda" (or /dev/sdb if you have a single real SCSI disk). Type "p" and hit return to see what filesystem is on the CompactFlash card. Type "q" and hit return to exit fdisk (leaving the memory on the card unchanged). If you use any actual real SCSI disks on your system, then the Flash partition may show up at sdb1, sdc1, or whatever is the first unused SCSI device. You may be able to figure this out by poking around in /proc/scsi. If you want to be able to mount and unmount this partition as a normal user, then add the following line to /etc/fstab: /dev/sda1 /mnt/flash vfat noauto,user 0 0 If, above, you found you needed to run "-ofat=12" to your mount command, then add ",fat=12" after "noauto,user" on this line. With this line in /etc/fstab, any user should be able to "mount /mnt/flash". Remember to "umount /mnt/flash" before removing the card from the USB reader!! PCMCIA CompactFlash Readers
This is an option for laptop owners, and also works well. I got a SanDisk reader from eLinux.com a while back, for something like $10. With the PCMCIA card utilities, it looks to the computer just like a standard PCMCIA IDE hard drive. To do it, make sure you've got a kernel with the PCMCIA modules compiled in, and make sure to compile the PCMCIA IDE module. (Kernels for laptops that come with distributions will almost certinaly have these in them.) Make yourself a directory /mnt/pcflash and then add the following line to /etc/fstab: /dev/hdc1 /mnt/pcflash vfat noauto,user 0 0
Replace /dev/hdc1 with whatever device the PCMCIA IDE module places the card at. You can figure this out by looking at your system messages file (/var/log/messages on a RedHat system) right after the card is inserted, or by looking at /var/lib/pcmcia/stab. If you have both a hard drive and an IDE CD-ROM drive on your system, it may well be that the PCMCIA Compact Flash card won't show up at /dev/hdc. As with the USB reader above, you may need to add ",fat=12" after "noauto,user". At this point, after inserting the card, any user can issue the command mount /mnt/pcflash and get to the images on the card just like files on any other filesystem. Remember to unmount the filesystem before physically removing the PCMCIA card reader! (The reason I made the mount point /mnt/pcflash rather than /mnt/flash is that the laptop I've used has a USB port. Sometimes I plug my USB flash reader into the laptop, and that gets mounted at /mnt/flash.) Accessing ImagesOnce you've figured out how to Read and Write the CompactFlash card, it's pretty easy: they're just normal files. Use your favorite image viewer to look at them, the Gimp or netpbm to process them, and standard Linux tools to copy the files out to your hard drive and rename them to something more descriptive than im000101.jpg. With a directory navigator such as Nautlius (or perhaps the KDE equivalent), you can get a directory with thumbnail previews. (Be aware that if you do this, a hidden "dot" directory may get created on the Compact Flash card, using up valuable memory. A quick "ls -a" in the relevant directory will tell you if something is there. |
Last modified: 2003-January-26, by Rob Knop