misc: configurator: Config usb mediator devices in dropdown list

Support detecting connected usb devices in board_inspector and list them
in the usb mediator configuration menu.

Tracked-On: #7424
Signed-off-by: Calvin Zhang <calvinzhang.cool@gmail.com>
This commit is contained in:
Calvin Zhang
2022-05-06 15:19:15 +08:00
committed by acrnsi-robot
parent 2d66ba4d40
commit e36b615fe1
4 changed files with 49 additions and 11 deletions

View File

@@ -0,0 +1,33 @@
# Copyright (C) 2022 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import os, re
from extractors.helpers import add_child, get_node
USB_DEVICES_PATH = "/sys/bus/usb/devices"
USB_DEVICES_REGEX = r"^\d-\d$" # only devices connecting to root hub
def extract(args, board_etree):
dev_regex = re.compile(USB_DEVICES_REGEX)
for dev in os.listdir(USB_DEVICES_PATH):
m = dev_regex.match(dev)
if m:
d = m.group(0)
devpath = os.path.join(USB_DEVICES_PATH, d)
with open(os.path.join(devpath, 'devnum'), 'r') as f:
devnum = f.read().strip()
with open(os.path.join(devpath, 'busnum'), 'r') as f:
busnum = f.read().strip()
cmd_out = os.popen('lsusb -s {b}:{d}'.format(b=busnum, d=devnum)).read()
desc = cmd_out.split(':', maxsplit=1)[1].strip('\n')
with open(devpath + '/port/firmware_node/path') as f:
acpi_path = f.read().strip()
usb_port_node = get_node(board_etree, f"//device[acpi_object='{acpi_path}']")
if usb_port_node is not None:
add_child(usb_port_node, "usb_device", location=d,
description=d + desc)