Linux gadget on iMX7

With:

The Angstrom Distribution colibri-imx7 ttymxc0
Angstrom v2015.12 - Kernel 4.1.15-v2.6b2+g0ff849d
Colibri_iMX7_LinuxImageV2.6_20160630

I am seeing an error starting the usbg service:
[FAILED] Failed to start Load default USB gadget schema g1.schema.
See ‘systemctl status usbg.service’ for details.

There seem to be a couple of problems but unless I read it wrong it seems that the device tree sets the OTG1 port in host mode.

Am I missing something?

Yes, on the Colibri iMX7 the automatic USB device/host switching (e.g. based on VBUS cable detect resp. ID pin) is not implemented in our BSP as of yet and the OTG port defaults to host functionality. For the time being you would need to change the device tree in order to configure the OTG port for device functionality.

Automatic switching is not supported yet, we track it here:
http://developer.toradex.com/software/linux/linux-software/release-details?view=all&issue=19050

However, when use USB Gadget by default loading the Gadget driver should actually work. I will look into this.

Loading the Gadget driver fails is due to missing Serial number in the device tree. The serial number from the device tree is passed to the USB Gadget descriptor so a host can read the serial number of the device.

For testing, the fdt_fixup allows to set the dr_mode property without recompiling the device tree:

setenv fdt_fixup 'fdt addr ${fdt_addr_r} && fdt resize && fdt set /soc/aips-bus@30800000/usb@30b10000 dr_mode peripheral'

You can disable the serial number coping by removing the ExecStartPost line which writes the serial number in /etc/systemd/system/multi-user.target.wants/usbg.service. With that USB Gadget should work fine.

Alternatively, you need to update U-Boot, there is a fixed version which passes the serial number through device tree:
http://git.toradex.com/cgit/u-boot-toradex.git/log/?h=2015.04-toradex-next

I had figured out the SN issue but what I needed was the DT edit magic above. Thanks!