Skip to content

exporter: Add USB hub abstraction for simpler device matching#1854

Open
sjg20 wants to merge 1 commit intolabgrid-project:masterfrom
sjg20:push5-hub
Open

exporter: Add USB hub abstraction for simpler device matching#1854
sjg20 wants to merge 1 commit intolabgrid-project:masterfrom
sjg20:push5-hub

Conversation

@sjg20
Copy link
Copy Markdown
Contributor

@sjg20 sjg20 commented Apr 14, 2026

The exporter config requires full @ID_PATH strings for every USB resource, which are long and hard to maintain, particular for labs with multiple hubs.

This PR adds a 'hubs' section to the exporter config that defines USB hubs by name, base path, and a mapping of logical port numbers to USB path suffixes. Resources can then use 'hub' and 'port' in their match dict instead of a raw @ID_PATH string.

For example, instead of:

board1:
USBSerialPort:
match:
'@ID_PATH': 'pci-0000:04:00.0-usb-0:2.2.3'

the config can be written as:

hubs:
a:
base: 'pci-0000:04:00.0-usb-0:2'
ports:
7: '2.3'

board1:
USBSerialPort:
match:
hub: a
port: 7

The expansion happens at config load time before any resource matching, so it works with any USB resource type.

This feature is used to help diagnose problems - e.g. if a device's UART stops working, which USB port do I need to replug? It saves a lot of confusion mapping a string of numbers to a physical port.

This feature has been manually verified on my lab (about 30 boards) with 7 16-port hubs connected to a single machine. Operation appears to be the same before and after the change. I think modified the lab to actually use this feature and checked that things still work.

Checklist

  • Documentation for the feature
  • Tests for the feature
    If you add a feature other drivers/resources can benefit from:
  • Add a section on how to use the feature to doc/usage.rst
  • Add a section on how to use the feature to doc/development.rst
  • PR has been tested

The exporter config requires full @ID_PATH strings for every USB
resource, which are long and hard to maintain. Add a 'hubs' section
to the exporter config that defines USB hubs by name, base path,
and a mapping of logical port numbers to USB path suffixes.
Resources can then use 'hub' and 'port' in their match dict instead
of a raw @ID_PATH string.

For example, instead of:

  board1:
    USBSerialPort:
      match:
        '@ID_PATH': 'pci-0000:04:00.0-usb-0:2.2.3'

the config can be written as:

  hubs:
    a:
      base: 'pci-0000:04:00.0-usb-0:2'
      ports:
        7: '2.3'

  board1:
    USBSerialPort:
      match:
        hub: a
        port: 7

The expansion happens at config load time before any resource
matching, so it works with any USB resource type.

Signed-off-by: Simon Glass <sjg@chromium.org>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 92.10526% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.3%. Comparing base (c246fab) to head (b4cc652).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/remote/exporter.py 92.1% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1854     +/-   ##
========================================
+ Coverage    45.8%   47.3%   +1.5%     
========================================
  Files         182     182             
  Lines       14718   14756     +38     
========================================
+ Hits         6743    6991    +248     
+ Misses       7975    7765    -210     
Flag Coverage Δ
3.10 47.3% <92.1%> (+1.5%) ⬆️
3.11 47.3% <92.1%> (+1.5%) ⬆️
3.12 47.3% <92.1%> (+1.5%) ⬆️
3.13 47.3% <92.1%> (+1.5%) ⬆️
3.14 47.3% <92.1%> (+1.5%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant