Introduction to Developing Embedded Linux Device Drivers

Slides:



Advertisements
Similar presentations
Lecture 101 Lecture 10: Kernel Modules and Device Drivers ECE 412: Microcomputer Laboratory.
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
RT_FIFO, Device driver.
Computer System Laboratory
USERSPACE I/O Reporter: R 張凱富.
04/14/2008CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
Embedded System Programming Introduction to Device Drivers.
04/16/2010CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying an earlier edition.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
Computer System Laboratory
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
An Introduction to Device Drivers Sarah Diesburg COP 5641 / CIS 4930.
M. Muztaba Fuad Advanced Operating System Project Device Drivers.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux.
Segmentation & O/S Input/Output Chapter 4 & 5 Tuesday, April 3, 2007.
I/O Systems I/O Hardware Application I/O Interface
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS6: Device Management 6.1. Principles of I/O.
Ethernet Driver Changes for NET+OS V5.1. Design Changes Resides in bsp\devices\ethernet directory. Source code broken into more C files. Native driver.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
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.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
An Introduction to Device Drivers Ted Baker  Andy Wang COP 5641 / CIS 4930.
Linux API Dr. Michael L. Collard 1.
Interfacing Device Drivers with the Kernel
Silberschatz, Galvin and Gagne  Operating System Concepts Six Step Process to Perform DMA Transfer.
User-Space-to-Kernel Interface
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
4P13 Week 12 Talking Points Device Drivers 1.Auto-configuration and initialization routines 2.Routines for servicing I/O requests (the top half)
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems Overview I/O Hardware Application.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
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.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
Tgt: Framework Target Drivers FUJITA Tomonori NTT Cyber Solutions Laboratories Mike Christie Red Hat, Inc Ottawa Linux.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Introduction to Operating Systems Concepts
Chapter 13: I/O Systems.
Linux Device Model A device model after 2.5
Module 12: I/O Systems I/O hardware Application I/O Interface
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Linux Details: Device Drivers
Linux Kernel Module Programming
Computer System Laboratory
Linux Kernel Driver.
The PCI bus (Peripheral Component Interconnect ) is the most commonly used peripheral bus on desktops and bigger computers. higher-level bus architectures.
Introduction to the Kernel and Device Drivers
An Introduction to Device Drivers
CSCI 315 Operating Systems Design
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
Kernel Structure and Infrastructure
Chapter 5: I/O Systems.
Department of School of Computing and Engineering
Linux Details: Device Drivers
Linux Architecture Overview.
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Implementation of Embedded OS
Computer System Laboratory
Loadable Kernel Modules
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

Introduction to Developing Embedded Linux Device Drivers Nick Gudman njgudman@gmail.com nicholas.jam.gudman@hp.com www.linkedin.com/in/njgudman

Going to Cover Not Going to Cover Kernel modules/objects Char, block, network, & binary blob drivers Char device functions Driver Infrastructure: Unified Device Model, SysFs, Platform driver, Device tree GPIO Interrupts Debugging & Tools References & Resource Discuss Edison Arduino libraries & mraa/upm Mutual Exclusion Blocking & Non-blocking Behavior* Kernel Threads* Timing Memory Allocation* Memory Mapping* Block Devices* Network Devices*

What is a device driver? Why program device drivers? Hides how a piece of hardware/device works behind a standardized set of calls Standardized set of calls allow drivers to be inserted into kernel at runtime Makes a device available, but doesn't dictate how it is used Why program device drivers? Common way to start learning kernel development Learn the internals of Unix/Linux or another operating system Somebody has to

Debugging Tools of the Trade dmesg, printk, Dynamic Debugging ProcFs DebugFs Kdbg Kernel Dumps Kernel Oops Hardware Debuggers <Insert editor of choice> Ctags & Cscope/Gscope Yocto Linaro Bitbake

Kernel Modules/Objects An object or collection of objects either built in the kernel or dynamically linked to a running kernel Stackable Not just for device drivers bitbake -c menuconfig virtual/kernel modprobe, insmod, rmmod, lsmod, modinfo

Types of Device Drivers Character Access as a stream of bytes like a file, usually sequentially Accessed through filesystem nodes (/dev) Ex. text consoles (/dev/console), serial ports (/dev/ttyS0, /dev/ttyUSB0) Block Device that can host a filesystem Any number of bytes can be read/write Ex. hard drives (/dev/sdaX), flash devices (/dev/mmcblkX) ls /dev/

Types of Device Drivers Network Sends & receives data packets through sockets Driven by kernel network subsystem Only handles packets; doesn't know about connections Communicates completely differently than character and block devices Ex. eth0, wlan0 Binary Blobs Source not given Open source glue layer between binary blob and kernel api Ex. Nvidia Linux drivers, ndiswrapper

DON'T. WRITE. BINARY BLOBS.

Types of Device Drivers Network Sends & receives data packets through sockets Driven by kernel network subsystem Only handles packets; doesn't know about connections Communicates completely differently than character and block devices Ex. eth0, wlan0 Binary Blobs Source not given Open source glue layer between binary blob and kernel api Ex. Nvidia Linux drivers, ndiswrapper

“Canonical” Functions of Char Devices Open int (*open)(struct inode *inodp, struct file *filp); Release int (*release)(struct inode *inodp, struct file *filp); Read ssize_t (*read)(struct *filp, char *buf, size_t count, loff_t *offset); put_user(x, addr); unsigned long copy_to_user(void *to, const void *from, unsigned long n); Write ssize_t (*write)(struct file *filp, const char *buf, size_t count, loff_t *offset); get_user(x, addr); unsigned long copy_from_user(void *to, const void *from, unsigned long n);

Other Important Functions unlocked_ioctl For device specific operations that don't fit well elsewhere Called when user application calls ioctl mmap Maps file or character device to user space processes Poll Lets an application wait (block) on several file descriptors at once fasync Asynchronously notifies (signals) application when data is ready lseek Update offsets for reads and writes

Driver Infrastructure Unified Device Model One framework with similar data structures & functional methods Kernel headers for specific hardware ex. linux/gpio.h, linux/i2c-dev.h, linux/spidev.h, linux/serial.h, linux/pci.h, include/usb.h, etc SysFs - /sys Virtual filesystem Not required by unified device model User space driver Class → directory Class Instance → sub-directory Attribute → file

Arduino Example

SysFs Example

Driver Infrastructure Platform Drivers Driver is an object Buses for hardware, classes for software groups Must provide at least probe and remove functions Device Tree Textual representation of board's hardware configuration Allow generic kernel to run To solve problem of growing number of hard coded, board-specific files Device tree source (.dts) and device tree source include (.dtsi) compiled into device tree blob (.dtb) with device tree compiler (dtc)

GPIO – General Purpose Input/Output Divided into chips of 32 gpio<bank>_<pin> Gpio = (bank * 32) + pin ex. GPIO0_16: (0 * 32) + 16 = 16 Sets/gets direction, active_low, value, etc Can be hooked up to interrupts

Interrupts Stops normal execution Typically divided into top & bottom halves Top Half Quick as possible Typically verifies hardware, clears pending interrupt, read/write or another action, prepares new info Bottom Half Tasklet/softirq Workqueue Kernel Thread Threaded Interrupt Handlers User Space Interrupt Handling – Userspace I/O (UIO), integrated into kernel

References & Resources https://www.kernel.org/doc/Documentation http://www.emutexlabs.com/project/215-intel-edison-gpio-pin-multiplexing-guide https://software.intel.com/en-us/blogs/2015/02/27/intel-edison-adding-kernel-modules-to- yocto-example-batman http://iotdk.intel.com/docs/master/mraa/ http://www.linuxjournal.com/article/7136?page=0,0 http://www.linuxjournal.com/content/kbuild-linux-kernel-build-system http://renjucnair.blogspot.ca/2012/01/writing-i2c-driver.html O'Reilly's Linux Device Drivers Book Linux Foundation & Feabhas Device Driver Courses

Introduction to Developing Embedded Linux Device Drivers Nick Gudman njgudman@gmail.com nicholas.jam.gudman@hp.com www.linkedin.com/in/njgudman

Why Linus Doesn't Like Kernel Debuggers “Because I'm a bastard, and proud of it!” “Without a debugger, you basically have to go the next step: understand what the program does.” “You can use a kernel debugger if you want to, and I won't give you the cold shoulder...But I'm not going to help you use one”