VIMs: Linux ADB over USB

The default VIMs fenix build include
/usr/local/bin/adbd : ADB daemon
/usr/local/bin/adb-setup : The script to enable ADB over USB but is empty.
/lib/systemd/system/adb-khadas.service: systemd service to enable ADB on boot but since the adb-setup is empty ADB won’t start.

Also any changes to above will get over written whenever package “linux-board-package--” gets upgraded.

Until the following is adopted in the default fenix build, here are the steps to enable ADB on your VIMs board.

Step 1 : Upgrade packages. this will pull in the otg-device overlay
$ sudo apt update && sudo apt dist-upgrade -y

Step 2 : Enable OTG device mode
$ sudo nano /boot/env.txt

append otg-device if it is not already to overlays=, example
overlays=uart3 pwm_f i2c3 otg-device

CTRL+s and CTRL+x to save and exit

Step 3 : Reboot
$ sync && sudo reboot

Step 4 : Add adb gadget setup script. Modified from the Edge adb-setup script
$ sudo nano /usr/local/bin/adb-gadget
Copy and paste the following “/usr/local/bin/adb-gadget”. CTRL+s and CTRL+x to save and exit.

# Start adb daemon service…

. /etc/fenix-release

# Last 12 digits of cpu serial
CPUSERIAL="$(grep Serial /proc/cpuinfo | grep -o -P ‘.{0,12}$’)"

export service_adb_tcp_port=5555
echo “Configuring ADB USB gadget driver…”
UDC="$(ls /sys/class/udc/| awk ‘{print $1}’)"
mkdir /dev/usb-ffs -m 0770
mkdir /dev/usb-ffs/adb -m 0770
mkdir /sys/kernel/config/usb_gadget/g1 -m 0770
echo 0x18d1 > /sys/kernel/config/usb_gadget/g1/idVendor
echo 0x4e12 > /sys/kernel/config/usb_gadget/g1/idProduct
mkdir /sys/kernel/config/usb_gadget/g1/strings/0x409 -m 0770
echo $CPUSERIAL > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber
echo “Khadas” > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer
echo $BOARD > /sys/kernel/config/usb_gadget/g1/strings/0x409/product

mkdir /sys/kernel/config/usb_gadget/g1/functions/ffs.adb
mkdir /sys/kernel/config/usb_gadget/g1/configs/b.1 -m 0770
mkdir /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409 -m 0770
echo 500 > /sys/kernel/config/usb_gadget/g1/configs/b.1/MaxPower

ln -s /sys/kernel/config/usb_gadget/g1/functions/ffs.adb /sys/kernel/config/usb_gadget/g1/configs/b.1/f1
echo “adb” > /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409/configuration
mount -t functionfs adb /dev/usb-ffs/adb

adbd &
sleep 1

echo $UDC > /sys/kernel/config/usb_gadget/g1/UDC

exit 0

Step 5 : Make ‘adb-gadget’ executable
$ sudo chmod +x /usr/local/bin/adb-gadget

Step 6 : Add systemd service file
$ sudo systemctl edit --force adb-gadget.service --full
Copy and paste the following into the editor. CTRL+s and CTRL+x to save and exit.

Description=ADB over USB



Step 7 : Test 'ADB over USB’
$ sudo systemctl start adb-gadget.service

On your PC, check if the VIMs is listed with “adb devices” command.
If all good proceed to next step else stop and report your observation in this thread.

Step 8 : Enable ‘ADB over USB’ on boot
$ sudo systemctl enable adb-gadget.service


Nice work!

But isn’t ADB, android debug bridge ?
Wouldn’t SSH over USB to get a linux shell be a better protocol ?

I can think of 3 ways to access the shell using OTG.

  1. ADB (Android Debug Bridge) gadget : Easy access to root shell without any login credentials.
  2. Serial gadget : I prefer this option but the default kernel is not compiled with any of the following configuration
  3. Network gadget : This is the only option that will allow SSH since it is network interface. I will be providing instructions in a separate post on how to enable a Windows 10 compatible RNDIS gadget on VIMs.
1 Like

@shyAm we have tried using network gadget before, but I had problems with RNDIS,
but it was possible with eem, as seen here:

but windows didn’t seem to identify the EEM gadget protocol properly and failed to enumerate…

I hope to see you make it happen,
best of luck :slight_smile:

1 Like

I just posted the instructions to setup a tested RNDIS gadget script.


Added to Fenix fix, thank you!