您的位置:首页 > 其它

好记性不如烂笔头系列:编译ko模块相关

2015-04-07 10:50 316 查看
环境:

[root@ko]# pwd
/home/android/android-4.0/ko
[root@ko]# ls
hello.c  Makefile
[root@omap]# pwd
/home/android/android-4.0/omap
[root@omap]# ls
arch           drivers   Kbuild       mm              scripts
block          firmware  Kconfig      Module.symvers  security
COPYING        fs        kernel       net             sound
CREDITS        include   lib          README          tools
crypto         init      MAINTAINERS  REPORTING-BUGS  usr
Documentation  ipc       Makefile     samples         virt


hello.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

static int __init hello_init(void)
{
printk("hello world!\n");
char cs[2] = {"xy""a"};
printk("cs[1] = %c\n",cs[1]);
int a = 2;
printk("a=%d\n",a);
return 0;
}

static void __exit hello_exit(void)
{
printk("Goodbye\n");
}
module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");


Makefile:

CROSS_COMPILE := /home/android/android-4.0/arm-2010q1/bin/arm-none-eabi-
ARCH := arm
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
obj-m       := hello.o
KDIR        := /home/android/android-4.0/omap
PWD         := $(shell pwd)

modules:
export ARCH=arm          #这句不应该写这里,在命令行运行先,不然make时会导致错误。cc1: error: unrecognized command line option "-m64"
$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
rm *.o -rf
rm *.mod.* -rf
rm *odule* -rf



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: