/*********************************************************************
* Author : Samson
* Date : 03/02/2014
* Test platform:
* Linux ubuntu 3.2.0-58-generic-pae
* GNU bash, version 4.2.39
* *******************************************************************/

hello module source:

#include <linux/init.h>

#include <linux/module.h>

static int hello_init(void)
{
printk(KERN_ALERT "Hello,world\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);


compile hello.ko module Makefile code:

obj-m := hello.o
all:
make ARCH=arm EXTRA_CFLAGS="-D_CONFIG_ARM_ -fno-pic" -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) cleanhe


Make hello.ko function:

make CROSS_COMPILE=arm-linux-androideabi- KDIR=/opt/hackandroid/goldfish_0228

NOTE: KDIR is kernel path. what's kernel path??? please refer to :http://blog.csdn.net/yygydjkthh/article/details/20172023


tested on android emulator:

run android emulator:

emulator -avd Android4.2.2 -kernel arch/arm/boot/zImage

push hello.ko to emulator:

testhello$ adb push hello.ko /data/local
60 KB/s (2648 bytes in 0.042s)


NOTE: what is zImage? How get the zImage??? please refer to : http://blog.csdn.net/yygydjkthh/article/details/20172023


testhello$ adb shell

[email protected]:/# cd data/local/
[email protected]:/data/local # ls
hello.ko

[email protected]:/data/local # insmod hello.ko
[email protected]:/data/local # dmesg -c

<1>Hello,world
[email protected]:/data/local # lsmod
hello 702 0 - Live 0x00000000 (PO)
[email protected]:/data/local # rmmod hello
[email protected]:/data/local # dmesg -c
<1>Goodbye, cruel world
[email protected]:/data/local # lsmod

[email protected]:/data/local #

<1>Hello,world



so, that's ok, good night :_).

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android获取通讯录
  2. android使用actionbar与fragment
  3. android 酷欧天气完整项目
  4. 触摸事件的机制
  5. ui?
  6. Android Volley的简单使用
  7. Android与JS通过JSBridge(BridgeWebView
  8. 下载显示网路图片的例子
  9. Android中的双击事件,GestureDetector无效
  10. android 设置 TextEdit 组件滚动条自动滚