FreeBSD: Using ‘amd’ for the MMC Card Reader


I’m tired of HAL and its problems in NetBSD and FreeBSD to automount devices. I don’t know if it’s a matter of the *BSD implementation, the HAL design, or what… The fact is I need to mount different kind of removable media as pendrives, e-book readers and SD cards in the MMC reader on my Thinkpad R61. The solution is the FreeBSD automounter daemon ‘amd’.

I found this great article that shows you how to use ‘amd’ to mount your CD or pendrive:

http://networking.ringofsaturn.com/Unix/freebsdautomount.php

First of all, the MMC Card Reader has to work! obvious!. Mine works out of the box in PC-BSD 8.1. The output of ‘pciconf -lv’ in my Thinkpad R61 shows:

sdhci0@pci0:21:0:2: class=0x080500 card=0x20c817aa chip=0x08221180 rev=0x21 hdr=0x00
vendor = ‘Ricoh Co Ltd’
device = ‘SDA Standard Compliant SD Host Controller (R5C832)’
class = base peripheral
subclass = SD host controller
none1@pci0:21:0:3: class=0x088000 card=0x20c917aa chip=0x08431180 rev=0x11 hdr=0x00
vendor = ‘Ricoh Co Ltd’
device = ‘Ricoh SD/MMC Host Controller (R5C853)’
class = base peripheral
none2@pci0:21:0:4: class=0x088000 card=0x20ca17aa chip=0x05921180 rev=0x11 hdr=0x00
vendor = ‘Ricoh Co Ltd’
device = ‘Ricoh Memory Stick Host Controller (13171043)’
class = base peripheral
none3@pci0:21:0:5: class=0x088000 card=0x20cb17aa chip=0x08521180 rev=0x11 hdr=0x00
vendor = ‘Ricoh Co Ltd’
device = ‘http://driverzone.com/device.php?id=51441 (01cf1028)’
class = base peripheral

Next, when I insert an SD card in the reader, ‘dmesg’ shows:

mmc0: <MMC/SD bus> on sdhci0 mmcsd0: 1876MB <SD Memory Card> at mmc0 33MHz/4bit

GEOM: mmcsd0: partition 1 does not start on a track boundary.

GEOM: mmcsd0: partition 1 does not end on a track boundary.

The device to be mounted will be ‘/dev/mmcsd0s1’. Test it before:

mount -t msdosfs /dev/mmcsd0s1 /mnt/mmc

Obviously,  ‘/mnt/mmc’ must exist. So, after testing the card reader it’s time to deal with ‘amd’. Add the following content to the files in bold font (do not delete any line, simply add the new ones):

/etc/fstab

#SD Card Reader

/dev/mmcsd0s1 /mnt/mmc msdosfs rw,noauto 0 0

/etc/amd.conf (maybe new file not existing previously)

[ global ]

restart_mounts = yes

unmount_on_exit= yes

/etc/amd.map

* opts:=rw,grpid,resvport,vers=3,proto=tcp,nfs_retransmit_counter=10,nosuid,nodev
localhost type:=auto;fs:=${map};pref:=${key}/

localhost/mmc type:=program;fs:=/mnt/mmc;\
mount:=”/sbin/mount mount /mnt/mmc”;\
unmount:=”/sbin/umount umount /mnt/mmc”

Be sure ‘rpcbind’ is running in your system.

Add the following lines to your ‘/etc/rc.conf’:

rpcbind_enable=”YES”

amd_enable=”YES”

amd_flags=”-p -a /.amd_mnt -c 10 -w 5 -l syslog /host /etc/amd.map /net /etc amd.map”

‘-w 5’ is the interval to wait after an ‘unmount’ attempt.

Start ‘rpcbind’ if necessary:

/etc/rc.d/rpcbind start

and restart/start ‘amd’ as ‘root’:

/etc/rc.d/amd start

Now it’s time to test it. Insert a SD card in the MMC reader and go to ‘/host/localhost/mmc’. If everything goes well you will see the contents of your card . When you go to another directory ‘amd’ will unmount the card. Simply and clever!. Even you can use ‘nautilus’ in your Gnome desktop to go to ‘/host/localhost/mmc’ and ‘amd’ will do the job. When you close the nautilus windows ‘amd’ will unmount it.

I clone the ‘mmc’ configuration for the ‘da1’ device in my e-book reader (BOOX) in order to mount the SD card inserted in it through the USB port (hal/gnome-vfs are not able to do it).

And with a similar philosophy you can mount your pendrives. For example, my ‘/etc/fstab’ has:

#Pendrive
/dev/da0s1 /mnt/da0 msdosfs rw,noauto 0 0
/dev/da1 /mnt/da1 msdosfs rw,noauto 0 0

My last version of ‘/etc/amd.conf’ contains:

# $FreeBSD$
#
#This is the original configuration with PC-BSD
#/defaults type:=host;fs:=${autodir}/${rhost}/host;rhost:=${key}
#* opts:=rw,grpid,resvport,vers=3,proto=tcp,nosuid,nodev#This is my configuration
* opts:=rw,grpid,resvport,vers=3,proto=tcp,nfs_retransmit_counter=10,nosuid,nodev
localhost type:=auto;fs:=${map};pref:=${key}/

localhost/mmc type:=program;fs:=/mnt/mmc;\
mount:=”/sbin/mount mount /mnt/mmc”;\
unmount:=”/sbin/umount umount /mnt/mmc”

localhost/da0 type:=program;fs:=/mnt/da0;\
mount:=”/sbin/mount mount /mnt/da0″;\
unmount:=”/sbin/umount umount /mnt/da0″

localhost/da1 type:=program;fs:=/mnt/da1;\
mount:=”/sbin/mount mount /mnt/da1″;\
unmount:=”/sbin/umount umount /mnt/da1″

TIP: very careful with copy&past from wordpress!!! probably your ‘”‘ characters are not really what they looks like.

And obviously I had to create the ‘/mnt/da0’ and ‘/mnt/da1’ directories.

About jjjesss

I'm a guy interested in technology, bsd fan and concerned about the world around.
This entry was posted in BSD, FreeBSD. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s