mips板子上跑usb_modeswitch遇到问题记录

来源:互联网 发布:电商大数据 豆瓣 编辑:程序博客网 时间:2024/05/20 19:29

4, 5年前在做手机产品的时候, 也移植过usb_modeswitch到ARM的板子上, 当时的版本已经不记得了.

这两天在弄mips板子上的移植工作, 到官网看了下, 版本已经到了2.2.0, 依赖的usblib也是新的1.0版本了, 不再兼容原来的0.1版本.

此外还有个usb-modeswitch-data package (2014-05-29)的数据库的东东.


首先, 交叉编译libusb.

1. 解压后进目录mkdir install, 然后./configure CC=/usr/local/codesourcery/mips-4.3/bin/mips-linux-gnu-gcc --host=mips-linux --prefix=`pwd`/install
2. make; make install 就会在新建的那个install目录下生成libusb-1.0.so


然后编译usb_modeswitch.

1. 修改makefile的CC为上面同样的配置

2. make  这边就报错了, 提示找不到libusb.h的头文件, 如下:
/usr/local/codesourcery/mips-4.3/bin/mips-linux-gnu-gcc -o usb_modeswitch usb_modeswitch.c -Wall  `pkg-config --libs --cflags libusb-1.0`
Package libusb-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libusb-1.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libusb-1.0' found
In file included from usb_modeswitch.c:59:
usb_modeswitch.h:26:20: error: libusb.h: No such file or directory


看了下makefile, google了一下, pkg-config能自动帮你找到安装的库的位置, 避免每个人安装的位置不同引起的编译错误.
`pkg-config --libs --cflags libusb-1.0`的返回结果是"-I/home/xioliu/concerto/libusb-1.0.9/install/include/libusb-1.0  -L/home/xioliu/concerto/libusb-1.0.9/install/lib -lusb-1.0".
在前面的步骤中, libusb在make install的时候, 已经在目录中生成了libusb.h

结合上面的提示, 在makefile中加一个 "export  PKG_CONFIG_PATH=/home/xioliu/concerto/libusb-1.0.9/install/lib/pkgconfig" 后重新make就ok了.

在目录下生成了usb_modeswitch的可执行档, 大约79K(没有strip过的).


好了, 将libusb的库和可执行档(包括usb_modeswitch.conf), 以及对应的database的文件(我的dongle是华为的E173u-2, 对应的pid是0x12d1, vid是0x1446, 所以就是data压缩包解压后usb_modeswitch.d目录中的12d1:1446那个文件)copy到u盘中, 在板子上mount, 并修改相应的权限.


运行"./usb_modeswitch -W -c 12d1\:1446",  直接提示line 1: syntax error: unexpected "(" 的错误.

这是怎么回事呢? 一般这个问题都是平台选择错没有交叉编译导致的. 但是显然我是交叉编译的.

想了一下, 猜测会不会是big endian, little endian的问题. 芯片是LE的, 刚才编译的会不会BE的呢.

在pc上直接 file usb_modeswitch, 果然是MSB的, 不是LSB.

于是直接将toolchain改为mipsel-linux-gcc, 重新编译libusb和usb_modeswitch, 然后执行usb_modeswitch -h, 顺利跑起来了.


再次运行"./usb_modeswitch -W -c 12d1\:1446 &", 结果console上什么也没出来.

lsusb发现, piv/vid还是原来的12d1/1446, /dev下面也没有ttyUSB的节点出现.


跑完正好开周会, 说到这个事情, 同事说手头有之前编译过能跑的版本, 看了下, 是2.1.0的版本.

拿source code过来后, 重复交叉编译的步骤, 编好后, 发现还是一样, 没反应.

很奇怪, 和同事讨论了一下, 确实不要改动source之类的东西.

然后他给了个之前编的可执行档过来, 发现确实能跑起来.

 * usb_modeswitch: handle USB devices with multiple modes
 * Version 2.1.0 (C) Josua Dietze 2013
 * Based on libusb1/libusbx

 ! PLEASE REPORT NEW CONFIGURATIONS !

TargetVendor=   0x12d1
TargetProductList="1001,1406,140b,140c,1412,141b,1432,1433,1436,14ac,1506,150c,1511"
NeedResponse=0

No default vendor/product ID given. Abort


虽然没切换模式成功, 但是至少跑起来了. 很疑惑, 究竟是什么原因导致的呢?

同事找了下服务器上的备份(前面给的是原始的2.1.0的压缩包), 对比了下, 是在makefile中添加了 -lpthread的选项.

$(PROG): $(OBJS) usb_modeswitch.h
    $(CC) -o $(PROG) $(OBJS) $(CFLAGS) $(LIBS) $(LDFLAGS) -lpthread


这个是个link的选项, 前面没有加这个选项, 也没出现link error啊. 虽然觉得很奇怪, 但还是也加上去试了一下, 果然, 能跑了.

同事这时候也回想起来, 说当时也遇到了问题, 后来也是google看别人加了这个选项, 于是也加上了. (所以说, 还是要把遇到的问题记录下来啊).

这个问题, 下周再google看看, 是怎么回事.

[2014.12.15 update] 后来google了一下, 添加 -lpthread的选项的基本是1.2.6版本那时候的, 貌似是那时候的代码用到了pthread相关的函数.

但是2.1.0或者2.2.0的版本, 没看见有解释的人. 本来想到论坛http://www.draisberghof.de/ 里面直接问老外的, 没想到注册需要邮箱认证, 留了163和另外一个邮箱,

过了一周都没收到注册认证的邮件, 只好暂时作罢. 希望要是哪位知道答案的, 还请不吝告知, 谢谢.


好了, 回到上面切换不成功的问题, 修改了下配置文件.

原来是

# Huawei, newer modems
TargetVendor=0x12d1
TargetProductList="1001,1406,140b,140c,1412,141b,1432,1433,1436,14ac,1506,150c,1511"
HuaweiNewMode=1

修改后

# Huawei, newer modems
DefaultVendor= 0x12d1
DefaultProduct= 0x1446
TargetVendor=  0x12d1
TargetProduct= 0x1001
#TargetProductList="1001,1406,140b,140c,1412,141b,1432,1433,1436,14ac,1506,150c,1511"
MessageContent="55534243123456780000000000000011062000000100000000000000000000"

再次运行, 切换成功.


 ! PLEASE REPORT NEW CONFIGURATIONS !


DefaultVendor=  0x12d1
DefaultProduct= 0x1446
TargetVendor=   0x12d1
TargetProduct=  0x1001
MessageContent="55534243123456780000000000000011062000000100000000000000000000"
NeedResponse=0

Look for target devices ...
  found USB ID 1d6b:0002
 found USB ID 1d6b:0002
  found USB ID 12d1:1446
   vendor ID matched
  found USB ID 0781:556b
 No devices in target mode or class found

Look for default devices ...
  found USB ID 1d6b:0002
  found USB ID 1d6b:0002
  found USB ID 12d1:1446
   vendor ID matched
   product ID matched
  found USB ID 0781:556b

 Found devices in default mode (1)
Access device 013 on bus 002
Current configuration number is 1
Use interface number 0
Use endpoints 0x01 (out) and 0x81 (in)

USB description data (for identification)

-------------------------

Manufacturer: HUAWEI Technology
     Product: HUAWEI Mobile
  Serial No.: not provided

-------------------------

Looking for active driver ...
 OK, driver detached

Set up interface 0
Use endpoint 0x01 for message sending ...
Trying to send message 1 to endpoint 0x01 ...
 OK, message successfully sent[29436.295000] usb 2-1: USB disconnect, address 13

Reset response endpoint 0x81
 Could not reset endpoint (probably harmless): -4
Reset message endpoint 0x01
 Could not reset endpoint (probably harmless): -4
[29436.422000] sys_block_reset usb 1
[29436.426000] halt controller status 0
[29436.426000]  <6>mt-ehci2 mt-ehci2.0: USB 0.0 started, EHCI 1.00
 Device is gone, skip any further commands
-> Run lsusb to note any changes. Bye!



# [29440.235000]
[29440.235000]
[29440.235000]  ^^^^^  ehci_bus_resume
[29440.413000] handshake start:  portsc: 0x08001205
[29440.413000] handshake end  :  portsc: 0x08001205
[29440.473000] usb 2-1: new high speed USB device using mt-ehci2 and address 14
[29440.531000] handshake start:  portsc: 0x08001205
[29440.531000] handshake end  :  portsc: 0x08001205
[29440.605000] usb 2-1: New USB device found, idVendor=12d1, idProduct=1436
[29440.612000] usb 2-1: New USB device strings: Mfr=4, Product=3, SerialNumber=0
[29440.619000] usb 2-1: Product: HUAWEI Mobile
[29440.623000] usb 2-1: Manufacturer: HUAWEI Technology
[29440.634000] usb 2-1: configuration #1 chosen from 1 choice
[29440.647000] storage_probe
[29440.650000] usb-storage: probe of 2-1:1.0 failed with error -5
[29440.656000] option 2-1:1.0: GSM modem (1-port) converter detected
[29440.674000] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB0
[29440.701000] storage_probe
[29440.706000] usb-storage: probe of 2-1:1.1 failed with error -5
[29440.724000] storage_probe
[29440.727000] usb-storage: probe of 2-1:1.2 failed with error -5
[29440.748000] storage_probe
[29440.753000] usb-storage: probe of 2-1:1.3 failed with error -5
[29440.759000] option 2-1:1.3: GSM modem (1-port) converter detected
[29440.777000] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB1
[29440.799000] storage_probe
[29440.804000] usb-storage: probe of 2-1:1.4 failed with error -5
[29440.810000] option 2-1:1.4: GSM modem (1-port) converter detected
[29440.828000] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB2
[29440.850000] storage_probe
[29440.856000] usb-storage: probe of 2-1:1.5 failed with error -1
[29440.878000] storage_probe
[29440.881000] usb-storage: probe of 2-1:1.6 failed with error -1
[29440.908000] usb device new down

# lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0002
Bus 002 Device 014: ID 12d1:1436
Bus 001 Device 012: ID 0781:556b

# ls -l /dev/ttyUSB*
crw-rw----    1 root     root      188,   0 Jan  1 01:15 /dev/ttyUSB0
crw-rw----    1 root     root      188,   1 Jan  1 01:15 /dev/ttyUSB1
crw-rw----    1 root     root      188,   2 Jan  1 01:15 /dev/ttyUSB2

#


0 0
原创粉丝点击