postmarketos-initramfs: check if UDC is configured before clearing (MR 5000)

This fixes the annoying "sh: write error" and "Couldn't write to clear
UDC" messages that happen on every single boot.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-04-10 03:26:08 +02:00 committed by Clayton Craft
parent 75613d9f69
commit 709768214c
No known key found for this signature in database
GPG key ID: 4A4CED6D7EDF950A

View file

@ -626,7 +626,9 @@ setup_usb_configfs_udc() {
fi
# Remove any existing UDC to avoid "write error: Resource busy" when setting UDC again
echo "" > /config/usb_gadget/g1/UDC || echo " Couldn't write to clear UDC"
if [ "$(wc -w <$CONFIGFS/g1/UDC)" -gt 0 ]; then
echo "" > /config/usb_gadget/g1/UDC || echo " Couldn't write to clear UDC"
fi
# Link the gadget instance to an USB Device Controller. This activates the gadget.
# See also: https://gitlab.com/postmarketOS/pmbootstrap/issues/338
echo "$_udc_dev" > /config/usb_gadget/g1/UDC || echo " Couldn't write new UDC"