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.
This way on kexec the device is in a better state, and the kernel that
boots next is able to use the controller.
This was verified to fix an issue with kexec+gadget on the Chuwi Hi10
Pro HQ64 tablet.
The detection cannot be done reliably. Some android_usb devices
(motorola-addison) have gadgetfs available, while some gadgetfs devices
will have the android_usb path available.
Anyway, this is probably better to explicitly declare the mode to use.