/ 임베디드시스템개요 / 임베디드운영체제 / 디바이스드라이버
01 Linux System Architecture Application Area Application System Call Interface BSD Socket Virtual File System INET(AF_INET) Kernel Area Buffer Cache Network Subsystem Transport(TCP, UDP) Network(IP) Character Device Driver Block Device Driver Network Device Driver Device Interface Hardware Hardware
02 디바이스드라이버의개념 Device 란? 하드디스크, 플로피디스크, 프린터, 단말기, 스캐너와같이컴퓨터시스템이외의다른주변장치 Device on Linux Linux 에서 Device 는파일을통해서접근가능 사용자는 File operation 을적용할수있음 Major number 와 Minor number 를가짐
02 디바이스드라이버의개념 Device Driver 서브루틴과데이터의집합체 Device와시스템사이에데이터를주고받기위한 Interface 표준적으로동일한서비스제공을목적디바이스의고유한특성을감춤커널의일부분으로내장
02 디바이스드라이버의개념 Device Driver Overview Linux Kernel Device Interface Table Boot code blkdevs[] chrdevs[] int code X_open() X_release() X_read() X_write() X_ioctl() X_int() X_init() Interrupt Y_open() Y_release() Y_read() Y_write() Y_ioctl() Y_int() Y_init() X_controller Z_open() Z_release() Z_readl() Z_write() Z_ioctl() Z_int() Z_init() Set of Registers dev1 dev2 dev3
02 디바이스드라이버의개념 1. Char Device Char device 의특징 1 2 3 4 자료의순차성을지닌장치버퍼캐쉬를사용하지않음장치의 raw data를사용자에게제공 Console, Tape, Keyboard, Sound Card, Scanner, Printer Char device on Linux null : black hole tty* : virtual console pt* : pseudo-terminal crw--w--w- 0 root root 5, 1 Oct 1 1998 console crw-rw-rw- 1 root root 1, 3 May 6 1998 null crw------- 1 root root 4, 0 May 6 1998 tty crw-rw---- 1 root disk 96, 0 Dec 10 1998 pt0 crw------- 1 root root 5, 64 May 6 1998 cua0
02 디바이스드라이버의개념 2. Block device Block device 특징 1 2 3 4 5 random access 가능버퍼캐쉬에의한내부장치표현파일시스템에의해 mount 되어관리되는장치블록단위의입출력이가능한장치디스크, CD-ROM, Floppy Char device on Linux fd* : Floppy disk sd* : Hard disk brw------- 1 root floppy 2, 0 May 6 1998 fd0 brw-rw---- 1 root disk 8, 0 May 6 1998 sda brw-rw---- 1 root disk 8, 1 May 6 1998 sda1
02 디바이스드라이버의개념 Major & Minor Number Major number Link to the Device 같은 Device 의종류를지칭, 1Byte ( 주번호 ) Minor number 각 Device 의부가적인정보를나타냄, 1Byte ( 부번호 ) brw-rw---- 1 root disk 1, 0 May 6 1998 sda brw-rw---- 1 root disk 1, 1 May 6 1998 sda1 brw-rw---- 1 root disk 1, 2 May 6 1998 sda2 brw-rw---- 1 root disk 1, 3 May 6 1998 sda3
03 디바이스드라이버의개발과정 1 Make new device driver functions struct file_operations 정의 init_module, cleanup_module 정의 2 Register device driver to the kernel Select unused major and minor number register_chrdev() register_blkdev() register_netdev() 3 Make special file mknod
03 디바이스드라이버의개발과정 1. File Operation <linux/fs.h> loff_t (*llseek)(struct file *, loff_t, int); 현재의 read/write 위치를옮긴다. ssize_t (*read)(struct file *, char *, size_t, loff_t *); 디바이스에서데이터를가져오기위해서사용 ssize_t (*write)(struct file*, const char*, size_t, loff_t*); 디바이스에데이터를쓰기위해서사용 int (*readdir)(struct file *, void *, filldir_t); 디렉토리를다룰때사용 unsigned int (*poll)(struct file*, struct poll_table_struct*); 현재프로세스를대기큐에넣기위해서사용
03 디바이스드라이버의개발과정 1. File Operation int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 디비아스에종속적인명령을만들기위해사용 Int (*mmap) (struct file *, struct vm_area_struct *); 디바이스메모리를프로세스메모리에매핑 int (*open) (struct inode *, struct file *); 디바이스노드에의해수행되는첫번째동작 int (*flush) (struct file *); 디바이스를닫기전에모든데이터를쓴다. int (*release) (struct inode *, struct file *); 디바이스를닫을때수행
03 디바이스드라이버의개발과정 2. Making Special File mknod (Linux Command) make block or character special files device node라고부름 mknod [OPTION]... NAME TYPE [MAJOR MINOR] $ mknod fd0 b 5 3 Minor number Major number b(block) or c(char) Device Name
03 디바이스드라이버의개발과정 3. etc. Device 의정보를가지는 File 들 /proc/devices 현재 System 에장착되어있는 Device 들의정보 /usr/src/linux/documentation/devices.txt 현재 Linux System 에서정의되어있는 Device 들의 Major, Minor Number 들에대한정보 /usr/src/linux/include/linux/major.h Major Number 를 define 한 header
03 디바이스드라이버의개발과정 4. Skeleton Device Driver 개발환경과 DD 및 App 실행과정 Host 용터미널 (Edit, compile) Minicom ( 타겟용터미널 ) JTAG cable Target HOST HDD test.c test 1.Edit sk.c sk.ko make 2Cross compile Backend Serial cable Ethernet cross cable RAMDISK test 6../test 3. 전송 (Zmodem) /dev/sk sk.ko 4.insmod Memory wmlinux test 5.mknod sk.o