Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Configuring USB Gadget through configfs #27

Closed
wants to merge 1 commit into from

Conversation

mobileoverlord
Copy link
Contributor

DO NOT MERGE

configfs seems to be the most modern and flexible way to configure USB Gadgets from the Linux user space.

From the config fs docs:

Where sysfs is a filesystem-based view of kernel objects, configfs is a filesystem-based manager of kernel objects, or config_items.

Using configfs, we can dynamically add and remove gadget functions at runtime without having to recompile the linux kernel. This PR demonstrates some of my findings.

/etc/gadget_start.sh
Represents recreating the current configuration where we have a CDC device with 1xACM and 1xECM. This setup is kinda neat, because we get to control the device name and serial number. In this example, I am able to set the device serial number to the boardid.

screen shot 2017-08-31 at 23 31 43

I added a busybox config because I needed to enable ln because calling File.ln_s was returning errors because the directories already existed. There might be a work around here, not sure.

In addition, I attempted to update the erlinit.config to execute the gadget script pre exec so that it might be able to use the ttyGS0 port that it creates. Unfortunately, this did not work and the serial console ended up coming across ttyACM0.

RFC
This is labeled as RFC because it has drawbacks but I wanted to demonstrate something interesting. I think that its really neat to be able to programmatically control the gadget properties and functions at runtime. In addition, you can enable a lot more combinations of functions that the gadget could serve such as USB HID, mass storage device, and more. I just through that this stuf was really cool and I wanted to share it with everyone.

Relevant Docs

ConfigFS Gadgets
http://elixir.free-electrons.com/linux/latest/source/Documentation/usb/gadget_configfs.txt

ConfigFS
https://www.kernel.org/doc/Documentation/filesystems/configfs/configfs.txt

@electricshaman
Copy link

This looks really cool! I'm excited to poke around and check it out. I should have more feedback after ElixirConf. A couple of small things I noticed for now:

  1. Instead of committing a whole new busybox config, can we use BR2_PACKAGE_BUSYBOX_CONFIG_FRAGMENT_FILES to merge in only the lines of config for the ln package that you added (assuming we don't find a workaround)? I think that should let us keep BR2_PACKAGE_BUSYBOX_CONFIG pointed at the base config in system_br's nerves-common. It's really hard to see what was added or changed. If that's not possible or desirable, then maybe we could commit the fresh busybox config separately from the commit that adds ln.

  2. Did you mean to upgrade Nerves and Distillery at the same time?

@fhunleth
Copy link
Member

I think this is cool. It would be great to document so that people can create custom systems for using HID. I know that creating custom systems can be an annoying way of adding functionality to the Linux side of Nerves, but it is our current official way, and I'd like to not abuse our core team privilege by adding features to the official systems that we use in one of our projects that are not of widespread use.

As it stands, unless this can be made transparent to the majority of users (especially new users) who are using the RPi0 for serial and Ethernet, I'm pretty opposed to merging it.

Also, the whole script thing would need to be reworked. I regret adding support for pre-run-exec since it leads to unsupervised (in the OTP sense) shell scripting. On the other hand, I suspect that you wrote this in haste since it was pre-ElixirConf. That also makes me sad, since it means that writing a shell script was easier than coding in Elixir. Is it possible to fix that for next time?

While I'm interested discussion, I think that the best course of action is for all of us who are interested in this feature to talk live. I'd also like to consider whether this is pre or post 1.0 so that we can prioritize it.

@mobileoverlord
Copy link
Contributor Author

I am going to close this and see about implementing it as a module

@mobileoverlord mobileoverlord deleted the configfs-gadget branch August 8, 2018 12:43
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.

None yet

3 participants