ubuntu10.04下驱动编程hello world

1.驱动源码:

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

2.编写Makefile:

obj-m := hello.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD       := $(shell pwd)

all:
	$(MAKE) -C $(KERNELDIR) M=$(PWD)

3.然后执行make

4.安装模块:insmod ./hello.ko

5.删除模块:rmmode ./hello.ko

你可能感兴趣的:(Linux编程)