Water - Meetup

Download Report

Transcript Water - Meetup

Linux Device Drivers
Prithvi N. Rao
January 12th, 2012
Agenda
●
Overview of Linux Device Driver Architecture (Desktop)
●
Overview of Linux Device Driver Architecture (Android)
●
Device Driver Development Checklist
●
How much do you really need to know about Hardware?
●
Writing a Linux/Android Device Driver – Getting Started
●
Debugging a Linux Device Driver in Android
●
Driver Event propagation to the Android Application
●
Accessing Events from Android User Space
●
Using CCSv5 for debugging Linux kernel in Android
!Agenda
●
Dinner – You're on your own :-)!
●
History of Linux
●
Details of how Linux works
●
Android Tutorial
●
How to Build Linux kernel for Android
●
How to create a NAND flash image
●
Shrink Wrapped Driver Development Kit !
Acknowledgements
●
Oleg Perelet
●
Tom Olson
●
Jeff Janis
●
Roger Yang
Overview of Linux Device Driver
Architecture (Desktop)
Overview of Linux Device Driver
Architecture (Android)
Overview of Linux Device Driver
Architecture (Android)
Device Driver Development Checklist
●
Machine Running Linux or Equivalent with sources installed (Git)
●
EVM for Development, RS232 Cable, USB Cable for EVM
●
JTAG Emulator/Trace 32 Lauterbach
●
Hardware Reference manuals
–
Board (Mistral AM/DM37x OMAP 3730 TRM)
–
Device (Avago ADBS-A350 Optical Finger Navigation Data Sheet)
●
Code Composer Studio version 5
●
Putty (for Unix connectivity)
●
SD Card and reader/writer
How Much Do You Really Need to Know
About Hardware?
●
●
The more you know the better
–
Be nice to the hardware chaps...you will need them :-)!
–
Bringing food and other goodies helps (Android Tablets, Android Phones)
Seriously you need to spend some time understanding
–
How the device is hooked up to the EVM
–
How to read a schematic
–
How interrupts work (edge triggered, level triggered)
–
How to use an oscilloscope
–
How to convince the hardware chaps that it is their problem :-)!
–
I2C Protocol and SMBUS
MOST OF ALL DON'T BE INTIMIDTED BY HARDWARE
Writing a Linux Device Driver
TIME TO GET REAL
Optical Finger Navigation Driver
●
●
●
First determine what is the purpose of this device
–
Input Only (in our case for OFN)
–
Output Only
–
Both
Decide where in the kernel sources it should reside
–
kernel/drivers/input/mouse/avagoADBMA350.c
–
kernel/drivers/input/mouse/avagoADBMA350.h
Edit the Kconfig and Makefile
–
Each directory in “drivers” has a Kconfig and Makefile
–
Enter the details of the driver code in here
–
Top level kernel build picks all this up and handles the build
Optical Finger Navigation Driver
●
Draw a block diagram of the hardware and control and data flows
–
●
K3-K4->Deliverables->K3-OpticalTouchPad
Follow the “guidelines” on how to write in-kernel device drivers
–
Look at ”safari books on line”
–
Use Google
–
kernel/Documentation has lots of stuff but requires filtering
–
Look at other in-kernel drivers in Linux - REALLY!
!PANIC
Debugging a Linux Device Driver
●
Panicking can be good
–
If it is in the kernel – you know where the PC is
–
printk can get you a long way
–
U-boot is very useful but requires some work
–
Debugfs is absolutely a must (in my opinion)
●
.config in kernel directory allows you to output various kernel driver messages
●
Look for #interrupts in /proc/interrupts
●
Look for events in /dev/input/eventX (from your device)
●
CCSv5 is useful for kernel debug in general
–
Talk to me if you want to know how to do this
Driver Event Propagation in Linux/Android
●
●
Linux exposes externally a uniform input event interface for each device
–
/dev/input/eventX
–
Each device driver has to register/unregister itself
–
Each device driver publishes input events that it receives
Sequence of events for device driver in the kernel
–
Probe detects if the device is connected
–
input-register-device invoked if device found
–
request_irq is used to associate a handler with interrupt
–
set up work_queue inside handler (linux version dependent)
It's more fun to look at code :-)!
Driver Event Propagation in Linux/Android
●
●
On receiving an interrupt (user pressed touchpad or moved it)
–
IRQ handler is invoked
–
Schedule work to propagate event to Android Framework
●
input_report_rel
●
input_sync
●
input_report_key
Android Framework provides a JNI interface to the upper layers.
Accessing Events from Android User
Space
●
Android GUI initiates access to events
–
Instance of WindowManagerService.java is created
–
Utilize MotionEvent.java, InputDevice.java,
InputEvent.java,InputQueue.java, EventHub.java
–
Android FrameWork intercepts events and provides a way to access
event queues (/dev/input/eventX)
Overview of Linux Device Driver
Architecture (Android)
Key Take Aways
●
Writing a Linux Device Driver is one of the most rewarding experiences
●
Don't be intimidated – it's only kernel programming :-)!
●
Respect the fact that you ARE working with a serious OS kernel
●
–
The driver must play well with the rest of the system
–
Linux has made it simpler than Unix
Understand the hardware as much as you can.
–
●
Share information with the hardware folks
–
●
You will do so eventually...trust me :-)!
Don't blind side them at the last minute with tons of debug info
Be aware that driver architecture has changed in Linux over time
ACCEPT THE CHALLENGE – YOU WON'T REGRET IT!