Since I have exactly the same issue and no solution so far, please allow me to repost the question by Charlotte J at superuser again on this board:
I am trying to turn Raspberry Pi Zero W as a "boot compatible" keyboard (USB gadget). I've followed this tutorial to make it work in OS, i.e. when plugged into a Mac computer that has been powered on and logged into a user, I can send keystrokes via Raspberry Pi to the Mac by running scripts writing bytes to the device file (/dev/hidg0). The tutorial makes use of two modules: dwc2 and libcomposite.
However, I need the Pi to work as a keyboard in Mac's EFI (BIOS). Specifically, I want to send Command+R keystroke as the Mac is booting up to enter the recovery mode.
[AlanT: My application would be to type in the user password to unlock rootFs encryption and let the macOS boot up to allow ssh login.]
Looking at the official document from the USB org, boot keyboards require support for SET_PROTOCOL and GET_PROTOCOL requests from the host (Appendix B.1 and F.3). I did modify the report descriptor as shown in Appendix B.1.
According to line 496 to 606 in this class in Raspberry Pi Linux source code, it seems like the module supports SET_PROTOCOL and GET_PROTOCOL requests.
However, Pi as a keyboard gadget does not work in EFI; only in OS.
Does libcomposite not include f_hid.c class? If not, does anyone have any insight into how to implement a boot keyboard gadget? I feel like I am missing something.
Thank you very much in advance!
Fyi (this is the descriptor cited by 1):
PS: My current descriptor looks like this (from https://github.com/pikvm/kvmd/blob/master/kvmd/apps/otg/hid/keyboard.py):
KEYBOARD_HID = Hid( protocol=1, # Keyboard protocol subclass=1, # Boot interface subclass report_length=8, report_descriptor=bytes([ # https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt # Keyboard 0x05, 0x01, # USAGE_PAGE (Generic Desktop) 0x09, 0x06, # USAGE (Keyboard) 0xA1, 0x01, # COLLECTION (Application) # Modifiers 0x05, 0x07, # USAGE_PAGE (Keyboard) 0x19, 0xE0, # USAGE_MINIMUM (Keyboard LeftControl) 0x29, 0xE7, # USAGE_MAXIMUM (Keyboard Right GUI) 0x15, 0x00, # LOGICAL_MINIMUM (0) 0x25, 0x01, # LOGICAL_MAXIMUM (1) 0x75, 0x01, # REPORT_SIZE (1) 0x95, 0x08, # REPORT_COUNT (8) 0x81, 0x02, # INPUT (Data,Var,Abs) # Reserved byte 0x95, 0x01, # REPORT_COUNT (1) 0x75, 0x08, # REPORT_SIZE (8) 0x81, 0x03, # INPUT (Cnst,Var,Abs) # LEDs output 0x95, 0x05, # REPORT_COUNT (5) 0x75, 0x01, # REPORT_SIZE (1) 0x05, 0x08, # USAGE_PAGE (LEDs) 0x19, 0x01, # USAGE_MINIMUM (Num Lock) 0x29, 0x05, # USAGE_MAXIMUM (Kana) 0x91, 0x02, # OUTPUT (Data,Var,Abs) # Reserved 3 bits in output 0x95, 0x01, # REPORT_COUNT (1) 0x75, 0x03, # REPORT_SIZE (3) 0x91, 0x03, # OUTPUT (Cnst,Var,Abs) # 6 keys 0x95, 0x06, # REPORT_COUNT (6) 0x75, 0x08, # REPORT_SIZE (8) 0x15, 0x00, # LOGICAL_MINIMUM (0) 0x25, 0x65, # LOGICAL_MAXIMUM (101) 0x05, 0x07, # USAGE_PAGE (Keyboard) 0x19, 0x00, # USAGE_MINIMUM (Reserved) 0x29, 0x65, # USAGE_MAXIMUM (Keyboard Application) 0x81, 0x00, # INPUT (Data,Ary,Abs) 0xC0, # END_COLLECTION ]), )