Linux Kernel Driver.

Slides:



Advertisements
Similar presentations
DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Advertisements

Linux device-driver issues
Linux Device Drivers & Project3 preview CSC345. Project 3 Preview Write a device driver for a pseudo stack device Idea from
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Device Drivers cs423, Fall 2007 Klara Nahrstedt/Sam King 6/6/20141.
RT_FIFO, Device driver.
Sogang University Advanced Operating Systems (Linux Device Drivers) Advanced Operating Systems (Linux Device Drivers) Sang Gue Oh, Ph.D.
Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Computer System Laboratory
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
USERSPACE I/O Reporter: R 張凱富.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Management.
Memory management.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
Embedded Systems Programming Writing Device Drivers.
63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03.
File System Implementation
CSE 451 Section 4 Project 2 Design Considerations.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Device Drivers In Linux © Gregory Kesden Fall 2000.
EECS 498 Advanced Embedded Systems Lecture 4: Linux device drivers and loadable kernel modules.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
M. Muztaba Fuad Advanced Operating System Project Device Drivers.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
Therac-25 Computer-controlled radiation therapy machine
Operating System Program 5 I/O System DMA Device Driver.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Modules and Device Drivers (ESP – Fall 2014) Computer Science & Engineering Department.
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
Lecture 2: Linux devices Roei Ben-Harush Agenda 1 1 Linux Devices About next Assignment Roei Ben-Harush 2015 Reminder.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
UNIX Files File organization and a few primitives.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
K ERNEL D EVELOPMENT CSC585 Class Project Dawn Nelson December 2009.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
Linux Device Driver 2009/04/08. Reference Book Another Reference Book Embedded Linux Primer: A Practical, Real-World Approach By Christopher Hallinan.
Interfacing Device Drivers with the Kernel
Laface 2007 File system 2.1 Operating System Design Filesystem system calls buffer allocation algorithms getblk brelse bread breada bwrite iget iput bmap.
Lecture 19 Linux/Unix – File System
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
CSE333 SECTION 3. Important Dates Jan 27 th – Homework 1 Due Feb 6 th – Midterm.
ICOM Noack Linux I/O structure Device special files Device switch tables and fops How the kernel finds a device Parts of a device driver or module.
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT Keun Soo Yim University of Illinois at Urbana-Champaign Department of Computer Science CS423 – Fall 2011.
Finish up OS topics Group plans. Today Finish up and review Linux device driver stuff – Walk example again – See how it all goes together – Discuss talking.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
 LED 를 직접 제어하는 디바이스 드라이버를 작성해 보자  Reminder: LED 는 SPI 를 통해 ARM7 과 연결된다. ◦ 그렇다면 고쳐야 하는 코드는 어디에 ?  linux-2.6.x/arch/arm/mach-nds/arm7 ◦ Hardware spec.
Input/Output (I/O) Important OS function – control I/O
Linux Device Model A device model after 2.5
Device Driver_Skeleton
Chapter 7-Android HAL 中国科学技术大学软件学院.
Introduction to Developing Embedded Linux Device Drivers
Lecture 3 Module Programming and Device Driver (Homework#1 included)
Lecture 31: Introduction to File System
Want to play a game? – Linux Kernel Modules
Scull device 사용 예 강서일( ) 최정욱( ).
ThreadOS: File System Implementation
Introduction to Linux Device Drivers
מערכות הפעלה ערן טרומר סמסטר א' תשע"ב
CSE 333 – Section 3 POSIX I/O Functions.
chapter 3-Char Device Driver
CSE 333 – Section 3 POSIX I/O Functions.
Computer System Laboratory
Loadable Kernel Modules
The File Manager Implementation issues
Presentation transcript:

Linux Kernel Driver

Char Driver: Basics Contact details exported to user space using /dev: bash$ ls -l /dev total 0 brw-rw---- 1 root disk 8, 0 2010-02-09 13:01 /dev/sda brw-rw---- 1 root disk 8, 1 2010-02-09 13:01 /dev/sda1 brw-rw---- 1 root disk 8, 2 2010-02-09 13:01 /dev/sda2 ... crw--w---- 1 root root 4, 0 2010-02-09 13:01 /dev/tty0 crw------- 1 root root 4, 1 2010-02-09 12:01 /dev/tty1 crw------- 1 root root 4, 2 2010-02-09 12:01 /dev/tty2 Block device Char device Major number Minor number

Char Driver: Codeflow Initialization Tie driver to the rest of the kernel I/O system entry points Read, write, open, seek, close (Interrupt routines) Cleanup

Char Driver: Initialization #define DEVICE_NAME “rot13crypt” struct cdev crypt_cdev; static dev_t crypt_dev; static struct file_operations crypt_fops = { ... }; static int __init crypt_init(void) { int result; result = alloc_chrdev_region(&crypt_dev, 0, 1, DEVICE_NAME); /* dynamic allocation van device major number */ /* connect file operations with character dev */ cdev_init(&crypt_cdev, &crypt_fops); result = cdev_add(&crypt_cdev, crypt_dev, 1); return 0; } module_init(crypt_init) Kernel abstraction for character drivers Addresses of IO system entry points

Char Driver: Cleanup static void __exit crypt_cleanup(void) { /* Remove the cdev */ cdev_del(&crypt_cdev); /* Release the major number */ unregister_chrdev_region(MAJOR(crypt_dev), 1); } module_exit(crypt_cleanup)

Char Driver: Entry points static struct file_operations crypt_fops = { .owner = THIS_MODULE, .read = crypt_read, .write = crypt_write, .open = crypt_open, .release = crypt_close, }; /* Called when application opens device node */ int crypt_open(struct inode *inode, struct file *file) { return 0; } /* Called when application closes device node */ int crypt_release(struct inode *inode, struct file *file) {

Char Device: read/write char *kbuf = NULL; static ssize_t crypt_write(struct file * file, const char * buf, size_t count, loff_t *ppos) { kbuf = kmalloc(count, GFP_KERNEL); if( buf == NULL ) return -ENOMEM; /* Copy the characters to kernel memory */ if( copy_from_user(kbuf, buf, count) ) { kfree(kbuf); return -EFAULT; } return nbyteswritten; static ssize_t crypt_read(struct file * file, char * buf, size_t count, loff_t *ppos) { if( copy_to_user(buf, kbuf, count) ) { return -EIO; return nbytesread;

Kernel Memory kmalloc, kfree Flag specifies the type of memory copy_[from|to]_user Copy data between user and kernel memory Between different virtual memory mappings

Practical Driver prints major number (see dmesg) Or 'cat /proc/devices | grep rot13crypt' minor = 0 mknod /dev/rot13crypt c major minor echo “string” > /dev/rot13crypt Calls open, write and close cat /dev/rot13crypt Calls open, read, close

Implementation Implement rot13 “encryption” The transformation done using a lookup table: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm

Build Makefile bash$ make obj-m := rot13crypt.o kernel_release=`uname -r` all: make -C /lib/modules/${kernel_release}/build/ SUBDIRS=${PWD} modules