一个hello程序的android内核模块编译,一個hello程序的android內核模塊編譯方法及在模擬器中進行測試結論...

hello module source:

#include

#include

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

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 :_).

查看本欄目更多精彩內容:http://www.bianceng.cn/OS/extra/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值