How to get USB OTG port to work in Device mode?

Did anyone manage to get this working? I want to use ethernet networking to connect a number of VIMs together to save on cabling in a project so need to get this working

thanks :slight_smile:

1 Like

looks like i need to enable USB gadget mode in the kernel and enable the USB ethernet gadget, but cant get a .config file that works and menuconfig setup that follows exmaples off the web just results in a restart of the config process when building debs, e.g.

will keep trying - as when i get a working kernel build then i dont get usb0 as a network device - so something wrong

Nope. I gave up on it because I realized there were too many hurdles to get a Khadas working my use-case. That said, we have yet to find something that will.

Have got USB0 as a device - now to get it working with the host…

Needed CONFIG_USB_ETH set in the kernel config along with gadget support

2 Likes

Can explain how to do this on vim 3
I want to do ssh over usb is it possible this way ?

@g4b42 has worked this out for me - you will need to modify a few files and rebuild the kernel - but its straight forward to do using fenix. How I did it yesterday:

  1. download fenix and pick the options that you want, then let it run until it has downloaded linux, the ctrl-c to halt the build (when it starts building linux is when i stopped it)

  2. in the linux directory apply the following changes
    => https://github.com/g4bwy/khadas-linux/commit/d9a6fe9e97bb1d2c55ed918f9fd7632d0d7dbb08
    => https://github.com/g4bwy/khadas-linux/commit/564439f83cfe63fef675991cdb94512eee14df04
    => https://github.com/g4bwy/khadas-linux/commit/d8b8378ed54d7572fa77c2f4e168a7d94b914bf2

  3. start the fenix build again and press enter when asked if you want to proceed with the modified files

  4. burn the resulting image to your VIM3

  5. create a script called usb.sh in /root/ with the following contents and make it executable. Note that each MAC address has to be unique - so if creating multiple devices to put on the same hub then you need to change these per device.
    #!/bin/sh
    [ ! -d “/config” ] && mkdir /config
    mount -t configfs none /config
    mkdir /config/usb_gadget/g1
    echo 0x18d1 > /config/usb_gadget/g1/idVendor
    echo 0x4ee1 > /config/usb_gadget/g1/idProduct
    mkdir /config/usb_gadget/g1/strings/0x409
    echo 12345678 > /config/usb_gadget/g1/strings/0x409/serialnumber
    echo Dummy > /config/usb_gadget/g1/strings/0x409/manufacturer
    echo Demo > /config/usb_gadget/g1/strings/0x409/product
    mkdir /config/usb_gadget/g1/configs/c.1
    mkdir /config/usb_gadget/g1/configs/c.1/strings/0x409
    echo “Conf 1” > /config/usb_gadget/g1/configs/c.1/strings/0x409/configuration
    echo 120 > /config/usb_gadget/g1/configs/c.1/MaxPower
    mkdir /config/usb_gadget/g1/functions/eem.f0
    echo “66:77:88:99:aa:00” > /config/usb_gadget/g1/functions/eem.f0/host_addr
    echo “00:11:22:33:44:00” > /config/usb_gadget/g1/functions/eem.f0/dev_addr
    ln -s /config/usb_gadget/g1/functions/eem.f0 /config/usb_gadget/g1/configs/c.1/$
    echo ff400000.dwc2_a > /config/usb_gadget/g1/UDC

  6. edit /etc/network/interfaces and add the following for usb0 - assumes an available DHCP server for where the device is being plugged into, can also set for a static IP address if required
    auto usb0
    iface usb0 inet dhcp
    pre-up /root/usb.sh

  7. reboot and use your device with USB ethernet - a useful check to make sure its working is to use ip a or ifconfig to make sure that a) usb0 shows up as a device and b) it has an IP address assigned to it

  8. ask Khadas nicely to put this config changes into the standard kernel build to save some steps :slight_smile:

3 Likes

cool does it work can I ssh into my VIM3 with this ?

yes - am using it to SSH into all the devices on my USB hub back plane in my miner thread

does this work on SD-USB images ?

not tried it but no reason it shouldn’t - its just a normal image with a few tweaks

It seems a bit complicated if you can could you please prepare me Build of this for Mainline Ubuntu Bionic 5.6 Server it could be really helpful :slightly_smiling_face:

its not complicated - only need to edit 3 files and build it - it just takes time to do. Really sorry but I have some rare spare time today and need to use it to get the software finished for my crypto miner web interface. Give it a go and shout if you get stuck - the fenix scripts do all the difficult work for you - the instructions are here Use Fenix scripts to build your own ubuntu image

Plus accepting built images from randoms on the internet is a good way to get malware into your network!

Hmm good point, ok sorry for disturbing you, tell me later when you have time which files to modify,
have a good day :slightly_smiling_face:

no problem - just building takes a while - the files to modify are in the links above - its the text above the changes - e.g. the first file to change is drivers/amlogic/usb/Kconfig

@birty I couldn’t find the directory called amlogic in the linux 5.6 /drivers
are you using kernel 4.9 ? what is your Firmware

yes - built using 4.9 ubuntu focal on emmc - can upload the image if you want to test that?

sure share me the download link but I will try my self for the SD-USB version,
BTW that version doesn’t have wifi right ?

ok - just zipping and uploading. Just plugged an antenna in and tried - wifi it works fine

So Wifi works, bluetooth should also work, Thanks @birty

Image with USB gadget mode enabled:

1 Like