Skip to main content

Tool to control an USB-Mux from the command line

Project description

LGPLv2.1 pypi.org

Purpose

This is the control software for the Linux Automation GmbH USB-Mux. This repository contains a standalone command line application and a python module, both of which may be used to control USB-Muxes on Linux.

USB-Muxes contain an USB Hub, high speed analog switches, power switches and a microcontroller for control. USB-Muxes enable the automated testing of embedded USB devices by allowing the connection of a USB device to a DUT (device under test) without requiring physical access.

The USB-Mux hardware and software is usually used with Labgrid, but can also be made to fit your workflow by using it standalone or in a custom application.

Functional overview

usbmuxctl provides the following sub-commands:

  • usbmuxctl list - Get a list of available USB-Muxes

  • usbmuxctl status - Get the current status of a particular USB-Mux

  • usbmuxctl update - Perform firmware upgrades

  • usbmuxctl disconnect - Tear down all USB connections to the DUT and Device ports

  • usbmuxctl connect - Create a connection between USB ports. Possible connections are:

    • --dut-device - Connect the DUT (e.g. a single board computer) to the Device port (e.g. an USB flash drive)

    • --host-dut - Connect the Host (e.g. a PC running usbmuxctl) to the DUT (acting as an USB device)

    • --host-device - Connect the Host to the Device port

  • usbmuxctl id - Set the status of the DUT’s id pin used for USB OTG negotiation

Possible example use cases are:

  • Testing the hot-plug reliability by toggling between usbmuxctl disconnect and usbmuxctl connect --dut-device.

  • Testing USB-based firmware upgrades by sharing a flash drive using usbmuxctl --host-device and usbmuxctl --dut-device.

  • Testing USB OTG functionality using usbmuxctl --dut-device (DUT in the USB host role) and usbmuxctl --host-dut (DUT in the USB device role).

Further documentation is available in the handbook.

Quickstart

You can install usbmuxctl either directly from git or from pypi. If you just want to give the tool a spin you should use the pypi-method.

Install from git

Clone this repository and create a virtualenv for usbmuxctl:

$ git clone https://github.com/linux-automation/usbmuxctl.git
$ cd usbmuxctl
$ python3 -m venv venv
$ source venv/bin/activate

Install usbmuxctl into the virtualenv:

$ pip3 install .

You can now continue to test your installation using the help command.

Install from pypi

Create and activate a virtualenv for usbmuxctl:

$ python3 -m venv venv
$ source venv/bin/activate

Install usbmuxctl into the virtualenv:

$ pip3 install usbmuxctl

Test your installation

You can now run usbmuxctl -h to get a list of available sub-commands:

$ usbmuxctl -h
usage: usbmuxctl [-h] [--serial SERIAL] [--path PATH] [--json | --raw] {list,status,update,
disconnect,connect,id,dfu} ...

USB-Mux control

positional arguments:
  {list,status,update,disconnect,connect,id,dfu}
                        Supply one of the following commands to interact with the USB-Mux
    list                Lists all connected USB-Mux
    status              Get the status of a USB-Mux
    update              Update software on the USB-Mux
    disconnect          Clear all connections between the ports of the USB-Mux
    connect             Make connections between the ports of the USB-Mux
    id                  Set the state of the ID-Pin to the DUT
    dfu                 Send the USB-Mux into the USB-Bootloader mode.

optional arguments:
  -h, --help            show this help message and exit
  --serial SERIAL       Serial number of the USB-Mux
  --path PATH           path to the USB-Mux
  --json                Format output as json. Useful for scripting.
  --raw                 Format output as raw info. Useful for command line scripting.

Using as root

To communicate with the USB-Muxes usbmuxctl needs permissions to access the USB-connected microcontroller. The section below describes the correct way to grant these permissions to your user.

To rule out issues with the configuration of these permissions for the initial test you can run usbmuxctl as root by using sudo and a path to the usbmuxctl file inside the previously set up virtualenv [1]:

$ sudo venv/bin/usbmuxctl list
Serial      | USB-Path           | Host-DUT Lock? | Connections
----------- | ------------------ | -------------- | -----------
22          | 1-3.1              | unlocked       | None

$ sudo venv/bin/usbmuxctl --serial 22 connect --host-device
                                     +-----------------------+
                                     | USB-Mux               |
                                  +--|                       |
                                  |  | SN:   22              |
                                  |  | Path: 1-3.1           |
                                  |  +-----------------------+
       VCC: 4.95V    +---------+  |
Host |>--------------|       1 |--+         ID: High
                     |         |           VCC: 0.00V
                     |       2 |----x    ------------|> DUT
                     |         |
                     |       3 |---------------------|> Device
                     +---------+           VCC: 4.62V

Using as non-root user

To use usbmuxctl as non-root user you should use an udev rule to grant access to the USB-Mux device to your user. An example rule for Debian and Debian based distributions (like Ubuntu or Mint) [2] is included in the contrib/udev folder of this repository. The content of this rule file should be placed in a file in the /etc/udev/rules.d/ directory. An example installation, including the reloading of udev rules is shown below:

$ echo 'ATTRS{idVendor}=="33f7", ATTRS{idProduct}=="0001", TAG+="uaccess", GROUP="plugdev"' \
 | sudo tee /etc/udev/rules.d/99-usbmux.rules
$ sudo udevadm control --reload-rules

After reattaching the USB-Mux you should be able to able to use it without requiring sudo permissions.

Using on Windows

Most features of the usbmuxctl utility can also be used on Windows.

Limitations on Windows

On Windows the following limitations apply:

  • Updating the firmware: this feature has not been tested successfully on Windows. (In theory it should be possible to install dfu-util and the drivers needed - but it has not yet been documented.)

  • Using the USB path to select an USB-Mux. (On Linux this feature can be used to select which USB-Mux to use by the physical path on the USB. On Windows the path is not exposed by libusb and thus this field is empty.)

Installation of dependencies

Install python3. Make sure to add the Python binaries to your path during installation.

Afterwards install the Windows driver package: Download and extract the archive. Then run InstallDriver.exe.

Install from pypi

We suggest to use the PowerShell to use this tool.

Create and activate a virtualenv for usbmuxctl:

PS > python -m venv venv
PS >.\venv\Scripts\Activate.ps1

Install usbmuxctl into the virtualenv:

(venv) PS > pip install usbmuxctl

You can now run usbmuxctl.exe -h to get a list of available sub-commands.

Contributing

Thank you for considering a contribution to this project! Changes should be submitted via a Github pull request.

We use the ruff code formatter and linter, please run ruff format and ruff check when contributing changes:

$ python3 -m pip install ruff
$ ruff format
6 files left unchanged
$ ruff check
All checks passed!

This project uses the Developer’s Certificate of Origin 1.1 with the same process as used for the Linux kernel:

Developer’s Certificate of Origin 1.1

By making a contribution to this project, I certify that:

  1. The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

  2. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

  3. The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

  4. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

Then you just add a line (using git commit -s) saying:

Signed-off-by: Random J Developer <random@developer.example.org>

using a known identity (sorry, no anonymous contributions).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usbmuxctl-0.1.4.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

usbmuxctl-0.1.4-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file usbmuxctl-0.1.4.tar.gz.

File metadata

  • Download URL: usbmuxctl-0.1.4.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for usbmuxctl-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f200647bd72ea5b5a77d6d9e1f0641e2aae1da37fc2317a2f73929b034388845
MD5 48df81636ec2dcfe87b2cd65c112e381
BLAKE2b-256 7557327df4cc8d267a348e1bcccf3f301c6db9f2c2ee2842dbf22035b515466b

See more details on using hashes here.

File details

Details for the file usbmuxctl-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: usbmuxctl-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 38.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for usbmuxctl-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f66d0fb044a55047d42e4808e2f035d63a15dc6b5666d11820eee716a7c663
MD5 17d4f64630dc1972f193d18ba5fb2726
BLAKE2b-256 8afa5f1a7a00ee4811f2228fd88833e7c77690235d5a9a2f7bf29c6f6c48e865

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page