Enable RNDIS USB Device in Torizon 7.x.x

I previously had the USB Device feature working nicely with Torizon 5.x.x, as described in this post from a few years ago:
Enabling USB Client feature in Torizon - Technical Support - Toradex Community

I’m struggling to get this same approach to work with Torizon 7.x.x.
The information on this page looks like it is still the same as when I had this feature working with Torizon 5.x.x in the past:
USB Device Mode (Linux) | Toradex Developer Center

The module I am currently using has this configuration:

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           6.6.69-7.1.0-00039-g0f10503b36ba #1-Torizon SMP PREEMPT Wed Dec 11 07:36:24 UTC 2024
Kernel command line:      enable_wait_mode=off galcore.contiguousSize=50331648 root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.0/torizon/1486769e784382ae271db5a556352ae078906b57e08d273a435e8121d0d79419/0
Distro name:              NAME="Torizon OS Upstream"
Distro version:           VERSION_ID=7.1.0-build.4
Distro variant:           VARIANT="Docker"
Hostname:                 colibri-imx6-10634753
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Colibri iMX6DL/S on Colibri Evaluation Board V3
Toradex version:          0015 V1.1A
Serial number:            10634753
Processor arch:           armv7l
------------------------------------------------------------

The first challenge is that the torizon user does not seem to have enough access to the files in the usb-gadet folder, even when using sudo. That makes it tricky to debug the process step by step. The first few commands in the process do work:

mount -t configfs none /sys/kernel/config
cd /sys/kernel/config/usb_gadget/
mkdir g2
cd g2

But the commands to enter data don’t work:

sudo echo 0x1b67 > idVendor
-sh: idVendor: Permission denied

I also tried the approach from my previous post of having a service run the whole script as root on startup. That does seem to set all the values correctly but the USB device does not seem to start running.

I do have this in my device tree, could that be a problem?

// Disable the USB host power regulator to liberate SODIMM 129
&reg_usb_host_vbus {
	status = "disabled";
};

Hi, I’m the Toradex AI Assistant.

I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.

Did you like my answer? :+1: :-1:


Hello! Thank you for your detailed description. Let’s address your questions and get USB device mode working on Torizon 7.x.x.

1. Permission Issue with echo and sudo

This is a common shell issue: sudo only elevates echo, not the redirection (>). The file write is still done as the regular user. To resolve, use sudo with sh -c like this:

sudo sh -c 'echo 0x1b67 > idVendor'

Apply this pattern for all echo commands writing to files under /sys.

You can also run a root shell with sudo -i or, in your script/service, ensure the whole process runs as root.

More details:
USB Device Mode (Linux) | Toradex Developer Center


2. USB Host Power Regulator and Device Functionality

Disabling the host VBUS regulator (&reg_usb_host_vbus) should not affect USB device mode; host and device use separate controllers. This device tree change only disables power switching for host mode, so it does not interfere with gadget/device operation.


3. Device Tree Branch

For Torizon OS 7.1.0, make sure you use the device tree based on branch toradex_6.6-2.2.x-imx for i.MX6. See more:
Add Device Tree Branch to Release Matrix


4. Gadget Not Starting

If the gadget is configured but not starting, ensure:

  • ConfigFS is mounted at /sys/kernel/config

  • All necessary function drivers (e.g., usb_f_mass_storage, usb_f_ecm, etc.) are loaded

  • udc is properly set: after creating and configuring, make sure you assign the UDC:

    sudo sh -c 'echo <udc_name> > UDC'
    

    where <udc_name> is typically found by listing /sys/class/udc/ (e.g., ci_hdrc.0).

  • Check for kernel logs (dmesg) for USB or gadget-related issues.


5. General Setup Steps

Here is a simplified sequence, run as root or with each command wrapped in sudo sh -c:

mount -t configfs none /sys/kernel/config
cd /sys/kernel/config/usb_gadget/
mkdir -p g2
cd g2

echo 0x1b67 > idVendor
echo 0x4000 > idProduct

mkdir -p strings/0x409
echo "1234567890" > strings/0x409/serialnumber
echo "Toradex" > strings/0x409/manufacturer
echo "USB Gadget" > strings/0x409/product

mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration

mkdir -p functions/ecm.usb0
ln -s functions/ecm.usb0 configs/c.1/

ls /sys/class/udc  # outputs something like 'ci_hdrc.0'
echo ci_hdrc.0 > UDC

See USB Device Mode (Linux) for more examples and explanation.


If after these steps the device is still not enumerating, let me know the dmesg output after configuring the gadget, and the result of lsusb on the host.

Best regards, Toradex AI Assistant.

Very helpful reply from @ToradexAI!

Using sudo sh - c '...' did indeed solve the first problem I reported, and the explanation from the AI makes sense. I learned something useful today.

This allowed me to debug my script and I found that the command echo "ci_hdrc.1" > g2/UDC which I used with Torizon 5.x.x needs to be echo "ci_hdrc.0" > g2/UDC with Torizon 7.x.x.

I can now start the RNDIS device from the command line, next step is to try to start is from a service.

Thanks for your response.

Please remember to tick the “Solution” checkbox below if my response solves your question. If you have follow-up questions, just continue to tag me using @ToradexAI in your new posts.

Did you like my answer? :+1: :-1:


Hello! I’m glad to hear the suggestions helped resolve your issues and you’re now able to start the RNDIS device from the command line.

For running this setup as a service in Torizon OS, you can use the systemd service approach. Here is a summary of the procedure, which works on Torizon 7.x.x as well:

  1. Create your RNDIS configuration script at /usr/local/bin/usb-function.sh and make sure it’s executable:

    chmod +x /usr/local/bin/usb-function.sh
    
  2. Create the systemd service file at /etc/systemd/system/usb-function.service:

    [Unit]
    After=network.target
    
    [Service]
    ExecStart=/usr/local/bin/usb-function.sh
    
    [Install]
    WantedBy=default.target
    
  3. Enable and start the service:

    sudo systemctl enable usb-function.service
    sudo systemctl start usb-function.service
    

This will ensure your RNDIS (or other USB gadget configurations) script runs automatically at boot.

You can find more details and examples here:

If you need help troubleshooting the service or adapting your script for systemd, just let me know!

Best regards, Toradex AI Assistant.

This is now working as a service. But I found that using network.target didn’t work as it seems the system is ready to enable the USB gadget at that point. Using multi-user.target does work although it delays the USB device coming on-line be a few seconds, which I think is acceptable.

Greetings @MikeS,

Glad to see you were able to work out a solution here. Sounds like you got everything more or less figured out.

Did you have any further questions/issues related to this topic?

Best Regards,
Jeremias

Hi @jeremias.tx, thanks for checking-in on this topic. I’m good for now, the AI helped me to solve the problem.