summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnest Van Hoecke <ernestvanhoecke@gmail.com>2025-07-02 16:32:09 +0200
committerKhem Raj <raj.khem@gmail.com>2025-07-02 23:27:07 -0700
commit88c7b3ee937bedc9ff46da009ca539662c4b6749 (patch)
treee922c77cadbdee8172bdd48232c4511f5e189373
parentb7e233f84aeca74147c3e3cdf16cbe58bd0239f0 (diff)
downloadmeta-openembedded-88c7b3ee937bedc9ff46da009ca539662c4b6749.tar.gz
libusbgx: exit with failure code when no UDC is detected
The systemd target `usb-gadget.target` is triggered by udev when a UDC first comes up. It can happen that by the time gadget-start runs, this UDC has been removed from the system again. Have the gadget-start script exit with status 1 when `ls /sys/class/udc` returns nothing. Causing a service failure when no UDC is detected and no default was given, allows the service to be restarted by a udev rule calling the service (and not the target since those are not reentrant) directly. On its own this patch will not do much. 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 device mode. 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 as 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 Signed-off-by: Ernest Van Hoecke <ernest.vanhoecke@toradex.com> Signed-off-by: Khem Raj <raj.khem@gmail.com>
-rwxr-xr-xmeta-oe/recipes-support/libusbgx/libusbgx/gadget-start6
1 files changed, 5 insertions, 1 deletions
diff --git a/meta-oe/recipes-support/libusbgx/libusbgx/gadget-start b/meta-oe/recipes-support/libusbgx/libusbgx/gadget-start
index e80cb2c340..4ef679888e 100755
--- a/meta-oe/recipes-support/libusbgx/libusbgx/gadget-start
+++ b/meta-oe/recipes-support/libusbgx/libusbgx/gadget-start
@@ -15,6 +15,10 @@ for i in $ENABLED_SCHEMAS; do
15 if [ -n "${configured_udc}" ] && [ -e "/sys/class/udc/${configured_udc}" ]; then 15 if [ -n "${configured_udc}" ] && [ -e "/sys/class/udc/${configured_udc}" ]; then
16 echo ${configured_udc} > /sys/kernel/config/usb_gadget/"$i"/UDC 16 echo ${configured_udc} > /sys/kernel/config/usb_gadget/"$i"/UDC
17 else 17 else
18 ls /sys/class/udc/ > /sys/kernel/config/usb_gadget/"$i"/UDC 18 detected_udc=$(ls /sys/class/udc/)
19 if [ -z "${detected_udc}" ]; then
20 exit 1
21 fi
22 echo "${detected_udc}" > /sys/kernel/config/usb_gadget/"$i"/UDC
19 fi 23 fi
20done 24done