Radxa Zero as USB C gadget for iPad Pro

Hi. Recently I read an awesome article about turning a Raspberry Pi to an USB C gadget.

Today I tried to apply the first steps of the article to my Radxa Zero which runs Manjaro ARM. However without success:

  • I don’t see the Ethernet options show up on my iPad and also my computer doesn’t list the usb0 interface when running dmesg .

  • The Radxa lists the interface but it is marked as DOWN.
    3: usb0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000 link/ether 00:dd:dc:eb:6d:a1 brd ff:ff:ff:ff:ff:ff inet 10.55.0.1/29 brd 10.55.0.7 scope global usb0 valid_lft forever preferred_lft forever

  • The USB C cable I am using is exactly the same described in the article.

Here are the commands I ran on a clean install.

I am not sure what I am missing here. I hope someone can help me :slightly_smiling_face:

I checked your scripts, you can not copy it directly from the raspberry pi but it’s similar. we will test and give you a method. We will test on a PC.

1 Like

Our preliminary attempt to enable USBNET on Radxa Zero was blocked by Amlogic binding the USB port on boot. Rebinding the USB device requires unplug and re-plug the device for the host to recognize it, which has the unfortunate side effect to also turn off the device :disappointed_relieved:

We are now looking to identify the root cause of this issue, and we will get back to you soon.

Since we were unable to load Manjaro ARM on Radxa Zero at the moment our testing was done on our official Ubuntu image. We are suspecting this is due to some kernel config. As such you can try the following script to see if Manjaro doesn’t have this issue:

# Based on https://www.collabora.com/news-and-blog/blog/2019/02/18/modern-usb-gadget-on-linux-and-how-to-integrate-it-with-systemd-part-1/
sudo -i
mkdir /sys/kernel/config/usb_gadget/radxa/ # different distro could have a different configfs mounting point: /sys/kernel/config
cd /sys/kernel/config/usb_gadget/radxa/
echo 0x1d6b > ./idVendor
echo 0x104 > ./idProduct
mkdir -p ./strings/0x409
echo "Radxa" > ./strings/0x409/manufacturer
echo "ECM" > ./strings/0x409/product
mkdir -p ./configs/r.1
mkdir -p ./functions/ecm.usb0
ln -s ./functions/ecm.usb0/ ./configs/r.1/
echo "" > ../amlogic/UDC # if you have this file and it is not empty then you won't be able to use USBNET for now
echo ff400000.usb > ./UDC # ls /sys/class/udc to see available UDCs

I just tested the new script you send me. Unfortunately without success.

So we have identified the issue on our official image. It is due to amlogic-adbd service is running on boot, occupying the OTG port.

Please check if your distro also has this service running by executing sudo systemctl status amlogic-adbd.service. If the output shows Active: active (running) you need to run sudo systemctl disable amlogic-adbd.service then shutdown, unplug from host PC, and replug. Once you power cycle the device you can try the following script:

# Based on https://www.collabora.com/news-and-blog/blog/2019/02/18/modern-usb-gadget-on-linux-and-how-to-integrate-it-with-systemd-part-1/
sudo -i
modprobe libcomposite
mkdir /sys/kernel/config/usb_gadget/radxa/ # different distro could have a different configfs mounting point: /sys/kernel/config
cd /sys/kernel/config/usb_gadget/radxa/
echo 0x1d6b > ./idVendor
echo 0x104 > ./idProduct
mkdir -p ./strings/0x409
echo "Radxa" > ./strings/0x409/manufacturer
echo "ECM" > ./strings/0x409/product
mkdir -p ./configs/r.1
mkdir -p ./functions/ecm.usb0
ln -s ./functions/ecm.usb0/ ./configs/r.1/
echo ff400000.usb > ./UDC # ls /sys/class/udc to see available UDCs

This should allow your host PC to have a new interface as well.

You will then need to configure the network on both end. You can refer to your distro’s manual for how-to. You will most likely want to config static IP.

Please let me know the result. If everything is good we will also prepare some systemd service to make this more permanent. Currently this script does not persist between boot.

2 Likes

Awesome! My PC and iPad now detect the Ethernet Gadget. :slightly_smiling_face:

Can You explain what Ethernet Gadget is?

It simply is my Radxa Zero which acts like a virtual Ethernet „adapter“

Awesome! I’ll update our Wiki to include this.

2 Likes

I’d like to let you know that a package specifically for enabling this feature is now available on GitHub for testing.

This package allows the USB Ethernet interface to be enabled between boot, and you can configure the interface with /etc/network/interfaces. Here is the setting I used for testing:

auto usb0
iface usb0 inet static
        address 192.168.222.1/24

Manually configure the other end with an IP address between 192.168.222.2 and 192.168.222.254 and you should be able to ping each other.

Any feedback is welcome.

Hi Janik, so it works with Radxa same as it should work for RasPi?
Akaik, Radxa board is connected and powered using one usbC cable?
And one more :slight_smile: are you was able to start any “virtual”/remote X window connection with this setup? (VNC, XRDP, etc.)
All the best! Nick

I believe these instructions no longer work with the latest release / image.

I’ve tested with https://github.com/radxa-build/radxa-zero/releases/tag/20220801-0213 using the image Armbian_22.08.0-trunk_Radxa-zero_focal_current_5.10.134_xfce_desktop.img.xz

The latest builds dont even have the amlogic-adbd service running anymore.

@RadxaYuntian would you be kind enough to update the instructions / wiki to work again with latest build?

Thank you.

You are using an unofficial Armbian build. Please try with our Debian or Ubuntu image.

1 Like

I can confirm that with the Official Ubuntu image, things work.

I did the following:

sudo systemctl disable amlogic-adbd.service
# Reboot

sudo apt install -y wget
wget https://github.com/radxa-pkg/radxa-otgutils/releases/download/0.1-2/radxa-otgutils_0.1-2_all.deb
sudo dpkg -i radxa-otgutils_0.1-2_all.deb
# it complains that android-tools-adbd cannot be installed, but that is a harmless error
sudo systemctl enable radxa-usbnet.service

Then, open the file /etc/network/interfaces

sudo emacs /etc/network/interfaces

Add the following content to the file:

auto usb0
iface usb0 inet static
        address 192.168.222.2/24
        gateway 192.168.222.1

Now, reboot the radxa zero.

The computer that it connects to will see a usbnet interface (tested on Mac and Linux). Have that interface’s ip address to 192.168.222.1, and enable Internet Sharing (mac).
Then you radxa is sshable at 192.168.222.2 from your usb-connected computer, and also uses internet from your computer.

Which image did you use? I am trying radxa-zero-ubuntu-focal-server-arm64-20220801-0346-mbr.img, but it does not even boot from the SD card.

I tried without success various images before :frowning: (USB Gadget Ethernet support on the zero)

Ok. So there is a mistake in the latest image boot configuration path to the dtb file: it tries to load dtbs/5.10.69-12-amlogic-g98700611d064/amlogic/amlogic/meson-g12a-radxa-zero.dtb instead of dtbs/5.10.69-12-amlogic-g98700611d064/amlogic/meson-g12a-radxa-zero.dtb, so that loading the dtb fails. Nice joke from radxa!

The adbd service is currently only called “adbd” and it didn’t work to just disable it by systemctl, so that I removed the file /etc/init.d/adbd.sh.

Now, it FINALLY works! Hooray!

Hi. I followed the instructions in a Dietpi v8.9 system, with my Radxa Zero, but ended up with this error in the radxa-usbnet service status:

systemd[1]: Starting Enable USB ethernet gadget on selected Radxa single board computers... radxa-usbnet.sh[2383]: /lib/radxa-otgutils/radxa-usbnet.sh: line 73: echo: write error: Device or resource busy systemd[1]: radxa-usbnet.service: Control process exited, code=exited, status=1/FAILURE systemd[1]: radxa-usbnet.service: Failed with result 'exit-code'. systemd[1]: Failed to start Enable USB ethernet gadget on selected Radxa single board computers.

That line in the scripts refers to:

local UDC=$(ls /sys/class/udc/ | head -1) echo $UDC > /sys/kernel/config/usb_gadget/radxa-$MODE/UDC

I’ve also manually configured my /etc/network/interfaces file but the usb0 interface is still in DOWN state.

Any ideas? :frowning:

That looks like adbd is still running and occupying the UDC.

@wanthalf I have not been able to locate the service using systemd:

systemctl status amlogic-adbd.service Unit amlogic-adbd.service could not be found.
systemctl status adbd.service Unit adbd.service could not be found.

Have you tried listing active kernel modules by lsmod? And/or search dmesg for anything that might be relevant to USB? Also, the USB might need to be explicitly configured as “peripheral” by the DTB, so that it does not become a “host”.