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
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
root@android:/# CD data/local/
Root@android:/data/local # ls
Hello.ko
Root@android:/data/local # Insmod Hello.ko
Root@android:/data/local # Dmesg-c
<1>hello,world
Root@android:/data/local # Lsmod
Hello 702 0-live 0x00000000 (PO)
Root@android:/data/local # Rmmod Hello
Root@android:/data/local # Dmesg-c
<1>goodbye, Cruel World
Root@android:/data/local # Lsmod
Root@android:/data/local #
<1>hello,world
So, that ' s OK, good night: _).
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/