nerves_init_gadget
nerves_init_gadget copied to clipboard
Use usb_gadget to configure gadget devices
This still needs the docs updated and other polishing, but I wanted to get it out there so people can give feedback and try it on their machines.
One thing I noticed is that Windows 10 is kind of annoying about how it does link-local addressing with IPv6 vs. IPv4, which I think is making the mDNS lookup fail even though I can ping the device by checking on the serial console to figure out its IP address.
Related to (but no longer depends on): https://github.com/nerves-project/nerves_system_rpi0/pull/62 Resolves #28
Ok, I re-worked things a bit so that it'll still work like it does today if you're using a system that doesn't support configfs. I also removed the terrible link-local DHCP server because I realized that it actually works fine without it, as long as you have mDNS set up properly on your host machine.
The only weirdness is that on Ubuntu, I have to tell it to explicitly use link-local - it doesn't fail-back from DHCP to link-local. It's annoying, but I figure people who are using Linux on their desktop will be fine with configuring their network interface to use link-local mode. It works automatically on OSX and Windows without the DHCP server or any special configuration required.
Just wanted to let you know that I've been watching this PR. It seems like it's in varying states of readiness. If there are little things to get in that are ready, could you split those out?
@fhunleth @mobileoverlord @ConnorRigby have you had a chance to look at the https://github.com/nerves-project/usb_gadget code yet? It doesn't make much sense to merge this PR until we're happy with how that works. I think if we're happy with that, I just need to push it to Hex and we need to get it all integrated into our Slack alerting, CircleCI, etc.
Other than that and the comments I made above, I think this is ready to go because it should gracefully work with existing systems.
@GregMefford I've had the quickest read through the usb-gadget code a few days ago. I think it is great for now. One thing i think we should address some day is the way the built in works. I think this should be either a protocol or behaviour of some sort. NBD for now tho. I'm still looking through the changes here.
FWIW i have to manually select link-local on Ubuntu/Linux with the current implementation anyway.
Ok, this PR should be ready for final review now. It should be safe to merge independent of the system release. The only missing piece is that I need to push an initial release of usb_gadget
to Hex, if people think it's ready. I pushed a commit there today that better handles returning an error, which the most-recent commit here depends on.
I included some code to detect when you're running on a system that doesn't support the configfs gadgets we're trying to use (whether than be an rpi0
system with compiled-in gadget devices, or something like rpi3
that doesn't have usb_gadget
configfs at all).
I need to double-check tonight that this works as advertised on rpi3
, but I did try it on existing rpi0
as well as the version I'm proposing in https://github.com/nerves-project/nerves_system_rpi0/pull/62.
I think we should hold off on updating the README here until there is actually a system release available that uses the new configfs interface, so that we can say something like:
If you are using v1.4.0 or later of the
rpi0
orbbb
Nerves systems, you should configureifname: "bond0"
instead ofifname: "usb0"
in your:nerves_init_gadget
configuration. On these systems, we configure a pair of virtual Ethernet interfaces that are bonded together as thebond0
interface on the Nerves device side. One sub-interface will work seamlessly with Windows hosts, while the other will work seamlessly with Linux and OSX hosts. By using thebond0
interface from your Nerves application, you can transparently connect with either type of host.
✅ Confirmed working on rpi3
as well (obviously with ifname: "eth0"
since it wouldn't have worked either before or after this PR using the default).
Could you break this into multiple PRs? There's a mix of changes in here. Some are easy to approve and some require more conversation.
I cleaned up this branch so it's just one commit on top of #35, since it directly depends on that change.
I've got this PR rebased (and added the rmmod g_cdc
call) in case you want to try it out with https://github.com/nerves-project/nerves_system_rpi0/pull/62.
It looks like the build is broken, probably because usb_gadget
isn't on Hex yet. If people are happy with releasing an initial version of that, I can push it up.