Linux 交叉编译 module 范本

hello.c

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("DUal BSD/GPL");

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);

交叉编译Makefile

obj-m := hello.o
KDIR := /home/lah/linux-2.6.31
PWD := $(shell pwd)
CROSS_ARCH := ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
default:
 $(MAKE) $(CROSS_ARCH) -C $(KDIR) M=$(PWD) modules
clean:
 rm -rf *.cmd *.o *.mod.c

直接编译,非交叉编译Makefile

obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
 $(MAKE) -C $(KDIR) M=$(PWD) modules

相关推荐