2023-11-03 android linux 如何从log信息查看接入的usb设备是usb3.0 还是usb2.0,log 会有super-speed 、high-speed子样。

本文介绍了在Linux系统中,如何通过观察log中的字样(super-speed或high-speed)以及使用`cat/sys/kernel/debug/usb/devices`命令来判断接收到的USB设备是3.0还是2.0,以USB3.0和USB2.0的工作模式为例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

dmesg | grep -i usb [ 21.897910] init: Command 'insmod /vendor/lib/usb/dwc3/dwc3.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:161) took 52ms and succeeded [ 21.987854] init: Command 'insmod /vendor/lib/usb/dwc3/dwc3-tcc.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:162) took 89ms and succeeded [ 22.006846] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 22.020681] tcc-ehci 11a00000.ehci: new USB bus registered, assigned bus number 1 [ 22.063784] tcc-ehci 11a00000.ehci: USB 2.0 started, EHCI 1.00 [ 22.064100] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002 [ 22.064114] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.064120] usb usb1: Product: EHCI Host Controller [ 22.064127] usb usb1: Manufacturer: Linux 4.14.65-tcc ehci_hcd [ 22.064131] usb usb1: SerialNumber: 11a00000.ehci [ 22.066712] hub 1-0:1.0: USB hub found [ 22.070177] init: Command 'insmod /vendor/lib/usb/host/ehci-tcc.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:164) took 63ms and succeeded [ 22.088711] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 22.094676] tcc-ohci 11a80000.ohci: new USB bus registered, assigned bus number 2 [ 22.169167] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001 [ 22.169183] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.169188] usb usb2: Product: OHCI Host Controller [ 22.169192] usb usb2: Manufacturer: Linux 4.14.65-tcc ohci_hcd [ 22.169196] usb usb2: SerialNumber: tcc [ 22.175045] hub 2-0:1.0: USB hub found [ 22.179510] init: Command 'insmod /vendor/lib/usb/host/ohci-tcc.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:166) took 90ms and succeeded [ 22.237866] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 3 [ 22.256510] usb usb3: New USB device found, idVendor=1d6b, idProduct=0002 [ 22.256518] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.256523] usb usb3: Product: xHCI Host Controller [ 22.256526] usb usb3: Manufacturer: Linux 4.14.65-tcc xhci-hcd [ 22.256530] usb usb3: SerialNumber: xhci-hcd.0.auto [ 22.262338] hub 3-0:1.0: USB hub found [ 22.267979] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 4 [ 22.267999] xhci-hcd xhci-hcd.0.auto: Host supports USB 3.0 SuperSpeed [ 22.268097] usb usb4: We don't know the algorithms for LPM for this host, disabling LPM. [ 22.268188] usb usb4: New USB device found, idVendor=1d6b, idProduct=0003 [ 22.268193] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.268197] usb usb4: Product: xHCI Host Controller [ 22.268200] usb usb4: Manufacturer: Linux 4.14.65-tcc xhci-hcd
最新发布
07-12
<think>我们正在分析Linux dmesg中与USB相关的日志信息。用户希望了解如何通过dmesg日志分析USB驱动加载情况以及可能的问题。 根据引用[1]和[2],我们知道dmesg命令用于查看内核环形缓冲区中的日志,这些日志包括硬件检测、驱动初始化等事件。 步骤: 1. 获取dmesg日志:在终端运行`dmesg`命令,但为了专注于USB,我们可以使用grep过滤。 2. 过滤USB相关日志:`dmesg | grep -i usb`,其中`-i`表示忽略大小写。 但是,为了更详细地分析,我们可以分步骤查看: 一、查看USB子系统初始化日志: dmesg | grep -i "usb core" dmesg | grep -i "usb subsystem" 二、查看USB主机控制器(Host Controller)的初始化: dmesg | grep -i "hcd" # HCD表示USB Host Controller Driver 三、查看具体USB设备的连接和驱动加载: dmesg | grep -i "usb" dmesg | grep -i "device descriptor" 四、错误和警告信息: dmesg | grep -i "error" dmesg | grep -i "warn" 五、具体设备节点(如U盘)的挂载: dmesg | grep -i "sd" # 因为U盘通常被识别为SCSI磁盘设备 示例分析: 假设我们插入一个U盘,dmesg日志可能如下: ``` [ 1234.567890] usb 1-1: new high-speed USB device number 2 using ehci_hcd [ 1234.698765] usb 1-1: New USB device found, idVendor=abcd, idProduct=1234 [ 1234.698777] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 1234.698782] usb 1-1: Product: DataTraveler 2.0 [ 1234.698787] usb 1-1: Manufacturer: Kingston [ 1234.698791] usb 1-1: SerialNumber: 000000000000 [ 1234.700123] usb-storage 1-1:1.0: USB Mass Storage device detected [ 1234.700456] scsi host0: usb-storage 1-1:1.0 [ 1235.701234] scsi 0:0:0:0: Direct-Access Kingston DataTraveler 2.0 1.00 PQ: 0 ANSI: 4 [ 1235.702345] sd 0:0:0:0: [sda] 15633408 512-byte logical blocks: (8.00 GB/7.45 GiB) [ 1235.703456] sd 0:0:0:0: [sda] Write Protect is off [ 1235.703461] sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00 [ 1235.704567] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn&#39;t support DPO or FUA [ 1235.707890] sda: sda1 [ 1235.710123] sd 0:0:0:0: [sda] Attached SCSI removable disk ``` 分析: 1. 第一行:检测到新设备,使用ehci_hcd(USB 2.0主机控制器驱动)分配了设备22. 第二行:找到新设备,并给出了供应商ID和产品ID。 3. 第三至五行:设备的制造商、产品名和序列号。 4. 第六行:检测为USB存储设备,并加载了usb-storage驱动。 5. 第七行:分配SCSI主机号(host0),并创建SCSI设备。 6. 第八行:SCSI设备信息,包括设备名(sda)。 7. 后续行:显示存储设备的容量、写保护状态、缓存设置以及分区(sda1)和挂载。 如果遇到问题,常见错误信息包括: - "unable to enumerate USB device": 枚举失败,可能是硬件问题或供电不足。 - "device descriptor read/64, error -110": 读取设备描述符超时。 - "usb usb1-port1: over-current condition": 过流保护,可能是设备耗电过大。 我们可以通过以下命令查看更详细的USB设备树: `lsusb`:列出所有USB设备 `lsusb -t`:以树状结构显示USB设备,包括端口和速度信息。 另外,为了实时监控USB事件,可以使用: `dmesg -wH` # -w: 持续输出新日志,-H: 以可读格式显示时间戳 注意:有些日志可能被循环覆盖,如果需要保存,可以使用: `dmesg > dmesg.log` 最后,我们生成相关问题。</think>### Linux dmesg USB驱动加载日志分析指南 #### 一、核心分析步骤 1. **获取USB专用日志** ```bash dmesg | grep -i usb > usb_log.txt # 提取所有USB相关日志 dmesg -T | grep -i "usb.*init" # 带时间戳的驱动初始化记录 ``` 2. **关键日志模式解析** ```bash [ 0.512345] usbcore: registered new interface driver usbfs [ 0.523456] usbcore: registered new interface driver hub [ 0.534567] usbcore: registered new device driver usb [ 1.234567] ehci_hcd: USB 2.0 &#39;Enhanced&#39; Host Controller (EHCI) Driver [ 1.245678] ohci_hcd: USB 1.1 &#39;Open&#39; Host Controller (OHCI) Driver [ 1.256789] xhci_hcd: USB 3.0 &#39;eXtensible&#39; Host Controller (XHCI) Driver ``` - **驱动加载成功标志**:`registered new interface driver` + 驱动名 - **控制器类型**:EHCI(USB2.0)、OHCI(USB1.1)、XHCI(USB3.0) - **时间戳分析**:`[秒.微秒]`格式,可判断启动阶段加载顺序[^1] 3. **设备枚举过程分析** ```bash [ 5.123456] usb 1-1: new high-speed USB device number 2 using xhci_hcd [ 5.234567] usb 1-1: New USB device found, idVendor=0781, idProduct=5581 [ 5.245678] usb 1-1: Product: Ultra Fit [ 5.256789] usb-storage 1-1:1.0: USB Mass Storage device detected ``` - **设备识别**:`New USB device found` + VID/PID - **速度标识**:`high-speed`(USB2.0), `super-speed`(USB3.0) - **驱动绑定**:`usb-storage`表示存储设备驱动已加载 #### 二、故障诊断技巧 1. **供电问题检测** ```bash [ 7.123456] usb 1-1: device descriptor read/64, error -110 [ 7.234567] usb 1-1: can&#39;t set config #1, error -110 ``` `error -110`通常表示**设备无响应**,可能因供电不足导致[^2] 2. **驱动加载失败分析** ```bash [ 3.123456] usbcore: cannot register driver usb_serial [ 3.234567] Error: Driver &#39;ftdi_sio&#39; already registered ``` - `cannot register driver`:驱动注册失败 - `already registered`:驱动冲突 3. **OTG模式冲突检测** ```bash [ 4.123456] dwc3 4e00000.dwc3: failed to request irq [ 4.234567] msm-dwc3 4e00000.dwc3: USB peripheral mode not supported ``` `peripheral mode not supported`表示**OTG主机模式不可用** #### 三、高级分析工具 ```bash # 查看USB设备树 lsusb -t # 输出示例 /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M ``` ```bash # 查看内核已加载的USB驱动 cat /proc/bus/usb/drivers # 输出示例 usb usb-storage usbhid ``` #### 四、典型故障解决方案 1. **驱动缺失处理** ```bash # 检查可用驱动模块 modprobe -c | grep usb # 手动加载驱动 sudo modprobe uas # USB Attached SCSI驱动 ``` 2. **供电不足修复** ```bash # 禁用USB自动挂起 echo 0 > /sys/bus/usb/devices/usb1/power/autosuspend # 增加USB电流限制(需root) echo 500 > /sys/bus/usb/devices/usb1/max_bus_power ``` 3. **内核配置验证** ```bash # 检查内核编译选项 zcat /proc/config.gz | grep -i usb # 关键选项 CONFIG_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_STORAGE=y ``` > **日志分析工具推荐**: > - `dmesg -wH`:实时监控日志(带人类可读时间戳) > - `journalctl -k --since="5 minutes ago"`:systemd系统的内核日志查询 > - `usbmon`:专业级USB流量分析工具(需内核支持)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值