배우고픈 공돌이

디바이스 드라이버 - 간단한 모듈 작성 본문

디바이스 드라이버

디바이스 드라이버 - 간단한 모듈 작성

내 마음 아홉수 2017. 9. 18. 15:07







- skeleton.c


#include <linux/module.h>

#include <linux/init.h>

#include <linux/kernel.h>

#include <linux/fs.h>


int result;

struct file_operations sk_fops;


//#insmod skeleton.ko <- init_module()  

//          Linux 3.x <- 2.x

static int skeleton_init(void)

{

printk("skeleton init success\n");

result = register_chrdev(0,"skeleton",&sk_fops);

//include kernel.h

printk("major number : %d\n",result);


return 0;

}


//#rmmod skeleton <- cleanup_module()

static void skeleton_exit(void)

{

unregister_chrdev(result,"skeleton");

printk("skeleton exit success\n");

}


//include init.h

module_init(skeleton_init);

module_exit(skeleton_exit);


//include module.h

//open source(no free source)

MODULE_LICENSE("GPL");



-Makefile


KDIR = /lib/modules/$(shell uname -r)/build

PWD = $(shell pwd)

TARGET = skeleton


obj-m = $(TARGET).o


all :

$(MAKE) -C $(KDIR) M=$(PWD) modules

cp $(TARGET).ko ../


clean :

$(MAKE) -C $(KDIR) M=$(PWD) clean




'디바이스 드라이버' 카테고리의 다른 글

1. 부번호 처리  (0) 2017.11.15
misc 장치에 등록하기  (0) 2017.09.20
디바이스 드라이버 - APP Open & Read  (0) 2017.09.19
2016] 모듈 제작에 대한 동영상  (0) 2017.09.19
디바이스 드라이버 - insmod  (0) 2017.09.18
Comments