kernel hexdump分析 (2.0)

本文介绍了一种针对UART串口大量数据打印时出现信息丢失问题的解决方案。通过自定义dump函数,每次打印128个字节并减少printk调用次数,有效避免了因缓冲区限制导致的数据丢失。

有的时候print_hex_dump_bytes循环打印很多信息的时候(大于1K)
用UART串口打印的信息总是会有丢失,估计是printk缓冲区的问题把,具体原因不是太清楚
于是自己写了个比较笨的dump函数,问题得到解决:

//每次打印128个字节(当然你也可以打印更多),只调用一次printk ,
// 而 print_hex_dump_bytes 则 最多32个字节 就调用一次printk

static void  dumpBuf(void * buf)
{
   unsigned char * temp;
   
   temp=(char *)buf;

   int i=0;
      printk(KERN_ERR  "[%s] \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n \
%02x %02x %02x %02x %02x %02x %02x %02x \r\n",__func__,  \
	   	temp[i+0],temp[i+1],temp[i+2],temp[i+3],temp[i+4],temp[i+5],temp[i+6],temp[i+7], \
	   	temp[i+8],temp[i+9],temp[i+10],temp[i+11],temp[i+12],temp[i+13],temp[i+14],temp[i+15],\
	   	temp[i+16],temp[i+17],temp[i+18],temp[i+19],temp[i+20],temp[i+21],temp[i+22],temp[i+23],\
	   	temp[i+24],temp[i+25],temp[i+26],temp[i+27],temp[i+28],temp[i+29],temp[i+30],temp[i+31],\
	   	temp[i+32],temp[i+33],temp[i+34],temp[i+35],temp[i+36],temp[i+37],temp[i+38],temp[i+39],\
	   	temp[i+40],temp[i+41],temp[i+42],temp[i+43],temp[i+44],temp[i+45],temp[i+46],temp[i+47],\
	   	temp[i+48],temp[i+49],temp[i+50],temp[i+51],temp[i+52],temp[i+53],temp[i+54],temp[i+55],\
	   	temp[i+56],temp[i+57],temp[i+58],temp[i+59],temp[i+60],temp[i+61],temp[i+62],temp[i+63],\
	   	temp[i+64],temp[i+65],temp[i+66],temp[i+67],temp[i+68],temp[i+69],temp[i+70],temp[i+71],\
	   	temp[i+72],temp[i+73],temp[i+74],temp[i+75],temp[i+76],temp[i+77],temp[i+78],temp[i+79],\
	   	temp[i+80],temp[i+81],temp[i+82],temp[i+83],temp[i+84],temp[i+85],temp[i+86],temp[i+87],\
	   	temp[i+88],temp[i+89],temp[i+90],temp[i+91],temp[i+92],temp[i+93],temp[i+94],temp[i+95],\
	   	temp[i+96],temp[i+97],temp[i+98],temp[i+99],temp[i+100],temp[i+101],temp[i+102],temp[i+103],\
	   	temp[i+104],temp[i+105],temp[i+106],temp[i+107],temp[i+108],temp[i+109],temp[i+110],temp[i+111],\
	   	temp[i+112],temp[i+113],temp[i+114],temp[i+115],temp[i+116],temp[i+117],temp[i+118],temp[i+119],\
	   	temp[i+120],temp[i+121],temp[i+122],temp[i+123],temp[i+124],temp[i+125],temp[i+126],temp[i+127]);
   //}


 

=========================== USB Port2 =========================== Connection Status : 0x01 (Device is connected) Port Chain : 2-5-2 Properties : 0x00 IsUserConnectable : no PortIsDebugCapable : no PortHasMultiCompanions : no PortConnectorIsTypeC : no ConnectionIndex : 0x02 (Port 2) ========================== Summary ========================= Vendor ID : 0x30FA (Wuxi Instant Microelectronics Co., Ltd.) Product ID : 0x0400 Manufacturer String : --- Product String : "USB Optical Mouse " Serial : --- USB Version : 1.1 (1.5 Mbit/s LowSpeed) Port maximum Speed : High-Speed Device maximum Speed : Low-Speed Device Connection Speed : Low-Speed Self powered : no Demanded Current : 100 mA Used Endpoints : 2 ======================== USB Device ======================== +++++++++++++++++ Device Information ++++++++++++++++++ Device Description : USB 输入设备 Device Path : \\?\USB#VID_30FA&PID_0400#6&d4e11cf&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed} (GUID_DEVINTERFACE_USB_DEVICE) Kernel Name : \Device\USBPDO-12 Device ID : USB\VID_30FA&PID_0400\6&D4E11CF&0&2 Hardware IDs : USB\VID_30FA&PID_0400&REV_0100 USB\VID_30FA&PID_0400 Driver KeyName : {745a17a0-74d3-11d0-b6fe-00a0c90f57da}\0899 (GUID_DEVCLASS_HIDCLASS) Driver : \SystemRoot\System32\drivers\hidusb.sys (Version: 10.0.19041.3636 Date: 2023-12-04 Company: Microsoft Corporation) Driver Inf : C:\Windows\inf\input.inf Legacy BusType : PNPBus Class : HIDClass Class GUID : {745a17a0-74d3-11d0-b6fe-00a0c90f57da} (GUID_DEVCLASS_HIDCLASS) Service : HidUsb Enumerator : USB Location Info : Port_#0002.Hub_#0003 Address : 2 Location IDs : PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(5)#USB(2), ACPI(_SB_)#ACPI(PC00)#ACPI(XHCI)#ACPI(RHUB)#ACPI(HS05)#USB(2) Container ID : {8d92ec79-b8d1-11f0-aca9-00e26970bcca} Manufacturer Info : (标准系统设备) Capabilities : 0x84 (Removable, SurpriseRemovalOK) Status : 0x0180600A (DN_DRIVER_LOADED, DN_STARTED, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER) First Install Date : 2025-11-04 00:29:38 Last Arrival Date : 2025-11-05 00:53:34 Bus Relations : HID\VID_30FA&PID_0400\7&25d0d99b&0&0000 SelectiveSuspendEnabled : 0 EnhancedPowerMgmtEnabled : 1 Power State : D0 (supported: D0, D1, D2, D3, wake from D0, wake from D1, wake from D2) ---------------- Connection Information --------------- Connection Index : 0x02 (Port 2) Connection Status : 0x01 (DeviceConnected) Current Config Value : 0x01 (Configuration 1) Device Address : 0x21 (33) Is Hub : 0x00 (no) Device Bus Speed : 0x00 (Low-Speed) Number of open Pipes : 0x01 (1 pipe to data endpoints) Pipe[0] : EndpointID=1 Direction=IN ScheduleOffset=0 Type=Interrupt wMaxPacketSize=0x5 bInterval=10 -> 168 Bits/ms = 21000 Bytes/s Data (HexDump) : 02 00 00 00 12 01 10 01 00 00 00 08 FA 30 00 04 .............0.. 00 01 00 01 00 01 01 00 00 21 00 01 00 00 00 01 .........!...... 00 00 00 07 05 81 03 05 00 0A 00 00 00 00 .............. --------------- Connection Information V2 ------------- Connection Index : 0x02 (2) Length : 0x10 (16 bytes) SupportedUsbProtocols : 0x03 Usb110 : 1 (yes, port supports USB 1.1) Usb200 : 1 (yes, port supports USB 2.0) Usb300 : 0 (no, port not supports USB 3.0) ReservedMBZ : 0x00 Flags : 0x00 DevIsOpAtSsOrHigher : 0 (Device is not operating at SuperSpeed or higher) DevIsSsCapOrHigher : 0 (Device is not SuperSpeed capable or higher) DevIsOpAtSsPlusOrHigher : 0 (Device is not operating at SuperSpeedPlus or higher) DevIsSsPlusCapOrHigher : 0 (Device is not SuperSpeedPlus capable or higher) ReservedMBZ : 0x00 Data (HexDump) : 02 00 00 00 10 00 00 00 03 00 00 00 00 00 00 00 ................ ---------------------- Device Descriptor ---------------------- bLength : 0x12 (18 bytes) bDescriptorType : 0x01 (Device Descriptor) bcdUSB : 0x110 (USB Version 1.1) bDeviceClass : 0x00 (defined by the interface descriptors) bDeviceSubClass : 0x00 bDeviceProtocol : 0x00 bMaxPacketSize0 : 0x08 (8 bytes) idVendor : 0x30FA (Wuxi Instant Microelectronics Co., Ltd.) idProduct : 0x0400 bcdDevice : 0x0100 iManufacturer : 0x00 (No String Descriptor) iProduct : 0x01 (String Descriptor 1) Language 0x0409 : "USB Optical Mouse " iSerialNumber : 0x00 (No String Descriptor) bNumConfigurations : 0x01 (1 Configuration) Data (HexDump) : 12 01 10 01 00 00 00 08 FA 30 00 04 00 01 00 01 .........0...... 00 01 .. ------------------ Configuration Descriptor ------------------- bLength : 0x09 (9 bytes) bDescriptorType : 0x02 (Configuration Descriptor) wTotalLength : 0x0022 (34 bytes) bNumInterfaces : 0x01 (1 Interface) bConfigurationValue : 0x01 (Configuration 1) iConfiguration : 0x00 (No String Descriptor) bmAttributes : 0xA0 D7: Reserved, set 1 : 0x01 D6: Self Powered : 0x00 (no) D5: Remote Wakeup : 0x01 (yes) D4..0: Reserved, set 0 : 0x00 MaxPower : 0x32 (100 mA) Data (HexDump) : 09 02 22 00 01 01 00 A0 32 09 04 00 00 01 03 01 ..".....2....... 02 00 09 21 11 01 00 01 22 40 00 07 05 81 03 05 ...!...."@...... 00 0A .. ---------------- Interface Descriptor ----------------- bLength : 0x09 (9 bytes) bDescriptorType : 0x04 (Interface Descriptor) bInterfaceNumber : 0x00 (Interface 0) bAlternateSetting : 0x00 bNumEndpoints : 0x01 (1 Endpoint) bInterfaceClass : 0x03 (HID - Human Interface Device) bInterfaceSubClass : 0x01 (Boot Interface) bInterfaceProtocol : 0x02 (Mouse) iInterface : 0x00 (No String Descriptor) Data (HexDump) : 09 04 00 00 01 03 01 02 00 ......... ------------------- HID Descriptor -------------------- bLength : 0x09 (9 bytes) bDescriptorType : 0x21 (HID Descriptor) bcdHID : 0x0111 (HID Version 1.11) bCountryCode : 0x00 (00 = not localized) bNumDescriptors : 0x01 Data (HexDump) : 09 21 11 01 00 01 22 40 00 .!...."@. Descriptor 1: bDescriptorType : 0x22 (Class=Report) wDescriptorLength : 0x0040 (64 bytes) 05 01 Usage Page (Generic Desktop Controls) 09 02 Usage (Mouse) A1 01 Collection (Application) 09 01 Usage (Pointer) A1 00 Collection (Physical) 05 09 Usage Page (Buttons) 19 01 Usage Minimum (1) 29 05 Usage Maximum (5) 15 00 Logical Minimum (0) 25 01 Logical Maximum (1) 95 05 Report Count (5) 75 01 Report Size (1) 81 02 Input (Var) 95 01 Report Count (1) 75 03 Report Size (3) 81 01 Input (Const) 05 01 Usage Page (Generic Desktop Controls) 09 30 Usage (Direction-X) 09 31 Usage (Direction-Y) 16 00 F8 Logical Minimum (-2048) 26 FF 07 Logical Maximum (2047) 75 0C Report Size (12) 95 02 Report Count (2) 81 06 Input (Var, Rel) 09 38 Usage (Wheel) 15 81 Logical Minimum (-127) 25 7F Logical Maximum (127) 75 08 Report Size (8) 95 01 Report Count (1) 81 06 Input (Var, Rel) C0 End Collection C0 End Collection Data (HexDump) : 05 01 09 02 A1 01 09 01 A1 00 05 09 19 01 29 05 ..............). 15 00 25 01 95 05 75 01 81 02 95 01 75 03 81 01 ..%...u.....u... 05 01 09 30 09 31 16 00 F8 26 FF 07 75 0C 95 02 ...0.1...&..u... 81 06 09 38 15 81 25 7F 75 08 95 01 81 06 C0 C0 ...8..%.u....... ----------------- Endpoint Descriptor ----------------- bLength : 0x07 (7 bytes) bDescriptorType : 0x05 (Endpoint Descriptor) bEndpointAddress : 0x81 (Direction=IN EndpointID=1) bmAttributes : 0x03 (TransferType=Interrupt) wMaxPacketSize : 0x0005 bInterval : 0x0A (10 ms) Data (HexDump) : 07 05 81 03 05 00 0A ....... -------------------- String Descriptors ------------------- ------ String Descriptor 0 ------ bLength : 0x04 (4 bytes) bDescriptorType : 0x03 (String Descriptor) Language ID[0] : 0x0409 (English - United States) Data (HexDump) : 04 03 09 04 .... ------ String Descriptor 1 ------ bLength : 0x26 (38 bytes) bDescriptorType : 0x03 (String Descriptor) Language 0x0409 : "USB Optical Mouse " *!*CAUTION trailing space character Data (HexDump) : 26 03 55 00 53 00 42 00 20 00 4F 00 70 00 74 00 &.U.S.B. .O.p.t. 69 00 63 00 61 00 6C 00 20 00 4D 00 6F 00 75 00 i.c.a.l. .M.o.u. 73 00 65 00 20 00 s.e. . 这个鼠标设备就是识别不了,直接插电脑是没有问题的,但是插入rp2350开发板,板子插入电脑,电脑可以识别rp2350开发板,但是鼠标没有任何反应,鼠标按键,侧键,移动,灯光等等都没有反应,你分析一看看看是什么问题呢?
11-07
=========================== USB Port1 =========================== Connection Status : 0x02 (Device failed enumeration) Port Chain : 1-2-1 Properties : 0x01 IsUserConnectable : yes PortIsDebugCapable : no PortHasMultiCompanions : no PortConnectorIsTypeC : no ConnectionIndex : 0x01 (Port 1) CompanionIndex : 0 CompanionHubSymLnk : USB#VID_05E3&PID_0626#5&34721134&0&14#{f18a0e88-c30c-11d0-8815-00a0c906bed8} CompanionPortNumber : 0x01 (Port 1) -> CompanionPortChain : 1-14-1 Device Manager Problem : 43 (CM_PROB_FAILED_POST_START) Used Endpoints : 0 ======================== USB Device ======================== +++++++++++++++++ Device Information ++++++++++++++++++ Device Description : 未知 USB 设备(设备描述符无效) Kernel Name (PDO) : \Device\USBPDO-9 Device ID : USB\VID_0000&PID_0005\6&2FA71A20&0&1 Hardware IDs : USB\DEVICE_DESCRIPTOR_VALIDATION_FAILURE Driver KeyName : {36fc9e60-c465-11cf-8056-444553540000}\0046 (GUID_DEVCLASS_USB) Driver Inf : C:\WINDOWS\inf\usb.inf Legacy BusType : PNPBus Class : USB Class GUID : {36fc9e60-c465-11cf-8056-444553540000} (GUID_DEVCLASS_USB) Enumerator : USB Location Info : Port_#0001.Hub_#0003 Address : 1 Manufacturer Info : (标准 USB 主控制器) Capabilities : 0x64 (Removable, SilentInstall, RawDeviceOK) Status : 0x01806400 (DN_HAS_PROBLEM, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER) Problem Code : 43 (CM_PROB_FAILED_POST_START) First Install Date : 2025-11-24 15:40:08 Last Arrival Date : 2025-11-25 15:20:45 EnhancedPowerMgmtEnabled : 0 Power State : D3 (supported: D0, D3, wake from D0) +++++++++++++++++ Registry USB Flags +++++++++++++++++ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags GlobalDisableSerNumGen : REG_BINARY 00 ---------------- Connection Information --------------- Connection Index : 0x01 (Port 1) Connection Status : 0x02 (DeviceFailedEnumeration) Current Config Value : 0x00 (Configuration 0) Device Address : 0x00 (0) Is Hub : 0x00 (no) Device Bus Speed : 0x02 (High-Speed) Number of open Pipes : 0x00 (0 pipes to data endpoints) Data (HexDump) : 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 02 ................ 00 00 00 ... --------------- Connection Information V2 ------------- Connection Index : 0x01 (1) Length : 0x10 (16 bytes) SupportedUsbProtocols : 0x03 Usb110 : 1 (yes, port supports USB 1.1) Usb200 : 1 (yes, port supports USB 2.0) Usb300 : 0 (no, port not supports USB 3.0) -> but Companion Port 1-14-1 does ReservedMBZ : 0x00 Flags : 0x00 DevIsOpAtSsOrHigher : 0 (Device is not operating at SuperSpeed or higher) DevIsSsCapOrHigher : 0 (Device is not SuperSpeed capable or higher) DevIsOpAtSsPlusOrHigher : 0 (Device is not operating at SuperSpeedPlus or higher) DevIsSsPlusCapOrHigher : 0 (Device is not SuperSpeedPlus capable or higher) ReservedMBZ : 0x00 Data (HexDump) : 01 00 00 00 10 00 00 00 03 00 00 00 00 00 00 00 ................ ---------------------- Device Descriptor ---------------------- bLength : 0x00 (0 bytes) -------------------- String Descriptors ------------------- String descriptors are not available (because the device has problem code CM_PROB_FAILED_POST_START) 这个是设备在boot模式下的信息,int detach(unsigned char target, unsigned char flag) { WriteLogE("Send DETACH CMD\n"); return sendCommand(0, flag, (target << 8)); } int sendCommand(unsigned char cmd, unsigned short wValue, unsigned short wIndex) { WriteLogE("Send CMD %d\n", cmd); int status; status = libusb_control_transfer(dev_handle, /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE, /* bRequest */ cmd, /* wValue */ wValue, /* wIndex */ wIndex, /* Data */ NULL, /* wLength */ 0, dfu_timeout); return status; }这个是相关调用代码,结合libusb的libusb_control_transfer这个函数分析下,上面的代码哪里不对,现在status返回-9
最新发布
11-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值