diff options
author | Ernest Van Hoecke <ernest.vanhoecke@toradex.com> | 2025-07-16 16:24:58 +0200 |
---|---|---|
committer | Ernest Van Hoecke <ernest.vanhoecke@toradex.com> | 2025-07-22 12:00:54 +0200 |
commit | b25ffb88658ca64944941648a0f5fcde8a51261d (patch) | |
tree | 8aa79bd334977b851e0a0425c30afea8cd9dd8d4 | |
parent | fcc6995eff6dfb78b224ccca3368d2b71de2c3a9 (diff) |
libusbgx: call gadget-start from udev instead of usbgx.service
The systemd target `usb-gadget.target` is triggered by udev when a UDC
first comes up. The usbgx service uses this target and executes
gadget-start to initialize the gadget. It can happen that by the time
gadget-start runs, the UDC has been removed from the system again.
For example, we saw such a situation using the DWC3 USB controller and
usb-conn-gpio kernel modules as loadables.
By the time of the DWC3 init, udev was active, and during init DWC3
started the USB OTG port in devicemode, generating a udev add event.
If a pen drive was plugged in at boot, it would quickly switch to
host mode right after initialisation, emitting another udev event for
the removal of the UDC. The systemd target is thus reached, but by the
time gadget-start ran, the UDC was gone.
dwc3 init usb-conn-gpio role switch
│ │
▼ ▼
udev: add UDC─┐ udev: del UDC─────►/sys/class/udc empty
│ │
│ x
│ │
│ ▼
└────────────►usb-gadget.target─────►gadget-start
Call gadget-start from udev every time a UDC comes up instead of only
once via the systemd service (usbgx.service). Repeated runs of this
script are not problematic.
Related-to: ELB-6355
Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com>
(cherry picked from commit 4ba1cebc6909ee7a83d569e8cc748f69e6a0a24f)
-rw-r--r-- | recipes-support/libusbgx/files/99-toradex-usb-udc.rules | 1 | ||||
-rw-r--r-- | recipes-support/libusbgx/libusbgx_%.bbappend | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/recipes-support/libusbgx/files/99-toradex-usb-udc.rules b/recipes-support/libusbgx/files/99-toradex-usb-udc.rules new file mode 100644 index 0000000..e535212 --- /dev/null +++ b/recipes-support/libusbgx/files/99-toradex-usb-udc.rules @@ -0,0 +1 @@ +ACTION=="add", SUBSYSTEM=="udc", RUN+="/usr/bin/gadget-start" diff --git a/recipes-support/libusbgx/libusbgx_%.bbappend b/recipes-support/libusbgx/libusbgx_%.bbappend new file mode 100644 index 0000000..e0a5ab1 --- /dev/null +++ b/recipes-support/libusbgx/libusbgx_%.bbappend @@ -0,0 +1,22 @@ +# When using the examples package, disable the usbgx service and instead +# call gadget-start from udev. +# +# The systemd target `usb-gadget.target` is triggered by udev when a UDC +# first comes up. The usbgx service uses this target and executes +# gadget-start to initialize the gadget. It can happen that by the time +# gadget-start runs, the UDC has been removed from the system again. +# +# Call gadget-start from udev every time a UDC comes up instead of only +# once via the systemd service (usbgx.service). Repeated runs of this +# script are not problematic. + +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" + +SRC_URI:append = " file://99-toradex-usb-udc.rules" + +SYSTEMD_AUTO_ENABLE:${PN}-examples = "disable" + +do_install:append() { + install -d ${D}${sysconfdir}/udev/rules.d + install -m 0644 ${WORKDIR}/99-toradex-usb-udc.rules ${D}${sysconfdir}/udev/rules.d/ +} |