Quantcast
Channel: 可丁丹尼 @ 一路往前走2.0
Viewing all articles
Browse latest Browse all 79

列出 USB Plug 資訊

$
0
0

USB Plug資訊可以由udevadm info [device name or path],但往往插入USB後跟本不知道產生週邊對應的資訊,可能知道在/sys/bus/usb/devices/,執行ls -l得到結果如下:

/sys/bus/usb/devices $ ls -la
total 0
drwxr-xr-x 2 root root 0 May 17 13:17 .
drwxr-xr-x 4 root root 0 May 17 13:17 ..
lrwxrwxrwx 1 root root 0 May 17 13:17 1-0:1.0 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-0:1.0
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1.1 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1.1:1.0 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1/1-1.1:1.0
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1:1.0 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1:1.0
lrwxrwxrwx 1 root root 0 May 17 13:17 usb1 -> ../../../devices/platform/soc/3f980000.usb/usb1

這個列表比較不直覺,接下來可以利用幾個命令取直接取得真實的位置

查看USB周邊

//-----------start-----------
lsusb
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
//------------end------------

上面列表的ID格式為:ID [vid]:[pid],記住格式,下面會利用這兩個資訊直接找到實際位置

取得USB週邊

雖然使用lsusb能看到接了什麼樣的USB週邊,但還是無法資料較詳細的資訊,下面script可以由pidvid取得在linux上實際產生的資訊的位置

//-----------start-----------
idVendor="vid"; idProduct="pid";   find -L /sys/bus/usb/devices/ -maxdepth 2 -name idVendor -exec grep -l $idVendor {} \; |     while read line; do       location=$(dirname $line);       grep -q $idProduct $location/idProduct;        if [ "$?" -eq "0" ]; then         echo $location;        fi ;     done
//------------end------------

只要修改idProduct(pid)、idVendor(vid)的內容就可以由pidvid找到,這次要查詢ID 0424:ec00代入

//-----------start-----------
idVendor="0424"; idProduct="ec00";   find -L /sys/bus/usb/devices/ -maxdepth 2 -name idVendor -exec grep -l $idVendor {} \; |     while read line; do       location=$(dirname $line);       grep -q $idProduct $location/idProduct;        if [ "$?" -eq "0" ]; then         echo $location;        fi ;     done
//------------end------------

執行範例:

script貼入shell執行

//-----------start-----------
idVendor="0424"; idProduct="ec00";   find -L /sys/bus/usb/devices/ -maxdepth 2 -name idVendor -exec grep -l $idVendor {} \; |     while read line; do       location=$(dirname $line);       grep -q $idProduct $location/idProduct;        if [ "$?" -eq "0" ]; then         echo $location;        fi ;     done
/sys/bus/usb/devices/1-1.1
//------------end------------

得到結果/sys/bus/usb/devices/1-1.1

取得Plug 資訊

從上面資訊取得Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter在Linux 位置/sys/bus/usb/devices/1-1.1,使用udevadm查看資訊

執行:

udevadm info /sys/bus/usb/devices/1-1.1

結果:

P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1
N: bus/usb/001/003
L: 0
E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1
E: DEVNAME=/dev/bus/usb/001/003
E: DEVTYPE=usb_device
E: DRIVER=usb
E: OF_NAME=usbether
E: OF_FULLNAME=/soc/usb@7e980000/usb1@1/usbether@1
E: OF_COMPATIBLE_0=usb424,ec00
E: OF_COMPATIBLE_N=1
E: OF_ALIAS_0=ethernet0
E: PRODUCT=424/ec00/200
E: TYPE=255/0/1
E: BUSNUM=001
E: DEVNUM=003
E: MAJOR=189
E: MINOR=2
E: SUBSYSTEM=usb
E: USEC_INITIALIZED=9975919
E: ID_VENDOR=0424
E: ID_VENDOR_ENC=0424
E: ID_VENDOR_ID=0424
E: ID_MODEL=ec00
E: ID_MODEL_ENC=ec00
E: ID_MODEL_ID=ec00
E: ID_REVISION=0200
E: ID_SERIAL=0424_ec00
E: ID_BUS=usb
E: ID_USB_INTERFACES=:ff00ff:
E: ID_VENDOR_FROM_DATABASE=Standard Microsystems Corp.
E: ID_MODEL_FROM_DATABASE=SMSC9512/9514 Fast Ethernet Adapter

要更詳細資訊加入-a -p參數

udevadm info -a -p /sys/bus/usb/devices/1-1.1

結果:

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1':
KERNEL=="1-1.1"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{configuration}==""
ATTR{devpath}=="1.1"
ATTR{bConfigurationValue}=="1"
ATTR{bDeviceProtocol}=="01"
ATTR{bcdDevice}=="0200"
ATTR{bNumInterfaces}==" 1"
ATTR{devnum}=="3"
ATTR{bmAttributes}=="e0"
ATTR{bMaxPacketSize0}=="64"
ATTR{urbnum}=="5815803"
ATTR{bDeviceClass}=="ff"
ATTR{ltm_capable}=="no"
ATTR{maxchild}=="0"
ATTR{tx_lanes}=="1"
ATTR{version}==" 2.00"
ATTR{avoid_reset_quirk}=="0"
ATTR{speed}=="480"
ATTR{quirks}=="0x0"
ATTR{bMaxPower}=="2mA"
ATTR{bNumConfigurations}=="1"
ATTR{bDeviceSubClass}=="00"
ATTR{idVendor}=="0424"
ATTR{rx_lanes}=="1"
ATTR{busnum}=="1"
ATTR{authorized}=="1"
ATTR{idProduct}=="ec00"
ATTR{removable}=="fixed"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1':
KERNELS=="1-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bmAttributes}=="e0"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0200"
ATTRS{maxchild}=="5"
ATTRS{tx_lanes}=="1"
ATTRS{bDeviceProtocol}=="02"
ATTRS{busnum}=="1"
ATTRS{devpath}=="1"
ATTRS{rx_lanes}=="1"
ATTRS{quirks}=="0x0"
ATTRS{configuration}==""
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{devnum}=="2"
ATTRS{idProduct}=="9514"
ATTRS{bDeviceClass}=="09"
ATTRS{idVendor}=="0424"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{speed}=="480"
ATTRS{urbnum}=="29"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPower}=="2mA"
ATTRS{bDeviceSubClass}=="00"
ATTRS{removable}=="unknown"
ATTRS{ltm_capable}=="no"
ATTRS{version}==" 2.00"
ATTRS{authorized}=="1"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{rx_lanes}=="1"
ATTRS{ltm_capable}=="no"
ATTRS{bNumConfigurations}=="1"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bcdDevice}=="0510"
ATTRS{idVendor}=="1d6b"
ATTRS{authorized}=="1"
ATTRS{devnum}=="1"
ATTRS{serial}=="3f980000.usb"
ATTRS{urbnum}=="26"
ATTRS{interface_authorized_default}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{authorized_default}=="1"
ATTRS{removable}=="unknown"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{configuration}==""
ATTRS{speed}=="480"
ATTRS{maxchild}=="1"
ATTRS{product}=="DWC OTG Controller"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bDeviceClass}=="09"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPower}=="0mA"
ATTRS{busnum}=="1"
ATTRS{manufacturer}=="Linux 5.10.17-v7+ dwc_otg_hcd"
ATTRS{quirks}=="0x0"
ATTRS{bmAttributes}=="e0"
ATTRS{tx_lanes}=="1"
ATTRS{devpath}=="0"
ATTRS{idProduct}=="0002"
ATTRS{bDeviceSubClass}=="00"
ATTRS{version}==" 2.00"

looking at parent device '/devices/platform/soc/3f980000.usb':
KERNELS=="3f980000.usb"
SUBSYSTEMS=="platform"
DRIVERS=="dwc_otg"
ATTRS{mode}=="Mode = 0x1"
ATTRS{fr_interval}=="Frame Interval = 0x1d4b"
ATTRS{spramdump}=="SPRAM Dump"
ATTRS{devspeed}=="Device Speed = 0x0"
ATTRS{hprt0}=="HPRT0 = 0x00001005"
ATTRS{buspower}=="Bus Power = 0x1"
ATTRS{bussuspend}=="Bus Suspend = 0x0"
ATTRS{hcddump}=="HCD Dump"
ATTRS{regvalue}=="invalid offset"
ATTRS{hnp}=="HstNegScs = 0x0"
ATTRS{mode_ch_tim_en}=="Mode Change Ready Timer Enable = 0x0"
ATTRS{gsnpsid}=="GSNPSID = 0x4f54280a"
ATTRS{hsic_connect}=="HSIC Connect = 0x1"
ATTRS{grxfsiz}=="GRXFSIZ = 0x00000306"
ATTRS{srp}=="SesReqScs = 0x1"
ATTRS{gpvndctl}=="GPVNDCTL = 0x00000000"
ATTRS{regoffset}=="0xffffffff"
ATTRS{remote_wakeup}=="Remote Wakeup Sig = 0 Enabled = 0 LPM Remote Wakeup = 0"
ATTRS{wr_reg_test}=="Time to write GNPTXFSIZ reg 10000000 times: 740 msecs (74 jiffies)"
ATTRS{driver_override}=="(null)"
ATTRS{gotgctl}=="GOTGCTL = 0x001c0001"
ATTRS{gusbcfg}=="GUSBCFG = 0x20001700"
ATTRS{ggpio}=="GGPIO = 0x00000000"
ATTRS{guid}=="GUID = 0x2708a000"
ATTRS{rd_reg_test}=="Time to read GNPTXFSIZ reg 10000000 times: 1410 msecs (141 jiffies)"
ATTRS{hptxfsiz}=="HPTXFSIZ = 0x02000406"
ATTRS{inv_sel_hsic}=="Invert Select HSIC = 0x0"
ATTRS{regdump}=="Register Dump"
ATTRS{srpcapable}=="SRPCapable = 0x1"
ATTRS{rem_wakeup_pwrdn}==""
ATTRS{hcd_frrem}=="HCD Dump Frame Remaining"
ATTRS{busconnected}=="Bus Connected = 0x1"
ATTRS{enumspeed}=="Device Enumeration Speed = 0x1"
ATTRS{gnptxfsiz}=="GNPTXFSIZ = 0x01000306"
ATTRS{hnpcapable}=="HNPCapable = 0x1"

looking at parent device '/devices/platform/soc':
KERNELS=="soc"
SUBSYSTEMS=="platform"
DRIVERS==""
ATTRS{driver_override}=="(null)"

looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""

The post 列出 USB Plug 資訊 appeared first on 可丁丹尼 @ 一路往前走2.0.


Viewing all articles
Browse latest Browse all 79

Trending Articles