现在的位置: 首页 > 综合 > 正文

Linux hello world 驱动

2018年01月11日 ⁄ 综合 ⁄ 共 444字 ⁄ 字号 评论关闭

1.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 int hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
    return 0;
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("Beyond");

2.Makefile

obj-m := hello.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

【上篇】
【下篇】

抱歉!评论已关闭.