Add hidraw backend for FreeBSD#730
Conversation
|
Currently, some stuff like the Report Descriptor parser and error registry routine are copied from Linux and I think they are platform independent. Can we create a common directory or hidraw directory in code then put them inside? Have tested by the hidtest program. |
49a7a62 to
6e7a25a
Compare
|
Thanks for @Youw your review:). Then, What is your opinion about this?
|
I thinjk that is a good idea, but I don't think it really is nesessary to do so in scope of this PR. |
|
Nice. This will address the following issue. |
|
Oops. I forget we have udev-devd stuff. Maybe we should use udev also? |
I lost context here. What for? Seem like you have all the functionality implemented already. Aren't you? |
Yes, all functionality is fully implemented. I am just thinking if we should use libudev make hidapi more portable. |
|
First test under FreeBSD 14.1 Release, under a physical machine (Chuwi mini PC, Intel J4125 CPU, 8GB RAM, 256GB SSD) There are a few compiler warnings. |
|
Fix it:). Forget to fix the warning. |
|
Somehow hidtest-hidraw will seg fault with the Microchip Simple HID example. |
Thanks. The compiler warnings are gone. The Segfault issue is still there though. |
BTW, EZ-USB FX2LP is a High Speed USB device, do you mean to say EHCI and not xHCI?
Another thing, I have tested different firmwares. So you may get confused here.
I will carry out tests under FreeBSD over the weekend. |
USB standard is a little bit confusing. You actually attached a USB 2.0 device to xHCI. But since the xHCI controller is a xHCI controller + eHCI controller internally, so...
I found a bug in the FreeBSD xHCI implementation that cause the data only receive bi-transfer in <= 64 byte case. Please also apply this patch while you are testing. https://reviews.freebsd.org/D57146. Send 64 bytes (report size is 128) can not be resolved as the problem I have explain previously. There is a flag in libusb call LIBUSB_TRANSFER_ADD_ZERO_PACKET that can solve this problem. |
|
@mcuee 3 bytes also work in both 64 and 128 bytes report. 2 bytes won't work as it is a hard limit in FreeBSD hidraw interface. If you need a ISO image to test, I can build one for you with my patch. |
Ok, will build one later. I just merge my patch upstream and need times to build world and kernel. |
Hi, I just send a link to your email. Please take a look. |
Great, now this PR works perfectly under your FreeBSD 16.0 Current build (tested with VirtualBox VM first). |
|
PR #728 also works fine and hidapi git has the issue with #274.
|
Indeed 2 bytes will not work with FreeBSD hidraw backend. libusb backend works fine (git or PR #728) I will carry out more testing later today and tomorrow. |
Thanks! Hope we can merge this patch ASAP:). |
|
Going back to the Generic HID PIC FW example (Full Speed USB device), there are no issues. |
|
Going to the original Generic PIC FW (unmodified, from Jan Axelson, Full Speed USB device) with two bytes reoort, it also works. |
|
Please re-review as well. Thanks. |
|
BTW, somehow your ISO image only works under VirtualBox VMs, I could not install it under an Intel N100 mini PC, not so sure about the reason (kernel panic). Therefore I cannot test it under physical machine as of now. Just FYI only. Now I am lazy to build FreeBSD using source code. I only did that a few times when HPS was developing the new FreeBSD USB Stack many years ago. |
Hi, is there any crash log? |
Let me capture the crash log over the weekend. I will also compare with FreeBSD 16.0-Current Snapshot. I have a few Chuwi Herobox mini PCs running Linux and BSDs. All of them have 8GB RAM. Each has the original 256GB SSD and one more SATA SSD (128GB or 256GB). Intel N4500 Mini PC -- OpenBSD 7.8 (will upgrade to 7.9 later) and NetBSD 10.1 I will kill the two Arch Based Linux distros (not really using them much) and install FreeBSD/OpenBSD. |
|
For quick testing I recommend VENTOY [1] it provides USB BOOT menu supporting MBR/GPT/BIOS/UEFI where you can choose ISO from the same pendrive to boot. So you can have multiple images on the same bootable pendrive.. and you can use it for storage as well :-) Please let me know if there is anything to test on FreeBSD 14 :-) I can also boot of 15 or 16 if needed :-) |
There is a known hardware bug in Alder Lake processors. See https://lists.freebsd.org/archives/freebsd-current/2025-January/006984.html |
Sorry I made a mistake, it is not kernel panic, rather the system does not recognize the USB Flash Disk as bootable at all. I tried the latest snapshot (FreeBSD-16.0-CURRENT-amd64-20260525-490c53e9353f-286096-disc1.iso) and the issue is the same, tested with two USB Flash disks. Then I tested OpenBSD 7.9 release and it is able to boot (but then it does not recognize the wired and wireless network adapter).
Interesting. |
Is it possible to choose EFI file from your UEFI? |
Using Ventoy and then I can do that. Interesting findings -- now FreeBSD 15.0 Release and OpenBSD 7.9 can boot and I have installed them to the second SATA SSDs of the two Intel N100 Mini PCs. Somehow I need to use HTTP install. For the FreeBSD 16.0-Current images (your version or the snapshot version), both will fail to boot. All in all, looks like the issue is related to file system corruption. Screen photo taken from my mobile phone.
|

FreeBSD support hidraw in Kernel from 13.0.
By using libusb only, we can only see the HID device from usb. To address this, we implement hidraw backend for FreeBSD.
Just like Linux use libudev to handle usb specified HID stuff (like Manufacture), we use libusb to handle it.
Sponsored-by: FreeBSD Foundation