• Save
Introduction to Linux Drivers
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Can you share Slides its very much usefull for me. My email ajai.ajaykumar@outlook.com

    Thanks
    Are you sure you want to
    Your message goes here
  • Can i get this slides please
    Are you sure you want to
    Your message goes here
  • Thanks for liking the slide sets
    Are you sure you want to
    Your message goes here
  • linux device driver
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
19,368
On Slideshare
9,603
From Embeds
9,765
Number of Embeds
26

Actions

Shares
Downloads
0
Comments
4
Likes
14

Embeds 9,765

http://www.sysplay.in 3,828
http://sysplay.in 2,906
http://profession.sarika-pugs.com 2,436
http://cheng-min-i-taiwan.blogspot.tw 245
http://cheng-min-i-taiwan.blogspot.com 219
http://embeddedsystemforu.blogspot.in 53
http://localhost 14
http://www.cheng-min-i-taiwan.blogspot.tw 11
http://translate.googleusercontent.com 10
http://cheng-min-i-taiwan.blogspot.hk 9
http://cheng-min-i-taiwan.blogspot.in 4
http://www.linkedin.com 4
http://www.cheng-min-i-taiwan.blogspot.com 4
http://dspembeddedvlsi.blogspot.com 4
http://embeddedsystemforu.blogspot.com 3
url_unknown 3
https://www.linkedin.com 2
http://dspembeddedvlsi.blogspot.in 2
http://cheng-min-i-taiwan.blogspot.com.au 1
http://cheng-min-i-taiwan.blogspot.ca 1
http://www.cheng-min-i-taiwan.blogspot.kr 1
http://ivalmiki.com 1
http://embeddedsystemforu.blogspot.tw 1
http://embeddedsystemforu.blogspot.sg 1
http://embeddedsystemforu.blogspot.co.at 1
http://embeddedsystemforu.blogspot.ru 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Introduction to Linux Drivers © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
  • 2. What to Expect?After this session, you would know Ws of Linux Drivers Ecosystem of Linux Drivers Types of Linux Drivers Vertical & Horizontal Driver Layering Various Terminologies in vogue Linux Driver related Commands & Configs Using a Linux Driver Our First Linux Driver © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
  • 3. Ws of Linux DriversWhat is a Driver?What is a Linux Driver?Is Linux Device Driver = Linux Driver?Why we need a Driver?What are the roles of Linux Driver? © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
  • 4. Functions of an OSProcess / Time / Processor ManagementMemory ManagementDevice I/O ManagementStorage ManagementNetwork Management © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
  • 5. Linux as an OSSo, Linux also has the same structureVisually, can be shown as © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
  • 6. Linux Driver Ecosystembash gvim X Server ssh gcc firefox Process Memory Device File Systems NetworkingManagement Management ControlConcurrency Virtual Ttys & Files & Dirs: ConnectivityMultiTasking Memory Device Access The VFSArchitecture Character Filesystem Network MemoryDependent Drivers Layer Subsystem Manager Code & Block Layer Interface Friends & Drivers Drivers Hardware Protocol Layers like PCI, USB, I2C, RS232, ... Consoles, Disks & Network CPU Memory ` etc CDs Interfaces © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
  • 7. Kernel Source Organization/usr/src/linux/ arch/<arch> mm drivers fs char mtd/ide net pci serial usb ... block net include linux asm-<arch> init kernel ipc lib scripts tools crypto firmware security sound ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
  • 8. Ws of a Module?Hot plug-n-play DriverDynamically Loadable & UnloadableLinux – the first OS to have such a featureLater many followed suitEnables fast development cycleFile: <module>.ko (Kernel Object) <module>.o wrapped with kernel signatureStd Modules Path /lib/modules/<kernel version>/kernel/...Module Configuration: /etc/modprobe.conf © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
  • 9. Module CommandsTypically needs root permissionResides in /sbinOperates over the kernel-module i/fFoundation of Driver DevelopmentNeed to understand thoroughly © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
  • 10. Listing ModulesCommand: lsmodFields: Module, Size, Used ByKernel Window: /proc/modulesAre these listed modules static ordynamic? © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
  • 11. Loading ModulesCommand: insmod <module_file>Go to modules directory and into fs/vfatTry: insmod vfat.ko © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
  • 12. Unloading ModulesCommand: rmmod <module_name>Try: rmmod fat © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
  • 13. Auto Loading ModulesCommand: modprobe <module_name>Try: modprobe vfat © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
  • 14. Kernel WindowsThrough virtual filesystems /proc /sysCommand: cat <window_file>System Logs: /var/log/messagesCommand: tail /var/log/messages dmesg | tail © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 14 All Rights Reserved.
  • 15. Other Useful CommandsDisassemble: objdump -d <object_file>List symbols: nm <object_file> © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
  • 16. Command Summarylsmodinsmodmodprobermmoddmesgobjdumpnm © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.
  • 17. The First Linux Driver© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 17 All Rights Reserved.
  • 18. The Kernels CNormal C but without access to Standard Headers (/usr/include) Standard Libraries (/usr/lib)Then, what? Kernel Headers @ <kernel src>/include Kernel Function Collection @ <kernel src>/kernel <kernel src>/ipc <kernel src>/libgcc need to be tuned to compile “Kernel C”Kernel C is a beautiful example of implementing objectoriented code using pure C © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.
  • 19. The Module Constructorstatic int __init mfd_init(void){ ... return 0;}module_init(mfd_init); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 19 All Rights Reserved.
  • 20. The Module Destructorstatic void __exit mfd_exit(void){ ...}module_exit(mfd_exit); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 20 All Rights Reserved.
  • 21. printk – Kernels printfHeader: <linux/kernel.h>Arguments: Same as printfFormat Specifiers: All as in printf, except float & double relatedAdditionally, a initial 3 character sequence for Log Level KERN_EMERG "<0>" /* system is unusable */ KERN_ALERT "<1>" /* action must be taken immediately */ KERN_CRIT "<2>" /* critical conditions */ KERN_ERR "<3>" /* error conditions */ KERN_WARNING "<4>" /* warning conditions */ KERN_NOTICE "<5>" /* normal but significant condition */ KERN_INFO "<6>" /* informational */ KERN_DEBUG "<7>" /* debug-level messages */ © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 21 All Rights Reserved.
  • 22. The Module Constructor (revisited)static int __init mfd_init(void){ printk(KERN_INFO "mfd registered"); ... return 0;}module_init(mfd_init); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 22 All Rights Reserved.
  • 23. The Module Destructor (revisited)static void __exit mfd_exit(void){ printk(KERN_INFO "mfd deregistered"); ...}module_exit(mfd_exit); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 23 All Rights Reserved.
  • 24. The Other Basics & OrnamentsBasic Headers #include <linux/module.h> #include <linux/version.h> #include <linux/kernel.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("Anil Kumar Pugalia");MODULE_DESCRIPTION("First Device Driver"); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 24 All Rights Reserved.
  • 25. Building the ModuleFor building our driver, it needs The Kernel Headers for Prototypes The Kernel Functions for Functionality The Kernel Build System & the Makefile for BuildingTwo options to Achieve 1. Building under Kernel Source Tree Put our driver appropriately under drivers folder Edit corresponding Kconfig(s) & Makefile to include our driver 2. Create our own Makefile to do the right invocation © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 25 All Rights Reserved.
  • 26. Our Makefileifeq (${KERNELRELEASE},) KERNEL_SOURCE := <kernel source directory path> PWD := $(shell pwd)default: $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) modulesclean: $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) cleanelse obj-m += <module>.oendif © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 26 All Rights Reserved.
  • 27. Try out your First Linux Driver © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 27 All Rights Reserved.
  • 28. What all have we learnt?Ws of Linux DriversEcosystem of Linux DriversTypes of Linux DriversVertical & Horizontal Driver LayeringVarious Terminologies in vogueLinux Driver related Commands & ConfigsUsing a Linux DriverOur First Linux Driver © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 28 All Rights Reserved.
  • 29. Any Queries?© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 29 All Rights Reserved.