제가 단순한 디바이스 드라이버를 만들고 drivers/char/폴더에 char 디바이스 드라이버 코드를 넣고

drivers/char/폴더의 Kconfig에 만든 디바이스 드라이버 정보를 넣고, Makefile에 디바이스 드라이버의 object를 추가해서

넣었습니다. 그런데 아래의 코드 Simple Device Driver가 정상적으로 포함되어 컴파일이 되었습니다.

그래서 만들어진 uImage (리눅스 커널)을 보드에 넣어서 정상 동작하는 것을 확이했습니다.

그런데 이 드라이버가 추가가 잘 되었는지 확인은 어떻게 하는 것인가요? 단순히 알 수 있는 방법이 없나요?

혹시나해서 제가 mknod해서 노드를 만들고 어플리케이션에서 디바이스 드라이버를 open()해서 사용을 하려고 하니

open했을 때 printk()함수로 커널 메세지가 디스플레이가 되어야 하는데 디스플레이가 되지 않고 있습니다.

그래서 제 짧은 생각으로는 이 문제를 다음과 같이 생각했습니다.

첫째, 제대로 디바이스 드라이버가 커널 추가가 되지 않았다?

둘째, 이 디바이스 드라이가 제가 사용하는 커널 버전에는 맞지 않는 것이 아닌가?

셋째, 먼가 옵션이 빠진 것이 아닌가?

제가 사용하는 커널은 2.6.30 버전입니다. 그리고 아래 코드는 제가 인터넷에서 가져온 단순 디바이스 드라이버 입니다.

리눅스 커널에 디바이스 드라이버를 포함하려면 먼가 빠진 것이 있는거 같은데 고수님들의 조언 부탁드립니다. ㅠㅠ;

======================================Simple Device Driver =========================================


#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#define CALL_DEV_NAME "template"
#define CALL_DEV_MAJOR 512
#define CALL_DEV_SUB 0
/*
Note:
check device name and major device number before test.
usage: mknod /dev/template c 512 0
*/
/*
* IO functions
*/
int template_open (struct inode *inode, struct file *fp)
{
int num = MINOR(inode->i_rdev);
printk ("open function has been called -> minor: \n", num);
// MOD_INC_USE_COUNT; // When use 2.4 kernel - information only
return 0;
}
int template_release (struct inode *inode, struct file *fp)
{
// MOD_DEC_USE_COUNT; // When use 2.4 kernel - information only
printk ("release function has been called\n");
return 0;
}
loff_t template_llseek (struct file *fp,loff_t offset,int whence)
{
printk ("llseek function has been called: off , whence \n", offset,whence);
return offset;
}
ssize_t template_read (struct file *fp, char *buf, size_t count, loff_t *f_pos)
{
printk ("read function has been called: buf , count \n", buf, count);
return count;
}
ssize_t template_write (struct file*fp, const char *buf, size_t count, loff_t *f_pos)
{
printk ("write function has been called: buf , count \n", buf, count);
return count;
}
int template_ioctl (struct inode *inode, struct file *fp, unsigned int cmd, unsigned long arg)
{
printk ("ioctl function has been called: cmd , arg \n", cmd,arg);
return 0;
}
/*
* Assigning functions
*/
struct file_operations template_fops = {
.owner = THIS_MODULE,
.llseek = template_llseek,
.read = template_read,
.write = template_write,
.ioctl = template_ioctl,
.open = template_open,
.release = template_release,
/* check linux/fs.h file for addtional information of this structure */
};
/*
* Initializer and finalizer
*/
static int template_init (void)
{
int res;
printk ("initializer has been called\n");
res = register_chrdev(CALL_DEV_MAJOR, CALL_DEV_NAME, &template_fops);
if (res < 0) return res;
return 0;
};
static void template_exit (void)
{
printk ("finalizer has been called\n");
unregister_chrdev (CALL_DEV_MAJOR, CALL_DEV_NAME);
};
//#ifndef MODULE
/*
* Receiving kernel option such as 'template=1'
*/
static int given_value = 0;
static int __init template_setup (char *str)
{
int passed_values[4];
str = get_options (str, ARRAY_SIZE(passed_values), passed_values);
if (passed_values[0] > 0) given_value = passed_values[1];
return 1;
}
__initcal(template_init);
__setup ("template=", template_setup);
//#endif
//module_init(template_init);
//module_exit(template_exit);
MODULE_LICENSE("Dual BSD/GPL");