环境:
[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