kernel configuration kernel MTD file system mount system

  • Slides: 33
Download presentation

kernel configuration • 기본 kernel 부팅을 위한 설정들 • MTD file system을 mount하기 위한

kernel configuration • 기본 kernel 부팅을 위한 설정들 • MTD file system을 mount하기 위한 설정들

system type

system type

Serial drivers • Device drivers -> Character devices -> Serial drivers

Serial drivers • Device drivers -> Character devices -> Serial drivers

Boot options

Boot options

MTD • Device drivers -> Memory Technology Devices (MTD) ->

MTD • Device drivers -> Memory Technology Devices (MTD) ->

MTD • Device drivers -> Memory Technology Devices (MTD) -> Ram/Rom/Flash chip drivers

MTD • Device drivers -> Memory Technology Devices (MTD) -> Ram/Rom/Flash chip drivers

MTD • Device drivers -> Memory Technology Devices (MTD) -> Mapping drivers for chip

MTD • Device drivers -> Memory Technology Devices (MTD) -> Mapping drivers for chip access

File systems • File systems -> Miscellaneous filesystems ->

File systems • File systems -> Miscellaneous filesystems ->

실습 : 커널 모듈 작성 • Hello World 프로그램 /* hello. c */ –

실습 : 커널 모듈 작성 • Hello World 프로그램 /* hello. c */ – 모듈이 로딩될 때 #include <linux/module. h> /* 모든 모듈에 필요 */ #include <linux/kernel. h> /* printk() 등에 필요 */ • Hello world 출력 – 모듈이 제거될 때 int hello_init(void) { // 모듈이 로딩될 때 호출 printk (“Hello worldn”); return 0; } • Goodbye world 출력 void hello_exit(void) { // 제거 될 때 호출 printk (“Goodbye world”); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE(“GPL”); 문자 디바이스 드라이버 11

리눅스 디바이스 드라이버의 종류(2) Application area Application System Call Interface VFS Kernel area Character

리눅스 디바이스 드라이버의 종류(2) Application area Application System Call Interface VFS Kernel area Character D/D Buffer Cache Network Subsystem Block D/D Network D/D Device Interface Hardware 문자 디바이스 드라이버 Hardware 16

문자 디바이스 드라이버 기본 골격 #include <linux/kernel. h> #include <linux/module. h> #include <linux/init. h>

문자 디바이스 드라이버 기본 골격 #include <linux/kernel. h> #include <linux/module. h> #include <linux/init. h> 헤더 파일 int device_open( … ) { … } int device_release( … ) { … } ssize_t device_write( … ) { … } ssize_t device_read( … ) { … } 파일 연산 함수 정의 static struct file_operations device_fops = { … ssize_t (*read) (…); ssize_t (*write) (…); … int (*open) (…); int (*release) (…); … }; 파일 연산 구조체 int init_module(void) { … } void cleanup_module(void) { … } module_init(hello_init); module_exit(hello_exit); 문자 디바이스 드라이버 19

실습 : Dummy 디바이스 드라이버 작성 • 헤더 파일 및 매크로 정의 #include <linux/module.

실습 : Dummy 디바이스 드라이버 작성 • 헤더 파일 및 매크로 정의 #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 DUMMY_NAME “dummy” #define DUMMY_MAJOR_NUMBER 240 문자 디바이스 드라이버 24

실습 : Dummy 디바이스 드라이버 작성(2) • 드라이버 등록 static int dummy_init(void) { int

실습 : Dummy 디바이스 드라이버 작성(2) • 드라이버 등록 static int dummy_init(void) { int ret; printk(“dummy initn”); ret = register_chrdev(DUMMY_MAJOR_NUMBER, DUMMY_NAME, &dummy_fops); if (res < 0) return ret; return 0; } module_init(dummy_init); 문자 디바이스 드라이버 25

실습 : Dummy 디바이스 드라이버 작성(3) • 드라이버 제거 static void dummy_exit(void) { printk(“dummy

실습 : Dummy 디바이스 드라이버 작성(3) • 드라이버 제거 static void dummy_exit(void) { printk(“dummy exitn”); unregister_chrdev( DUMMY_MAJOR_NUMBER, DUMMY_NAME); } module_exit(dummy_exit); MODULE_LICENSE(“GPL”); 문자 디바이스 드라이버 26

실습 : Dummy 디바이스 드라이버 작성(4) • 파일 연산 구조체 정의 struct file_operations dummy_fops

실습 : Dummy 디바이스 드라이버 작성(4) • 파일 연산 구조체 정의 struct file_operations dummy_fops = { . owner = THIS_MODULE, . open = dummy_open, . read = dummy_read, . write = dummy_write, . ioctl = dummy_ioctl, . release = dummy_release, }; 문자 디바이스 드라이버 27

실습 : Dummy 디바이스 드라이버 작성(5) • open & release int dummy_open(struct inode *inode,

실습 : Dummy 디바이스 드라이버 작성(5) • open & release int dummy_open(struct inode *inode, struct file *filep) { int num = MINOR(inode->i_rdev); printk(“dummy dev open -> minor %dn”, num); return 0; } int dummy_release(struct inode *inode, struct file *filep) { printk(“dummy dev closen”); return 0; } 문자 디바이스 드라이버 28

실습 : Dummy 디바이스 드라이버 작성(6) • read & write size_t dummy_read(struct file *filep,

실습 : Dummy 디바이스 드라이버 작성(6) • read & write size_t dummy_read(struct file *filep, char *buf, size_t count, loff_t *f_pos) { printk(“dummy dev read -> buf 0 x%08 x, count 0 x%08 xn”, buf, count); return 0 x 33; } size_t dummy_write(struct file *filep, const char *buf, size_t count, loff_t *f_pos) { printk(“dummy dev write -> buf 0 x%08 x, count 0 x%08 xn”, buf, count); return 0 x 43; } 문자 디바이스 드라이버 29

실습 : Dummy 디바이스 드라이버 작성(7) • ioctl int dummy_ioctl(struct inode *inode, struct file

실습 : Dummy 디바이스 드라이버 작성(7) • ioctl int dummy_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg) { printk(“dummy dev ioctl -> cmd 0 x%08 x, arg 0 x%08 xn”, cmd, arg); return 0 x 53; } 문자 디바이스 드라이버 30

실습 : Dummy 드라이버를 제어하기 위한 어플리케이션 작성 • app. c #include <stdio. h>

실습 : Dummy 드라이버를 제어하기 위한 어플리케이션 작성 • app. c #include <stdio. h> #include <sys/types. h> #include <sys/stat. h> #include <sys/ioctl. h> #include <fcntl. h> #include <unistd. h> printf(“ 2> read functionn”); #define DEV_NAME “/dev/dummy_device” ret = write(dev, 0 x 40, 0 x 41); printf(“ret = 0 x%x 08 xn”, ret); ret = read(dev, 0 x 30, 0 x 31); printf(“ret = 0 x%x 08 xn”, ret); printf(“ 3> write functionn”); int main() { int dev; char buf[128]; int ret; printf(“ 4> ioctl functionn”); ret = ioctl(dev, 0 x 51, 0 x 52); printf(“ret = 0 x%x 08 xn”, printf(“ 1> device openn”); printf(“ 5> device closen”); dev = open(DEV_NAME, O_RDWR|O_NDELAY); ret = close(dev); printf(“ret = 0 x%x 08 xn”, ret); } printf(“dev %dn”, dev); if (dev >= 0) { 문자 디바이스 드라이버 return 0; } 31