From 9ce53ad72ba97cd30b0f1aab6b6473e66c788074 Mon Sep 17 00:00:00 2001 From: Cedric Hombourger Date: Thu, 15 Feb 2024 13:50:07 +0100 Subject: [PATCH] support/usb: check for udc instance Check if the system has any udc instances to avoid a nasty exception. Closes: #367 Signed-off-by: Cedric Hombourger --- mtda/support/usb.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mtda/support/usb.py b/mtda/support/usb.py index 541a7029..ee636ee9 100644 --- a/mtda/support/usb.py +++ b/mtda/support/usb.py @@ -86,10 +86,20 @@ def _configure(what, conf): return result def _enable(): - usbdrv = os.listdir("/sys/class/udc")[0] - udc = os.path.join(Composite.path, "UDC") - result = write(udc, usbdrv) - return result > 0 + Composite.debug(3, "composite._enable()") + + instances = os.listdir("/sys/class/udc") + result = False + if instances: + usbdrv = instances[0] + udc = os.path.join(Composite.path, "UDC") + result = write(udc, usbdrv) > 0 + else: + Composite.debug(1, "composite._enable(): " + "platform does not support udc") + + Composite.debug(3, f"composite._enable(): {result}") + return result def _disable(): udc = os.path.join(Composite.path, "UDC")