Automatic Activation, Hotplug and UDEV, Configuration
Post Reply
mostafanfs
Posts: 7
Joined: 28 Oct 2014, 17:57

Problem with cross compiling USB_ModeSwitch

Post by mostafanfs » 28 Oct 2014, 18:14

Hi guys
I have downloaded usb-modeswitch-2.2.0.tar.bz2 and tried to compile it with gcc in ubuntu and it had no problem. But when I tried to cross compile it with arm-linux-gcc it was unsuccessful. I want to cross compile it and run the executable on my board. I ran following commands :

Code: Select all

$ export CC=arm-linux-gcc
$ make
and the result was :

Code: Select all

arm-linux-gcc -o usb_modeswitch usb_modeswitch.c -Wall `pkg-config --libs --cflags libusb-1.0` 
/usr/local/arm/4.4.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lusb-1.0
collect2: ld returned 1 exit status
make: *** [usb_modeswitch] Error 1
I'm guessing it's linker error and I think it's looking for something related to libusb. But I already have libusb source package installed on my ubuntu. Of course it's for x86 and again I think I have to cross compile it too. Am I right?
So how do I do that? How to link necessary libraries to usb-modeswitch?
Please help me. I really need to get my USB 3G Modem to work with my board but I think it has already being recognized as a USB Storage or something.

mostafanfs
Posts: 7
Joined: 28 Oct 2014, 17:57

Re: Problem with cross compiling USB_ModeSwitch

Post by mostafanfs » 29 Oct 2014, 09:04

Ok I managed to compile it successfully. All I had to do was cross compiling libusb and add libusb header and lib files path to the USB_ModeSwitch makefile.
Now I'm working on USB_ModeSwitch.conf file see if I can get my 3G USB Modem to work. I'll post the result here.

Josh
Site Admin
Posts: 6570
Joined: 03 Nov 2007, 00:30

Re: Problem with cross compiling USB_ModeSwitch

Post by Josh » 29 Oct 2014, 09:33

You know that you can pick the file for your modem from the usb-modeswitch-data package, right?

mostafanfs
Posts: 7
Joined: 28 Oct 2014, 17:57

Re: Problem with cross compiling USB_ModeSwitch

Post by mostafanfs » 29 Oct 2014, 11:38

Hi Josh
Well actually I have downloaded that file. I have a Huawei E303 3G USB Modem with these IDs: idVendor=12d1, idProduct=1f01
I looked into usb-modeswitch-data package and there is a 12d1:1f01 file but I dont know what to do with this file !
What is the purpose of this file when you should have a .conf file?

By the way I copied a usb_modeswitch.conf file inside /etc directory of my board and tried to run usb_modeswitch this way :

Code: Select all

usb_modeswitch -c /etc/usb_modeswitch.conf
But it gives this message :

Code: Select all

Look for target devices ...
Segmentation fault
What's wrong? Could it be because of the .conf file contents? I don't think so since I changed its content several times based on device_reference.txt (of course there is not a sample for my E303 3G USB Modem in device_reference file but there is Huawei E353 with the same DefaultVendor and DefaultProduct numbers and I copied them into my .conf file)

Anyway Segmentation fault sounds like a big deal, doesn't it?

Josh
Site Admin
Posts: 6570
Joined: 03 Nov 2007, 00:30

Re: Problem with cross compiling USB_ModeSwitch

Post by Josh » 29 Oct 2014, 22:40

The "segmentation fault" is rather a problem with the binary you created (or with the one from libusb).

/etc/usb_modeswitch.conf is not intended for device configuration. I suggest you have a look at the usb_modeswitch main page (link in the top nav bar), paragraph "How to use".

You can use the device config file with the "-c" parameter like you did already, but you have to add the default USB ID with "-v" and "-p" parameters. Or you can add "DefaultVendor" and "DefaultProduct" lines in the file itself and then just run "usb_modeswitch -c <your-config-file>".

See also the man page of usb_modeswitch.

mostafanfs
Posts: 7
Joined: 28 Oct 2014, 17:57

Re: Problem with cross compiling USB_ModeSwitch

Post by mostafanfs » 30 Oct 2014, 10:31

Hi Josh
I did some tests and I figured the "segmentation fault" error is most likely not from usb_modeswitch binary. Then it just leaves me libusb. Right?
I figured usb_modeswitch binary needs "libusb-1.0.so.0" and I tried to cross compile libusb again. So I got libusb source from git and I think this time it went better (because of the below error log message!). I compiled usb_modeswitch again with the new libusb-1.0.so.0 and copied libusb-1.0.so.0 into /usr/lib directory of the board and this time when I tried to run usb_modeswitch with -c option and .conf file it says:
libusb: 0.000000 debug [libusb_init] libusb-1.0.9 git:1.0.9-28-g7634714
libusb: 0.002362 error [op_init] could not find usbfs
Look for target devices ...
libusb: 0.002591 debug [libusb_get_device_list]
Segmentation fault
Could you help me? What is it that I'm doing wrong? It seems so simple, first compile libusb then compile usb_modeswitch. I don't get it...

Josh
Site Admin
Posts: 6570
Joined: 03 Nov 2007, 00:30

Re: Problem with cross compiling USB_ModeSwitch

Post by Josh » 31 Oct 2014, 01:03

You could try playing around with the ARM compiler options, but if that does not improve things, I think this is rather a case for the libusb community ...

mostafanfs
Posts: 7
Joined: 28 Oct 2014, 17:57

Re: Problem with cross compiling USB_ModeSwitch

Post by mostafanfs » 05 Nov 2014, 10:34

Hi Josh. I'm back !
Seems like I managed to fix that problem (after 1 week struggling!). Now I can call usb_modeswitch. But I'm not sure if I'm calling it right. Could you please help me. I try to explain it pretty clear.
lsusb shows below line for my device before running usb_modeswitch :
Bus 001 Device 006: ID 12d1:1f01 Huawei Technologies Co., Ltd.
I called usb_modeswitch with -v and -p like this:
/home/usb_modeswitch451 -v 12d1 -p 1f01
And it gives:
Look for default devices ...
product ID matched
Found devices in default mode (1)
Access device 006 on bus 001
Current configuration number is 1
Use interface number 0

USB description data (for identification)
-------------------------
Manufacturer: HUAWEI
Product: HUAWEI HiLink
Serial No.: not provided
-------------------------
Warning: no switching method given. See documentation
-> Run lsusb to note any changes. Bye!
Now lsusb still shows :
Bus 001 Device 006: ID 12d1:1f01 Huawei Technologies Co., Ltd.
Which is not right because it's still in default mode I guess.

I tried to run sub_modeswitch with --huawei-new-mode like this: /home/usb_modeswitch451 -v 12d1 -p 1f01 -J
But it gives:
Look for default devices ...
product ID matched
Found devices in default mode (1)
Access device 006 on bus 001
Current configuration number is 1
Use interface number 0
Use endpoints 0x01 (out) and 0x81 (in)

USB description data (for identification)
-------------------------
Manufacturer: HUAWEI
Product: HUAWEI HiLink
Serial No.: not provided
-------------------------
Using standard Huawei switching message
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
Reset response endpoint 0x81
Could not reset endpoint (probably harmless): -99
Reset message endpoint 0x01
Could not reset endpoint (probably harmless): -99
-> Run lsusb to note any changes. Bye!
Those last lines show -99 . I don't think that's right.
I'm not sure if it's mode has changed successfully and I highly doubt that specially since after running above command lsusb doesn't show anything anymore.
So could you help? What am I doing wrong? I decided not to use a .conf file and use other arguments cause it's much simpler this way. Could that be a problem?

Edit: After running last command when I run that command again it shows:
Look for default devices ...
No devices in default mode found. Nothing to do. Bye!
But I kind of don't believe it! .How can I be sure that it has really changed ?

BTW I changed the binary name usb_modeswitch to usb_modeswitch451 (which shows the version of arm-linux-gcc that this binary was created with) and I don't think it could be a problem.

mostafanfs
Posts: 7
Joined: 28 Oct 2014, 17:57

Re: Problem with cross compiling USB_ModeSwitch

Post by mostafanfs » 05 Nov 2014, 13:31

One more thing. I checked the dmesg log and turns out that after running /home/usb_modeswitch451 -v 12d1 -p 1f01 -J
usb_modeswitch disconnects my device and another device with different device number and different ProductID but the same VendorID (which is HUAWEI) loads by kernel. This time it doesn't see it as a CD-ROM Mass Storage like it did before running usb_modeswitch. But it doesn't see it as a GSM Modem neither. It reports something like this:
[ 357.305000] usb 1-2.3.1: USB disconnect, device number 7
[ 357.495000] usb 1-2.3.1: new high-speed USB device number 8 using s5p-ehci
[ 357.585000] usb 1-2.3.1: New USB device found, idVendor=12d1, idProduct=14db
[ 357.585000] usb 1-2.3.1: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[ 357.585000] usb 1-2.3.1: Product: HUAWEI HiLink
[ 357.585000] usb 1-2.3.1: Manufacturer: HUAWEI
[ 357.620000] cdc_ether 1-2.3.1:1.0: eth1: register 'cdc_ether' at usb-s5p-ehci-2.3.1, CDC Ethernet Device, 58:2c:80:13:92:63
As you can see it's not a GSM or something like this. It's another total different thing. What is cdc_ether or CDC Ethernet Device ?
How can this be?

LOM
Posts: 1404
Joined: 11 Jul 2012, 15:14
Location: Koh Samui, TH

Re: Problem with cross compiling USB_ModeSwitch

Post by LOM » 05 Nov 2014, 15:10

mostafanfs wrote:One more thing. I checked the dmesg log and turns out that after running /home/usb_modeswitch451 -v 12d1 -p 1f01 -J
usb_modeswitch disconnects my device and another device with different device number and different ProductID but the same VendorID (which is HUAWEI) loads by kernel.
Yes that is what modeswitching is supposed to do.
mostafanfs wrote: As you can see it's not a GSM or something like this. It's another total different thing. What is cdc_ether or CDC Ethernet Device ?
How can this be?
I suggest you google "Huawei CDC Ethernet Device" and read a few of the articles about it.

mostafanfs
Posts: 7
Joined: 28 Oct 2014, 17:57

Re: Problem with cross compiling USB_ModeSwitch

Post by mostafanfs » 06 Nov 2014, 19:48

Thanks LOM
I found this link http://www.draisberghof.de/usb_modeswit ... f=4&t=1734 and seems like everything is fine now.

Post Reply