Skip to content

Overlay USB config instead of sed-patching upstream's config/usb.h - #4

Merged
mastacontrola merged 1 commit into
masterfrom
fix-efi-usb-keyboard-config
Aug 6, 2026
Merged

Overlay USB config instead of sed-patching upstream's config/usb.h#4
mastacontrola merged 1 commit into
masterfrom
fix-efi-usb-keyboard-config

Conversation

@mastacontrola

Copy link
Copy Markdown
Member

Every EFI binary this repository publishes is built without a USB keyboard driver. On ipxe.efi that leaves the machine with no keyboard at all at the FOG boot menu — reported against Lenovo M70t/M80t Gen3 in forums #18213.

buildipxe.sh patched three settings into upstream's config/usb.h with sed. v2.0.0 restructured that file — a space where the pattern wants a tab, and USB_KEYBOARD/USB_EFI moved into a live PLATFORM_efi block instead of being commented-out lines:

#if defined ( PLATFORM_efi )
  #define USB_EFI
  //#define USB_HCD_USBIO
  #undef USB_KEYBOARD	/* Use built-in EFI keyboard driver */
#endif

All three patterns stopped matching. sed exits 0 when nothing matches, so the build stayed green and every EFI binary silently took upstream's defaults.

Upstream's default is coherent on its own terms: leave USB_KEYBOARD out and re-expose the devices iPXE owns through USB_EFI so the firmware's keyboard driver can re-bind. But ipxe.efi carries the native xHCI/EHCI/UHCI drivers and efi_driver_connect_all() binds them, taking the controller off the firmware first. Where that re-bind doesn't happen, no keyboard driver is left anywhere.

Fixed by overlaying config/local/usb.h, which upstream's config/usb.h includes last, so FOG's values win. This restores the configuration FOG shipped for years rather than inventing one. The point isn't only that it works today — an overlaid file can't half-apply the way a sed pattern can, so the next refresh onto a new upstream tag can only break this loudly. Same pattern as the general.h override in 9b69e5b.

Verification

Built config/config_usb.c both ways and read the objects it drags in:

build before after
EFI obj_efi_usb obj_xhcino keyboard driver obj_usbio obj_usbkbd obj_xhci
BIOS obj_usbkbd obj_xhci obj_usbkbd obj_xhci (unchanged)

Linked both EFI targets to confirm the blast radius is limited to ipxe.efi:

ipxe.efi     ehci.o uhci.o usbblk.o usbhid.o usbio.o usbkbd.o xhci.o
snponly.efi  (none)

snponly.efi links no USB objects either way and is byte-identical with and without the overlay (267776 bytes both). That also confirms the reported asymmetry: ipxe.efi binds the USB controllers away from the firmware and then has nothing to drive the keyboard with, while snponly.efi never touches USB.

Not yet verified on affected hardware.

Scope

Does not address the other half of #18213, the /dev/ram0 kernel panic on snponly.efi. That one is the installer publishing autoexec.ipxe into the TFTP root and is fixed in fogproject.

Refs FOGProject/fogproject#960.

🤖 Generated with Claude Code

Every EFI binary this repository publishes is built without a USB keyboard
driver. On ipxe.efi that leaves the machine with no keyboard at all at the FOG
boot menu (forums #18213, Lenovo M70t/M80t Gen3).

buildipxe.sh patched three settings into upstream's config/usb.h with sed:

    sed -i 's+//#define\tUSB_HCD_USBIO+#define\tUSB_HCD_USBIO+g'
    sed -i 's+//#undef\tUSB_KEYBOARD+#define\tUSB_KEYBOARD+g'
    sed -i 's+//#undef\tUSB_EFI+#undef\tUSB_EFI+g'

v2.0.0 restructured that file. USB_HCD_USBIO now has a space where the pattern
wants a tab, and USB_KEYBOARD/USB_EFI are no longer commented-out lines at all
-- upstream moved them into a live PLATFORM_efi block:

    #if defined ( PLATFORM_efi )
      #define USB_EFI
      //#define USB_HCD_USBIO
      #undef USB_KEYBOARD	/* Use built-in EFI keyboard driver */
    #endif

All three patterns stopped matching. sed exits 0 when nothing matches, so the
build stayed green and every EFI binary silently took upstream's defaults.

Upstream's default is coherent on its own terms: leave USB_KEYBOARD out, and
re-expose the devices iPXE owns through USB_EFI so the firmware's own keyboard
driver can re-bind on top. But ipxe.efi carries the native xHCI/EHCI/UHCI
drivers and efi_driver_connect_all() binds them, taking the controller off the
firmware first. Where that re-bind does not happen there is no keyboard driver
left anywhere. snponly.efi has no native host controller drivers, so the
firmware keeps USB and its keyboard works -- which is exactly the asymmetry
reported.

Fixed by overlaying config/local/usb.h, which upstream's config/usb.h includes
last, after its own PLATFORM_efi block, so FOG's values win. This restores the
configuration FOG shipped and tested for years rather than inventing one. The
point is not just that it works today: an overlaid file cannot half-apply the
way a sed pattern can, so the next refresh onto a new upstream tag can only
break this loudly. Same reasoning as the general.h override in 9b69e5b --
state the deviation, do not edit upstream's copy.

The BIOS overlay is a no-op against v2.0.0, where USB_HCD_USBIO exists only
inside the PLATFORM_efi block and a BIOS build cannot pick it up. It is kept
because the sed it replaces was load-bearing against an older layout that did
define it unconditionally, and a standing #undef holds whichever way a future
refresh moves the default.

Verified by building config/config_usb.c both ways and reading the objects it
drags in:

  EFI, before:  obj_efi_usb obj_xhci                 (no keyboard driver)
  EFI, after:   obj_usbio obj_usbkbd obj_xhci
  BIOS, after:  obj_usbkbd obj_xhci                  (unchanged)

Does not address the second half of #18213, the /dev/ram0 kernel panic on
snponly.efi -- that one is the installer publishing autoexec.ipxe into the
TFTP root, and is fixed in fogproject.

Refs FOGProject/fogproject#960.

Co-Authored-By: Claude Opus 5 <[email protected]>
@mastacontrola
mastacontrola merged commit e380ec8 into master Aug 6, 2026
1 check passed
@mastacontrola
mastacontrola deleted the fix-efi-usb-keyboard-config branch August 6, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant