Home > AllWinner A1X, Android > Building Kernel Modules for AllWinner A10 Android Devices (e.g. Joystick Support)

Building Kernel Modules for AllWinner A10 Android Devices (e.g. Joystick Support)

September 11th, 2012 Leave a comment Go to comments

Reader JP has enabled Joystick support in Android 4.0.4 on its Mele A1000, this now works with a Playstation2 joystick via USB adapter, a Huskee PC joystick, and 2 other unbranded joysticks. In order to enable Joystick support he had to build a kernel module, and encountered a few issues, so he wrote an how-to which shows what challenges he went through and what solutions he found to those issues.I’m sharing today a slightly edited version of this how-to.

This How-to assumes that you have a valid Linux environment where you can build allwinner A10 kernel. The toolchain used was “Sourcery CodeBench for ARM GNU/Linux Lite“ which can be downloaded here: http://www.codesourcery.com/sgpp/lite/arm/portal/package7853/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi.bin

To install it, simply run:

sudo ./arm-2010.09-50-arm-none-linux-gnueabi.bin

You’ll also need the latest Allwinner A10 kernel source:

git clone git://github.com/amery/linux-allwinner.git

Then follow the usual procedure:

make ARCH=arm sun4i_crane_defconfig
make menuconfig ARCH=arm

I then selected the modules needed for different kind of joysticks namely:

 --- Networking support
  <*>   Bluetooth subsystem support  ---> 
  <M>   HIDP protocol support
        Bluetooth device drivers  --->
  <M> HCI USB driver

[*] HID Devices  --->  
    Special HID drivers  --->    
  <M> Sony PS3 controller
  <M> DragonRise Inc. game controller                                                                              
           [*]   DragonRise Inc. force feedback
  <M> Pantherlord/GreenAsia game controller                                                                         
           [*]   Pantherlord force feedback support
  <M> GreenAsia (Product ID 0x12) game controller support                                                           
           [*]   GreenAsia (Product ID 0x12) force feedback support                                                         
  <M> SmartJoy PLUS PS2/USB adapter support                                                                         
           [*]   SmartJoy PLUS PS2/USB adapter force feedback support

I saved the settings and continued the build:

modules_install INSTALL_MOD_PATH=/MELE/Modules39
make ARCH=arm CROSS_COMPILE=/root/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-
make ARCH=arm CROSS_COMPILE=/root/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi- modules_install INSTALL_MOD_PATH=/MELE/MODULES

Then I copied my modules to my sdcard, went to a terminal that I downloaded from the android market and did (as root):

# insmod mymodule.ko

And received the following error:

insmod: init_module 'joydev.ko' failed (Exec format error)

So I thought: “It cannot be, I compiled the right kernel the right way, with the correct compiler that the guys at Mele used…” After some cups of coffee I found the mystical mistake by checking an existing kernel module from the Mele:

# modinfo rtl8150.ko

filename:       rtl8150.ko
license:        GPL
description:    rtl8150 based usb-ethernet driver
author:         Petko Manolov <[email protected]>
alias:          usb:v0586p401Ad*dc*dsc*dp*ic*isc*ip*
alias:          usb:v1557p8150d*dc*dsc*dp*ic*isc*ip*
alias:          usb:v07B8p401Ad*dc*dsc*dp*ic*isc*ip*
alias:          usb:v3980p0003d*dc*dsc*dp*ic*isc*ip*
alias:          usb:v0411p0012d*dc*dsc*dp*ic*isc*ip*
alias:          usb:v0BDAp8150d*dc*dsc*dp*ic*isc*ip*
depends:
vermagic:       3.0.8+ preempt mod_unload modversions ARMv7

And compared it to the output generated with my module:

# modinfo hid-sony.ko

filename:       hid-sony.ko
license:        GPL
alias:          hid:b0003v0000054Cp0000024B
alias:          hid:b0005v0000054Cp00000268
alias:          hid:b0003v0000054Cp0000042F
alias:          hid:b0003v0000054Cp00000268
depends:
vermagic:       3.0.39 preempt mod_unload modversions ARMv7

Do you see the small difference?

Original Mod:

vermagic:       3.0.8+ preempt mod_unload modversions ARMv7

My Module compiled from amery sources:

vermagic:       3.0.39 preempt mod_unload modversions ARMv7

So that was the problem, the kernel refused to load the module because the “vermagic” is not the same.

So the logical thought would be to get the sources of 3.0.8+ kernel, and amery github repo has that too in a specific branch (lichee-3.0.8-sun4i)

So I compiled it, made the modules and the new vermagic looked as follows:

vermagic:       3.0.8 preempt mod_unload modversions ARMv7

The missing “+” is the problem, as it should show 3.0.8+ instead..

So I said, If I change the vermagic of the module the problem will be resolved, but.. if I change the vermagic and use the 3.0.39 source the kernel will explode and the world will collapse!

According to tldp.org and haifu.org, you can build a kernel module using version 3.0.xx (e.g. kernel 3.0.39), and load it in a system running kernel 3.0.yy (e.g. kernel 3.0.8.

So here are 2 methods I’ve followed to change the vermagic:

  • The hard and dirty way: With objcopy you can remove the .modinfo from the original Mele Module and insert that part on your compiled module, so the vermagic will be the same.
  • The easy and “not so dirty way”: Well, I know that this is dirty, but if you’re in a hurry…
    Go to amery source folder, edit the .config file and change:

    CONFIG_LOCALVERSION=""

    to

    CONFIG_LOCALVERSION="+"

    Then edit the Makefile file and change:

    SUBLEVEL = 39

    to

    SUBLEVEL = 8

    and then complete the full build:

    # make clean
    # make ARCH=arm CROSS_COMPILE=/root/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-
    # make ARCH=arm CROSS_COMPILE=/root/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi- modules_install INSTALL_MOD_PATH=/MELE/MODULES

You MUST compile the entire kernel, so the proper vermagic is inserted into the modules, if you are lazy and just compile the modules, the vermagic will be not inserted and you’ll see the same error again.

Then I checked the vermagic again:

Original Mele Module

vermagic:       3.0.8+ preempt mod_unload modversions ARMv7

My NEW Module

vermagic:       3.0.8+ preempt mod_unload modversions ARMv7

So to be sure, I copied the module to the sdcard, went to the terminal as root and did:

# insmod mymodule.ko

and no message was displayed, so I typed:

# dmesg

And at the end of the message, the module was correctly inserted!!

So that’s all what I needed.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

  1. JP
    September 11th, 2012 at 19:09 | #1

    Where it says “According to tldp.org and haifu.org, you can’t build a kernel module using version 3.0.xx (e.g. kernel 3.0.39), and load it in a system running kernel 3.0.yy (e.g. kernel 3.0.8).”

    It should be “According to tldp.org and haifu.org, you CAN build a kernel module using version 3.0.xx (e.g. kernel 3.0.39), and load it in a system running kernel 3.0.yy (e.g. kernel 3.0.8).

  2. September 11th, 2012 at 21:20 | #2

    @JP
    Thanks. I’ve updated the post.

  3. JP
    September 11th, 2012 at 21:27 | #3

    There’s a new official release of the Android 4.0 for the Mele AX000:
    http://pan.baidu.com/share/link?shareid=24132&uk=3610159878 (now it’s 1.2)

  4. Alexufo
    September 11th, 2012 at 23:39 | #4

    @JP
    Official firmware are encrypted for unpack.

  5. JP
    September 11th, 2012 at 23:55 | #5

    @Alexufo
    You mean that the rar is password protected?
    The rar file doesn’t have a password, I just unpacked it.

  6. JP
    September 12th, 2012 at 00:11 | #6

    I’ve uploaded the firmware to two random file hostings:

    http://speedy.sh/SrAhj/Mele-HTPC-120907-Ver1.2.rar
    http://www.sendspace.com/file/klfjzi

    Remember to use the PhoenixCard 3.0.6 (not included on the rar) under Windows 7.

  7. Alexufo
    September 12th, 2012 at 00:52 | #7

    @JP
    No) img file for phoenix card encrypted. This is image byte 2 byte copy of prepare SD card.

  8. Lori Wing
    September 12th, 2012 at 00:56 | #8

    Hi All, this information you’re providing is great if you are into building the Allwinner A-10 tablets themselves, but I am a new owner of one of them and am just trying to find a manual where I can find out how to make it work. The one that was included in the box is basically useless and I know there has got to be something out there that will make my experience a whole lot happier one then it has been thus far. Can anyone point me in a direction to find an “ENGLISH” version instruction manual of how to make an Allwinner A-10 tablet work…even the basics would be great, like how to make a bookmark, make a widget, etc. I’m just lost. Thanks so much for reading this and any help you are willing to provide. Have a great day and keep up the good work!!

    Lori

  9. Loran
    September 12th, 2012 at 04:33 | #9

    It’s also possible, and simpler IMO, to use the options ‘–force-vermagic’ and/or ‘–force-modversion’ to skip the (protection) check done for kernel module loading.

    However these options are only available for ‘modprobe’ tool, and apparently not for the simpler ‘insmod’. (but if ‘modprobe’ is present on the Android image you’re using, it seems easier to use it than forcing a different LOCALVERSION /SUBLEVEL in your kernel config).

  10. io
    September 12th, 2012 at 04:51 | #10

    after the clone command, is sufficient enter in the folder linux-allwinner

    cd linux-allwinner
    git checkout lichee-3.0.8-sun4i

    and when you compile, compile for 3.0.8+

  11. JP
    September 12th, 2012 at 07:11 | #11

    Hey don’t install this update, is completely focused to Chinese market. Most common components has been removed (at first sight), so don’t say that you weren’t informed (even the launcher has changed).

  12. September 12th, 2012 at 10:00 | #12

    I recently learnt the “+” is added to EXTRAVERSION if you have local git changes. (so related to git). So you don’t have to edit the local file per se.

  13. September 12th, 2012 at 10:01 | #13

    As for HTPC V1.2, I have a dd image too, which isn’t “encrypted”. But, I would not recommend International users install this. Stay with the previous ICS image.

  14. Sergey
    September 12th, 2012 at 12:26 | #14

    I am totally confused as to beg for help from you! those who are in what I will describe below understands and can help me.
    It’s about the MELE A2000 rev 1.3 with firmware version Android 4.0.4 v 1.1 (kernel version 3.0.8 +)
    About the desired result:
    1-Connect USB GPS to SirfIII via the existing bridge on the PL2303.
    2 USB Bluetooth connection to use OBDII ELM327 scanner.
    3-Connect USB DAC PCM2704
    On firmware downloaded and installed to the office site, all konechnozhe not work.
    Searching on the Internet responses,
    I realized that the simple solution to make it work not
    Who can do zip that all modules install and make their work
    I do not understand how to install the module and driver :(
    good for me if there is a zip
    I load CWM select install zip from SD card
    Disconnect the power, turned on and the desired module and the driver is installed
    I chalk can work with USB GPS USB Bluetooth and USB Audio (USB DAC PCM2704)
    I beg your help, I spent more than two weeks
    and can not seem to deal with all these the problem remains

  15. JP
    September 12th, 2012 at 19:22 | #15

    @Lundman
    Hi Lundman,
    Thank you for your tip, there’s people that download the source using the “zip” method of github and don’t want to mess with git :).

    (I want to say thank you for your hard work in the linux/opensolaris community and I respect and admire your constantly commitment to the community. Keep up the good work!!.)

  16. Adi
    September 13th, 2012 at 09:56 | #16

    Hi JP, can this be used to building drivers(modules) for other devices such as bluetooth dongle ?
    You see I had been trying to similar for the hackberry board its based on A10 chip and quite similar to melee >>https://www.miniand.com/products/Hackberry%20A10%20Developer%20Board

    Let me know if there can be any help, I am new to this (will be happy to provide the board too )

    Cheers !

  17. JP
    September 13th, 2012 at 18:38 | #17

    @Adi
    I added support for USB bluethoot dongles, but I just have one to test (an unbranded chinese one), and it failed. I guess that it was incompatible with the internal USB uhb, I’ve seen this kind of problem with other development boards (mini6410, mini2440, Vortex86) with devices that have multiple descriptors.

  18. JP
    September 13th, 2012 at 21:23 | #18

    For all the people reading this article:
    There are some essential tools needed (can be downloaded from the market)
    An updated “su” binary (switch user, no “superuser”)
    https://play.google.com/store/apps/details?id=com.noshufou.android.su&hl=en

    a complete busybox:
    https://play.google.com/store/apps/details?id=stericson.busybox&feature=search_result#?t=W251bGwsMSwxLDEsInN0ZXJpY3Nvbi5idXN5Ym94Il0.

    a SSH/SFTP server:
    https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid&feature=search_result#?t=W251bGwsMSwxLDEsImJlcnNlcmtlci5hbmRyb2lkLmFwcHMuc3NoZHJvaWQiXQ..

    Script Manager:
    https://play.google.com/store/apps/details?id=os.tools.scriptmanager&feature=search_result

    This applications (for me) are a MUST have if you want to mess with the OS.

  19. September 27th, 2012 at 18:45 | #19

    I’m selling my A10 hacking kit, as I have no time to exercise with it: http://txlab.wordpress.com/2012/09/27/for-sale-allwinner-a10-hacking-kit/

  20. Sergey
    October 10th, 2012 at 17:50 | #20

    Hello, may you can halp me?
    I want connect a touchscreen to mk802, I have compiled module (usbtouchscreen.ko), which loaded, but /dev/input/event* don`t appear.
    In dmesg I see that module was loaded. In /sys touchscreen is present. Vendor id and product id in /sys and in module source are correct. Why touchscreen may not work?
    ps sorry for my english :)

  21. Waldemar
    October 20th, 2012 at 21:29 | #21

    @Sergey
    Sergey, could you please make this loadable usbtouchscreen.ko available somehow for me? I am also trying to get my usb touchscreen working and will work on it. i’m struggling for a long time and it’s very high on my priority list :) or have you in the meantime got it working ?
    Thanks a lot ! :)

  22. Ilya
    December 7th, 2012 at 15:32 | #22

    Hi, please upload compiled joydev module to a file share service.

  23. gingsz
    January 27th, 2013 at 06:38 | #23

    Hello
    I builded the module, but there is no .ko file, where can in find it?

  24. January 27th, 2013 at 09:11 | #24

    @gingsz
    It should be in /MELE/MODULES

  25. gingsz
    January 29th, 2013 at 04:08 | #25

    @cnxsoft
    Thank you, it’s a very useful tutorial. :)

  26. Tomas Kaluza
    February 6th, 2013 at 03:47 | #26

    Hello!
    I am asking for help.

    I want to add bluetooth support to my Mele A2000. I want to be able to add bluetooth mouse, keyboard and headphones. I want to use D-Link DBT-122 USB Dongle.

    I created a virtual sever on Virtualmaster.com to do the development. (I also created a template for everybodys use, it is called “Mele A2000 android kernel development”, direct link is https://www.virtualmaster.com/virtualmaster/cs/images/3087. Feel free to use it. The server that can be created using this template is paid, but costs only some 3,- EUR / month. I choose this way for the poor internet connection I have. If You are asked for invitation, drop me an email, I do not know if they still ask for them at virtualmaster.com)

    My question is:
    Which modules (and in which order) do I need to load to enable this USB Dongle?
    (I already looked a lot around, and tried many combinationas, but no success yet)
    Does the bluetooth support appear in the settings after loading required modules? Do I neeed to add something else?
    (what is it I need to add if I need to add something?)

    Thanks a lot for any help!!

  27. DOH
    August 2nd, 2013 at 04:50 | #27

    @JP
    you have to follow the instructions and select the components you want to include. This is a good thing. Many of us don’t want the entire world.

  28. DOH
    August 2nd, 2013 at 04:52 | #28

    @DOH
    not sure why this went to the bottom. I replied in response to JP who said not to install this update.

  1. May 15th, 2013 at 18:25 | #1