HTC Desire

HTC Desire Patches

My work on the USB Hostmode for the HTC Desire is based on the patch provided by Sven Killig for the Nexus one:

http://sven.killig.de/android/N1/2.2/usb_host/

Basically Sven’s patch also works for the HTC Desire. However since there has been a small change in the Kernel API for Kernel 3.6.37, I had to amend one line of the patch in order to make it work on the new kernel version.

Downloads:

Patches Available:

Kernels Available:
The discussion about this is going on at xda-developers.com:

 

Even though I did not have any problems with these patches and kernels so far, I cannot guarantee for any damage to your devices. Applying the provided kernel or any of the patches to your device and following any guide I provide happens on your own risk.

 

Using the Host mode

 

In my version of the Kernel, USB host mode is only available as a kernel module. I also had a version of the Kernel, where it was compiled right in the kernel but that resulted in having to connect at least a USB hub before booting the device. The advantage of using modules is that it is only required to connect the USB device before inserting the module into the kernel.

To load Hostmode, enter the following lines in a shell on your Desire:

insmod /system/lib/modules/$(uname -r)/kernel/drivers/usb/core/usbcore.ko
insmod /system/lib/modules/$(uname -r)/kernel/drivers/usb/host/ehci-hcd.ko

Connecting a USB mass storage device

After installing the above kernel you can connect USB mass storage to your HTC-Desire.

Connect your USB mass storage device to your HTC-Desire

Open a shell and enter:

insmod /system/lib/modules/$(uname -r)/kernel/drivers/usb/core/usbcore.ko
insmod /system/lib/modules/$(uname -r)/kernel/drivers/usb/host/ehci-hcd.ko
insmod /system/lib/modules/$(uname -r)/kernel/drivers/scsi/scsi_wait_scan.ko
insmod /system/lib/modules/$(uname -r)/kernel/drivers/scsi/scsi_mod.ko
insmod /system/lib/modules/$(uname -r)/kernel/drivers/scsi/sd_mod.ko
insmod /system/lib/modules/$(uname -r)/kernel/drivers/usb/storage/usb-storage.ko

Navigate to /dev/block and check if you have a sda1 in there. This is of course only for the first mass storage device. The second one is called sdb1 and so on. The following assumes that we take the first device. For all other devices, you will have to adjust the guide a little bit.

Load the filesystems:

insmod /system/lib/modules/$(uname -r)/kernel/fs/ntfs.ko
insmod /system/lib/modules/$(uname -r)/kernel/fs/msdos.ko

So far, I only included FAT and NTFS as modules. Ext4 is built in. If you need any other file systems, please ask below in the comments area and I can compile them for you.

To mount your disk, you first need a folder you want to mount into. I chose to create a folder “mnt” on my sdcard. Then issue one of the following commands:

mount -t vfat /dev/block/sda1 /mnt/sdcard/mnt/
mount -t ntfs /dev/block/sda1 /mnt/sdcard/mnt/

depending on weather you have a NTFS of FAT Filesystem.

Now you should be able to access the files on your USB mass storage device.

WLAN sleep off

In my scenario, I need the WLAN to be running all the time without switching to sleep. This is only necessary if you are connecting to an ad-hoc network. In a managed network the base station will make sure you still receive the packets, even if the WLAN goes to sleep.

I wrote a small patch, that simply disables the sleeping function of the WLAN driver. It can be found above.

 

Changelog

  • Du kannst diese HTML tags verwenden: <a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <strike> <strong>

  • #1 geschrieben von Zesotar vor 1 Woche

    Thanks for your work Tim.

    I’ve tried a few steps of this USB HOST thread, but I just read your full explanation on comments and the “* a solution for the power supply” just killed me.

    For me it has no sense to try it, because if I want my Desire to read an USB mass storage device, it wouldn’t be “power supply” available in that moment, so I’m gonna leave this mission.

    Thanks again!

    • #2 geschrieben von Tim  vor 1 Woche

      Well, yeah… that is a big problem with the USB Host…. :(

  • #3 geschrieben von renderit  vor 2 Wochen

    I have your old bcm4329.ko,I replace it manually , it work well.
    I have a question,why you copy the bcm4329.ko twice, one in /system/lib/modules,another one in /system/lib/modules/2.6.37-cyanogenmod+/kernel/drivers/net/wireless. I just replace them all.

    • #4 geschrieben von Tim  vor 1 Woche

      I actually don’t know why there are more than one… the one in /system/lib/modules is the one that is used by the system.
      I built up my kernel package from the blueprint of another one… that one also hat the module in the other dir. Basically I just added it b/c i thought it good for tidiness of the package ;)

  • #5 geschrieben von renderit  vor 2 Wochen

    Finally ,I got Ethernet adapter with asix chipset (ax88772a).I work great.Unlike the sr9700 Ethernet adapter, asix chipset Ethernet is REAL usb 2.0 ethernet adapter,it is much faster ,about 10M/s from Desire to PC,and 4M/s from PC to Desire.
    The sr9700 adapter only 600k/s atmost (only test on window ,not work on android).
    By the way ,the WLAN sleep off patched wifi driver is very useful, not only connecting to an ad-hoc network,but also for
    connecting to router.

    • #6 geschrieben von Tim  vor 1 Woche

      Sounds great :)
      Yes, also find it very annoying, if the WiFi always turns itself off, when the display is going to sleep. Even in infrastructure mode, this leads to increased response times of the phone… maybe I should add that to my website again :D

  • #7 geschrieben von Tim  vor 3 Wochen

    No, for me it’s no problem, WiFi is working the whole time. I use adb over WiFi to debug, so I really rely it ;)

    Once I inserted the USB core and ehci-ehd modules, I somehow cannot unload them anymore, so to answer your question: I have to restart to get them unloaded…
    If somebody knows stuff about USB host and kernel programming, this would be a great point to start fixing bugs ;)
    This problem is around since the very first patch, so I don’t see this being fixed anytime soon.
    I have a couple of days in-between exams right now, so don’t worry about distracting me. I am quite busy though still, b/c all the stuff that piled up while I studied for the last exam is now slowly being caught up.

  • #8 geschrieben von nick  vor 3 Wochen

    I agree. I tried your kernal on an older rom and wifi worked until the modules were loaded. In your configuration do you have wifi working whilst host is active? This is what I’m after. I can happily lose slave functionality if I have wifi. Also can you remove your modules then reinsert them to reenable your USB devices or do you have to restart your device? There’s no rush to reply so don’t use this as an excuse to procrastinate. Exams are horrible but important.

  • #9 geschrieben von Tim  vor 3 Wochen

    This seems to me as if they changed something with the WiFi kernel module in the newer CM versions. If you can’t use WiFi, it means, that the kernel module cannot be loaded, or that they changed something major within the module. I will have a look into it. Maybe I just have top update my kernel source.

    I am using CyanogenMod-7-07312011-NIGHTLY-Desire

  • #10 geschrieben von Nick  vor 3 Wochen

    Good luck with your exams and thanks for the help. One last query though… now I’m using the stable cm7 rom the wifi stops working when the host kernel is flashed. It seems only flashing the cm7 rom again fixes it but it would be great if I could use wifi and USB host at the same time. Any ideas how I might sort this out? Which cm7 rom do you have it working on?

  • #11 geschrieben von Tim  vor 3 Wochen

    Sorry for not answering for so long.
    I am in the middle of examinations at the moment, so I won’t have much time to help you guys for the next few weeks.
    Nick, I’m glad you figured this out yourself. If the Kernel doesn’t work with the newest CM Nightlys I should add a note to the webpage. After the exams I can try to compile an updated kernel that works with the newest nightly builds.

  • #12 geschrieben von nick  vor 3 Wochen

    sorry about all of the comments. i have finally go usb host working on my desire. i was running the last CM7 nightly so i downgraded back to the last stable version and tried from the beginning. the only problem I had was that it said the msdos.ko module wasnt valid or something. it still seemed to work though!
    thanks for all your help.
    for anyone else who is stuck, just make sure you’re using the latest (as of now) stable release of CM7.1.0

  • #13 geschrieben von nick  vor 4 Wochen

    Hello again,
    My USB otg cable finally arrived so I have all of the hardware I need now. I’ve installed your kernel zip through recovery and have all of the cables and a hard drive plugged in. Unfortunately I’m having problems with the insmod commands.
    I’m not well practised with using the terminal but i’ve used lsmod to check whether they insert or not.
    So far I have managed to insert three of the modules (usb core and the fs modules) I dont understand why they wont all work. I get can’t open for most and no such file or directory for another.
    I got fed up of typing them all in individually so I wrote a script containing exactly what you have above.
    Could you help me figure out what I’m doing wrong please?
    Many thanks

    • #14 geschrieben von nick  vor 4 Wochen

      I’m also getting device or resource busy errors

      • #15 geschrieben von nick  vor 4 Wochen

        I’ve entered each line seperately and that seems to work better so now I have succesfully inserted
        usbcore.ko
        scsi_wait_scan.ko
        scsi_mod.ko
        sd_mod.ko
        ntfs.ko
        msdos.ko
        but still I cannot insmod ehci-hcd.ko it says “device or resource is busy”
        I tried rmmod usbcore then insmod usbcore followed by insmod ehci-hcp but still get “device or resource is busy”
        the last part of dmesg gives
        Error: Driver ‘msm_hsusb’ is already registered, aborting…
        does this help?

  • #16 geschrieben von Tim  vor 1 Monat

    You were right, sorry about that, I guess I copied the link without changing it appropriately. Here’s the correct one now:
    2.6.37 cyanogen 7.x Kernel with multicasting enabled

    • #17 geschrieben von nick  vor 1 Monat

      many thanks. enabling host on my desire will definitely keep me interested.

  • #18 geschrieben von Tim  vor 1 Monat

    Hey,

    since I recompiled my kernel from scratch, the original CM7 modules do not work with the kernel. Fortunately cm7 only has the wifi driver as module. By installing my kernel, it replaced your wifi kernel module with mine, which does not work with the cm7 kernel.
    You have 3 solutions:
    1. Flash the kernel and wifi module back from your backup. The wifi module is located at: /system/lib/modules/bcm4329.ko
    2. Find an cm7 kernel packet that contains the wifi module and flash that
    3. Flash my 2.6.37 cyanogen 7.x Kernel with multicasting enabled kernel. It is identical to the cm7 kernel but I enabled IP-multicasting which enabled the device to receive multicast packets. If you don’t use this, it will not make any difference for you. This is probably the easiest way, and also what I do, if I need my Desire to communicate via USB again.

    • #19 geschrieben von nick  vor 1 Monat

      Thanks for the quick reply and good explanation but it looks very much like the “2.6.37 cyanogen 7.x Kernel with multicasting enabled” that you supplied is the same as the “2.6.37 cyanogen 7.x Kernel Patched with USB Host”. Have you uploaded the wrong one or am I confused (likely).

  • #20 geschrieben von Nick  vor 1 Monat

    Do we need to flash the original cm7 Kemel after using host in order to restore usb slave mode? I restored only the kernel from my nandroid backup but got a wifi error so had to do a full restore. Or did I miss something? For example should I wipe something when flashing a kernel?
    Thanks for your work this guide gave me the confidence to try it for myself.

  • #21 geschrieben von Tim  vor 1 Monat

    I did not actually write the patch, I only adapted a single line to make it compatible with the 2.6.37 Kernel. As long as the Kernel didn’t change too much it should not be to hard to adapt.
    I actually don’t have a device with ICS and probably won’t in the near future. Once I get a hand on a 3.x Kernel for android, I could try to apply the patch and see if it compiles. However I won’t really be able to test it, since I’m not planning on moving my Desire to ICS.

  • #22 geschrieben von Slava  vor 1 Monat

    Hi Tim,
    great work

    Do you plan to adopt your patch with ICS?
    For example with this rom:
    http://forum.xda-developers.com/showthread.php?t=1355660

  • #23 geschrieben von renderit  vor 1 Monat

    My sr9700 ‘s ID is 0FE6:9700.

    Because now is in the Chinese Spring Festival,I can not buy a new Ethernet with Axis chip .I have to use my old one .I just found another old Ethernet ,which is sr9600 chip set .sr9600 ‘s ID is 0FE6:8101 ,exactly is the card talk about in http://21500.net/?p=616.so if it not too trouble, I wish get sr9600.ko too.

  • #24 geschrieben von Tim  vor 1 Monat

    Of course I can compile the driver for you :)
    Could you try to do the lsusb step described here: http://21500.net/?p=616
    Then I can try to change the driver source accordingly and send the module to you.

  • #25 geschrieben von renderit  vor 1 Monat

    Forget my last post please,the source is about qf9700,not sr9700.Mine is sr9700.I think they are different.

  • #26 geschrieben von renderit  vor 1 Monat

    Thanks for your pointing ,I am learning compile the modules myself from the very beginning.
    I thought this is the source code of my Ethernet adapt:
    in this article,
    http://blogs.mail.ru/mail/theism/5239EFF6E96DDDEE.html
    the address is :
    http://blackcatlinux.nxt.ru/trash/usbtolan/usblan.tar.gz
    When I can compile the modules successfully ,is would be 2 or 3 weeks later,so would you please compile the modules for me?

  • #27 geschrieben von Tim  vor 1 Monat

    Yes, you’re correct. Asix is the chipset driver….

    Seems like your chipset is not natively supported my Linux. I found this here:
    http://21500.net/?p=616
    So with the vendor ID, it seems possible to change the driver to allow usage of your adaptor.

  • #28 geschrieben von renderit  vor 1 Monat

    I have took a look at the “HowTo.AddEthernetAdapter”,I only have a usbtoRJ45 with SR9700 chip-set.Coincidentally I need another Ethernet,since you compile the asix.ko already, I will get a new Ethernet with asix chip-set.Asix.ko is a driver of chip set,right?

  • #29 geschrieben von Tim  vor 1 Monat

    I didn’t find time to get around to that yet.
    I posted a comment on the website for the patch, asking weather he would supply a paths without the device specific host-mode changes, but that comment is gone from the page.

    I’m not sure when I will get around to testing anything with that.

    Another problem also remains: For me, once I actually use the usb host mode, I am unable to unload the host mode modules. I have no idea why this is, so a reboot would still be needed, even with this patch.

  • #30 geschrieben von Grzesiek  vor 1 Monat

    How with your attempts to compile device-mode also as a module?
    It would be great if they could be changed on a single kernel. Lots of people would be grateful : )

  • #31 geschrieben von Tim  vor 1 Monat

    At least you didn’t get any error messages this time :)

    Once the adaptor is connected, it should not yet be activated as it states here:
    http://www.nslu2-linux.org/wiki/Peripherals/EthernetAdapter?from=HowTo.AddEthernetAdapter

    Could you try to run ifconfig -a to see weather the connector is found, but just inactive?
    If it is inactive you can activate it with something like ifconfig eth1 up

  • #32 geschrieben von renderit  vor 1 Monat

    I always load the modules as the order as you.Now I only load the 5 modules ,carefully. I got the same result as you.
    usbcore: registered new interface driver asix

    Then I plug in a usb to RJ45 adaptor, I got :new full speed USB device using msm_hsusb and address 3 ……..

    Still no eth0 or somthing like that.

  • #33 geschrieben von Tim  vor 1 Monat

    Hey renderit,

    I tried inserting the modules on my device, and I did not get any error messages… the only message I got on dmesg was:
    usbcore: registered new interface driver asix
    which sound pretty good to me.
    Just to be sure, I repacked the kernel and uploaded it again. I tested on my phone with exactly this kernel. The order in which I inserted was:

    insmod /system/lib/modules/$(uname -r)/kernel/drivers/usb/core/usbcore.ko
    insmod /system/lib/modules/$(uname -r)/kernel/drivers/usb/host/ehci-hcd.ko
    insmod /system/lib/modules/$(uname -r)/kernel/drivers/net/mii.ko
    insmod /system/lib/modules/$(uname -r)/kernel/drivers/net/usb/usbnet.ko
    insmod /system/lib/modules/$(uname -r)/kernel/drivers/net/usb/asix.ko

    I guess you did it the same way, but just wanted to be sure.
    Unfortunately I don’t have a usb ethernet adaptor, so I can’t test anything further for you.
    Hope the repacked Kernel solves the problem.

  • #34 geschrieben von Tim  vor 1 Monat

    Also be sure to make a backup of all your data before flashing or rooting anything!

  • #35 geschrieben von Tim  vor 1 Monat

    Hey Gerald,

    unfortunately I do not yet have a step by step guide for this…

    Yes, correct, you will need:
    * A rooted HTC Desire
    * Cyanogenmod 7 because my kernel its compiled for that
    * A USB OTG Cable
    * a solution for the power supply

    These Steps are fairly easy… But Before you do any of this:
    Even though I did not have any problems with these steps (I performed them on about 10 phones) you can never be sure if it won’t brick your phone. So proceed on your own risk.

    There is a good guide for rooting and installing Cyanogenmod on your device at: http://wiki.cyanogenmod.com/wiki/HTC_Desire_(GSM):_Full_Update_Guide

    They state that you should use the revolutionary tool to gain root access to your phone. This tool is still in alpha development, so I would still recommend using unrevoked. That is available here: http://unrevoked.com/recovery/
    This is a very simple way of rooting your device. It should also install Clockwork Recovery on your phone.

    Once you have root and Clockwork Recovery continue with the “Flashing CyanogenMod” part of the above mentioned website.

    Once this is done, you should be somewhat familiar with the Clockwork recovery. Copy my above Kernel to your phones SDcard, reboot into recovery and flash the kernel zip. You might have to turn of signature verification for this.
    Once flashed, you just have to insert the modules like described above to gain Host-Mode.

    Now to the cables: First you need some cable converting the micro usb port into a female USB port. Additionally, since the phone does not provide any power over the usb port, you will need a USB Y-Cable like the first picture on this page:
    http://htc-linux.org/wiki/index.php?title=Msm_Usb_Host
    Use this cable as an intermediate cable which you plug into the OTG cable and which you connect to your Camera. The second USB plug of your Y-Cable needs to be connected to some USB Port witch supplies power, like one on your computer, or just a usb Power adaptor.

    Well, this has gotten pretty lengthy… maybe I should dedicate a page to this topic, if I find the time.
    Anything unclear? Any more questions?

    Tim

  • #36 geschrieben von Gerald Domaldson  vor 1 Monat

    Hi, thank you so much for this post! Do you have a step by step guide for getting the USB mode active on the HTC Desire? I have a Canon DSLR and would like to run the DSLR Controller app, which requires an android device capable of running USB host mode.

    I am new to Android Phones, and do not know much about how to run code on it. Am I required to “root” my phone for this to work? Also, this would require a USB Host/OTG Cable to work correct? Thanks for the help and keep up the great work!

  • #37 geschrieben von Tim  vor 1 Monat

    mmmh.. it seems as if there are still some symbols missing.. I will look into it

  • #38 geschrieben von renderit  vor 1 Monat

    and here is the dmesg about usbnet:

    [ 398.595275] usb 1-1.4: new full speed USB device using msm_hsusb and address 3
    [ 403.018707] usbnet: Unknown symbol mii_ethtool_sset (err 0)
    [ 403.020538] usbnet: Unknown symbol mii_link_ok (err 0)
    [ 403.025360] usbnet: Unknown symbol mii_nway_restart (err 0)
    [ 403.027862] usbnet: Unknown symbol mii_ethtool_gset (err 0)
    [ 403.055114] asix: Unknown symbol usbnet_set_msglevel (err 0)
    [ 403.056152] asix: Unknown symbol mii_link_ok (err 0)
    [ 403.056976] asix: Unknown symbol usbnet_change_mtu (err 0)
    [ 403.083068] asix: Unknown symbol usbnet_unlink_rx_urbs (err 0)
    [ 403.084014] asix: Unknown symbol usbnet_get_msglevel (err 0)
    [ 403.084472] asix: Unknown symbol mii_check_media (err 0)
    [ 403.084930] asix: Unknown symbol usbnet_open (err 0)
    [ 403.085357] asix: Unknown symbol usbnet_skb_return (err 0)
    [ 403.085815] asix: Unknown symbol usbnet_tx_timeout (err 0)
    [ 403.086883] asix: Unknown symbol usbnet_get_settings (err 0)
    [ 403.087646] asix: Unknown symbol usbnet_suspend (err 0)
    [ 403.088195] asix: Unknown symbol usbnet_start_xmit (err 0)
    [ 403.095703] asix: Unknown symbol usbnet_get_drvinfo (err 0)
    [ 403.100616] asix: Unknown symbol usbnet_get_endpoints (err 0)
    [ 403.101409] asix: Unknown symbol mii_nway_restart (err 0)
    [ 403.104675] asix: Unknown symbol usbnet_nway_reset (err 0)
    [ 403.110809] asix: Unknown symbol usbnet_stop (err 0)
    [ 403.111267] asix: Unknown symbol usbnet_defer_kevent (err 0)
    [ 403.111572] asix: Unknown symbol generic_mii_ioctl (err 0)
    [ 403.111999] asix: Unknown symbol usbnet_disconnect (err 0)
    [ 403.112457] asix: Unknown symbol usbnet_set_settings (err 0)
    [ 403.112762] asix: Unknown symbol usbnet_probe (err 0)
    [ 403.146850] asix: Unknown symbol usbnet_resume (err 0)
    [ 403.147583] asix: Unknown symbol mii_ethtool_gset (err 0)

  • #39 geschrieben von renderit  vor 1 Monat

    Even update the busybox you provided,I can not find a ethernet device(wifi turned off) .
    Here is the result after excute lsmod and busybox ifconfig:

    # lsmod
    asix 11477 0 – Live 0xbf0a4000
    usbnet 12608 1 asix, Live 0xbf09a000
    mii 3212 2 asix,usbnet, Live 0xbf094000
    usb_storage 34128 0 – Live 0xbf06e000
    sd_mod 22717 0 – Live 0xbf062000
    scsi_mod 81414 2 usb_storage,sd_mod, Live 0xbf03f000
    scsi_wait_scan 442 0 – Live 0xbf039000
    ehci_hcd 33661 0 – Live 0xbf02a000
    usbcore 110381 5 asix,usbnet,usb_storage,ehci_hcd, Live 0xbf000000
    # busybox ifconfig
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

    #

  • Kommentar-Feed für diesen Beitrag
nach oben