Fix host USB HID boot, mode, and recovery bugs#814
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors USB gadget init scripts to share common logic, adds regression tests for gadget configuration, and improves HID/USB status handling in both the Go server and support firmware.
Changes:
- Introduce
S03usb-commonand refactorS03usbdev/S03usbhidto use shared gadget setup + action routing. - Add a shell-based regression test suite for init scripts and a
make test-usb-scriptstarget. - Improve HID mode/state detection and robustness (Go HID stale-handle recovery; C++ HID symlink checks).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/usb-init-scripts-test.sh | Adds regression coverage for gadget configuration and actions in test mode. |
| kvmapp/system/init.d/S03usb-common | New shared USB gadget script library used by init scripts. |
| kvmapp/system/init.d/S03usbdev | Refactors normal mode init to use shared common functions. |
| kvmapp/system/init.d/S03usbhid | Refactors HID-only init to use shared common functions. |
| server/service/hid/status.go | Makes mode flag testable and adds timeout-bounded PHY reset execution. |
| server/service/hid/status_test.go | Adds tests for HID mode detection via bcdDevice. |
| server/service/hid/hid.go | Adds stale HID handle detection/reopen & error factoring. |
| server/service/hid/hid_test.go | Adds unit tests for stale HID error classification and deleted-fd detection. |
| support/sg2002/kvm_system/main/lib/system_state/system_state.cpp | Fixes HID presence detection (no wildcard access) via explicit paths. |
| Makefile | Adds test-usb-scripts target to run the new regression suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a65a15b to
3d3c5e0
Compare
3d3c5e0 to
04e0aa5
Compare
|
Rebased this branch onto current upstream The only conflict was in After the rebase I re-ran: sh tests/usb-init-scripts-test.sh
git diff --check origin/main..HEADBoth passed. |
Summary
This PR fixes NanoKVM host HID failures by making the USB gadget definition correct and consistent, then hardening the server-side HID writer against gadget resets.
The failures were host-visible USB bugs, not just a web UI toggle problem. On affected machines, BIOS/UEFI and boot menus could ignore keyboard or mouse input, Linux could partially bind or reject HID interfaces,
usbhid/hid-genericcould fail probing, and host-side consumers such as udev could churn around unstable or malformed gadget identifiers. NanoKVM could also keep stale/dev/hidg*file handles after the gadget was rebuilt.The branch keeps the scope to HID and host-visible USB gadget correctness. It does not change virtual media behavior and does not change the UI.
中文说明
这个 PR 修复 NanoKVM 在 BIOS/UEFI 和启动菜单阶段 HID 键盘、鼠标不能被主机稳定识别的问题。核心修复是统一 normal 和 HID-only 两种模式的 USB gadget 配置,并按 USB HID 规范暴露 boot keyboard、boot mouse 和 non-boot absolute/touch mouse。
同时,这个 PR 修复了 gadget 重建后服务端继续使用旧
/dev/hidg*句柄的问题,并让 USB 字符串 descriptor 写入精确内容,避免 shell 换行影响主机侧识别。范围仅限 HID 和主机可见的 USB gadget 正确性,不包含虚拟媒体和 UI 修改。What changed
1, protocol11, protocol20, protocol2os_desc/c.1links before recreating the gadget/boot/usb.notwakeupexists/dev/hidg*handlesaccess()Scope
Included here:
/boot/usb.notwakeupas the opt-out.Explicitly not included here:
/dev/mmcblk0p3cleanup.Related issues and PRs
Most directly related:
May overlap but may have additional causes:
/dev/hidg*handle path and gadget rebuild drift, but those reports may also involve host, cable, power, or unrelated reset behavior.Related PRs:
/boot/usb.notwakeupexists.Validation
Automated validation run on this branch:
tests/usb-init-scripts-test.shkvm_systemsupport binary buildgit diff --checkHardware validation:
usbhidprobe failure for the fixed gadget definition.