Skip to content

Commit dc8392a

Browse files
authored
Merge pull request #852 from jluebbe/suggest
try to use ID_PATH and ID_SERIAL_SHORT on the device itself
2 parents b1229ff + c9bbdd7 commit dc8392a

File tree

5 files changed

+93
-37
lines changed

5 files changed

+93
-37
lines changed

doc/configuration.rst

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ This allows identification through hot-plugging or rebooting.
7474
7575
USBSerialPort:
7676
match:
77-
'ID_SERIAL_SHORT': 'P-00-00682'
77+
ID_SERIAL_SHORT: P-00-00682
7878
speed: 115200
7979
8080
The example would search for a USB serial converter with the key
8181
`ID_SERIAL_SHORT` and the value `P-00-00682` and use it with a baud rate
8282
of 115200.
83+
The `ID_SERIAL_SHORT` property is set by the usb_id builtin helper program.
8384

8485
- match (str): key and value for a udev match, see `udev Matching`_
8586
- speed (int, default=115200): baud rate of the serial port
@@ -430,7 +431,7 @@ A USBMassStorage resource describes a USB memory stick or similar device.
430431
431432
USBMassStorage:
432433
match:
433-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0-scsi-0:0:0:3'
434+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0-scsi-0:0:0:3
434435
435436
- match (str): key and value for a udev match, see `udev Matching`_
436437

@@ -473,7 +474,7 @@ An IMXUSBLoader resource describes a USB device in the imx loader state.
473474
474475
IMXUSBLoader:
475476
match:
476-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0'
477+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
477478
478479
- match (str): key and value for a udev match, see `udev Matching`_
479480

@@ -489,7 +490,7 @@ An MXSUSBLoader resource describes a USB device in the mxs loader state.
489490
490491
MXSUSBLoader:
491492
match:
492-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0'
493+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
493494
494495
- match (str): key and value for a udev match, see `udev Matching`_
495496

@@ -505,7 +506,7 @@ An RKUSBLoader resource describes a USB device in the rockchip loader state.
505506
506507
RKUSBLoader:
507508
match:
508-
'sys_name': '1-3'
509+
sys_name: '1-3'
509510
510511
- match (str): key and value for a udev match, see `udev Matching`_
511512

@@ -532,7 +533,7 @@ An AndroidFastboot resource describes a USB device in the fastboot state.
532533
533534
AndroidFastboot:
534535
match:
535-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0'
536+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
536537
537538
- match (str): key and value for a udev match, see `udev Matching`_
538539

@@ -548,7 +549,7 @@ Ethernet or WiFi)
548549
549550
USBNetworkInterface:
550551
match:
551-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0'
552+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
552553
553554
- match (str): key and value for a udev match, see `udev Matching`_
554555

@@ -565,7 +566,7 @@ An AlteraUSBBlaster resource describes an Altera USB blaster.
565566
566567
AlteraUSBBlaster:
567568
match:
568-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0'
569+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
569570
570571
- match (dict): key and value for a udev match, see `udev Matching`_
571572

@@ -582,7 +583,7 @@ FT2232H).
582583
583584
USBDebugger:
584585
match:
585-
ID_PATH: 'pci-0000:00:10.0-usb-0:1.4'
586+
ID_PATH: pci-0000:00:10.0-usb-0:1.4
586587
587588
- match (dict): key and value for a udev match, see `udev Matching`_
588589

@@ -613,7 +614,7 @@ A SigrokUSBDevice resource describes a sigrok USB device.
613614
driver: fx2lafw
614615
channel: "D0=CLK,D1=DATA"
615616
match:
616-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0'
617+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
617618
618619
- driver (str): name of the sigrok driver to use
619620
- channel (str): optional, channel mapping as described in the sigrok-cli man page
@@ -633,7 +634,7 @@ host which is exported over the network. The SigrokDriver will access it via SSH
633634
driver: fx2lafw
634635
channel: "D0=CLK,D1=DATA"
635636
match:
636-
'ID_PATH': 'pci-0000:06:00.0-usb-0:1.3.2:1.0'
637+
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
637638
host: remote.example.computer
638639
639640
- driver (str): name of the sigrok driver to use
@@ -672,7 +673,7 @@ device.
672673
673674
USBSDMuxDevice:
674675
match:
675-
'@ID_PATH': 'pci-0000:00:14.0-usb-0:1.2'
676+
'@ID_PATH': pci-0000:00:14.0-usb-0:1.2
676677
677678
- match (str): key and value for a udev match, see `udev Matching`_
678679

@@ -693,7 +694,7 @@ A :any:`LXAUSBMux` resource describes a Linux Automation GmbH USB-Mux device.
693694
694695
LXAUSBMux:
695696
match:
696-
'@ID_PATH': 'pci-0000:00:14.0-usb-0:1.2'
697+
'@ID_PATH': pci-0000:00:14.0-usb-0:1.2
697698
698699
- match (str): key and value for a udev match, see `udev Matching`_
699700

@@ -716,7 +717,7 @@ device.
716717
717718
USBSDWireDevice:
718719
match:
719-
'@ID_PATH': 'pci-0000:00:14.0-usb-0:1.2'
720+
'@ID_PATH': pci-0000:00:14.0-usb-0:1.2
720721
721722
- match (str): key and value for a udev match, see `udev Matching`_
722723

@@ -739,7 +740,7 @@ Video4Linux2 kernel driver.
739740
740741
USBVideo:
741742
match:
742-
'@ID_PATH': 'pci-0000:00:14.0-usb-0:1.2'
743+
'@ID_PATH': pci-0000:00:14.0-usb-0:1.2
743744
744745
- match (str): key and value for a udev match, see `udev Matching`_
745746

@@ -801,7 +802,7 @@ The low-level communication is handled by the ``usbtmc`` kernel driver.
801802
802803
USBTMC:
803804
match:
804-
'@ID_PATH': 'pci-0000:00:14.0-usb-0:1.2'
805+
'@ID_PATH': pci-0000:00:14.0-usb-0:1.2
805806
806807
- match (str): key and value for a udev match, see `udev Matching`_
807808

@@ -863,7 +864,7 @@ running a flashing program with `FlashScriptDriver`_.
863864
864865
USBFlashableDevice:
865866
match:
866-
SUBSYSTEM: 'usb'
867+
SUBSYSTEM: usb
867868
ID_SERIAL: '1234'
868869
869870
- match (str): key and value pairs for a udev match, see `udev Matching`_
@@ -919,7 +920,7 @@ A :any:`HTTPVideoStream` resource describes a IP video stream over HTTP or HTTPS
919920
.. code-block:: yaml
920921
921922
HTTPVideoStream:
922-
url: 'http://192.168.110.11/0.ts'
923+
url: http://192.168.110.11/0.ts
923924
924925
- url (str): URI of the IP video stream
925926

@@ -1008,7 +1009,7 @@ created through interaction with that daemon.
10081009
.. code-block:: yaml
10091010
10101011
DockerDaemon:
1011-
docker_daemon_url: 'unix://var/run/docker.sock'
1012+
docker_daemon_url: unix://var/run/docker.sock
10121013
10131014
The example describes a docker daemon accessible via the
10141015
'/var/run/docker.sock' unix socket. When used by a `DockerDriver`, the
@@ -1098,7 +1099,7 @@ don't use a parent match.
10981099
10991100
AndroidFastboot:
11001101
match:
1101-
'sys_name': '1-1.2.3'
1102+
sys_name: '1-1.2.3'
11021103
11031104
Matching a Specific UART in a Dual-Port Adapter
11041105
+++++++++++++++++++++++++++++++++++++++++++++++
@@ -1150,7 +1151,7 @@ We use the ``ID_USB_INTERFACE_NUM`` to distinguish between the two ports:
11501151
USBSerialPort:
11511152
match:
11521153
'@sys_name': '3-10.2.2.2'
1153-
'ID_USB_INTERFACE_NUM': '01'
1154+
ID_USB_INTERFACE_NUM: '01'
11541155
11551156
Matching a USB UART by Serial Number
11561157
++++++++++++++++++++++++++++++++++++
@@ -1164,14 +1165,39 @@ changes or a board has been moved between host systems.
11641165
11651166
USBSerialPort:
11661167
match:
1167-
'ID_SERIAL_SHORT': 'P-00-00679'
1168+
ID_SERIAL_SHORT: P-00-03564
11681169
11691170
To check if your device has a serial number, you can use ``udevadm info``:
11701171

11711172
.. code-block:: bash
11721173
11731174
$ udevadm info /dev/ttyUSB5 | grep SERIAL_SHORT
1174-
E: ID_SERIAL_SHORT=P-00-00679
1175+
E: ID_SERIAL_SHORT=P-00-03564
1176+
1177+
In the background, the additional properties are provided by the builtin ``usb_id``
1178+
udev helper::
1179+
1180+
$ udevadm test-builtin usb_id /sys/class/tty/ttyUSB0
1181+
Load module index
1182+
Parsed configuration file /lib/systemd/network/99-default.link
1183+
Parsed configuration file /lib/systemd/network/73-usb-net-by-mac.link
1184+
Created link configuration context.
1185+
ID_VENDOR=Silicon_Labs
1186+
ID_VENDOR_ENC=Silicon\x20Labs
1187+
ID_VENDOR_ID=10c4
1188+
ID_MODEL=CP2102_USB_to_UART_Bridge_Controller
1189+
ID_MODEL_ENC=CP2102\x20USB\x20to\x20UART\x20Bridge\x20Controller
1190+
ID_MODEL_ID=ea60
1191+
ID_REVISION=0100
1192+
ID_SERIAL=Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_P-00-03564
1193+
ID_SERIAL_SHORT=P-00-03564
1194+
ID_TYPE=generic
1195+
ID_BUS=usb
1196+
ID_USB_INTERFACES=:ff0000:
1197+
ID_USB_INTERFACE_NUM=00
1198+
ID_USB_DRIVER=cp210x
1199+
Unload module index
1200+
Unloaded link configuration context.
11751201

11761202
Drivers
11771203
-------
@@ -1217,7 +1243,7 @@ Implements:
12171243
ShellDriver:
12181244
prompt: 'root@\w+:[^ ]+ '
12191245
login_prompt: ' login: '
1220-
username: 'root'
1246+
username: root
12211247
12221248
Arguments:
12231249
- prompt (regex): shell prompt to match after logging in

doc/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ Additional groups and resources can be added:
228228
location: example-location
229229
USBSerialPort:
230230
match:
231-
'ID_SERIAL_SHORT': 'P-00-00682'
231+
ID_SERIAL_SHORT: P-00-00682
232232
speed: 115200
233233
NetworkPowerPort:
234234
model: netio

labgrid/resource/udev.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,18 @@ def suggest_match(self, device):
8585
if self.device.properties.get('ID_REVISION'):
8686
meta['revision'] = self.device.properties.get('ID_REVISION')
8787

88-
if self.match.get('SUBSYSTEM', None) == 'usb':
89-
path = self._get_usb_device().properties.get('ID_PATH')
90-
if path:
91-
suggestions.append({'ID_PATH': path})
92-
serial = self._get_usb_device().properties.get('ID_SERIAL_SHORT')
93-
if serial:
94-
suggestions.append({'ID_SERIAL_SHORT': serial})
88+
path = self.device.properties.get('ID_PATH')
89+
if path:
90+
suggestions.append({'ID_PATH': path})
9591
elif self.match.get('@SUBSYSTEM', None) == 'usb':
9692
path = self._get_usb_device().properties.get('ID_PATH')
9793
if path:
9894
suggestions.append({'@ID_PATH': path})
95+
96+
serial = self.device.properties.get('ID_SERIAL_SHORT')
97+
if serial:
98+
suggestions.append({'ID_SERIAL_SHORT': serial})
99+
elif self.match.get('@SUBSYSTEM', None) == 'usb':
99100
serial = self._get_usb_device().properties.get('ID_SERIAL_SHORT')
100101
if serial:
101102
suggestions.append({'@ID_SERIAL_SHORT': serial})

man/labgrid-suggest.1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,30 @@ enable debug mode
5454
.SH EXAMPLES
5555
.sp
5656
For a device that has an \fBID_SERIAL_SHORT\fP key with a unique ID embedded
57-
in the USB\-serial converter, the resource match configuration is:
57+
in the USB\-serial converter, \fBlabgrid\-suggest\fP shows two alternatives:
5858
.INDENT 0.0
5959
.INDENT 3.5
6060
.sp
6161
.nf
6262
.ft C
63+
=== added device ===
64+
USBSerialPort for /devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1\-3/1\-3.1/1\-3.1:1.0/ttyUSB0/tty/ttyUSB0
65+
=== device properties ===
66+
device node: /dev/ttyUSB0
67+
udev tags: , systemd
68+
vendor: Silicon_Labs
69+
vendor (DB): Advanced Micro Devices, Inc. [AMD]
70+
model: CP2102_USB_to_UART_Bridge_Controller
71+
revision: 0100
72+
=== suggested matches ===
6373
USBSerialPort:
6474
match:
65-
\(aq@ID_SERIAL_SHORT\(aq: \(aqP\-00\-00682\(aq
75+
ID_PATH: pci\-0000:02:00.0\-usb\-0:3.1:1.0
76+
\-\-\-
77+
USBSerialPort:
78+
match:
79+
ID_SERIAL_SHORT: P\-00\-03564
80+
\-\-\-
6681
.ft P
6782
.fi
6883
.UNINDENT

man/labgrid-suggest.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,28 @@ EXAMPLES
4545
--------
4646

4747
For a device that has an ``ID_SERIAL_SHORT`` key with a unique ID embedded
48-
in the USB-serial converter, the resource match configuration is:
48+
in the USB-serial converter, ``labgrid-suggest`` shows two alternatives:
4949

5050
.. code-block:: yaml
5151
52+
=== added device ===
53+
USBSerialPort for /devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1-3/1-3.1/1-3.1:1.0/ttyUSB0/tty/ttyUSB0
54+
=== device properties ===
55+
device node: /dev/ttyUSB0
56+
udev tags: , systemd
57+
vendor: Silicon_Labs
58+
vendor (DB): Advanced Micro Devices, Inc. [AMD]
59+
model: CP2102_USB_to_UART_Bridge_Controller
60+
revision: 0100
61+
=== suggested matches ===
5262
USBSerialPort:
5363
match:
54-
'@ID_SERIAL_SHORT': 'P-00-00682'
55-
64+
ID_PATH: pci-0000:02:00.0-usb-0:3.1:1.0
65+
---
66+
USBSerialPort:
67+
match:
68+
ID_SERIAL_SHORT: P-00-03564
69+
---
5670
5771
SEE ALSO
5872
--------

0 commit comments

Comments
 (0)