Device Drivers, Part 11: USB Drivers in Linux

Let's ride the USB

This article, which is part of the series on Linux device drivers, gets you started with writing your first USB driver in Linux.

Pugs’ pen drive was the device Shweta was playing with, when both of them sat down to explore the world of USB drivers in Linux. The fastest way to get the hang of it, and Pugs’ usual way, was to pick up a USB device, and write a driver for it, to experiment with. So they chose a pen drive (a.k.a. USB stick) that was at hand — a JetFlash from Transcend, with vendor ID 0x058f and product ID 0x6387.

USB device detection in Linux

Whether a driver for a USB device is there or not on a Linux system, a valid USB device will always be detected at the hardware and kernel spaces of a USB-enabled Linux system, since it is designed (and detected) as per the USB protocol specifications. Hardware-space detection is done by the USB host controller — typically a native bus device, like a PCI device on x86 systems. The corresponding host controller driver would pick and translate the low-level physical layer information into higher-level USB protocol-specific information. The USB protocol formatted information about the USB device is then populated into the generic USB core layer (the usbcore driver) in kernel-space, thus enabling the detection of a USB device in kernel-space, even without having its specific driver.

After this, it is up to various drivers, interfaces, and applications (which are dependent on the various Linux distributions), to have the user-space view of the detected devices. Figure 1 shows a top-to-bottom view of the USB subsystem in Linux.

USB subsystem in Linux

Figure 1: USB subsystem in Linux

A basic listing of all detected USB devices can be obtained using the lsusb command, as root. Figure 2 shows this, with and without the pen drive plugged in. A -v option to lsusbprovides detailed information.

Output of lsusb

Figure 2: Output of lsusb

In many Linux distributions like Mandriva, Fedora,… the usbfs driver is loaded as part of the default configuration. This enables the detected USB device details to be viewed in a more techno-friendly way through the /proc window, using cat /proc/bus/usb/devices. Figure 3 shows a typical snippet of the same, clipped around the pen drive-specific section. The listing basically contains one such section for each valid USB device detected on the system.

USB's proc window snippet

Figure 3: USB's proc window snippet

Decoding a USB device section

To further decode these sections, a valid USB device needs to be understood first. All valid USB devices contain one or more configurations. A configuration of a USB device is like a profile, where the default one is the commonly used one. As such, Linux supports only one configuration per device — the default one. For every configuration, the device may have one or more interfaces. An interface corresponds to a function provided by the device.

There would be as many interfaces as the number of functions provided by the device. So, say an MFD (multi-function device) USB printer can do printing, scanning and faxing, then it most likely would have at least three interfaces, one for each of the functions. So, unlike other device drivers, a USB device driver is typically associated/written per interface, rather than the device as a whole — meaning that one USB device may have multiple device drivers, and different device interfaces may have the same driver — though, of course, one interface can have a maximum of one driver only.

It is okay and fairly common to have a single USB device driver for all the interfaces of a USB device. The Driver=... entry in the proc window output (Figure 3) shows the interface to driver mapping — a (none) indicating no associated driver.

For every interface, there would be one or more end-points. An end-point is like a pipe for transferring information either into or from the interface of the device, depending on the functionality. Based on the type of information, the endpoints have four types: Control, Interrupt, Bulk and Isochronous.

As per the USB protocol specification, all valid USB devices have an implicit special control end-point zero, the only bi-directional end-point. Figure 4 shows the complete pictorial representation of a valid USB device, based on the above explanation.

USB device overview

Figure 4: USB device overview

Coming back to the USB device sections (Figure 3), the first letter on each line represents the various parts of the USB device specification just explained. For example, D for device, C for configuration, I for interface, E for endpoint, etc. Details about these and various others are available in the kernel source, in Documentation/usb/proc_usb_info.txt.

The USB pen drive driver registration

“Seems like there are so many things to know about the USB protocol, to be able to write the first USB driver itself — device configuration, interfaces, transfer pipes, their four types, and so many other symbols like T, B, S, … under a USB device specification,” sighed Shweta.

“Yes, but don’t you worry — all of that can be covered in detail later. Let’s do first things first — get the pen drive’s interface associated with our USB device driver (pen_register.ko),” consoled Pugs.

Like any other Linux device driver, here, too, the constructor and the destructor are required — basically the same driver template that has been used for all the drivers. However, the content would vary, as this is a hardware protocol layer driver, i.e., a horizontal driver, unlike a character driver, which was one of the vertical drivers discussed earlier. The difference would be that instead of registering with and unregistering from VFS, here this would be done with the corresponding protocol layer — the USB core in this case; instead of providing a user-space interface like a device file, it would get connected with the actual device in hardware-space.

The USB core APIs for the same are as follows (prototyped in <linux/usb.h>):

int usb_register(struct usb_driver *driver);
void usb_deregister(struct usb_driver *);

As part of the usb_driver structure, the fields to be provided are the driver’s name, ID table for auto-detecting the particular device, and the two callback functions to be invoked by the USB core during a hot plugging and a hot removal of the device, respectively.

Putting it all together, pen_register.c would look like what follows:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>

static int pen_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
    printk(KERN_INFO "Pen drive (%04X:%04X) plugged\n", id->idVendor, id->idProduct);
    return 0;
}

static void pen_disconnect(struct usb_interface *interface)
{
    printk(KERN_INFO "Pen drive removed\n");
}

static struct usb_device_id pen_table[] =
{
    { USB_DEVICE(0x058F, 0x6387) },
    {} /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, pen_table);

static struct usb_driver pen_driver =
{
    .name = "pen_driver",
    .id_table = pen_table,
    .probe = pen_probe,
    .disconnect = pen_disconnect,
};

static int __init pen_init(void)
{
    return usb_register(&pen_driver);
}

static void __exit pen_exit(void)
{
    usb_deregister(&pen_driver);
}

module_init(pen_init);
module_exit(pen_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Kumar Pugalia <email_at_sarika-pugs_dot_com>");
MODULE_DESCRIPTION("USB Pen Registration Driver");

Then, the usual steps for any Linux device driver may be repeated:

  • Build the driver (.ko file) by running make.
  • Load the driver using insmod.
  • List the loaded modules using lsmod.
  • Unload the driver using rmmod.

But surprisingly, the results wouldn’t be as expected. Check dmesg and the proc window to see the various logs and details. This is not because a USB driver is different from a character driver — but there’s a catch. Figure 3 shows that the pen drive has one interface (numbered 0), which is already associated with the usual usb-storage driver.

Now, in order to get our driver associated with that interface, we need to unload the usb-storage driver (i.e., rmmod usb-storage) and replug the pen drive. Once that’s done, the results would be as expected. Figure 5 shows a glimpse of the possible logs and a procwindow snippet. Repeat hot-plugging in and hot-plugging out the pen drive to observe the probe and disconnect calls in action.

Pen driver in action

Figure 5: Pen driver in action

Summing up

“Finally! Something in action!” a relieved Shweta said. “But it seems like there are so many things (like the device ID table, probe, disconnect, etc.), yet to be understood to get a complete USB device driver in place.”

“Yes, you are right. Let’s take them up, one by one, with breaks,” replied Pugs, taking a break himself.

  • Baban Gaigole

    Learn how to create drivers for Micromax mmx 352g for ubuntu 11.04

  • Baban Gaigole
  • Pingback: driver for a device in linux

  • Karan86 Mehra

    I am trying to implement the above module but when i do rmmod usb-storage it shows me following error:
    ERROR: Module usb_storage does not exist in /proc/modules
    could anyone help me out

    • http://twitter.com/anil_pugalia Anil Pugalia

      usb_storage might be built into the kernel. You might have to recompile the kernel with usb_storage built as a module.

  • http://sosaysharis.wordpress.com/ Haris Ibrahim K. V.

    This is weird. I do not have the ‘usb’ folder within my /proc/bus ! I have folders ‘input’ and ‘pci’ there. Why is there this mismatch? My kernel is 2.6.32-40-generic

    • free4freedom

      I tried using older kernel( I used Ubuntu 8.04, with 2.6.24.x ) , but surprisingly it showed me /proc/bus/usb/ , thats all , no device file !!

      Anyway, I found another way out, use command :
      udevadm info –attribute-walk –name
      where : could be /dev/sdb1 etc. It gives a lengthy o/p , try using a pipe & then grep to get what ever u want.

    • akash

      i am facing same problm … I do not have the ‘usb’ folder within my /proc/bus ..

      do i need to custumize ma kernel or here is any other way also ..bcos i hv not done this before …m kind of afraid ..

      • http://twitter.com/anil_pugalia Anil Pugalia

        Follow the instructions as mentioned above. Ubuntu doesn’t have it by default. Or, use lsusb -v

        • akash

          root@ubuntu:/home/ayush# sudo apt-get install linux-source-3.2.0 kernel-package libncurses5-dev fakeroot
          Reading package lists… Error!
          E: Encountered a section with no Package: header
          E: Problem with MergeList /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise_main_binary-i386_Packages
          E: The package lists or status file could not be parsed or opened.

          I was trying 1st command mentioned in above link …. can u tell wht is the problm in above cmmnd

          • http://twitter.com/anil_pugalia Anil Pugalia

            Not really sure. But looks like something to do with your package management on ubuntu. Check out & resolve by googling for the error.

  • chipGIR

    @twitter-41866709:disqus ,
    Many thanks for sharing the post and everything you explained works like charm, but I might be doing something stupid or probably not aware if some other things need to be tweaked.

    device driver: insmod pen_register.ko triggers probe and I confirmed by dmesg but I’m not able to see the pen drive neither in nautilus nor in file system disk usage( df -h).

    Secondly, issuing #cat /dev/pen1 results in -110 results is connection timeout.

    here is the strace of read

    #strace -e trace=read cat /dev/pen1
    read(3, “177ELF111331000m1004″…, 512) = 512
    read(3, “# Locale name alias data base.n#”…, 4096) = 2570
    read(3, “”, 4096) = 0
    read(3, 0x8d4f000, 32768) = -1 ETIMEDOUT (Connection timed out)
    cat: /dev/pen1: Connection timed out
    #

    Please let know further steps to perform a read/write on the usb drive

    • http://www.facebook.com/anil.pugalia Anil Pugalia

      I believe if you have followed the article – you are anyway not expected to be able to read & write yet. I am doubtful as what is this /dev/pen1 referring to – it might be the one exposed by the usb-storage driver. Read the next articles in series to get the next steps

  • bill

    thank you for the article !
    I think that “lsusb -v” has a sufficient output for those who have usbfs disabled. isn’t it ?

    • anil_pugalia

      Yes, at least what ever is required for the first level.

      • akash

        my kernel version is new ..so i did lsusb -v ….bt by using this command how can i check which driver is associated with the my pendrive … i want to see that my pendrive is connected to driver = usb-storage ..

        result(partial) of lsusb -v :
        Bus 001 Device 004: ID 0951:1643 Kingston Technology DataTraveler G3 4GB
        Device Descriptor:
        bLength 18
        bDescriptorType 1
        bcdUSB 2.00
        bDeviceClass 0 (Defined at Interface level)
        bDeviceSubClass 0
        bDeviceProtocol 0
        bMaxPacketSize0 64
        idVendor 0×0951 Kingston Technology
        idProduct 0×1643 DataTraveler G3 4GB
        bcdDevice 1.00
        iManufacturer 1 Kingston
        iProduct 2 DataTraveler G3
        iSerial 3 001CC0EC32BCBB611712008E
        bNumConfigurations 1
        Configuration Descriptor:
        bLength 9
        bDescriptorType 2
        wTotalLength 32
        bNumInterfaces 1
        bConfigurationValue 1
        iConfiguration 0
        bmAttributes 0×80
        (Bus Powered)
        MaxPower 200mA
        Interface Descriptor:
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 2
        bInterfaceClass 8 Mass Storage
        bInterfaceSubClass 6 SCSI
        bInterfaceProtocol 80 Bulk-Only
        iInterface 0
        Endpoint Descriptor:
        bLength 7
        bDescriptorType 5
        bEndpointAddress 0×81 EP 1 IN
        bmAttributes 2
        Transfer Type Bulk
        Synch Type None
        Usage Type Data
        wMaxPacketSize 0×0200 1x 512 bytes
        bInterval 0
        Endpoint Descriptor:
        bLength 7
        bDescriptorType 5
        bEndpointAddress 0×02 EP 2 OUT
        bmAttributes 2
        Transfer Type Bulk
        Synch Type None
        Usage Type Data
        wMaxPacketSize 0×0200 1x 512 bytes
        bInterval 0
        Device Qualifier (for other device speed):
        bLength 10
        bDescriptorType 6
        bcdUSB 2.00
        bDeviceClass 0 (Defined at Interface level)
        bDeviceSubClass 0
        bDeviceProtocol 0
        bMaxPacketSize0 64
        bNumConfigurations 1
        Device Status: 0×0000
        (Bus Powered)

        pls reply :)

        • http://twitter.com/anil_pugalia Anil Pugalia

          Install & try the usbview app.

          • akash

            hi .. i hav downloaded this usbview app ..bt how to install it on ubuntu ..pls help.. i knw i m asking very silly questions bt i m a begginer pls help

          • akash

            i was trying to install using ubuntu software centre bt some erreor : System program problem detected is coming and ubuntu software centre get stopped unexpectedly
            also Could not determine the package or source package name. this error is coming pls help

          • http://twitter.com/anil_pugalia Anil Pugalia

            I think you do not need to download or so. As you are on ubuntu, you may just type the following command on the shell: sudo apt-get install usbview

          • akash

            i got this error while using : sudo apt-get install usbview

            Reading package lists… Error!
            E: Encountered a section with no Package: header
            E: Problem with MergeList /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise_main_binary-i386_Packages
            E: The package lists or status file could not be parsed or open: do apt-get install usbview

          • http://twitter.com/anil_pugalia Anil Pugalia

            Something wrong with the network or the installation. Please check & fix.

  • shivang

    it gives me following error when it insert module by writing insmod command

    insmod: error inserting ‘usbstick.ko’: -1 Unknown symbol in module

    • anil_pugalia

      Check out the dmesg output for which symbol in your driver is not yet resolved. And then, fix that. Possibly, you might have got warnings while compilation and have ignored them.

      • akash

        i also got the same error … bt in my case it was bcos i hav not included

        MODULE_LICENSE(“GPL”); this line …. can u explain me why it was giving this error insmod: error inserting usb.ko :-1 Unknown symbol in module
        for not including license macro

        • http://twitter.com/anil_pugalia Anil Pugalia

          That may be just a coincidence. You may have fixed it somewhere else.

  • jaya

    thanks for this awesome post .. yesterday i tried it and it worked fine … but i have a small doubt if u can help :

    1) when i plugs in my pen drive it is getting detected by my driver . but when i am using another pen drive usb-storage module(which i removed by rmmod usb-storage) get inserted by itself . how it is happening ??

    2) and is there any way so that all the pendrive get detected by my module only not by usb-storage ..

    • http://twitter.com/anil_pugalia Anil Pugalia

      1) module autoload rules under /lib/modules//modules.usbmap, typically get the modules loaded automatically.
      2) Change the above file.

  • pteaches

    Sir, what is the difference between USB device driver and USB interface driver? because interface is a part of device, so we are writting drivers for interfaces and not for a device . do we writting driver for device or interface ? I am confused in these terminologies . Please guide me .

    • anil_pugalia

      We write a (USB) device driver only. But interesting, you can have one driver per interface of the USB device. Hence, if we have multiple interfaces in a USB device, we technically could have more than one device driver for that same device. That’s what is being highlighted as “… so we are writing drivers for interfaces and not for a device …”.

  • SID

    Hey help me..
    Got everthing right.. and worked like charm….
    Now we did “rmmod usb-driver” after this when i insert my pen drive for the normal usage it does not show me my files. I mean the auto pop up file whioch appear after the insertion of the pendrive
    please help ,how do i revert back.

    Thanks

    SID

    • anil_pugalia

      Just load the usb-storage driver back. Or, just plug out & plug in the pen drive.

  • SID

    I would like to add something here.

    In latest Ubuntu and the kernel higher than v3 you will not find the detailed description of the device in “cat /proc/bus/usb/devices”. In fact there is not “/proc/bus/usb/” present. You can find the detailed info in “sys/kernel/debug/usb/devices”. ‘cat’ this particular location for the detailed info of the USB devices which you cannot get from ‘lsusb’ command

    SID

    • anil_pugalia

      Thanks for sharing that info.

  • Tanmay

    What M.Tech intern projects do you suggest based on the USB device drivers, if you have any ideas please tell me.

    • anil_pugalia

      Take up a USB Device like the DDK (http://lddk.eSrijan.com) and then write a driver for it. Make it multi-device capable.

      • Tanmay

        Hello Sir,
        Thanks for the reply, but i have one question in mind, as my project is of one year duration so can this project be regarded as major project for the internship purpose??or if you have any suggestion regarding any other project please give it to me.
        Thanks once again.

        • anil_pugalia

          If you want to make that project a one year project, you may also take up writing the firmware for the DDK, to make it your customized USB device, and then write the drivers for it.

      • Tanmay

        Also,sir if you have any ideas regarding the projects based on device drivers other then this then please tell me.

        • anil_pugalia

          Just to clarify, it is a device driver project.

          • Tanmay

            yes,sir i know it’s a device driver based project but if the you have any other project then this please tell me…Thanks..

          • anil_pugalia

            As I work mainly with the DDK, I can only suggest something with it only. For more options, please do google.

  • Tanmay

    Sir, I am doing lsusb -v from the terminal but it didn’t show the detailed information about the vendor id and product id, i also tried /proc/bus/usb/devices but there is no such directory present with this name,i also tried cat “/sys/kernel/debug/usb/devices” but it is showing the error as “permission denied”, so what’s the solution of this problem please tell me.

    • anil_pugalia

      Do cat /sys/kernel/debug/usb/devices, as root.

      • Tanmay

        sir, i have tried this also but it is showing “Permission denied” error so now what next step i can do plz tell me.

        • anil_pugalia

          Just show the permissions of each folder in the path.

          • Tanmay

            hello sir,
            Didn’t get you, please tell me the detailed steps how to solve this problem.

          • anil_pugalia

            Send the output of the following (as root):
            ls -ld /sys/kernel/debug
            ls -ld /sys/kernel/debug/usb
            ls -ld /sys/kernel/debug/usb/devices

          • Tanmay

            Hello Sir,

            The output of the following will be as follows:-

            (1) ls -ld /sys/kernel/debug

            O/p–> drwx—— 17 root root 0 Sep13 13:13 /sys/kernel/debug

            (2) ls -ld/sys/kernel/debug/usb

            O/P—- > ls: cannot access /sys/kerneldebug/usb: Permission denied.

            (3) ls -ld/sys/kernel/debug/usb/devices

            O/P—-> ls: cannot access /sys/kerneldebug/usb: Permission denied.

          • anil_pugalia

            Have you done all these as root? Seems like not – otherwise the second command should not give the mentioned error.

          • Tanmay

            Hello Sir,
            I have done all this as a root only but it gives me same error time and again please tell me the solution to it.

          • anil_pugalia

            Do the following as root: mount -t debugfs none /sys/kernel/debug/ and then check out.

  • Tanmay

    Hello Sir,

    When i am using Oracle VM VirtualBox, then it will not show the usb device connected, and will not show any information about it, while when i dual boot the PC and installed Linux Ubuntu separately, then it will show the detailed report of all the usb devices connected just by doing “sudo lsusb”and “lsusb -v” as mentioned above,
    Showing detailed report of vendor id and product id.

    Please, tell me what is the reason behind not showing what sort of usb devices connected when i use VirtualBox.

    • anil_pugalia

      Virtual Boxes typically need various configuring and setting for the real hardware mapping into the virtual box, which is by default not done. And hence, you do not see the real devices, as such, unless specifically configured.

      • Tanmay

        So, sir is there a way i can see my usb devices connected to my computer while using VirtualBox. How can i then see all the usb devices connected configuring my VirtualBox??

        • anil_pugalia

          Typically, while setting up virtual box, you need to configure that it should allow/connect the USB devices. Once done, you can see the connected USB devices, as in any normal Linux system.

  • Siddique

    Hi Anil Sir,

    In this article, you have not used alloc_chrdev_region(..) like in previous articles to register the device, but instead you have used usb defined function.
    Is this function intern typedef with alloc_chrdev_region ?

    If both are not related functions, Can you please explain when to use alloc_chrdev_region and when to not ?

    Thanks,
    Siddique

  • Tanmay

    Why we need to remove the usb-storage module to get the result displayed on the terminal with the dmesg command ???

    • anil_pugalia

      The usb-storage driver has already acquired the pen drive’s interface. So, for our driver to take it, we need to get it released from the usb-storage driver – and the easiest way is to remove that.

  • Mayank

    I removed usb-storage module as mentioned above but it gets automatically inserted when the pendrive is plugged in again. Can anyone tell me how to stop automatic loading of usb-storage module?

    • anil_pugalia

      Easiest way is to plugin the pendrive and then unload the driver. Harder way would be to comment out the auto load settings in the udev configs &/or /lib/modules//modules.usbmap

  • Souarv

    Hi Anil ,

    I am also facing the same problem what Mayank is facing. usb-storage module gets automatically inserted when the usb is plugged-in again. plz help.

    • anil_pugalia

      Try out the suggestion mentioned below.

  • Pranav

    Dear Sir ,

    I have executed the makefile but when I try to insert the module by calling the insmod command – I get the following error :

    root@ubuntu:/home/pranav/Desktop/test# insmod pen_register.ko
    insmod: error inserting ‘pen_register.ko’: -1 Unknown symbol in module

    Sir , Please help me out urgently as I have a project deadline in a few days .

    Looking forward to your reply .

    • anil_pugalia

      After the error, do “dmesg | tail” to check out the details of the “unknown symbol” error. That would help you check which symbol in the pen-driver.ko is unresolved, and that will give a direction to fix that.

      • Pranav

        Thank You Sir .

        Actually the problem was cropping up because I had not added :

        MODULE_LICENSE(“GPL”); which is necessary to load the module in linux kernel 2.6.3 upwards

  • Ajay

    hi sir,
    i m geting tis msg whem i m trying to insert the module,
    plz let me know the solution.

    root@ubuntu:/home/ajay/modules# insmod usb.ko
    insmod: error inserting ‘usb.ko’: -1 Device or resource busy
    root@ubuntu:/home/ajay/modules# make

    • anil_pugalia

      What is this usb.ko? Please provide some details.

  • Prakash S

    Can you please tell me y it shows 3 times ?
    “Pen drive (..) plugged” on insmod
    “Pen drive removed” on rmmod

    i am Using Ubuntu 12.04..

  • Sreenadh S

    Sir,

    I want to write bare minimum Linux device drivers
    of USB, Ethernet and SATA for my arm board.
    The USB, Ethernet and SATA IP
    cores are developed by us. So it is not possible to download those drivers from
    internet. We have the working full fledged firmware for those.
    The only need
    is to convert those firmware to simple Linux device driver format.
    I just
    want a simple structure of the drivers for doing that. I have read many
    documents; but all those documents are complicated and so I am not getting a
    start to develop those drivers.

    Sincerely,

    Sreenadh S.

  • Sunitha Parunandi

    Hi Sir,

    while removing usb_storage am getting it is in use ,please how should i remove .

    sunitha@SUNITHA:~$ sudo rmmod usb_storage
    ERROR: Module usb_storage is in use by ums_realtek

    • anil_pugalia

      What is the ums_realtek driver for? You may have to remove that, to be able to remove usb_storage.

  • Alexandre

    Dear Anil, first of all thank you for having taken the time to spread your knowledge with us. I really appreciate people doing that. Then my question: was is the Terminating entry line ? Why do we have to add and empty {} inside the usb_device_id array ?
    Thanks,

    • anil_pugalia

      To figure out that no more entries exist. Because there could be any number of entries.

  • Juri Pospelow

    Dear Anil, could you say me please, how can I unload the usb-storage driver under ubuntu?
    thank you

    • anil_pugalia

      Lot of discussions are there below, regarding the same. Though in the simplest form, it should happen by doing “rmmod usb-storage”. Otherwise, dig through the discussions below.

      • Juri Pospelow

        it is resolved! Under Ubuntu you must as first disconnect the USB-stick, then rmmod usb-storage! Else you get error message from Ubuntu!
        But thank you anyway!

  • Akshay

    HI,
    1)
    I’m trying to insmod/modprobe usb-storage.
    I’m getting the following error:
    FATAL: Module usb_storage not found.

    I dont know why is it not found.
    neither am i able to access any flash drive.

    2)
    By using .config, how can u alter usb storage devices settings.. any particular device like sandisk cruzer pop!?

    Thanks!

    • anil_pugalia

      1) Seems like you have renamed / moved the usb_storage.ko* file.

      2) .config is a kernel configuration file and have nothing to do directly with any device.

      • Akshay

        Hi Anil,
        How do you modify a class driver of a particular device.
        For e.g i have a SanDisk flash drive, i want to edit its class driver so that whenever it is attached to the system, a message should appear on the console or something. And by the way where in the tree, can i find the code for the class driver?

        • anil_pugalia

          The corresponding driver is the usb_storage driver – source code of which is available inside the kernel sources under the following folder: drivers/usb/storage

  • Rahul

    Hi,

    In this post you are installing the module using insmod, is there any way to do the same thing automatically, while I am building my kernel ?

    • anil_pugalia

      I assume you mean to say building the module into the kernel. Yes, it can be done. For that you need to add corresponding entries into the relevant Makefile & Kconfig file of the kernel.

      • Rahul

        So you mean to say it will load automatically ?? And what will happen to usb-storage, as it will also be there? I am asking because i have tried this ..but now luck in auto loading.

        • anil_pugalia

          Once compiled into the kernel, it is no longer a module but part of the kernel and hence gets loaded as part of the kernel itself. Any module, whether it is usb-storage or any other, it should either be compiled into the kernel or as a separate .ko module, not as both.

  • Akshay

    Hi Anil,
    I wanna know what happens before a USB device is connected.
    1. I mean, what initialization process takes place related to USB?
    2. How the core gets “ready”?
    3. Are all the probe functions in usb set up initially or only when a device is connected?
    4. Is there an array where the core stores all the class drivers (HID, Mass storage etc) so that it can decide which one to load?

    Sorry a long list. Please bear!

    • anil_pugalia

      1. As per the USB protocol.
      2. Its typically pre-loaded or loaded on first USB request.
      3. probe functions are part of device drivers
      4. auto load is typically achieved using the modules.usbmap &/or udev configurations.

      • Akshay

        Thanks.

        About the last one, I have seen (in the /USB/core/driver.c code) that the core, based on the idVendor, idProduct or class/subClass/protocol will decide which class driver to allocate (rather load) when a particular device is added (eg. USB mass storage). So what does it compare with? There must be some table or array or maybe a list which stores all the data regarding all the class drivers available under USB. I wanted to know, at the code level, what is there? I tried to search, couldn’t find anything.

        • anil_pugalia

          That’s what I mentioned. Check out /lib/modules//modules.usbmap

          • Akshay

            Oh yeah. thanks. i checked it now.

All published articles are released under Creative Commons Attribution-NonCommercial 3.0 Unported License, unless otherwise noted.
Open Source For You is powered by WordPress, which gladly sits on top of a CentOS-based LEMP stack.

Creative Commons License.