/[gentoo]/xml/htdocs/doc/en/usb-guide.xml
Gentoo

Contents of /xml/htdocs/doc/en/usb-guide.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (show annotations) (download) (as text)
Tue Mar 13 01:04:29 2007 UTC (7 years, 5 months ago) by nightmorph
Branch: MAIN
Changes since 1.14: +2 -2 lines
File MIME type: application/xml
typo fix, thanks to ewould on IRC for pointing it out

1 <?xml version='1.0' encoding="UTF-8"?>
2 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/usb-guide.xml,v 1.14 2007/03/13 00:40:27 nightmorph Exp $ -->
3
4 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
5
6 <guide link="/doc/en/usb-guide.xml">
7 <title>Gentoo Linux USB Guide</title>
8
9 <author title="Author">
10 <mail link="fox2mike@gentoo.org">Shyam Mani</mail>
11 </author>
12
13 <abstract>
14 This document helps a user setup USB on a Gentoo system and configure various
15 USB devices as well.
16 </abstract>
17
18 <!-- The content of this document is licensed under the CC-BY-SA license -->
19 <!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
20 <license/>
21
22 <version>1.12</version>
23 <date>2007-03-12</date>
24
25 <chapter>
26 <title>Introduction</title>
27 <section>
28 <title>What is USB?</title>
29 <body>
30
31 <p>
32 USB stands for Universal Serial Bus and is basically an external interface
33 standard that enables communication between the computer and various other
34 peripherals. Some of the most commonly used USB devices today are keyboards,
35 mice, pen drives, digital cameras, external CD &amp; DVD writers, printers etc.
36 </p>
37
38 <p>
39 There are currently two versions of USB in use, i.e. USB 1.1 and USB 2.0.
40 Since USB has always been backward compatible with its previous versions,
41 USB 2.0 is backwards compatible with USB 1.1. The latest USB devices are
42 typically USB 2.0 compatible. USB 2.0 supports a maximum data transmission
43 speed of 480 Mbps or 60 MBps and this is the major difference between the two
44 standards. Another advantage with USB is that the devices are all
45 <e>hot-pluggable</e>, which means that you do not have to restart your system
46 in order for you to be able to use these devices.
47 </p>
48
49 </body>
50 </section>
51 <section>
52 <title>A Technical Perspective</title>
53 <body>
54
55 <p>
56 Before we go onto the exact configuration options in the kernel, it would
57 be apt to look at USB in a little more detail. If you're in a hurry or want
58 to skip this section, please go to <uri link="#kernel">Kernel Configuration</uri>.
59 </p>
60
61 <p>
62 A USB system has a host controller, hubs, a <e>root hub</e> amongst others
63 and can support up to 127 USB devices including the hubs. The host controller
64 is nothing but the hardware interface between the USB device and the
65 operating system. There are a couple of HCI (Host Controller Interface)
66 in use today and they are the OHCI (Open HCI) by Compaq, UHCI (Universal HCI)
67 and EHCI (Enhanced HCI), both from Intel. The OHCI/UHCI are the two industry
68 standard USB 1.1 interfaces whereas the EHCI is for USB 2.0.
69 </p>
70
71 <p>
72 The hardware vendor provides an interface for the programmer that allows
73 the system to interact with the hardware and this is called the HCD or Host
74 Controller Device. It is through this HCD that the device interacts with the
75 system software. The following diagram should make things easier to comprehend.
76 </p>
77
78 <pre caption="General USB Architecture">
79 <comment>(Software consists of other components as well like the device driver, but
80 for the sake of simplicity, they are not shown)</comment>
81
82 + ---- Hardware ---- + ---- Software ---- +
83 | | |
84 | [USB Dev] -+-> {EHCI} -+---> ( EHCD ) |
85 | | | | User
86 | `-> {UHCI} -+---> ( UHCD ) |
87 | | |
88 + ---- Hardware ---- + ---- Software ---- +
89 </pre>
90
91 <p>
92 A USB device can either use a custom driver or use one already present in
93 the system and this is based on the concept of a device <e>class</e>. This
94 means that if a device belongs to a certain <e>class</e>, then other devices
95 belonging to the same <e>class</e> can make use of the same device driver.
96 Some of these <e>classes</e> are the USB HID (Human Interface Devices) class
97 which covers input devices like keyboards and mice, the USB Mass Storage
98 devices class which covers devices like pen drives, digital cameras, audio
99 players etc and the USB CDC (Communication Devices Class) which essentially
100 covers USB modems and similar devices.
101 </p>
102
103 </body>
104 </section>
105 <section>
106 <title>What's on your machine?</title>
107 <body>
108
109 <p>
110 It is very simple to find out whether your machine has USB 2.0 support or not.
111 We make use of the <c>lspci</c> command for this purpose.
112 </p>
113
114 <note>
115 The <c>lspci</c> tool is a part of the <c>sys-apps/pciutils</c> package. If
116 you do not have this installed, please <c>emerge pciutils</c>. Please note
117 that you have to be root while running the <c>lspci</c> command.
118 </note>
119
120 <pre caption="Various lspci outputs">
121 <comment>(In system that is USB 1.1 compliant, note the UHCI only)</comment>
122
123 # <i>lspci -v | grep USB</i>
124 0000:00:04.2 USB Controller: Intel Corp. 82371AB/EB/MB PIIX4 USB (rev 01) (prog-if 00 [UHCI])
125
126 <comment>(A system that is USB 2.0 compliant, note the EHCI and UHCI)</comment>
127
128 00:1d.0 USB Controller: Intel Corp. 82801DB USB (Hub #1) (rev 01) (prog-if 00 [UHCI])
129 00:1d.1 USB Controller: Intel Corp. 82801DB USB (Hub #2) (rev 01) (prog-if 00 [UHCI])
130 00:1d.2 USB Controller: Intel Corp. 82801DB USB (Hub #3) (rev 01) (prog-if 00 [UHCI])
131 00:1d.7 USB Controller: Intel Corp. 82801DB USB EHCI Controller (rev 01) (prog-if 20 [EHCI])
132 </pre>
133
134 <p>
135 So using the <c>lspci</c> command, we can find out if the system supports
136 USB 2.0. This is useful as we will be enabling the corresponding options in
137 the kernel.
138 </p>
139
140 </body>
141 </section>
142 </chapter>
143
144 <chapter id="kernel">
145 <title>Kernel Configuration</title>
146 <section>
147 <title>Getting the kernel</title>
148 <body>
149
150 <note>
151 Since the 2005.0 release, Gentoo Linux uses 2.6 as the default kernel. Unless
152 you are specifically using the 2.4 profile, <c>gentoo-sources</c> will be a
153 2.6 kernel on <e>most</e> architectures. Please check your kernel version and
154 then proceed with the configuration accordingly.
155 </note>
156
157 <p>
158 First emerge the kernel sources of your choice. Here we'll use the
159 <c>gentoo-sources</c>. For more information on the various kernel sources
160 available on Portage, please look up the <uri
161 link="/doc/en/gentoo-kernel.xml">Gentoo Linux Kernel Guide</uri>.
162 </p>
163
164 <pre caption="Getting the kernel sources">
165 # <i>emerge gentoo-sources</i>
166 </pre>
167
168 <p>
169 Now, lets get on with the task of configuring the kernel.
170 </p>
171
172 <pre caption="Heading over to the source">
173 # <i>cd /usr/src/linux</i>
174 # <i>make menuconfig</i>
175 </pre>
176
177 <note>
178 The above example assumes that <path>/usr/src/linux</path> symlink points to
179 the kernel sources you want to use. Please ensure the same before proceeding.
180 </note>
181
182 </body>
183 </section>
184 <section id="newkernelconfig">
185 <title>Config options for the 2.6.x kernel</title>
186 <body>
187
188 <p>
189 Now we will look at some of the options we will have to enable in the 2.6
190 kernel to ensure proper USB support for our devices. If you are using a 2.4
191 kernel, please proceed with <uri link="#oldkernelconfig">Config options for the
192 2.4.x kernel</uri>.
193 </p>
194
195 <note>
196 Examples in this document will show configuration options for basic USB
197 support as well as those needed commonly, for example a USB mass storage
198 device (most cameras and USB pen drives). If you have a specific USB device
199 that needs to be configured, please look up your device's manual or search
200 online to see if that device has support built-in into the kernel or custom
201 drivers that you can use. Please note that for the sake of ease, all examples
202 have the options compiled into the kernel. If you would like to have a modular
203 kernel, ensure that you note down the various modules and adjust your config
204 files accordingly.
205 </note>
206
207 <pre caption="make menuconfig options for 2.6 kernels">
208 Device Drivers ---&gt;
209 SCSI device support ---&gt;
210
211 <comment>(Although SCSI will be enabled automatically when selecting USB Mass Storage,
212 we need to enable disk support.)</comment>
213 --- SCSI support type (disk, tape, CD-ROM)
214 &lt;*&gt; SCSI disk support
215
216 <comment>(Then move back a level and go into USB support)</comment>
217 USB support ---&gt;
218
219 <comment>(This is the root hub and is required for USB support.
220 If you'd like to compile this as a module, it will be called usbcore.)</comment>
221 &lt;*&gt; Support for Host-side USB
222
223 <comment>(Enable this option to see your USB devices in /proc/bus/usb.
224 This is recommended.)</comment>
225 [*] USB device filesystem
226
227 <comment>(Select at least one of the HCDs. If you are unsure, picking all is fine.)</comment>
228 --- USB Host Controller Drivers
229 &lt;*&gt; EHCI HCD (USB 2.0) support
230 &lt; &gt; OHCI HCD support
231 &lt;*&gt; UHCI HCD (most Intel and VIA) support
232
233 <comment>(Moving a little further down, we come to CDC and mass storage.)</comment>
234 &lt; &gt; USB Modem (CDC ACM) support
235 &lt;*&gt; USB Printer support
236 &lt;*&gt; USB Mass Storage support
237
238 <comment>(Then the HID bits.
239 You have to select HID input support if you have a USB keyboard,
240 mouse, joystick or any other USB input device)</comment>
241 --- USB Input Devices
242 &lt;*&gt; USB Human Interface Device (full HID) support
243 [*] HID input layer support
244
245 <comment>(If you have a USB Network Card like the RTL8150, you'll need this)</comment>
246 USB Network Adapters --->
247 &lt;*&gt; USB RTL8150 based ethernet device support (EXPERIMENTAL)
248
249 <comment>(If you have a serial to USB converter like the Prolific 2303, you'll need this)</comment>
250 USB Serial Converter support --->
251 &lt;*&gt; USB Serial Converter support
252 &lt;*&gt; USB Prolific 2303 Single Port Serial Driver (NEW)
253 </pre>
254
255 <p>
256 Now that your options are set, you can (re)compile the kernel and USB support
257 should be functional once you reboot into the new kernel. You can now proceed
258 to <uri link="#postkern">Seeing USB at work</uri> and see if everything is
259 working as it should.
260 </p>
261
262 </body>
263 </section>
264 <section id="oldkernelconfig">
265 <title>Config options for the 2.4.x kernel</title>
266 <body>
267
268 <p>
269 We will look at the options the we will have to enable in the 2.4 kernel to
270 ensure proper USB support for our devices. If you are using a 2.6 kernel,
271 please look at <uri link="#newkernelconfig">Config options for the 2.6.x
272 kernel</uri>.
273 </p>
274
275 <note>
276 Examples in this document will show configuration options for basic USB
277 support as well as those needed commonly, for example a USB mass storage
278 device (most cameras and USB pen drives). If you have a specific USB device
279 that needs to be configured, please look up your device's manual or search
280 online to see if that device has support built-in into the kernel or custom
281 drivers that you can use. Please note that for the sake of ease, all examples
282 have the options compiled into the kernel. If you would like to have a modular
283 kernel, ensure that you note down the various modules and adjust your config
284 files accordingly.
285 </note>
286
287 <pre caption="make menuconfig options for 2.4 kernels">
288 <comment>(This immediate config is only for those who have USB input devices.
289 Input core support is needed by USB HID later.)</comment>
290 Input core support ---&gt;
291 &lt;*&gt; Input core support
292 &lt; &gt; Keyboard support
293 &lt; &gt; Mouse support
294 &lt; &gt; Event interface support
295
296 USB support ---&gt;
297
298 <comment>(This is the root hub and is required for USB support.
299 If you'd like to compile this as a module, it will be called usbcore.o)</comment>
300 &lt;*&gt; Support for USB
301
302 <comment>(Enable this option to see your USB devices in /proc/bus/usb.
303 This is recommended.)</comment>
304 [*] Preliminary USB device filesystem
305
306 <comment>(Select at least one of the HCDs. If you are unsure, picking all is fine.)</comment>
307 --- USB Host Controller Drivers
308 &lt;*&gt; UHCI Alternate Driver (JE) support
309 &lt; &gt; OHCI (Compaq, iMacs, OPTi, SiS, ALi, ...) support
310
311 <comment>(This is the device section. Select only what you need.)</comment>
312 --- USB Device Class drivers
313 &lt; &gt; USB Audio support
314 &lt;*&gt; USB Mass Storage support
315 &lt; &gt; USB Modem (CDC ACM) support
316 &lt;*&gt; USB Printer support
317
318 <comment>(Followed by the HID section. This is needed if you have an USB based input device.)</comment>
319 --- USB Human Interface Devices (HID)
320 &lt;*&gt; USB Human Interface Device (full HID) support
321 [*] HID input layer support
322
323 <comment>(If you have a serial to USB converter like the Prolific 2303, you'll need this)</comment>
324 USB Serial Converter support --->
325 &lt;*&gt; USB Serial Converter support
326 &lt;*&gt; USB Prolific 2303 Single Port Serial Driver (NEW)
327 </pre>
328
329 <p>
330 Now that the options are set, you can (re)compile the kernel and USB support
331 should be functional once you reboot into the new kernel.
332 </p>
333
334 </body>
335 </section>
336 </chapter>
337
338 <chapter id="postkern">
339 <title>Seeing USB at work</title>
340 <section>
341 <title>dmesg is your friend!</title>
342 <body>
343
344 <p>
345 The time has finally come to play with those USB devices :) So let's get
346 started. In this chapter, we'll see how the system responds to various USB
347 devices. We'll start by plugging in a USB 512 MB Memory Stick/Pen Drive. You
348 could use some other similar mass storage device. We will primarily use
349 <c>dmesg</c> to see what is happening and how the system responds to the
350 device.
351 </p>
352
353 <note>
354 <c>dmesg</c> will generally give a lot of output up front before coming to the
355 info we need, as it reads the kernel ring buffer that has all the boot up
356 messages as well. The output in the following examples have only the relevant
357 portion(s) and extra spaces in between to enable better readability. If needed
358 please use a <c>dmesg | more</c> or <c>dmesg | less</c> to see the output
359 better in your system.
360 </note>
361
362 <pre caption="dmesg output for Memory Stick">
363 <comment>(Plug in Memory Stick into available USB port and then..)</comment>
364 # <i>dmesg | less</i>
365
366 <comment>(The device is picked up as a USB 1.1 and allocated an address.
367 Also says what HCD it is using.)</comment>
368 usb 1-1: new full speed USB device using uhci_hcd and address 2
369
370 <comment>(SCSI emulation automatically kicks in)</comment>
371 scsi0 : SCSI emulation for USB Mass Storage devices
372 usb-storage: device found at 2
373
374 <comment>(Now the device information including model number is retrieved)</comment>
375 usb-storage: waiting for device to settle before scanning
376 Vendor: JetFlash Model: TS512MJF2A Rev: 1.00
377 Type: Direct-Access ANSI SCSI revision: 02
378 SCSI device sda: 1003600 512-byte hdwr sectors (514 MB)
379
380 <comment>(The write-protect sense is EXPERIMENTAL code in the later kernels)</comment>
381 sda: Write Protect is off
382 sda: Mode Sense: 0b 00 00 08
383 sda: assuming drive cache: write through
384 SCSI device sda: 1003600 512-byte hdwr sectors (514 MB)
385 /dev/scsi/host0/bus0/target0/lun0: p1
386 Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
387 Attached scsi generic sg0 at scsi0, channel 0, id 0, lun 0, type 0
388 usb-storage: device scan complete
389 <comment>(At this point, the device is generally accessible by mounting /dev/sda1)</comment>
390
391 <comment>(When the device is disconnected, the system acknowledges the same)</comment>
392 usb 1-1: USB disconnect, address 2
393 </pre>
394
395 <p>
396 Once the device is connected and mounted, you can access it like a normal hard
397 disk. Usual operations like <c>cp</c>, <c>mv</c>, <c>rm</c>, etc work fine. You
398 could also create a filesystem on the USB stick/format it.
399 </p>
400
401 <pre caption="Accessing the Memory Stick">
402 # <i>mount /dev/sda1 /mnt/usb</i>
403 # <i>df -h</i>
404 Filesystem Size Used Avail Use% Mounted on
405 /dev/hda8 9.4G 7.5G 1.9G 80% /
406 /dev/hda9 11G 8.1G 2.4G 78% /usr
407 none 189M 0 189M 0% /dev/shm
408 /dev/sda1 490M 34M 457M 7% /mnt/usb
409 </pre>
410
411 <note>
412 Digital cameras can be accessed the same way as memory sticks. I have a Nikon
413 Coolpix 5200 and this is the way I access it. Cameras these days usually have
414 two modes to transfer pictures; USB mass storage and PTP (Picture Transfer
415 Protocol). The camera is set to USB mass storage mode and hence the procedure is
416 exactly the same as that of accessing a memory stick because of which I have not
417 explained in detail about it. Please note that this may NOT work in all cases
418 and with all digital cameras that have USB support.
419 </note>
420
421 <p>
422 How would a USB mouse show up in case you had one? It will show up as an HID
423 device.
424 </p>
425
426 <pre caption="USB Optical Mouse">
427 # <i>dmesg | grep USB</i>
428 drivers/usb/input/hid-core.c: v2.0:USB HID core driver
429 usb 1-1: new low speed USB device using address 2
430 input: USB HID v1.10 Mouse [Logitech USB-PS/2 Optical Mouse] on usb-0000:00:07.2-1
431 </pre>
432
433 <p>
434 Another nifty command you can use to see the status of your USB ports is
435 <c>lsusb</c>. This is part of <c>sys-apps/usbutils</c> and will be covered in
436 the next chapter.
437 </p>
438
439 </body>
440 </section>
441 </chapter>
442
443 <chapter>
444 <title>Userspace USB</title>
445 <section>
446 <title>Nifty tools</title>
447 <body>
448
449 <p>
450 So far we've seen how much support exists on the kernel/system side for USB on
451 Linux. Now we'll take a peek into what kind of support is provided by Gentoo
452 for USB in the userspace.
453 </p>
454
455 <p>
456 One of the most useful tools around is <c>lsusb</c>. This lists all the usb
457 devices connected to the system. Installing it is a breeze.
458 </p>
459
460 <pre caption="Installing usbutils">
461 # <i>emerge usbutils</i>
462 </pre>
463
464 <p>
465 Once installed, you can just run <c>lsusb</c> to get simple info on the USB
466 devices attached to the machine.
467 </p>
468
469 <note>
470 You have to be root in most cases to run <c>lsusb</c>.
471 </note>
472
473 <warn>
474 <c>lsusb</c> reads the information for the USB devices from
475 <path>/proc/bus/usb</path>. If you have not enabled that in your kernel,
476 chances are that <c>lsusb</c> may not work at all. Please ensure you have
477 <path>/proc</path> filesystem support enabled in your kernel and that
478 <c>usbfs</c> is mounted at <path>/proc/bus/usb</path> (which should happen
479 automatically).
480 </warn>
481
482 <pre caption="lsusb at work">
483 # <i>lsusb</i>
484 <comment>(This is the 512 MB Memory Stick from Transcend)</comment>
485 Bus 001 Device 003: ID 0c76:0005 JMTek, LLC. USBdisk
486 <comment>(This is the Optical Mouse)</comment>
487 Bus 001 Device 002: ID 046d:c00e Logitech, Inc. Optical Mouse
488 <comment>(This is the root hub)</comment>
489 Bus 001 Device 001: ID 0000:0000
490 </pre>
491
492 <p>
493 If you are one of those types who love to see lots of information, you have
494 the option of running <c>lsusb -v</c>. Try that and see the amount of info it
495 gives out. Another good option is that <c>lsusb</c> dumps the current physical
496 USB hierarchy as a tree and thus makes it easier to understand the exact
497 device map. The command is <c>lsusb -t</c>. For example,
498 </p>
499
500 <pre caption="lsusb showing USB hierarchy">
501 # <i>lsusb -t</i>
502 Bus# 1
503 `-Dev# 1 Vendor 0x0000 Product 0x0000
504 |-Dev# 2 Vendor 0x046d Product 0xc00e
505 `-Dev# 3 Vendor 0x0c76 Product 0x0005
506 </pre>
507
508 <p>
509 You can easily correlate the outputs of <c>lsusb</c> and <c>lsusb -t</c>,
510 which helps debugging as well as understanding how USB works.
511 </p>
512
513 </body>
514 </section>
515 <section>
516 <title>Hotplug</title>
517 <body>
518
519 <p>
520 Gentoo uses <c>sys-apps/hotplug</c> to do some magic with <e>hot-pluggable</e>
521 devices. Just like any other magic trick, there is a simple logic behind this
522 one too. We shall now see what that is, and in the process hopefully we will be
523 able to understand it better.
524 </p>
525
526 <p>
527 Firmware can be defined as the software on a piece of hardware that is loaded
528 and executed but can't be modified easily. Many devices have firmware in them
529 to ensure that they work properly and often firmware may contain code that is
530 critical to ensure that the hardware performs as expected. Firmware is present
531 in a wide variety of computer devices ranging from ROM chips to state of the
532 art USB and PCMCIA cards. When a device is plugged in, the firmware (which may,
533 in some cases, be the driver as well) is read and loaded onto memory after
534 which the device can be used by the system.
535 </p>
536
537 <p>
538 To cut the long story short, Gentoo uses <c>sys-apps/hotplug</c> to handle
539 the firmware side of things in <e>hot-pluggable</e> devices.
540 <c>sys-apps/hotplug</c> will use the required firmware to make that device
541 usable. The firmware should be put in the <path>/lib/firmware</path> directory
542 and is picked up from there. Getting it is simple; the usual emerge will do.
543 </p>
544
545 <pre caption="Installing hotplug">
546 # <i>emerge hotplug</i>
547 </pre>
548
549 </body>
550 </section>
551 </chapter>
552
553 <chapter>
554 <title>And thanks to...</title>
555 <section>
556 <title>References</title>
557 <body>
558
559 <p>
560 A good number of online documents helped me during the development of this
561 document and there are some that are highly technical but truly interesting.
562 I thought they all deserve some credit, so here we go!
563 </p>
564
565 <ul>
566 <li><uri link="http://www.usb.org">The Official USB Website</uri></li>
567 <li><uri link="http://www.usb.org/about/faq">The USB FAQ</uri></li>
568 <li>
569 <uri
570 link="http://h18000.www1.hp.com/productinfo/development/openhci.html">Compaq's
571 OHCI Standard</uri>
572 </li>
573 <li>
574 <uri link="http://developer.intel.com/technology/usb/uhci11d.htm">Intel's
575 UHCI Standard</uri>
576 </li>
577 <li>
578 <uri link="http://www.intel.com/technology/usb/ehcispec.htm">Intel's EHCI
579 Standard</uri>
580 </li>
581 </ul>
582
583 </body>
584 </section>
585 <section>
586 <title>Other Interesting Links</title>
587 <body>
588
589 <ul>
590 <li><uri link="/doc/en/liveusb.xml">Gentoo Linux LiveUSB HOWTO</uri></li>
591 </ul>
592
593 </body>
594 </section>
595 </chapter>
596 </guide>

  ViewVC Help
Powered by ViewVC 1.1.20