Thanks to everyone who sent feedback. Here's where I've gotten.
First I got a current libpayload. That made the biggest difference. Evidently something critical changed in the last month.
The USB keyboard specific stuff in my code is... usb_initialize(); if (havekey()) usb_key = getchar();
The havekey() function is still always returning 1. But now the call to getchar() is returning valid keystrokes.
The first time havekey() is called the following is output to the console...
00:12.2 4396:1002.2 EHCI controller * found device (0x0403:0x6014, USB 2.0), class: unsupported class ff 00:12.0 4397:1002.0 OHCI controller OHCI Version 1.0 00:13.2 4396:1002.2 EHCI controller 00:13.0 4397:1002.0 OHCI controller OHCI Version 1.0 * found device (0x045e:0x009d, USB 2.0) NOTICE: This driver defaults to using the first interface. This might be the wrong choice and lead to limited functionality of the device. Please report such a case to coreboot@coreboot.org as you might be the first. , class: HID Keyboard layout 'us'
The mainboard I'm currently debugging this on doesn't have a PS/2 keyboard controller. It just has a USB keyboard. I'm going to move over to another mainboard that has both to see what happens there.
Thanks again, Dave
----- Original Message -----
From: "Nico Huber" nico.huber@secunet.com To: "Dave Frodin" dave.frodin@se-eng.com Cc: coreboot@coreboot.org Sent: Monday, November 19, 2012 6:14:42 AM Subject: Re: [coreboot] Using USB keyboard in payloads
I'm unable to get the USB keyboard to work in payloads. I'm using it with libpayload, and configured libpayload to enable the USB_HID, USB_OHCI, USB_EHCI, USB_UHCI, USB_XHCI drivers.
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() regularly.
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).
Nico
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());
- } halt(); return 0;
}