1. 安装依赖包
sudo apt-get install libusb-1.0-0-dev
2. 下载并编译uhubctl
git clone https://github.com/mvp/uhubctl
cd uhubctl
make
j将在uhubctl目录中产生一个uhubctl二进制执行文件。 你可以选择是否安装,如果要安装,则运行以下命令,程序将安装到/usr/sbin
目录
sudo make install
3. 查找USB设备
-
在DLAP221的前面板USB口上,插入一个USB设备,并运行以下命令,我这里使用的时Sandisk的U盘
root@davinci-mini:/home/HwHiAiUser/uhubctl# lsusb Bus 002 Device 024: ID 0781:55a3 SanDisk Corp. Bus 002 Device 007: ID 0bda:8153 Realtek Semiconductor Corp. Bus 002 Device 006: ID 0bda:8153 Realtek Semiconductor Corp. Bus 002 Device 008: ID 0bda:8153 Realtek Semiconductor Corp. Bus 002 Device 003: ID 174c:3074 ASMedia Technology Inc. ASM1074 SuperSpeed hub Bus 002 Device 004: ID 174c:55aa ASMedia Technology Inc. ASM1051E SATA 6Gb/s bridge, ASM1053E SATA 6Gb/s bridge, ASM1153 SATA 3Gb/s bridge Bus 002 Device 002: ID 174c:3074 ASMedia Technology Inc. ASM1074 SuperSpeed hub Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 174c:2074 ASMedia Technology Inc. ASM1074 High-Speed hub Bus 001 Device 002: ID 174c:2074 ASMedia Technology Inc. ASM1074 High-Speed hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub root@davinci-mini:/home/HwHiAiUser/uhubctl# lsusb -t /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M |__ Port 1: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 5000M |__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M |__ Port 3: Dev 7, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M |__ Port 1: Dev 8, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M |__ Port 4: Dev 24, If 0, Class=Mass Storage, Driver=usb-storage, 5000M |__ Port 2: Dev 6, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M root@davinci-mini:/home/HwHiAiUser/uhubctl#
这里我的Sandisk的U盘是连接到Bus 002,设备号为:024
Bus 002 Device 024: ID 0781:55a3 SanDisk Corp.
通过Bus和设备号,我们查到设备挂在2-2.4的位置:
Port 4: Dev 24, If 0, Class=Mass Storage, Driver=usb-storage, 5000M -
拔掉U盘,发现Sandisk U盘已经不在
root@davinci-mini:/home/HwHiAiUser/uhubctl# lsusb Bus 002 Device 007: ID 0bda:8153 Realtek Semiconductor Corp. Bus 002 Device 006: ID 0bda:8153 Realtek Semiconductor Corp. Bus 002 Device 008: ID 0bda:8153 Realtek Semiconductor Corp. Bus 002 Device 003: ID 174c:3074 ASMedia Technology Inc. ASM1074 SuperSpeed hub Bus 002 Device 004: ID 174c:55aa ASMedia Technology Inc. ASM1051E SATA 6Gb/s bridge, ASM1053E SATA 6Gb/s bridge, ASM1153 SATA 3Gb/s bridge Bus 002 Device 002: ID 174c:3074 ASMedia Technology Inc. ASM1074 SuperSpeed hub Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 174c:2074 ASMedia Technology Inc. ASM1074 High-Speed hub Bus 001 Device 002: ID 174c:2074 ASMedia Technology Inc. ASM1074 High-Speed hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub root@davinci-mini:/home/HwHiAiUser/uhubctl# lsusb -t /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M |__ Port 1: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 5000M |__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M |__ Port 3: Dev 7, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M |__ Port 1: Dev 8, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M |__ Port 2: Dev 6, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
4. 运行以下命令对原来U盘所在的端口进行下电操作
root@davinci-mini:/home/HwHiAiUser/uhubctl# ./uhubctl -p 4 -a 0 -l 2-2 -e
Current status for hub 2-2 [174c:3074 ASMedia AS2107 USB2.0 Hub, USB 3.00, 4 ports, ppps]
Port 4: 02a0 power 5gbps Rx.Detect
Sent power off request
New status for hub 2-2 [174c:3074 ASMedia AS2107 USB2.0 Hub, USB 3.00, 4 ports, ppps]
Port 4: 00a0 off
具体参数含义,请参见–help输出,或参见https://github.com/mvp/uhubctl
5. 插入U盘进行验证
root@davinci-mini:/home/HwHiAiUser/uhubctl# lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 1: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
|__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 3: Dev 7, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
|__ Port 1: Dev 8, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
|__ Port 2: Dev 6, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
没有发现U盘设备被挂载
6. 对2-2.4端口进行上电操作
root@davinci-mini:/home/HwHiAiUser/uhubctl# ./uhubctl -p 4 -a 1 -l 2-2 -e
Current status for hub 2-2 [174c:3074 ASMedia AS2107 USB2.0 Hub, USB 3.00, 4 ports, ppps]
Port 4: 00a0 off
Sent power on request
New status for hub 2-2 [174c:3074 ASMedia AS2107 USB2.0 Hub, USB 3.00, 4 ports, ppps]
Port 4: 00a0 power ##如果此处不是为power,请运行进行再次查询,此处状态有可能刷新不及时
root@davinci-mini:/home/HwHiAiUser/uhubctl# ./uhubctl
Current status for hub 2-2 [174c:3074 ASMedia AS2107 USB2.0 Hub, USB 3.00, 4 ports, ppps]
Port 1: 0203 power 5gbps U0 enable connect [0bda:8153 Realtek USB 10/100/1000 LAN 001000001]
Port 2: 0203 power 5gbps U0 enable connect [0bda:8153 Realtek USB 10/100/1000 LAN 001000001]
Port 3: 0203 power 5gbps U0 enable connect [0bda:8153 Realtek USB 10/100/1000 LAN 001000001]
Port 4: 0203 power 5gbps U0 enable connect [0781:55a3 SanDisk Ultra Luxe 01017d50a4ee2385e020ef9ca36aeadf27dc755b7cb2c4b208d282a963b8e8f]
Current status for hub 2-1 [174c:3074 ASMedia AS2107 USB2.0 Hub, USB 3.00, 4 ports, ppps]
Port 1: 0203 power 5gbps U0 enable connect [174c:55aa asmedia ASMT1051 1234567890AA002A]
Port 2: 02a0 power 5gbps Rx.Detect
Port 3: 02a0 power 5gbps Rx.Detect
Port 4: 02a0 power 5gbps Rx.Detect
Current status for hub 1-2 [174c:2074 ASMedia AS2107 USB2.0 Hub, USB 2.10, 4 ports, ppps]
Port 1: 0100 power
Port 2: 0100 power
Port 3: 0100 power
Port 4: 0100 power
Current status for hub 1-1 [174c:2074 ASMedia AS2107 USB2.0 Hub, USB 2.10, 4 ports, ppps]
Port 1: 0100 power
Port 2: 0100 power
Port 3: 0100 power
Port 4: 0100 power
看到2-2.4的电源状态是power了
7. 查看U盘是否挂载
root@davinci-mini:/home/HwHiAiUser/uhubctl# lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 1: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
|__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 3: Dev 7, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
|__ Port 1: Dev 8, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
|__ Port 4: Dev 25, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
|__ Port 2: Dev 6, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
root@davinci-mini:/home/HwHiAiUser/uhubctl#
设备已经挂载了,并且也能查看到磁盘
root@davinci-mini:/home/HwHiAiUser/uhubctl#
[ 9263.317759] usb 2-2.4: USB disconnect, device number 24
[10085.951092] usb 2-2.4: new SuperSpeed Gen 1 USB device number 25 using xhci_hcd
[10085.994562] usb-storage 2-2.4:1.0: USB Mass Storage device detected
[10085.994804] scsi host2: usb-storage 2-2.4:1.0
[10087.003862] scsi 2:0:0:0: Direct-Access SanDisk Ultra Luxe 1.00 PQ: 0 ANSI: 6
[10087.004370] sd 2:0:0:0: Attached scsi generic sg1 type 0
[10087.004544] sd 2:0:0:0: [sdc] 120176640 512-byte logical blocks: (61.5 GB/57.3 GiB)
[10087.006250] sd 2:0:0:0: [sdc] Write Protect is off
[10087.006259] sd 2:0:0:0: [sdc] Mode Sense: 43 00 00 00
[10087.007236] sd 2:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[10087.015767] sdc: sdc1 sdc2
[10087.019249] sd 2:0:0:0: [sdc] Attached SCSI removable disk
root@davinci-mini:/home/HwHiAiUser/uhubctl# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sdc /dev/sdc1 /dev/sdc2
8. Known Issues
- 当设备插入USB口在线时,无法设备所在的USB端口进行下电操作,必须拔掉设备后才能对设备所在的端口进行下电