Development: How to develop drivers for USB based devices

From LinuxTVWiki

(Difference between revisions)
Jump to: navigation, search
m (Initial Steps: minor fixes and additons)
m (add cat.)
 
(8 intermediate revisions not shown)
Line 5: Line 5:
The next logical step would be to try to obtain technical datasheets on the component ICs.  Many [[List_of_Chipset_Vendors|chip manufacturers]] make this documentation directly readily available.  In other cases, the datasheets are available, but it will take the likes of a google search to find (i.e. using the chip's part or model number can quickly track down multiple sources for such documentation ... Note: some "datasheet archive" websites ask you to log in or pay in order to obtain the information, however, be advised that the documentation will almost always be available elsewhere completely free of such restrictions).  When no information whatsoever exists, or has been freely released by the chip vendor, if you are still serious about developing driver support for your device, you may wish to contact the vendor directly to see if they will agree to releasing such information to you (which most likely will come in the form of being under a [[NDA]]).  In the very worst instances, particularly those cases of complex chips that also contain DRM (digital rights management) type engines for conditional access purposes, it is unlikely you, as an individual, will be able to obtain help or information from the vendor.
The next logical step would be to try to obtain technical datasheets on the component ICs.  Many [[List_of_Chipset_Vendors|chip manufacturers]] make this documentation directly readily available.  In other cases, the datasheets are available, but it will take the likes of a google search to find (i.e. using the chip's part or model number can quickly track down multiple sources for such documentation ... Note: some "datasheet archive" websites ask you to log in or pay in order to obtain the information, however, be advised that the documentation will almost always be available elsewhere completely free of such restrictions).  When no information whatsoever exists, or has been freely released by the chip vendor, if you are still serious about developing driver support for your device, you may wish to contact the vendor directly to see if they will agree to releasing such information to you (which most likely will come in the form of being under a [[NDA]]).  In the very worst instances, particularly those cases of complex chips that also contain DRM (digital rights management) type engines for conditional access purposes, it is unlikely you, as an individual, will be able to obtain help or information from the vendor.
 +
 +
If you couldn't get enough info, you may try identify what commands are sent to the device by [http://www.linuxtv.org/wiki/index.php/Bus_snooping/sniffing Snooping the device bus]. This procedure is generally simpler with USB devices.
==Familiarizing yourself with a USB driver==
==Familiarizing yourself with a USB driver==
-
To start with, there are some great Linux USB tutorials on Linux Journal:
+
To start with:
 +
* For general references on how to develop a Linux kernel driver module, take a look at the [http://jungla.dit.upm.es/%7Ejmseyas/linux/kernel/hackers-docs.html Index of Documentation for People Interested in Writing and/or Understanding the Linux Kernel].
 +
As for USB drivers specifically, there are some great Linux USB tutorials on Linux Journal:
 +
{{Note|It's likely that these Linux Journal articles contain a fair measure of outdated information (e.g. Hot Plug etc have been replaced by [[Wikipedia:Udev|udev]]).  Nonetheless, they may still contain plenty of other quality information, so it may be well worth a perusal through them}}
 +
 
* start here: [http://www.linuxjournal.com/article/4786 How to Write a Linux USB Device Driver]
* start here: [http://www.linuxjournal.com/article/4786 How to Write a Linux USB Device Driver]
* then here: [http://www.linuxjournal.com/article/7353 Writing a Simple USB Driver]
* then here: [http://www.linuxjournal.com/article/7353 Writing a Simple USB Driver]
-
* here: [http://www.linuxjournal.com/article/5604 Hot Plug]
+
* here: [http://www.linuxjournal.com/article/5604 Hot Plug]  
* and then here: [http://www.linuxjournal.com/article/7582 Snooping the USB Data Stream]
* and then here: [http://www.linuxjournal.com/article/7582 Snooping the USB Data Stream]
In addition, get the source code for the [http://www.linuxtv.org/repo/ LinuxTV V4L-DVB driver set]. You will find that USB based DVB drivers are contained within the ''./v4l-dvb/linux/drivers/media/dvb/dvb-usb'' directory.  Have a bit of a browse through them while you're reading through the first article listed above, and try to get a feel for how the driver is put together (note: there is also a procedure about this that is described in a thread found [http://www.ubuntuforums.org/showthread.php?p=1067326 here]).  Sometimes you can get a good head start in your own development efforts by attempting to leverage parts of earlier released code -- that which may have been written specifically for the exact same chip as contained in your own device or via code for a near similar chip, such as say from a previous production generation.  Simply, modifying existing code to suite your own endeavour can greatly expediate the process of driver development.
In addition, get the source code for the [http://www.linuxtv.org/repo/ LinuxTV V4L-DVB driver set]. You will find that USB based DVB drivers are contained within the ''./v4l-dvb/linux/drivers/media/dvb/dvb-usb'' directory.  Have a bit of a browse through them while you're reading through the first article listed above, and try to get a feel for how the driver is put together (note: there is also a procedure about this that is described in a thread found [http://www.ubuntuforums.org/showthread.php?p=1067326 here]).  Sometimes you can get a good head start in your own development efforts by attempting to leverage parts of earlier released code -- that which may have been written specifically for the exact same chip as contained in your own device or via code for a near similar chip, such as say from a previous production generation.  Simply, modifying existing code to suite your own endeavour can greatly expediate the process of driver development.
-
===Some useful tools===
+
There is also a small amount of information in the "[[DVB via USB|General Information Regarding DVB via USB]]" article.  Likewise, the "[[Development: Reverse Engineering USB Webcams|Reverse Engineering USB Webcams]]" article may contain information of interest.
-
*  [http://benoit.papillault.free.fr/usbsnoop/ usbsnoop] - a Windows USB sniffer utilitly, which adheres to the WDM architecture
+
 
-
** also see [http://www.pcausa.com/Utilities/UsbSnoop/default.htm SniffUSB 2.0] - a usbsnoop derivative
+
==Some useful USB related tools==
-
* parser.pl - a script for parsing the huge usbsniff log file
+
===Windows===
-
* [http://mcentral.de/wiki/index.php5/Usbreplay USB Replay] - allows one to replay parsed usbsnoop logfiles on a Linux system
+
* [[usbsnoop]] - a Windows based utility for sniffing/monitoring communications traffic for a USB device. Note: In case usbsnoop/SniffUSB doesn't work for you, here are a few time limited apps that should work under Vista:
-
** also see this [[ULi_M920x_parse|M920x specific script]] for some ideas
+
** [http://www.hhdsoftware.com/Family/usb-monitor.html USB Monitor] - 14-day trial period
-
* USBmon
+
** [http://www.usblyzer.com/ USBlyzer] - fully functional evaluation version for 33 days
-
* [[Usbmon2usbsnoop]] - a script that converts the output from usbmon to a format that is compatible with USB Replay
+
 
 +
===Linux===
 +
* [[usbmon]] - a Linux kernel module which can snoop and output USB communications traffic
 +
** [[Usbmon2usbsnoop]] - a script that converts the output from usbmon to usbsnoop log format, thereby making the captured data compatible for use with usbreplay (see description below)
 +
** [http://www.wireshark.org/ Wireshark] - can interface with usbmon's output; see the Wireshark wiki page's regarding USB: [http://wiki.wireshark.org/USB here] and [http://wiki.wireshark.org/CaptureSetup/USB here]
 +
* [http://mcentral.de/hg/~mrec/usbreplay/archive/tip.tar.gz parser.pl] - a script for parsing the huge output log files produced by usbsnoop/SniffUSB
 +
* [[usbreplay]] - allows one to replay parsed usbsnoop log files on a Linux system
 +
* [http://usb-robot.sourceforge.net/ usb-robot] (also see [http://sourceforge.net/projects/usb-robot/]) - can play back a log file captured with [[usbsnoop|USB Snoopy]]
-
==Also See==
+
[[Category:Development]]
-
* [[DVB via USB|General Information Regarding DVB via USB]]
+

Latest revision as of 23:49, 15 January 2009

This article is meant to serve as an introduction to the task of developing a driver for a usb based dvb device. Currently, in terms of this subject, there are a number of scattered resources available that, when organized together, could form the basis of a howto suitable for the noice developer. Hence, it might be very worthwile documenting the process.

Contents

Initial Steps

The very first thing you would want to do is to identify the components used in your device as well as determine the device's subsystem ID; refer to the section entitled "Gathering Information About Your Unidentified/Unsupported Device" for details.

The next logical step would be to try to obtain technical datasheets on the component ICs. Many chip manufacturers make this documentation directly readily available. In other cases, the datasheets are available, but it will take the likes of a google search to find (i.e. using the chip's part or model number can quickly track down multiple sources for such documentation ... Note: some "datasheet archive" websites ask you to log in or pay in order to obtain the information, however, be advised that the documentation will almost always be available elsewhere completely free of such restrictions). When no information whatsoever exists, or has been freely released by the chip vendor, if you are still serious about developing driver support for your device, you may wish to contact the vendor directly to see if they will agree to releasing such information to you (which most likely will come in the form of being under a NDA). In the very worst instances, particularly those cases of complex chips that also contain DRM (digital rights management) type engines for conditional access purposes, it is unlikely you, as an individual, will be able to obtain help or information from the vendor.

If you couldn't get enough info, you may try identify what commands are sent to the device by Snooping the device bus. This procedure is generally simpler with USB devices.

Familiarizing yourself with a USB driver

To start with:

As for USB drivers specifically, there are some great Linux USB tutorials on Linux Journal:

Note: It's likely that these Linux Journal articles contain a fair measure of outdated information (e.g. Hot Plug etc have been replaced by udev). Nonetheless, they may still contain plenty of other quality information, so it may be well worth a perusal through them

In addition, get the source code for the LinuxTV V4L-DVB driver set. You will find that USB based DVB drivers are contained within the ./v4l-dvb/linux/drivers/media/dvb/dvb-usb directory. Have a bit of a browse through them while you're reading through the first article listed above, and try to get a feel for how the driver is put together (note: there is also a procedure about this that is described in a thread found here). Sometimes you can get a good head start in your own development efforts by attempting to leverage parts of earlier released code -- that which may have been written specifically for the exact same chip as contained in your own device or via code for a near similar chip, such as say from a previous production generation. Simply, modifying existing code to suite your own endeavour can greatly expediate the process of driver development.

There is also a small amount of information in the "General Information Regarding DVB via USB" article. Likewise, the "Reverse Engineering USB Webcams" article may contain information of interest.

Some useful USB related tools

Windows

  • usbsnoop - a Windows based utility for sniffing/monitoring communications traffic for a USB device. Note: In case usbsnoop/SniffUSB doesn't work for you, here are a few time limited apps that should work under Vista:

Linux

  • usbmon - a Linux kernel module which can snoop and output USB communications traffic
    • Usbmon2usbsnoop - a script that converts the output from usbmon to usbsnoop log format, thereby making the captured data compatible for use with usbreplay (see description below)
    • Wireshark - can interface with usbmon's output; see the Wireshark wiki page's regarding USB: here and here
  • parser.pl - a script for parsing the huge output log files produced by usbsnoop/SniffUSB
  • usbreplay - allows one to replay parsed usbsnoop log files on a Linux system
  • usb-robot (also see [1]) - can play back a log file captured with USB Snoopy
Personal tools