上文中提到了kconfig文件修改,
在里面加入了
config EmbedSky_HELLO
tristate "TQ2440/SKY2440 Hello Driver"
depends on ARCH_S3C2440
help
EmbedSky TQ2440/SKY2440 Hello.
这几行代码,表示要编译EmbedSky_HELLO这个驱动进去,我们还要作的工作是
修改同母录下的makefile文件
在makefile里加入了这一行,
obj-$(CONFIG_EmbedSky_HELLO) += EmbedSky_hello.o
然后在内核编译选项里选定,后直接编译内核,或是使用命令#make SUBDIR=drivers/char/ modules,然后编译出驱动模块。
我们来看看驱动模块
*************************************
NAME:EmbedSky_hello.c
COPYRIGHT:www.embedsky.net
*************************************/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>
MODULE_LICENSE("GPL");
static int __init EmbedSky_hello_init(void) //insmod驱动的时候,系统会自动调用的函数。
{
printk("<1>/n Hello,EmbedSky!/n");
printk("<1>/nThis is first driver program./n/n");
return 0;
}
static void __exit EmbedSky_hello_exit(void)
{
printk("<1>/n Exit!/n");
printk("<1>/nGoodbye EmbedSky!/n/n");
}
module_init(EmbedSky_hello_init);
module_exit(EmbedSky_hello_exit);
很简短的一段代码,但是似乎只能在内核里打印出几行字,没有跟硬件交互。
GPIO的驱动明天再看。