[coreboot] Using USB keyboard in payloads

Nico Huber nico.huber at secunet.com
Mon Nov 19 14:14:42 CET 2012

> I'm unable to get the USB keyboard to work in payloads.
> I'm using it with libpayload, and configured libpayload to enable
> I call usb_initialize() in the early part of my payload.
> Calls to usbhid_havechar() just return 0.
When calling usbhid_havechar() directly, one should also call usb_poll()
> Calls to havechar() just return 0xFF.
Suspicious, havechar is defined as havekey in libpayload.h, havekey()
should return 0 or 1. However, havekey() calls usb_poll() and, thus,
should work.

> The USB keyboard works fine with SeaBIOS, which I am using to
> load my payload as a boot option. I see no difference if I load
> my payload directly from coreboot.
> Does anyone have any ideas as to what I'm missing?
If you use an USB hub, you should also enable USB_HUB. If you have
an OHCI controller, try the latest upstream version, OHCI was broken
for some time.

> Any suggestions or examples?
Well, the USB HID implementation is quite fragile when it comes to
timing. usb_poll() should be called at least once every 200ms with no
guaranty what happens when you fail to do so. Also, detaching devices
(hot unplugging) is broken.

You should see some output from libpayload when it detects USB
controllers / devices, did you?

With some modification (see below), libpayload's 'Hello World' example
shows input from keyboards (works with UHCI / EHCI+hub for me).


> Thanks in advance,
> Dave

diff --git a/payloads/libpayload/sample/hello.c b/payloads/libpayload/sample/hello.c
index 677a96f..86113af 100644
--- a/payloads/libpayload/sample/hello.c
+++ b/payloads/libpayload/sample/hello.c
@@ -34,7 +34,13 @@
 int main(void)
+	usb_initialize();
 	printf("Hello world!\n");
+	while (1) {
+		if (havechar())
+			putchar(getchar());
+	}
 	return 0;

More information about the coreboot mailing list