Using udev with containers

  1. Plug in your SEGGER JLink

  2. On the host terminal type lsusb

Bus 002 Device 003: ID 17ef:305b Lenovo Lenovo ThinkPad WS Dock
Bus 002 Device 002: ID 17ef:305a Lenovo Lenovo ThinkPad WS Dock
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 138a:0090 Validity Sensors, Inc. VFS7500 Touch Fingerprint Sensor
Bus 001 Device 003: ID 5986:0706 Acer, Inc Integrated Camera
**Bus 001 Device 024: ID 1366:0101 SEGGER J-Link PLUS**
Bus 001 Device 010: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 001 Device 008: ID 0bda:5411 Realtek Semiconductor Corp. 
Bus 001 Device 006: ID 17ef:305b Lenovo Lenovo ThinkPad WS Dock
Bus 001 Device 004: ID 04b3:310c IBM Corp. Wheel Mouse
Bus 001 Device 002: ID 17ef:305a Lenovo Lenovo ThinkPad WS Dock
Bus 001 Device 011: ID 8087:0a2b Intel Corp. 
Bus 001 Device 009: ID 0765:5010 X-Rite, Inc. X-Rite Pantone Color Sensor
Bus 001 Device 007: ID 058f:9540 Alcor Micro Corp. AU9540 Smartcard Reader
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Note the highlighted line. This translates a node in thebussection of the device tree:

/dev/bus/usb/001/024

3) Confirm this is our device with the udevadm info command:

chris@chris-ThinkPad-P50:~$ udevadm info -q all -n /dev/bus/usb/001/024
P: /devices/pci0000:00/0000:00:14.0/usb1/1-6
N: bus/usb/001/024
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-6
E: DEVNAME=/dev/bus/usb/001/024
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=1366/101/100
E: TYPE=0/0/0
E: BUSNUM=001
E: DEVNUM=024
E: MAJOR=189
E: MINOR=23
E: SUBSYSTEM=usb
E: USEC_INITIALIZED=21876919603
E: ID_VENDOR=SEGGER
E: ID_VENDOR_ENC=SEGGER
E: ID_VENDOR_ID=1366
E: ID_MODEL=J-Link
E: ID_MODEL_ENC=J-Link
E: ID_MODEL_ID=0101
E: ID_REVISION=0100
E: ID_SERIAL=SEGGER_J-Link_000261002652
E: ID_SERIAL_SHORT=000261002652
E: ID_BUS=usb
E: ID_USB_INTERFACES=:ffffff:
E: ID_VENDOR_FROM_DATABASE=SEGGER
E: ID_MODEL_FROM_DATABASE=J-Link PLUS
E: ID_PATH=pci-0000:00:14.0-usb-0:6
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_6

  1. Mount this device when running our container.

I am using VScode devcontainers extension:

{
    "image": "my-image",
    "name": "stm32 dev",
    "extensions": [
        "ms-vscode.cpptools",
        "ms-vscode.cmake-tools",
        "marus25.cortex-debug"
    ],
    "runArgs": [
        "-P",
        "--privileged"
    ],
    "remoteEnv": {
        "PATH": "/vscode/vscode-server/bin/linux-x64/e7f30e38c5a4efafeec8ad52861eb772a9ee4dfb/bin/remote-cli:${containerEnv:PATH}"
    },
    "containerEnv": {
        "DISPLAY": "unix:0"
    },
    "mounts": [
        "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached",
        // mount the JLink device from the host fielsystem to the local container filesystem
        "source=/dev/bus/usb/001/024,target=/dev/bus/usb/001/024,type=bind,consistency=cached"
    ]
}

Now when I run JLinkExe the usb device connects. However this is prefaced with a request to update the firmware. If select Yes then the update fails and the USB device disconnects and gets reassigned to a different bus/device number. So I have to select NO. to the update each time. I tried to disable it using a jlinkscript but this is ignored it seems.

The file noupdate.jlink has the following line:

exec SuppressInfoUpdateFW

And the new command is:

JLinkExe -JLinkScriptFile noupdate.jlink 

X Server settings are also required unless you runJLinkExewith the-NoGui=1option. However, if you do this it silently updates (and fails).

Leave a Reply

Your email address will not be published. Required fields are marked *