USB Gadget/Ethernet

Jump to: navigation, search

USB Ethernet support

This allows ethernet emulation over USB, allowing for all sorts of nifty things like SSH and NFS in one go plus charging over the same wire, at higher speeds than most Wifi connections.

Kernel support

Mainline kernel


(Instructions below were tested on A20 with kernel 4.4.6.)

For Allwinner SoCs based on the sun4i controller (CONFIG_PHY_SUN4I_USB=y), the "MUSB" (Multipoint Highspeed Dual-Role Controller) driver provides the OTG / gadget functionality. For successful operation, a number of Kconfig options need to be enabled:


(Substitute "y" for "m" where desired, if you do not wish modules to be built and want the drivers compiled-in instead.)

With menuconfig this looks like

    Device Drivers  --->
        [*] USB support  --->
        <M> Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)
                MUSB Mode Selection (Dual Role mode)  --->
                *** Platform Glue Layer ***
            <M> Allwinner (sunxi)
                *** MUSB DMA mode ***
            [*] Disable DMA (always use PIO)
        USB Physical Layer drivers  --->
            <M> NOP USB Transceiver Driver
Sticky-note-pin.png Note: You need to select both "Inventra Highspeed Dual Role Controller" and "NOP USB Transceiver Driver" before the required "Allwinner (sunxi)" option (CONFIG_USB_MUSB_SUNXI) becomes available.

You'll probably also want to select

        <*> USB Gadget Support

and any desired gadget drivers on top of that.

Proceed with compiling and installing your kernel and its corresponding modules (for assistance check our howto).

MBOX icon information.png If you compiled the MUSB driver as module(s), make sure to load those first - before you attempt to use any of the gadget drivers:
modprobe sunxi

Upon successful initialization the kernel will report something similar to:

[   33.950832] supply vcc not found, using dummy regulator
[   33.951799] musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, bulk combine, bulk split, HB-ISO Rx, HB-ISO Tx, SoftConn)
[   33.951833] musb-hdrc: MHDRC RTL version 0.0 
[   33.951872] musb-hdrc: 11/11 max ep, 5184/8192 memory
[   33.952312] musb-hdrc MUSB HDRC host driver
[   33.952355] musb-hdrc new USB bus registered, assigned bus number 5
[   33.956664] hub 5-0:1.0: USB hub found
[   33.956828] hub 5-0:1.0: 1 port detected

After that, you should be able to use the USB gadget drivers/modules (g_ether, g_mass_storage, ...) as described below.


Currently, the g_ether module is not compiled as part of our kernel configuration.

To enable this, follow the kernel building information of our manual build howto. But then after making defconfig, either run:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

Then trawl down the options and set the "Ethernet Gadget" to "m":

    Device Drivers  --->
        USB support  --->
            <*>    USB Gadget Support  --->
                <m>    Ethernet Gadget (with CDC Ethernet support)
            <*>    NOP USB Transceiver Driver
            [*]    SUNXI USB2.0 Dual Role Controller support --->
                [*]    Sunxi USB2.0 Manager
                       USB0 Controller support (otg support) --->
                           (*) otg support

Or just run:


You can now continue following our manual build howto to continue kernel compilation and installation.

Note that for sun4i devices (A10), you also need to enable SoftWinner SUNXI USB peripheral controller in order to enable high-speed operation for gadget- otherwise it will be limited to full-speed only.

    Device Drivers  --->
        USB support  --->
            <*>     USB Gadget Support --->
                <m> SoftWinner SUNXI USB Peripheral Controller 

Loading the driver (on the device)

We should now be able to run:

modprobe g_ether

successfully. We can then make this module autoload by adding it to /etc/modules.

Now, so that g_ether doesn't randomly generate a new id every reboot, stick the following in /etc/modprobe.d/g_ether.conf:

options g_ether host_addr=00:11:22:33:44:55

g_ether should've just generated a pair of addresses for you, so replace 00:11:22:33:44:55 with the outcome of:

 dmesg | grep "HOST MAC"

We can also use dev_addr option to set device MAC address.

Configuring the device's networking


Without network manager

Stop networkmanager:

 stop network-manager 

To prevent network-manager from starting, run:

echo "manual" > /etc/init/network-manager.override

Now add the following to /etc/network/interfaces:

auto usb0
iface usb0 inet static

To manually activate the interface and set an IP (NOTE: if configured with ip from iproute2 it will not work):

     ifconfig usb0 up
     ifconfig usb0

Setting up the host

You can convince networkmanager to connect automatically to a specific MAC address, and then you need to hardcode the address to for this connection.

If all goes well, you should now be able to just plug in the USB cable.

See also

Experiments with USB ethernet and H3 @ Armbian forums: