diff options
author | Max Krummenacher <max.krummenacher@toradex.com> | 2024-02-15 20:16:59 +0100 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2024-02-15 14:14:26 -0800 |
commit | 0b6224a322a7535151859027c1b256a8834f9469 (patch) | |
tree | ef265437830774bb8065062b325aae2cf54756ea | |
parent | 066f509f15d7a06deab200663b54b3bd19839ed9 (diff) | |
download | meta-openembedded-0b6224a322a7535151859027c1b256a8834f9469.tar.gz |
libusbgx: fix usbgx.service stop / restart
On start the usbgx service configures the usb gadget. However if
one stops the service nothing is done, a subsequent start then
tries to configure the gadget again and fails. `systemctl restart`
is implemented by doing a stop followed by a start and thus is
also affected.
Doing a start/stop/start results with the following reported in
status:
| systemd[1]: Starting Load USB gadget schemas...
| gadget-start[801]: usbg_create_gadget() duplicate gadget name
| gadget-start[801]:
| gadget-start[801]: Error on import gadget
| gadget-start[801]: Error: USBG_ERROR_EXIST : Already exist
| gadget-start[812]: ls: write error: Device or resource busy
The run-postinsts service does execute a restart for each package
which uses the systemd class which creates a race condition that the
usbgx service is already started when run-postinsts restarts usbgx
and creates the above error output.
Fix that by unconfiguring the usb gadget on stop.
Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
-rwxr-xr-x | meta-oe/recipes-support/libusbgx/libusbgx/gadget-stop | 13 | ||||
-rw-r--r-- | meta-oe/recipes-support/libusbgx/libusbgx/usbgx.service | 2 | ||||
-rw-r--r-- | meta-oe/recipes-support/libusbgx/libusbgx_git.bb | 3 |
3 files changed, 18 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/libusbgx/libusbgx/gadget-stop b/meta-oe/recipes-support/libusbgx/libusbgx/gadget-stop new file mode 100755 index 0000000000..24b7caed5e --- /dev/null +++ b/meta-oe/recipes-support/libusbgx/libusbgx/gadget-stop @@ -0,0 +1,13 @@ +#!/bin/sh + +[ -r /etc/default/usbgx ] && . /etc/default/usbgx + +for i in $IMPORT_SCHEMAS; do + if [ -e /sys/kernel/config/usb_gadget/"$i"/idVendor ]; then + if [ -e /sys/kernel/config/usb_gadget/"$i"/idProduct ]; then + idVendor=$(cat /sys/kernel/config/usb_gadget/"$i"/idVendor) + idProduct=$(cat /sys/kernel/config/usb_gadget/"$i"/idProduct) + /usr/bin/gadget-vid-pid-remove ${idVendor}:${idProduct} + fi + fi +done diff --git a/meta-oe/recipes-support/libusbgx/libusbgx/usbgx.service b/meta-oe/recipes-support/libusbgx/libusbgx/usbgx.service index d7d394cfe1..7210969d62 100644 --- a/meta-oe/recipes-support/libusbgx/libusbgx/usbgx.service +++ b/meta-oe/recipes-support/libusbgx/libusbgx/usbgx.service @@ -5,7 +5,9 @@ After=sys-kernel-config.mount [Service] Type=oneshot +RemainAfterExit=yes ExecStart=/usr/bin/gadget-start +ExecStop=/usr/bin/gadget-stop [Install] WantedBy=usb-gadget.target diff --git a/meta-oe/recipes-support/libusbgx/libusbgx_git.bb b/meta-oe/recipes-support/libusbgx/libusbgx_git.bb index f8ebcc7767..4841105619 100644 --- a/meta-oe/recipes-support/libusbgx/libusbgx_git.bb +++ b/meta-oe/recipes-support/libusbgx/libusbgx_git.bb @@ -13,6 +13,7 @@ SRC_URI = " \ file://0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch \ file://0001-fix-stack-buffer-overflow-in-usbg_f_foo_attr_val-pro.patch \ file://gadget-start \ + file://gadget-stop \ file://usbgx.initd \ file://usbgx.service \ " @@ -39,6 +40,8 @@ INHIBIT_UPDATERCD_BBCLASS = "${@bb.utils.contains('PACKAGECONFIG', 'examples', ' do_install:append() { install -Dm 0755 ${WORKDIR}/gadget-start ${D}${bindir}/gadget-start sed -i -e 's,/usr/bin,${bindir},g' -e 's,/etc,${sysconfdir},g' ${D}${bindir}/gadget-start + install -m 0755 ${WORKDIR}/gadget-start ${D}${bindir}/gadget-stop + sed -i -e 's,/usr/bin,${bindir},g' -e 's,/etc,${sysconfdir},g' ${D}${bindir}/gadget-stop if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then install -Dm 0644 ${WORKDIR}/usbgx.service ${D}${systemd_system_unitdir}/usbgx.service |