[TriEmbed] Is that ttyUSB0 or ttyUSB1 this time?
Pete Soper
pete at soper.us
Fri Feb 19 19:32:55 CST 2021
My memory was off: was using symlinks. The script below after === did
the work. After --- are my udev rules. This all ran on Ubuntu (probably
16.04).
Many little local files having meaningful labels. File names with the
file contents to the right of the name:
DM01L0P2 SW-GW-CELL
DM01L2BU GW-USB2
DM01LZ2F SW-GW-WIFI
DO00W275 GW-USB4
DO00WYOK GW-USB0
DO00WYOT GW-USB3
DO01TY7B GW-USB1
L2000G0A X-SP1___
L20900F01 X-SP2___
X-NC____ DEB-NC-SERIAL
X-NE____ DEB-NE-SERIAL
X-NW____ DEB-NW-SERIAL
X-SWCELL DEB-SW-CELL-SERIAL
X-SWWIFI DEB-SW-WIFI-SERIAL
--------------------------------------------
SUBSYSTEMS=="usb", ATTRS{serial}=="DO00WYOK", ATTRS{product}=="FT230X
Basic UART", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403",
MODE="0666", GROUP:=dialout", SYMLINK="GW0" # GW-USB0
SUBSYSTEMS=="usb", ATTRS{serial}=="DO01TY7B", ATTRS{product}=="FT230X
Basic UART", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403",
MODE="0666", GROUP:=dialout", SYMLINK="GW0" # GW-USB1
SUBSYSTEMS=="usb", ATTRS{serial}=="DM01L2BU", ATTRS{product}=="FT230X
Basic UART", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403",
MODE="0666", GROUP:=dialout", SYMLINK="GW1" # GW-USB2
SUBSYSTEMS=="usb", ATTRS{serial}=="DO00WYOT", ATTRS{product}=="FT230X
Basic UART", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403",
MODE="0666", GROUP:=dialout", SYMLINK="GW0" # GW-USB3
SUBSYSTEMS=="usb", ATTRS{serial}=="DM01L0P2", ATTRS{product}=="FT230X
Basic UART", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403",
MODE="0666", GROUP:=dialout", SYMLINK="DM01L0P2" # SW-GW-USB0
SUBSYSTEMS=="usb", ATTRS{serial}=="DM01LZ2F", ATTRS{product}=="FT230X
Basic UART", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403",
MODE="0666", GROUP:="dialout", SYMLINK="DM01LZ2F" # SW-GW-USB1
SUBSYSTEMS=="usb", ATTRS{serial}=="DM01LZ2F", ATTRS{product}=="FT230X
Basic UART", ATTRS{idProduct}=="bef3", ATTRS{idVendor}=="0451",
MODE="0666", GROUP:="dialout", SYMLINK="DM01LZ2F" # SW-GW-USB1
===================
#!/bin/sh
# This script creates symbolic links in /dev with meaningful names to actual
# devices that are highly volatile as USB connections change over time. It's
# in two pieces: A general mechanism that works for simple serial USB
# devices like FTDI chips followed by a specialized mechanism for
handling one
# of TI's standard debug probes.
# Make symbolic links (with "dialout" group for terminal emulator
access) for
# USB devices. For each USB serial string value a meaningful name stored in
# a file of the same name in the command's directory is used to create the
# symbolic link. Tested with X64 Ubuntu 18.04.
# This depends on udev rules such as this one:
#SUBSYSTEMS=="usb", ATTRS{serial}=="DM01LZ2F", ATTRS{product}=="FT230X
Basic UAR
T", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403", MODE="0666",
GROUP="dialo
ut", SYMLINK="DM01LZ2F" # SW-PD-USB1
# By convention the comment shows the symlink that will be created in
/dev to
# access the device matched. There must be a file in the same directory
as this
# command named "DM01LZ2F" containing the string "SW-PD-USB1" for this
example.
# Also find all the symlinks in /dev/serial/by-id that have an assigned
XDS110
# serial string we know about (a second list of names that have to be files
# in the directory containing this command). For these the second serial
# device assigned by the TI udev rules is linked to from the name
contained in
# the label file. The second of the two devices supports debug I/O via JTDI
# and JTDO pins in the target chip (that can be driven by a real or emulated
# UART.
# Apex Proto Factory March, 2019 MIT license
FILEPATH=`dirname $0`
# Traverse the list of unique USB serial attribute values to be matched
# This works for vanilla USB serial devices such as those with FTDI chips
for id in DO00W275 DO00WYOT DO00WYOK DM01L2BU DO01TY7B DM01L0P2 DM01LZ2F
; do
# Fetch the symlink name
label=`cat $FILEPATH/$id`
if [ -h /dev/$id ] ; then
devname=`ls -l /dev/serial/by-id/*$id* | sed -e"s at .*tty\(.*\)@\1@"`
# It's quite likely the symlink exists already, so blow it away if so
sudo rm -f /dev/$label
# Create the link and assign it to the dialup group
sudo ln -s /dev/tty$devname /dev/$label
sudo chgrp -h dialout /dev/$label
echo "ID: $id DEV: /dev/$label"
fi # // matching symlink in /dev
done # traversing serial ids
# Now traverse all the TI XDS110 debugger serial strings that might be
# in /dev/serial/by-id
for id in L2000F01 X-NC____ X-NE____ X-NW____ X-SWCELL X-SWWIFI ; do
ls /dev/serial/by-id/*$id* >/dev/null 2>&1
if [ $? -ne 2 ] ; then
# There is a symlink in by-id with the current id being handled
# For TI XDS110 devices there are two serial devices: ACMn and ACMn+1
# We want to ignore ACMn and only make a symlink to ACMn+1 for access
# to the exported serial connection to the target (via JTDI/JTDO).
So use
# a flag to ignore the first entry. We're banking on the ls to offer
# ACMn lexically ahead of ACMn+1. If its random this will just get
harder.
seenfirst=0
ls /dev/serial/by-id/*$id* | while read f ; do
if [ $seenfirst -eq 0 ] ; then
seenfirst=1
continue # go to next loop iteration
else
# Found the second device of the pair. Fetch the symlink name and
# remove any stale instance
label=`cat $FILEPATH/$id`
sudo rm -f /dev/$label
# Now add the link and assign it to the dialup group
path=`readlink -f "$f"`
sudo ln -s $path /dev/$label
sudo chgrp -h dialout /dev/$label
echo "ID: $id DEV: /dev/$label"
fi # first or second device of pair
done # traversing serial device pair
fi # symlink pair found in by-id
done # traversing XDS110 serial ids
On 2/19/21 6:33 PM, Michael Monaghan via TriEmbed wrote:
> Pete,
>
> Do you have an example? I've never tried hard links.
>
More information about the TriEmbed
mailing list