16 March, 2010

Getting a USB Mass Storage (UMS) device to work in Ubuntu

I recently had a need to get an unrecognized USB mass storage (UMS) device to work in Ubuntu (my favorite desktop operating system). While this is seldom needed anymore due to the rich driver support built into Ubuntu/Linux, I had a USB mass storage device that was not recognized. In this case, I knew that it was indeed a ums device, as it had a custom MS Windows driver. This post will step through what I did in case anyone else might benefit.

Step 1: Determine the vendor and product id of the device

Run lsusb to list all devices. If you don't have lsusb installed, install usbutils via apt-get or synaptic.

The output from lsusb should look something like this:

Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID bbbb:b001 Unrecognized Device
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 046d:c521 Logitech, Inc. MX620 Laser Cordless Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

lsusb will list all usb devices present on the system, including usb hubs. As you can see I have 2 client devices plugged in - a mouse and the "Unrecognized Device". The ID of the device is what is important here. The name of the device is immaterial. Now I note the ID of the device "bbbb:b001". The first part of the ID is the vendor ID, while the second part is the device ID.

Step 2: Add the device to the usb module map.

The usb module map is used to map device IDs to the appropriate usb module. In Ubuntu 9.10, this map is stored in /lib/modules/<kernel>/modules.usbmap, where kernel is the name of the kernel you are currently running. Run "uname -r" to get the kernel name for your system.

Once you have located the modules.usbmap file, add a line to the end of the file for your device. The line we add in this case is:

usb-storage 0x000f 0xbbbb 0xb001 0x0001 0x0001
0x00 0x00 0x00 0x00 0x00
0x00 0x0

I must confess that I have not bothered to fully understand what all of the values here mean. That being said, the relevant values are the 1st, 3rd and 4th values. The first value indicates the driver module to load. For a ums device, the module is usb-storage. The 3rd and 4th values are the vendor and device IDs we noted in step 1.

Once this is complete, run depmod, which will regenerate the binary files for the kernel to load.

Step 3. Add a custom rules.dev entry to set the permissions.

At this point, you may have enough for your device to be recognized, but it won't have the permissions that you'll need to use it as a normal user. To get past this, we're going to add a simple custom udev entry.

We'll create a new file in /etc/udev/rules.d to modify the permissions. Udev loads rules files based on alphabetical order. The default rules are 50-udev-default.rules. We'll name our rules file 51-unrecognized.rules with the following content:

SUBSYSTEM=="usb", SYSFS{idVendor}=="bbbb", MODE="0666"

The vendor ID from step 1 is placed in the SYSFS{idVendor} field.

Step 4. Test it out!

At this point you can try to connect your device. If it works, you're done. If not, you'll need to re-compile the usb-storage driver as I did. In my next post I'll break down the steps necessary to accomplish that.

No comments:

Post a Comment