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

Enable ADB with GadgetFS devices #290

Merged
merged 14 commits into from Jan 31, 2021

Conversation

samueldr
Copy link
Member

@samueldr samueldr commented Jan 28, 2021

It happens that, with time, I learned enough to finally be able to tackle this problem.

With these changes, adb in stage-1 (and I expect the system) works with GadgetFS devices:

While it doesn't seem needed, after all we have rndis working just fine, it is. See, sometimes rndis is a big unknown variable that is hard to correctly guess the proper solution for. With these changes you can get insight into the device using adb, and gather the required knowledge to setup rndis, if desired.

Tested on

  • asus-z00t (verify against regression with android_usb)
  • motorola-surfna
  • razer-cheryl2
  • sony-pioneer
  • xiaomi-begonia
  • chuwi-hi10prohq64 (out of tree; mainline linux)

Cannot test on, due to hardware issues:

  • pine64-pinephone

 - It was running too late.
 - Wasn't actually using `shellOnFail` config
The service and mount points are more of an implementation detail of the
GadgetFS handling library and not an implementation detail of the init
library.

In turn, this means that we are decoupling this from the init, follow-up
on the next commit...
@samueldr samueldr added the 4. type: enhancement New feature or request label Jan 28, 2021
(Though it may require fiddling with udev perms)
FunctionFS on GadgetFS requires this to happen in order:

 - (1) preparing the gadget
 - (2) preparing the function
 - (3) mounting the functionfs
 - (4) starting the daemon
 - (5) enabling the device

Doing any of these steps in the wrong order *will* fail. You cannot
mount functionfs if the function name hasn't been allocated yet. You
cannot start the daemon without functionfs being mounted. You cannot
enable the device without the daemon running on the USB endpoints.

This is why the GadgetFS stuff here *has* to know about mounting the
filesystem and starting the daemon.

In fact, the generic library to be written to handle USB gadget mode
**will** have to have that knowledge!

The added TODOs are to be done when extracting as a standalone library.
Also warn if it could not be enabled.
Also warn if it could not be enabled.
@samueldr
Copy link
Member Author

Hmm... the use of "more proper" USB identifiers is problematic.

Pine doesn't have any (AFAIK). Which in turn means we're squatting into a well-known PID area.

In turn, this means that there is no udev rules that properly configure the endpoints for things like ADB. Which in turn means that adb shell fails with: error: insufficient permissions for device.

@samueldr samueldr merged commit 9cc2b0a into NixOS:master Jan 31, 2021
@samueldr samueldr deleted the feature/gadgetfs-adb branch January 31, 2021 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant