一个hello程序的android模块编译方法及在模拟器中进行测试结论

/*********************************************************************
 * 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

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

一个hello程序的android模块编译方法及在模拟器中进行测试结论,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。