Android内核模块的编译与普通Linux内核的编译稍有不同
1.下载android内核

#如果git需要使用代理可以使用如下命令
export https_proxy="http://192.168.1.105:8087"

git clone https://android.googlesource.com/kernel/goldfish.git

上面得到的是主线上的内核源代码,现在我们需要适用于模拟器用的内核,因此,我们需要checkout goldfish版本:
cd goldfish
git branch -a //查看branch

git checkout remotes/origin/android-goldfish-3.4

2.下载交叉编译工具
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
设置环境变量
export PATH=$PATH:/home/alan/workspace/arm_toolchain/arm-eabi-4.6/bin
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-

3、现在是要得到android的内核编译参数的配置文件的时候了,该文件需要从已经安装好的android的模拟器
配置文件在模拟器的"/proc/config.gz"目录,pull出来,解压,将config文件改名为.config,拷贝到内核代码goldfish目录下。

这是在goldfish目录下make,可编译内核

http://source.android.com/source/building-kernels.html

下面讲解编译内核模块

1.在内核源码drives目录下添加hello目录,内含hello.c Kconfig Makefile文件
hello.c
#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>MODULE_LICENSE("Dual BSD/GPL");static int hello_init (void){printk("hello linux kernel\n");return 0;}static void hello_exit (void) {    printk("bye..lwave from the kernel\n");}module_init(hello_init);module_exit(hello_exit);


Kconfig
config HELLOtristate "Helllo module test created by lz"  default mhelptest for adding driver to menuconfig


Makefile
KERNELDIR :=/home/alan/workspace/android_kernel/goldfishPWD :=$(shell pwd)ARCH=armCROSS_COMPILE=arm-eabi-CC=$(CROSS_COMPILE)gccLD=$(CROSS_COMPILE)ldobj-$(CONFIG_HELLO) +=hello.o


1.通过给下面的Kconfig文件再加上下面的代码,可使hello项出现在配置菜单中:

(1)在arch/arm/Kconfig文件中 menu "Device Drivers" endmenu之间添加 source "drivers/hello/Kconfig"(这个文件好像没有menu "Device Drivers" endmenu,要自己写)

menu "Device Drivers"source "drivers/hello/Kconfig"endmenu


(2)在drivers/Kconfig文件中 menu "Device Drivers" endmenu之间添加 source "drivers/hello/Kconfig"

2.修改Drivers目录下的Makefile文件,添加如下行:
obj-$(CONFIG_HELLO) += hello/
当CONFIG_HELLO为y或m时,使系统能找到hello驱动的makefile

以上过程完成便将hello模块添加至内核menuconfig菜单,注意格式与上下文保持一致

这是在goldfish目录下make,则模块在
drivers/hello/目录的hello.ko

更多相关文章

  1. 在LinearLayout中嵌套RelativeLayout来设置Button的位置(xml文件)
  2. Android内核的编译与裁剪
  3. android studio ndk 编译自定义MK文件
  4. Android Studio-Gradle项目中添加JNI生成文件(.so文件)
  5. Android 一个APK文件部署产生多个应用安装的效果

随机推荐

  1. Android内核开发:学会分析系统的启动log
  2. 解开Android应用程序组件Activity的"sing
  3. 信息浏览器从Android的浏览器中传递cooki
  4. 转载:Android(安卓)解压zip文件
  5. 基于Xmpp,Openfire和Asmack的聊天软件的开
  6. Android自定义字体样式Typeface的三种技
  7. [转]自己整理的android入门QA表,希望能帮
  8. Android系统的架构
  9. Android样式和主题
  10. Looper