USB Support for GRUB 2

For USB keyboard, use:

grub> insmod uhci; insmod usb_keyboard; terminal_input usb_keyboard
grub> (input is now processed using USB keyboard)

For USB mass storage, use:

grub> insmod uhci
grub> insmod usbms
grub> ls -l

Testing on QEmu

To test USB Mass Storage, use:

$ qemu -usb -usbdevice disk:/dev/sda ...

To test USB keyboard, use:

$ qemu -usb -usbdevice keyboard ...

To test using real hardware on QEmu (has some problems):

In case QEMu reports that the device cannot be used, read: https://bugs.launchpad.net/virtualbox/+bug/156085

Run lsusb and look at look up the USB device you want to use. For example the following device has bus 5 and device address 7:

Bus 005 Device 007: ID 0781:5406 SanDisk Corp. Cruzer Micro 4GB Flash Drive

$ qemu -usb -usbdevice host:5.7 -fda usb.img

Testing in grub-emu

Compile GRUB 2 with grub-emu enabled. You need to install libusb first.

When starting grub-emu, you need to make sure that grub-emu can access the devices. Also, drivers like usb_storage have to be rmmod'ed.

The "usb" command can be used to list all USB devices. Mass Storage devices that have been added can now be accessed.

Code and Interfaces

include/grub/usbdesc.h: USB Descriptors

include/grub/usbtrans.h: USB Transfers and Transactions

include/grub/usb.h: Should be included by all USB users

include/grub/scsi.h: SCSI support

include/grub/scsicmd.h: SCSI Commands

bus/usb.c: USB helper functions common for all HCIs

bus/usbhub.c: Support for USB Root Hubs and USB Hubs

bus/usb/usbtrans.c: Generic support for USB transfers and transactions

bus/usb/uhci.c: UHCI support

bus/usb/ohci.c: OHCI support

Host Controllers

Every host controller needs to export 5 functions:

Iterate over all host controllers found and supported by this driver

Transfer data over the USB. This supports Control and Bulk transfers. This is called by the functions in usbtrans.c. The host controller can use grub_usb_transfer_t to access information about the transfer, the endpoint and the device.

Returns the number of ports connected to the controller

Sets the status of the port. This function can be used to enable or disable the port.

Detects if a device connected to a certain port and its speed.

All these Host Controller Interfaces should *NOT* be used directly. Instead, helper functions are defined for usage by USB drivers:

USB Functions

Iterate over all USB devices

Returns the endpoint descriptor of a certain endpoint

Clears the STALL state on an endpoint

Requests string descriptions and translates them to UTF-8

Commit a Control transaction to endpoint 0

Commit a Bulk Read transaction

Commit a Bulk Write transaction

GrubWiki: USBSupport (last edited 2009-03-14 13:07:13 by RobertMillan)