hello world 驱动编写

1,hello.c文件

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

 static int __init hello_init(void)

{
printk("hello world! ");
return 0;
}

static void __exit hello_exit(void)
{
printk("byebye ");
return ;
}

module_init(hello_init);    //加载模块时调用  insmod s3c_hello.ko
module_exit(hello_exit);  //卸载模块时调用  rmmod s3c_hello(linux3.0版本以前用rmmod s3c_hello.ko)

MODULE_AUTHOR("suo~");
MODULE_DESCRIPTION("hello world");
MODULE_LICENSE("GPL");

2,编写Makefile

obj-m += s3c_hello.o

modules:
@make -C /home/lingyun/zhoutian/kernel/linux-3.0 M=`pwd` modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

3,tftp -gr s3c_hello.ko

也可以将模块编译进内核(这样很麻烦)

cp s3c_hello.c ../kernel/linux-3.0/drivers/char/

修改Kconfig

config HELLO
bool "hello module"
default y

修改Makefile

obj-$(CONFIG_HELLO)         += s3c_hello.o

原文地址:https://www.cnblogs.com/zhoutian220/p/3953965.html