How to compile a kernel module outside the kernel
来源:互联网 发布:临床数据质量管理规范 编辑:程序博客网 时间:2024/05/29 11:36
l转:http://forum.xda-developers.com/showthread.php?p=17020258
I've built few kernel modules (governors - ineractive and smartass, cifs, nls, etc) and I started receiving private messages asking how I did it.
For kernel modules that come with the kernel itself - cifs / tun for example - they just work if you compile the kernel and activate correct config parameters.
Some other modules (such as the smartass governor that doesn't come with the kernel) you compile outside the kernel source. However they require changes since kernel does not export the symbols the module needs to use - so you have to know what k_all_syms are needed, grab them from the phone and update the kernel module.
So there will be changes there. However, the main steps are:
a) follow tutorials to get the kernel / android ndk to compile. People seem able to do this.
b) then take the module you want (For example cpufreq_smartass.c from here: http://pastebin.com/rR4QUCrk ) and copy it in a new folder on the disk.
c) create a Makefile like the one below, but with your paths of course:
Code:
KERNEL_DIR=/home/viulian/android_platform/kernel-2.1.A.0.435/kernelobj-m := cpufreq_smartass.oPWD := $(shell pwd)default: $(MAKE) ARCH=arm CROSS_COMPILE=/home/viulian/android_platform/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- -C $(KERNEL_DIR) SUBDIRS=$(PWD) modulesclean: $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) clean
Of course, the module source needs to be adjusted as you need to put in the frequencies, and also update the k_all_syms pointers .. But you can retrieve them from /proc/kallsyms on the device itself - just look for the method name, and use the address you see in the log.
If you still can't get it to compile, try to compile a very basic hello_world kernel module. I used the code below when testing:
Code:
#include <linux/module.h> /* Needed by all modules */#include <linux/kernel.h> /* Needed for KERN_ALERT */MODULE_LICENSE("GPL");MODULE_AUTHOR("viulian, 2011");MODULE_DESCRIPTION("Demo module for X10i");int init_module(void){ printk("<1>Hello world\n"); // A non 0 return means init_module failed; module can't be loaded. return 0;}void cleanup_module(void){ printk(KERN_ALERT "Goodbye world 1.\n");}
One more thing, linux kernel is fussy about the module versions. Even if nothing is changed between two kernel versions related to what a module needs, is enough a small difference in module's modinfo value to make the kernel to refuse the module.
For this, you need to trick your local kernel and adjust EXTRAVERSION value in kernel's main Makefile to have the exact version of the one on the device:
In X10 stock kernel (GB 2.3.3 release), the kernel version is 2.6.29-00054-g5f01537 visible in phone settings.
This means that the kernel on the phone will only accept modules that are compiled for that exact version. But the kernel version is just a string in the module .ko, so is a string comparison - the module might work perfectly, but is not loaded.
There is luck though, the string value comes from a define in kernel's Makefile, which you can change before you compile!
The Makefile in the kernel you are going to use to build the module will have to include these lines at the top:
Code:
VERSION = 2PATCHLEVEL = 6SUBLEVEL = 29EXTRAVERSION = -00054-g5f01537
I usually had to keep another adb shell opening with 'cat /proc/kmsg' which showed as much as possible from the module's outputs.
and then
make the kernel berfore making modules
modify:
your_kernel_folder/include/config/kernel.release
your_kernel_folder/include/generated/utsrelease.h
to you wanted version strings.
then make your module.
you can use command in shell to check modify is or isn't success:
$ strings modulename.ko | grep vermagic
Happy compiling on your risk!
阅读全文
0 0
- How to compile a kernel module outside the kernel
- How To Compile A Kernel - The Ubuntu Way
- How To Compile A Kernel - The Ubuntu Way
- How To Compile A Kernel - The Ubuntu Way
- How the Kernel compile .c files for Kernel Module
- how to compile kernel
- how to compile kernel
- How to Compile the Linux Kernel
- how to compile the linux kernel
- How to compile kernel modules for the kernel 2.6
- Cross compile the kernel module
- how to compile uClinux kernel
- How to compile your kernel
- How to load a camera module in kernel space
- How to unload a kernel module in use
- How to read/write files within a Linux kernel module?
- How to: Compile Linux kernel 2.6
- How to: Compile Linux kernel 2.6
- linux下各种解压方法
- opencv for python (2) 视频的读入、输出、保存
- 找回消失的IBus图标:
- Android SDK更新以及ADT更新出现问题的解决办法
- 用上网卡ppp拔号上网
- How to compile a kernel module outside the kernel
- Android 开发中常用 ADB 命令总结
- 读取Json配置文件问题
- How to install your own zImage
- spring+springmvc+hibernate整合
- [原] [kernel]Using UMTS stick on nexus7(2013)
- Ubuntu 12.04 搭建 Eclipse Android 开发环境
- word导出
- 星際翻譯軟件的安裝