Linux Device Driver. Analog/Digital Signal Interfacing

Similar documents
CPSC Tutorial 17

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014

Linux Kernel Modules & Device Drivers April 9, 2012

Workspace for '5-linux' Page 1 (row 1, column 1)

Step Motor. Step Motor Device Driver. Step Motor. Step Motor (2) Step Motor. Step Motor. source. open loop,

CS 378 (Spring 2003)

Virtual File System (VFS) Implementation in Linux. Tushar B. Kute,

Unix (Linux) Device Drivers

Operating Systems. V. Input / Output. Eurecom

INSTRUMENTATION. using FREE/OPEN CODE

Operating Systems. V. Input / Output

USB. Development of a USB device driver working on Linux and Control Interface. Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi

Linux Device Drivers. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5. Interrupts

3 Character Drivers. 3.1 The Design of scullc. Linux Device Drivers in Assembly

Operating Systems II BS degree in Computer Engineering Sapienza University of Rome Lecturer: Francesco Quaglia. Topics: 1.

ELEC 377 Operating Systems. Week 4 Lab 2 Tutorial

Loadable Kernel Module

Linux Loadable Kernel Modules (LKM)

Chapter 12 IoT Projects Case Studies. Lesson-01: Introduction

Linux drivers - Exercise

The kernel constitutes the core part of the Linux operating system. Kernel duties:

Overview. I/O Devices. Memory Access. Device Controller. Advanced Operating System Project. Device Drivers. M. Muztaba Fuad

Linux Kernel Module Programming. Tushar B. Kute,

Kernel Modules. Kartik Gopalan

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

What is a Linux Device Driver? Kevin Dankwardt, Ph.D. VP Technology Open Source Careers

INSTRUMENTATION. using FREE/OPEN CODE

Operating System Concepts Ch. 11: File System Implementation

Comp 204: Computer Systems and Their Implementation. Lecture 18: Devices

Devices. Today. Comp 104: Operating Systems Concepts. Operating System An Abstract View 05/01/2017. Devices. Devices

Introduction Reading Writing scull. Linux Device Drivers - char driver

Lecture 1. Virtualization, Linux kernel (modules and networking) and Netfilter Winter 15/16. Roei Ben-Harush 2015

To understand this, let's build a layered model from the bottom up. Layers include: device driver filesystem file

Intrusion Prevention Method on LKM (Loadable Kernel Module) Backdoor Attack. Ji-Ho CHO, Han LEE, Jeong-Min KIM and Geuk LEE *

Finish up OS topics Group plans

MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT

PCI 32 BIT Multi I/O Cards Linux Kernel 2.4 Installation Guide

Virtual File System. Don Porter CSE 306

Device Drivers. CS449 Fall 2017

Linux Shell, 1 LKM Journal of Software /2002/13(01) Vol.13, No.1

The device driver (DD) implements these user functions, which translate system calls into device-specific operations that act on real hardware

Linux Device Drivers

Linux Device Drivers. 3. Char Drivers cont. 3. Char Drivers. 1. Introduction 2. Kernel Modules 3. Char Drivers 4. Advanced Char Drivers 5.

CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A)

Loadable Kernel Modules

PMON Module An Example of Writing Kernel Module Code for Debian 2.6 on Genesi Pegasos II

RCU. ò Dozens of supported file systems. ò Independent layer from backing storage. ò And, of course, networked file system support

Designing and developing device drivers. Coding drivers

Oracle Linux 7: System Administration Ed 1 LVC

Design and Implementation of an Asymmetric Multiprocessor Environment Within an SMP System. Roberto Mijat, ARM Santa Clara, October 2, 2007

First order of Business

Software Layers. Device Drivers 4/15/2013. User

The Device Driver Interface. Input/Output Devices. System Call Interface. Device Management Organization

Modules. Mail: Web: University of Nice - Sophia Antipolis

University of Texas at Arlington. CSE Spring 2018 Operating Systems Project 4a - The /Proc File Systems and mmap. Instructor: Jia Rao

Virtual File System. Don Porter CSE 506

Introduction p. 1 Why Linux? p. 2 Embedded Linux Today p. 3 Open Source and the GPL p. 3 Free Versus Freedom p. 4 Standards and Relevant Bodies p.

Loadable Kernel Modules Juan-Mariano de Goyeneche and Elena Apolinario Fernández de Sousa, Technical University of Madrid

Oracle Linux 7: System Administration Ed 1

NPTEL Course Jan K. Gopinath Indian Institute of Science

Oracle Linux 7: System Administration Ed 1

NPTEL Course Jan K. Gopinath Indian Institute of Science

Hardware-Assisted Intrusion Monitoring System (HAIMS TM )

Table of Contents. Preface... xi

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

File System (FS) Highlights

Make Your Own Linux Module CS 444/544

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Networks and Operating Systems ( ) Chapter 9: I/O Subsystems

VIRTUAL FILE SYSTEM AND FILE SYSTEM CONCEPTS Operating Systems Design Euiseong Seo

CS330: Operating System and Lab. (Spring 2006) I/O Systems

Storage Systems. NPTEL Course Jan K. Gopinath Indian Institute of Science

Oracle Linux 7: System Administration Ed 2 Duration: 5 Days

/dev/hello_world: A Simple Introduction to Device Drivers under Linux

Operating Systems. II. Processes

The bigger picture. File systems. User space operations. What s a file. A file system is the user space implementation of persistent storage.

Lecture 4: Extensibility (and finishing virtual machines) CSC 469H1F Fall 2006 Angela Demke Brown

Linux File System Study Guide

Linux Distribution: Kernel Configuration

NVDIMM Overview. Technology, Linux, and Xen

GNV / bash für OpenVMS

Operating Systems 2010/2011

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

CptS 360 (System Programming) Unit 6: Files and Directories

I/O Systems. Jo, Heeseung

I/O and Device Drivers

User Space Device Drivers Introduction and Implementation using VGAlib library

Oracle Linux 7: System Administration Ed 2 NE

AVT Cameras and Linux

Filesystem. Disclaimer: some slides are adopted from book authors slides with permission 1

Chapter 12: File System Implementation

Linux Kernel Development (LKD)

Input & Output 1: File systems

Advanced Operating Systems #13

Oracle Linux System AdministrationNEW

Oracle Linux 5 & 6 System Administration TOD

Network File System (NFS)

Data Block. Data Block. Copy A B C D P HDD 0 HDD 1 HDD 2 HDD 3 HDD 4 HDD 0 HDD 1

Abstraction via the OS. Device Drivers. Software Layers. Device Drivers. Types of Devices. Mechanism vs. Policy. Jonathan Misurda

Chapter 8: Filesystem Implementation

Transcription:

Linux Device Driver Analog/Digital Signal Interfacing

User Program & Kernel Interface

Loadable Kernel Module(LKM) A new kernel module can be added on the fly (while OS is still running) LKMs are often called kernel modules They are not user program

Loadable Kernel Module (LKM) A new kernel module can be added on the fly (while OS is still running) LKMs are often called kernel modules They are not user program

Types of LKM Device drivers Filesystem driver (one for ext2, MSDOS FAT16, 32, NFS) System calls Network Drivers TTY line disciplines. special terminal devices. Executable interpreters.

Basic LKM (program) Every LKM consist of two basic functions (minimum) : int init_module(void) /*used for all initialition stuff*/ {... } void cleanup_module(void) /*used for a clean shutdown*/ {... } Loading a module - normally retricted to root - is managed by issuing the follwing command: # insmod module.o

LKM Utilities cmd insmod Insert an LKM into the kernel. rmmod Remove an LKM from the kernel. depmod Determine interdependencies between LKMs. kerneld Kerneld daemon program ksyms Display symbols that are exported by the kernel for use by new LKMs. lsmod List currently loaded LKMs. modinfo Display contents of.modinfo section in an LKM object file. modprobe Insert or remove an LKM or set of LKMs intelligently. For example, if you must load A before loading B, Modprobe will automatically load A when you tell it to load B.

Common LKM util cmd Create a special device file % mknode /dev/driver c 40 0 Insert a new module % insmod modname Remove a module %rmmod modname List module % lsmod Or % more /proc/modules audio 37840 0 cmpci 24544 0 soundcore 4208 4 [audio cmpci] nfsd 70464 8 (autoclean)

Linux Device Drivers A set of API subroutines (typically system calls) interface to hardware Hide implementation and hardware-specific details from a user program Typically use a file interface metaphor Device is a special file

Linux Device Drivers (continued) Manage data flow between a user program and devices A self-contained component (add/remove from kernel) A user can access the device via file name in /dev, e.g. /dev/lp0

General implementation steps 1. Understand the device characteristic and supported commands. 2. Map device specific operations to unix file operation 3. Select the device name (user interface) Namespace (2-3 characters, /dev/lp0) 4. (optional) select a major number and minor (a device special file creation) for VFS interface Mapping the number to right device sub-routines 5. Implement file interface subroutines 6. Compile the device driver 7. Install the device driver module with loadable kernel module (LKM) 8. or Rebuild (compile) the kernel

Read/write (I/O) Polling Interrupt based

Device Driver interface Note: This picture is excerpted from Write a Linux Hardware Device Driver, Andrew O Shauqhnessy, Unix world

VFS & Major number principal interface between a device driver and Linux kernel

File operation structure struct file_operations Fops = { NULL, /* seek */ xxx_read, xxx_write, NULL, /* readdir */ NULL, /* select */ NULL, /* ioctl */ NULL, /* mmap */ xxx_open, NULL, /* flush */ xxx_release /* a.k.a. close */ }; struct file_operations Fops = { read: xxx_read, write: xxx_write, open: xxx_open, release: xxx_release, /* a.k.a. close */ }; Watch out compatibility issue with Linux version

Device special file Device number Major (used to VFS mapping to right functions) Minor (sub-devices) mknod /dev/stk c 38 0 ls l /dev/tty crw-rw-rw- 1 root root 5, 0 Apr 21 18:33 /dev/tty

Register and unregister device int init_module(void) /*used for all initialition stuff*/ { /* Register the character device (atleast try) */ Major = register_chrdev(0, DEVICE_NAME, &Fops); : } void cleanup_module(void) /*used for a clean shutdown*/ {ret = unregister_chrdev(major, DEVICE_NAME);... }

Register and unregister device compile -Wall -DMODULE -D KERNEL -DLINUX DDEBUG -I /usr/include/linux/version.h -I/lib/modules/`uname -r`/build/include Install the module %insmod module.o List the module %lsmod If you let the system pick Major number, you can find the major number (for special creation) by % more /proc/devices Make a special file % mknod /dev/device_name c major minor

Device Driver Types A character device driver ( c ) Most devices are this type (e.g.modem, lp, USB No buffer. A block device driver (b) through a system buffer that acts as a data cache. Hard drive controller and HDs

Implementation Assuming that your device name is Xxx Xxx_init() initialize the device when OS is booted Xxx_open() open a device Xxx_read() read from kernel memory Xxx_write() write Xxx_release() clean-up (close) init_module() cleanup_module()