FORUMS
Remove All Ads from XDA

Compiling Android USB Gadget drivers and insmod

21 posts
Thanks Meter: 4
 
By darcpyro, Junior Member on 5th September 2012, 12:34 PM
Post Reply Email Thread
Hi everyone,
I have been trying for quite a while now to compile HID Gadget support for my galaxy S3 and think i may be getting close. My current problem is that when i run insmod g_hid.ko i receive the following
Code:
insmod: init_module 'g_hid.ko' failed (Device or resource busy)
. The weird thing is that next time the screen turns off or if i attempt to insert it again the phone crashes (kernel panic i assume). I get this same error when i try and insmod g_zero.ko (although this one doesn't kill the phone). Can anyone tell me how i would attempt to debug this? Or even better, has anyone got g_hid working on there phone and if so, what modifications/kernel configs did you use?

Also, when compiling the kernel, in "USB gadget support" if i select any option other than Android Gadget in USB Gadget Drivers my kernel fails to build. Has anyone got any USB gadgets to compile and run and if so what procedure/modifications did you have to make. Currently i am compiling my kernel with android gadget selected as the usb gadget driver and then changing it to HID module and running make module_prepair and make module to get my .ko files (which may be why i am getting the above error).

If anyone can provide some insite and advice it would be greatly appreciated.
Thank you
Adrian
The Following 2 Users Say Thank You to darcpyro For This Useful Post: [ View ] Gift darcpyro Ad-Free
 
 
5th September 2012, 03:21 PM |#2  
OP Junior Member
Thanks Meter: 4
 
More
After months of trying, it appears i have got it solved. Unfortunately its not the most graceful solution and currently it disables MTP but i dont care. To fix it i searched every file in the kernel for mentions of CONFIG_USB_G_ANDROID and everywhere it was involved in an #if defined statement i added another section like so
Code:
#if defined(CONFIG_USB_ANDROID) || defined(CONFIG_USB_G_ANDROID) || defined(CONFIG_USB_S3C_OTGD)
In this case i added USB_S3C_OTG. As i said, it isn't pretty but it works.

Hope this helps someone in the future coz there is very little info on the net about this
Enjoy
Adrian
The Following User Says Thank You to darcpyro For This Useful Post: [ View ] Gift darcpyro Ad-Free
28th September 2012, 10:05 AM |#3  
Junior Member
Thanks Meter: 1
 
More
Code sample
I asked a question on Stack Overflow about exactly this issue. There is a small group of people who seem quite interested in this issue, and there really is not a lot of information on the net.

I would very much appreciate if you could explain in a little more detail what steps you took to get this to work for you. You could probably answer the Stack Overflow question more decisively than the current answers too: stack-overflow questions/9805731 - is-it-possible-to-program-android-to-act-as-physical-usb-keyboard. (I can't post the link as this forum blocks it.)

Quote:
Originally Posted by darcpyro

After months of trying, it appears i have got it solved. Unfortunately its not the most graceful solution and currently it disables MTP but i dont care. To fix it i searched every file in the kernel for mentions of CONFIG_USB_G_ANDROID and everywhere it was involved in an #if defined statement i added another section like so

Code:
#if defined(CONFIG_USB_ANDROID) || defined(CONFIG_USB_G_ANDROID) || defined(CONFIG_USB_S3C_OTGD)
In this case i added USB_S3C_OTG. As i said, it isn't pretty but it works.

Hope this helps someone in the future coz there is very little info on the net about this
Enjoy
Adrian

28th September 2012, 11:34 AM |#4  
OP Junior Member
Thanks Meter: 4
 
More
No worries, im happy to help. The funny thing is by reading the answers you got it started me on the right path to finding a solution. Im not sure how this will translate to other devices firmware but in the case of the galaxy S3 it was i went threw every file and added the
Code:
|| defined(CONFIG_USB_S3C_OTGD)
to all if defined statement that made any mention of CONFIG_USB_GADGET so that the code inside would be compiled. This was so that in the .config file for the kernel CONFIG_USB_GADGET would be set to yes and would then allow the hid driver to be compiled. Basically every time i got an error i saying something wasn't compiled or wasn't declared i went to that file, found where it was declared and added that if defined statement. I would upload my working source code but it would take weeks on my internet connection. If there is a specific file you want to see then let me know and i will post its contents.
Good luck
Adrian
22nd July 2013, 11:05 AM |#5  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by darcpyro

No worries, im happy to help. The funny thing is by reading the answers you got it started me on the right path to finding a solution. Im not sure how this will translate to other devices firmware but in the case of the galaxy S3 it was i went threw every file and added the

Code:
|| defined(CONFIG_USB_S3C_OTGD)
to all if defined statement that made any mention of CONFIG_USB_GADGET so that the code inside would be compiled. This was so that in the .config file for the kernel CONFIG_USB_GADGET would be set to yes and would then allow the hid driver to be compiled. Basically every time i got an error i saying something wasn't compiled or wasn't declared i went to that file, found where it was declared and added that if defined statement. I would upload my working source code but it would take weeks on my internet connection. If there is a specific file you want to see then let me know and i will post its contents.
Good luck
Adrian

Hi Adrian

did you manage to use your android phone as a keyboard with USB_H_HID module ? I'm trying to do the same thing and I would be interested if you have more informations. For now, I had cyanogendmod source for Samsung Galaxy S III and I've compiled the default 10.1 ROM.

Yesterday, I tried to modify kernel options to include USB_H_HID in the kernel but the build fails on some android.c error.

See you

--
Thus0
22nd July 2013, 11:18 AM |#6  
OP Junior Member
Thanks Meter: 4
 
More
Hi Thus0

I did manage to get it to work late last year (Just so you know that it can be done).From memory i basically ran grep over every file in the modules directory looking for CONFIG_USB_GADGET and then edited those files to say something like:

#if defined(CONFIG_USB_ANDROID) || defined(CONFIG_USB_G_ANDROID) || defined(CONFIG_USB_S3C_OTGD)

This way it would compile the USB Gadget modules as well. Let em know if you have any more questions and ill try and help.

Adrian
6th October 2013, 10:47 PM |#7  
Shir_man's Avatar
Junior Member
Flag Moscow
Thanks Meter: 0
 
More
Huh – is it possible to make apk file for root devices?
7th October 2013, 05:27 AM |#8  
OP Junior Member
Thanks Meter: 4
 
More
Quote:
Originally Posted by Shir_man

Huh – is it possible to make apk file for root devices?

No sorry, as far as i know a custom kernal is compiled
9th October 2013, 10:45 PM |#9  
Junior Member
Thanks Meter: 1
 
More
Quote:
Originally Posted by darcpyro

No sorry, as far as i know a custom kernal is compiled


Is it possible to only use a driver and to load it with insmod in a stock rom? What modification require a custom kernel?
16th May 2014, 11:25 AM |#10  
Senior Member
Thanks Meter: 43
 
More
i was looking for a solution and ou,d something for the nexus 7
https://play.google.com/store/apps/d...eyboard.client

open xource here with kernel patch
https://www.google.com/url?q=https:/...DLzdg_qBxLb7gw

maybe someone can use it
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes