Gadget mode setup file doesnt work on zero 2w #2

Closed
opened 2026-09-03 17:22:02 +00:00 by aleksa24 · 11 comments

I found a fix, if you replace the line:
if lsmod | grep -q "dwc2"; then
with:
if [ -d /sys/class/udc ] && [ -n "$(ls -A /sys/class/udc)" ]; then

Apparently the problem is on some pi 2s since Foley said his worked with no issues.

I found a fix, if you replace the line: if lsmod | grep -q "dwc2"; then with: if [ -d /sys/class/udc ] && [ -n "$(ls -A /sys/class/udc)" ]; then Apparently the problem is on some pi 2s since Foley said his worked with no issues.
Owner

lsmod finds a dwc2 on my pi running the service
uname -a
Linux foley-rover 6.18.34+rpt-rpi-v7 #1 SMP Raspbian 1:6.18.34-1+rpt1 (2026-06-09) armv7l GNU/Linux

lsmod finds a dwc2 on my pi running the service uname -a Linux foley-rover 6.18.34+rpt-rpi-v7 #1 SMP Raspbian 1:6.18.34-1+rpt1 (2026-06-09) armv7l GNU/Linux
Author

aleksa24@aleksa24-pi2:~$ uname -a
Linux aleksa24-pi2 6.18.39+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.18.39-1+rpt1 (2026-07-29) aarch64 GNU/Linux

This is mine, seems like a later version

aleksa24@aleksa24-pi2:~$ uname -a Linux aleksa24-pi2 6.18.39+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.18.39-1+rpt1 (2026-07-29) aarch64 GNU/Linux This is mine, seems like a later version
Owner

It looks like dwc2 is not built as a module on later kernels, so it does not show up as a module with lsmod. They also seem to have deprecated the USB serial gadget. g_serial is still a module, though, but marked legacy.

It looks like `dwc2` is not built as a module on later kernels, so it does not show up as a module with lsmod. They also seem to have deprecated the USB serial gadget. `g_serial` is still a module, though, but marked legacy.
Owner

I updated my (not fresh) install on a pi zero w 2 and still get dwc2
foley@foley-rover:~ $ lsmod | grep dwc
dwc2 176128 0
roles 16384 1 dwc2
foley@foley-rover:~ $ uname -a
Linux foley-rover 6.18.39+rpt-rpi-v7 #1 SMP Raspbian 1:6.18.39-1+rpt1 (2026-07-29) armv7l GNU/Linux

I updated my (not fresh) install on a pi zero w 2 and still get dwc2 foley@foley-rover:~ $ lsmod | grep dwc dwc2 176128 0 roles 16384 1 dwc2 foley@foley-rover:~ $ uname -a Linux foley-rover 6.18.39+rpt-rpi-v7 #1 SMP Raspbian 1:6.18.39-1+rpt1 (2026-07-29) armv7l GNU/Linux
Owner

@marcel reminds me that he discovered this earlier. I will need to reflash a pi zero w 2 image on a SD and see if also happens to me.

@marcel reminds me that he discovered this earlier. I will need to reflash a pi zero w 2 image on a SD and see if also happens to me.
Owner

Commit 9c49411159 now includes the check for udc. I need to figure out how best to "disable" it. I think I will have the script check for a DWC or gadget file in the /boot/firmware directory which can be changed directly on the SD card without booting the Pi.

Commit 9c49411159038efc998d723b9e31ccdb79b4ed23 now includes the check for udc. I need to figure out how best to "disable" it. I think I will have the script check for a DWC or gadget file in the `/boot/firmware` directory which can be changed directly on the SD card without booting the Pi.
Owner

commit e6a0556147 now has it look for a file called GADGET_MODE in /boot/firmware (accessible by an SD card reader) to enable or disable. My initial test says it works.

commit e6a0556147a62b18a81237024c9d8c5278a7ed31 now has it look for a file called GADGET_MODE in /boot/firmware (accessible by an SD card reader) to enable or disable. My initial test says it works.
Owner

Weird. It's not coming back up. I need to do more debugging.

Weird. It's not coming back up. I need to do more debugging.
Owner

@marcel reminds me that serial USB is depricated and perhaps we need to use the supported (and suggested) ethernet gadget which is documented in https://github.com/raspberrypi/rpi-usb-gadget

@marcel reminds me that serial USB is depricated and perhaps we need to use the supported (and suggested) ethernet gadget which is documented in https://github.com/raspberrypi/rpi-usb-gadget
Owner

I just tested the pre-installed rpi-usb-gadget and it just worked. I think I'll change the directions to have people just use that instead of the serial method.

I just tested the pre-installed rpi-usb-gadget and it just worked. I think I'll change the directions to have people just use that instead of the serial method.
foley added reference dwc2-detect 2026-09-06 20:09:40 +00:00
foley changed reference from dwc2-detect to dwc2-detect 2026-09-06 20:09:47 +00:00
Owner

We have a system that works (but is tricky to turn back on offline) but I consider this bug fixed for now. I'll continue work on making that switch work in branch dwc-detect on Issue #1

We have a system that works (but is tricky to turn back on offline) but I consider this bug fixed for now. I'll continue work on making that switch work in branch dwc-detect on Issue #1
foley closed this issue 2026-09-06 20:10:24 +00:00
Sign in to join this conversation.