Find Courses Here
Writing Linux Device Drivers Print E-mail
Course Length - 4 Days 
  
Course Description

Writing Linux Device Drivers is a 4-day course that shows you how to write kernel-mode device drivers for Linux.

 
  
Course Objectives:
  • Learn the architecture of Linux, and where device drivers fit within that architecture. 
  • Understand how Linux applications and services access device drivers. 
  • Do User/Kernel Data Transfers.
  • Write code to automate the installation of device drivers. 
  • Learn how to write code to stress and test device drivers. 
  • Learn how to write all kinds of kernel-mode device drivers, including drivers that perform programmed I/O, interrupt-driven I/O, and DMA I/O. 
  • Develop a number of fully functioning device drivers.
 
     
Course Prerequisites:
  • Familiarity with Linux basic commands and functions 
  • Ability to read and understand the C Programming Language
  • A general understanding of operating system fundamentals 
  • A general understanding of hardware concept such as I/O ports, interrupts, and bus mastering  
Course Outline:  

Chapter 1 - The Linux World

 
  • Overview of Linux System 
  • Three components of Linux 
  • The Kernel and What it Does 
  • User Space vs. Kernel Space 
  • User Processes 
  • User View of Devices 
  • User access to devices 
  • Major & Minor Device Number 
  • Making a Device File 
  • What's in a name 
  • Other Device-like Kernel Items 
  • Process access to Devices and other System services 
  • Example of User/Device Interaction 
  • A Driver as done in Linux 
  • Where is the lp Driver? 
  • Linux Distribution Numbers 
 
Chapter 2 - Linux Code Development 
  • Vi, the Unix Visual Editor  at a Glance (is it possible?) 
  • C Compiler Identifying File Types using Filename 
  • C Command Line Flags 
  • Using 'make' 
  • Fun 'make' Rules 
  • 'make' Variables and Comments 
  • 'make' Shortcuts and Functions 
 
Chapter 3 - Kernel Code Development  
  • The Driver as a Module 
  • Adding Code to Running Kernels 
  • Module Locations, and Types
  • Module Example, with Variable Descriptors
  • Connecting/Disconnecting a Module to/from the Kernel 
  • Naming and Namespace Pollution 
  • Interfacing via System Calls and via '/proc' 
  • Kernel Symbols via '/proc' 
  • Interfacing between the Kernel, Hardware, and Device Drivers
  • Device Driver Interrupt Handling 
  • Device Driver Requirements 
  • Creating a Device Driver and "Real"  Module
  • Kernel Versions and Modules
  • Module Installation
  • Grabbing Resources on 'init_module' 
  • Memory Probing 
  • Special Memory Considerations 
  • Device Access 
 
Chapter 4 - Character Drivers  
  • Typical Character Drivers 
  • Kernel Memory Character Driver Example 
  • Character Device Registration 
  • Character Device Special File and Device Numbers 
  • file_operations structure 
  • struct file, struct inode 
  • Character Device Methods open(), release(), read(), write() 
  • Data Transfers between User Process and Driver 
    • copy_from_user(), copy_to_user() 
 
Chapter 5 - Testing  
  • Testing using 'printk()' 
  • Control of 'printk()' Display 
  • Transfer of Kernel Messages 
  • Control of Kernel Message Creation 
  • Entries in the '/proc' Filesystem and 'ioctl()' 
  • Proc file methods and registration
  • Testing and Debugging from User Space 
  • 'strace' Command 
  • Kernel Dumps 
  • Help for Hanging System 
  • SysRq Commands and Examples 
  • Using a Debugger? 
  • 'gdb' the GnuDeBugger 
  • Using KDB 
  • KGDB
 
Chapter 6 - Enhanced Character Drivers  
  • Driver and Device Control with 'ioctl()' 
  • Blocking VS Non-Blocking I/O
  • Sleep vs Wakeup 
  • poll()
  • llseek()
  • Access Control through Drivers 
 
Chapter 7 - Time Flow  
  • Managing Time, Linux Style
  • Utilizing Kernel Timers, Wait queues, and Task Queues
  • 'task_queue' Functions 
  • Lists and their macros
  • Why Bother with Task Queues?  (for Interrupts)
 
Chapter 8 - Memory, Hardware, and Interrupt Management 
  • Accessing Memory 
  • Get Some Space (kmalloc())
  • Get Some Pages  (get_free_page())
  • Get Some Virtual Memory
  • Get Some Boot-time Space 
  • Using I/O Ports 
  • Example: the Parallel Port 
  • Memory Access of ISA Devices below 1 Meg and 15 to 16 Meg
  • PCI Memory 
  • Interrupt Management, Handling and Registration
  • Autodetecting IRQ's 
  • Kernel Help in detecting IRQ's 
  • Enabling and Disabling Interrupts 
  • Splitting Interrupt Handling - Top Half & Bottom Half 
  • Combating Race Conditions 
  • Atomic Actions 
  • Spinlocks
 
Chapter 9 - Block Device Drivers  
  • Block Device Driver Characteristics
  • Similarities to Character Drivers 
  • Differences between Block and Character Drivers 
  • Block Driver Variables and Functions 
  • blk_dev_struct struct & request_fn() 
  • The Mount Problem 
  • 'ioctl()' and Block Drivers 
  • Partitions in Block Drives 
  • Partitionable Devices 
  • gendisk structure and Location 
  • Modules and Partition Tables 
 
Chapter 10 - Network Drivers  
  • Network Driver Characteristics
  • netdevice structure fields 
  • netdevice structure methods 
  • ether_setup() and its brothers 
  • irq2devmap 
  • netif_rx() 
  • skb buffer structure fields 
 

Optional Chapters

 
Chapter K - Kernel Upgrading 
  • Getting Kernel source and Patches
  • Adding KDB
  • Checking Documentation/Changes
  • Configuring, Compiling, Loading
  • initrd