PREREQUISITES
Disclaimer: This list may be incomplete, since I've not tried it on a fresh install. Please let me know if I've missed anything.
- Install the general android prereqs found here.
- Download and un(zip|tar) the android NDK found here.
- Download and un(zip|tar) the android SDK found here.
- Download and untar the kernel source for your device. This can usually be found on the website of your device manufacturer or by a quick Google search.
- Root your phone. In order to run custom kernel modules, you must have a rooted phone.
- Plug your phone into your computer.
PREPARING YOUR KERNEL SOURCE
First we must retrieve and copy the kernel config from our device.
$ cd /path/to/android-sdk/toolsNext we have to prepare our kernel source for our module.
$ ./adk pull /proc/config.gz
$ gunzip ./config.gz
$ cp config /path/to/kernel/.config
$ cd /path/to/kernel
$ make ARCH=arm CROSS_COMPILE=/path/to/android-ndk/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/arm-eabi- modules_prepare
PREPARING YOUR MODULE FOR COMPILATION
We need to create a Makefile to cross-compile our kernel module. The contents of your Makefile should be similar to the following:
Ineviditibly you'll run into some errors that you will need to sort out, as I did with both my droid 2 and evo devices. Feel free to post in the comments if you run into any major problems, and I'll try my best to help you out.
We need to create a Makefile to cross-compile our kernel module. The contents of your Makefile should be similar to the following:
obj-m := modulename.oCOMPILING AND INSTALLING YOUR MODULE
KDIR := /path/to/kernel
PWD := $(shell pwd)
CCPATH := /path/to/android-ndk/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-eabi- -C $(KDIR) M=$(PWD) modules
$ cd /path/to/module/srcRUNNING YOUR MODULE
$ make
$ cd /path/to/android-sdk/tools/
$ ./adb push /path/to/module/src/modulename.ko /sdcard/modulename.ko
$ cd /path/to/android-sdk/CONCLUSION
$ ./adb shell
$ su
# insmod /sdcard/modulename.ko
Ineviditibly you'll run into some errors that you will need to sort out, as I did with both my droid 2 and evo devices. Feel free to post in the comments if you run into any major problems, and I'll try my best to help you out.
This comment has been removed by the author.
ReplyDeleteWhen you say /path/to/kernel, I am assuming that it is the path in the /out/....//... directory. Am I right? If so, for some reason, there is no kernel directory in there. Also, it gives me an error saying that there is no rule to prepare for 'modules_prepare'. I am not sure if I am missing any step here. Do you know why this could be happening?
ReplyDeleteIt should read /path/to/kernel/source. I have to update this post to make it more precise. You need to download the kernel source from the phone's manufacturer.
ReplyDeleteI'll update the post to contain new information and troubleshooting as soon as I can.
Is that a typo? "./adk pull /proc/config.gz" Should be "./adb"?
ReplyDelete-Brendan ;)
Hello.
ReplyDeleteI have a problem. I found this "source code" :
https://github.com/vurrut/android_ke...ockchip_rk2918
or here
https://github.com/yatto/Smartpad-810c-Kernel-3.0.8
But does not contain the "source code" of the module touch my tablet .
How do I add it to the compilation?
I have compiled the module apart and also I have the "source code".
Thank
Hi Joe,
ReplyDeleteI'm trying to compile the kernel source and when I use ./adb pull /proc/config.gz I get the following error :
remote object '/proc/config.gz' does not exist
Do you have any info about this ? Please help.
Thanks !