You are on page 1of 20

Linux Device Driver

Development
Chris Lydick
Spring 2007
Class Schedule
CIS e(π*i) TU 10:30 Intro to Device Drivers Lydick

PSYCH MWF 11:30 My Motivation Lydick


012
EECE MWF 9:30 Reverse Engineering Lydick
92181
LAB F 2:30p Demonstrations Lydick
0
Textbook List
J. Corbet, A Rubini, G Kroah-Hartman. Linux
Device Drivers, 3rd Ed.

Available for download online!


http://lwn.net/Kernel/LDD3/
Operating Systems 101
• I’ve not had Operating Systems…but…
– Role of Device Drivers
• Mechanism vs. Policy
• Black Box
• Semi/undefined interface (device) -> Well
defined interface (Linux API)
Operating Systems 102
• Uses C Language
• Gets complicated very quickly (lots of
macros, code)
• Need to have a sense of ...
– concurrency, race conditions
– interrupts, deferred work
– mutual exclusion
– kernel and user-space memories
– ****pointers, structures, … (lots to consider)
Operating Systems 103
• Textbook has provided lots of
“skeletons” and demos (Wheew!)
• My testbed: Fedora Core 4, 2.6.11 (book
requested 2.6.10)

• Should we start with…. Hello World?


Operating Systems 104
• OK, easy… So what.

• Before digging deeper, consider 3 types


of device drivers
– Character Devices (stream of bytes)
– Block Devices (file systems)
– Network Interfaces (duh.)
Operating Systems 105
• Char devices:
– Scull (Simple Character Utility for Loading
Localities)… testbed for Char devices.
– Scull0..3 : global/persistent memory
– Scullpipe0..3 : FIFO pipes demonstrate
contention
– Scullpriv : private data for each console
Operating Systems Lab
Exercises
• Scull0 demonstration
• Scullpipe0 demonstration
• Scullpriv demonstration
• Short (Temperature Sensor)
• Shortprint demonstration
1
3
Operating Systems… Final
• Other Areas of Interest:
– Snull (network interface skeleton)
– USB-Skeleton (yep.)
– PCI-Skeleton (ok.)
– Sample Disk Driver (cool.)
– TTY Drivers, DMA and Memory Mapping,
etc.
Motivation
• My Thesis: Supercomputing Cluster in 031
Rathbone:
– USB Connectivity: driver timeouts/overflows in
OpenBSD
– Communicated with Chris Pascoe (OpenBSD
Developer)
Motivation
• Acer Labs M5632 Bridge Cable
– Worked fine using the standard USB 1.0
Driver
– Issues arose with the USB 2.0 (EHCI)
driver [diff file]
• “Abused” the kernel profiling framework to
check at runtime for kernel stack overflows.
– We’re switching to Linux (no issues), but it’s good
to know how to dig into drivers… right?
– Plus, isn’t Linux supposed to be better than
Windoze?
Reverse Engineering 101
• Reverse Engineering: Getting something
to work by watching it work when
correctly loaded.
– Usually occurs within Windows (sorry, we
just can’t get away from Microsoft!)
Reverse Engineering 102
• USB Devices (URB):
• USB Analyzer/Sniffer (Snoopy, USB Monitor,..)
• Acts similarly to Ethereal
• /sys/devices/pci0000:00/000:00:02.0/usb2/
• PCI Bus
• Hardware Sniffers… (much more difficult to
analyze!)
Conclusions
• GET THE BOOK! It’s very helpful and is
a great reference!
• Examples are available for download
• Book is freely available (wget it before
it’s gone!)
• Next step: USB!

You might also like