SlideShare une entreprise Scribd logo
1  sur  29
© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Introduction to Linux Drivers
2© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
After this session, you would know
W's 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
3© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
W's of Linux Drivers
What 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?
4© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Functions of an OS
Process / Time / Processor Management
Memory Management
Device I/O Management
Storage Management
Network Management
5© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux as an OS
So, Linux also has the same structure
Visually, can be shown as
6© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux Driver Ecosystem
bash gvim X Server gcc firefox
`
Process
Management
ssh
Memory
Management
File Systems
Device
Control
Networking
Architecture
Dependent
Code
Character
Drivers
&
Friends
Memory
Manager
Filesystem
Layer
Block Layer
& Drivers
Network
Subsystem
Interface
Drivers
Concurrency
MultiTasking
Virtual
Memory
Files & Dirs:
The VFS
Ttys &
Device Access
Connectivity
CPU Memory
Disks &
CDs
Consoles,
etc
Network
Interfaces
Hardware Protocol Layers like PCI, USB, I2C, RS232, ...
7© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Source Organization
/usr/src/linux/
net
drivers
block
fs
mm
init
arch/<arch>
char mtd/ide net pci ...usbserial
include
asm-<arch>linux
kernel ipc lib scripts toolsscripts
crypto firmware security sound ...
8© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
W's of a Module?
Hot plug-n-play Driver
Dynamically Loadable & Unloadable
Linux – the first OS to have such a feature
Later many followed suit
Enables fast development cycle
File: <module>.ko (Kernel Object)
<module>.o wrapped with kernel signature
Std Modules Path
/lib/modules/<kernel version>/kernel/...
Module Configuration: /etc/modprobe.conf
9© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Module Commands
Typically needs root permission
Resides in /sbin
Operates over the kernel-module i/f
Foundation of Driver Development
Need to understand thoroughly
10© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Listing Modules
Command: lsmod
Fields: Module, Size, Used By
Kernel Window: /proc/modules
Are these listed modules static or dynamic?
11© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Loading Modules
Command: insmod <module_file>
Go to modules directory and into fs/vfat
Try: insmod vfat.ko
12© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Unloading Modules
Command: rmmod <module_name>
Try: rmmod fat
13© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Auto Loading Modules
Command: modprobe <module_name>
Try: modprobe vfat
14© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Windows
Through virtual filesystems
/proc
/sys
Command: cat <window_file>
System Logs: /var/log/messages
Command:
tail /var/log/messages
dmesg | tail
15© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Other Useful Commands
Disassemble: objdump -d <object_file>
List symbols: nm <object_file>
16© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Command Summary
lsmod
insmod
modprobe
rmmod
dmesg
objdump
nm
17© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The First Linux Driver
18© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Kernel's C
Normal 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>/lib
gcc need to be tuned to compile “Kernel C”
Kernel C is a beautiful example of implementing object
oriented code using pure C
19© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Module Constructor
static int __init mfd_init(void)
{
...
return 0;
}
module_init(mfd_init);
20© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Module Destructor
static void __exit mfd_exit(void)
{
...
}
module_exit(mfd_exit);
21© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
printk – Kernel's printf
Header: <linux/kernel.h>
Arguments: Same as printf
Format Specifiers: All as in printf, except float & double related
Additionally, 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 */
22© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Module Constructor (revisited)
static int __init mfd_init(void)
{
printk(KERN_INFO "mfd registered");
...
return 0;
}
module_init(mfd_init);
23© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Module Destructor (revisited)
static void __exit mfd_exit(void)
{
printk(KERN_INFO "mfd deregistered");
...
}
module_exit(mfd_exit);
24© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Other Basics & Ornaments
Basic 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");
25© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Building the Module
For building our driver, it needs
The Kernel Headers for Prototypes
The Kernel Functions for Functionality
The Kernel Build System & the Makefile for Building
Two 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
26© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Our Makefile
ifeq (${KERNELRELEASE},)
KERNEL_SOURCE := <kernel source directory path>
PWD := $(shell pwd)
default:
$(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) clean
else
obj-m += <module>.o
endif
27© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Try out your First Linux Driver
28© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
W's 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
29© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

Contenu connexe

Tendances

Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device driversHoucheng Lin
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation Jiann-Fuh Liaw
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversSatpal Parmar
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)shimosawa
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionGene Chang
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal BootloaderSatpal Parmar
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/CoreShay Cohen
 
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedVmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedAdrian Huang
 

Tendances (20)

I2C Drivers
I2C DriversI2C Drivers
I2C Drivers
 
Interrupts
InterruptsInterrupts
Interrupts
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
Character drivers
Character driversCharacter drivers
Character drivers
 
Introduction to Modern U-Boot
Introduction to Modern U-BootIntroduction to Modern U-Boot
Introduction to Modern U-Boot
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedVmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
 
BeagleBoard-xM Booting Process
BeagleBoard-xM Booting ProcessBeagleBoard-xM Booting Process
BeagleBoard-xM Booting Process
 

En vedette (17)

File System Modules
File System ModulesFile System Modules
File System Modules
 
References
ReferencesReferences
References
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
Serial Drivers
Serial DriversSerial Drivers
Serial Drivers
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Embedded C
Embedded CEmbedded C
Embedded C
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
Low-level Accesses
Low-level AccessesLow-level Accesses
Low-level Accesses
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
BeagleBoard-xM Bootloaders
BeagleBoard-xM BootloadersBeagleBoard-xM Bootloaders
BeagleBoard-xM Bootloaders
 
File Systems
File SystemsFile Systems
File Systems
 

Similaire à Introduction to Linux Drivers

Quick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOQuick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOChris Simmonds
 
Cooking security sans@night
Cooking security sans@nightCooking security sans@night
Cooking security sans@nightjtimberman
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversAnil Kumar Pugalia
 
Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devicesChris Simmonds
 
IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...
IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...
IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...William Holmes
 
Chapter17 Using SMPE.ppt
Chapter17 Using SMPE.pptChapter17 Using SMPE.ppt
Chapter17 Using SMPE.pptFlavio787771
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded SystemsAnil Kumar Pugalia
 
TWS 8.6 new features (from the 2013 European Tour)
TWS 8.6 new features (from the 2013 European Tour)TWS 8.6 new features (from the 2013 European Tour)
TWS 8.6 new features (from the 2013 European Tour)Nico Chillemi
 
리눅스 드라이버 #2
리눅스 드라이버 #2리눅스 드라이버 #2
리눅스 드라이버 #2Sangho Park
 
Release notes 3_d_v61
Release notes 3_d_v61Release notes 3_d_v61
Release notes 3_d_v61sundar sivam
 

Similaire à Introduction to Linux Drivers (20)

Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
 
Processes
ProcessesProcesses
Processes
 
Quick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOQuick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIO
 
BeagleBone Black Booting Process
BeagleBone Black Booting ProcessBeagleBone Black Booting Process
BeagleBone Black Booting Process
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Symm.63
Symm.63Symm.63
Symm.63
 
Cooking security sans@night
Cooking security sans@nightCooking security sans@night
Cooking security sans@night
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devices
 
IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...
IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...
IBM Lotusphere 2012 Show301: Leveraging the Sametime Proxy to support Mobile ...
 
Chapter17 Using SMPE.ppt
Chapter17 Using SMPE.pptChapter17 Using SMPE.ppt
Chapter17 Using SMPE.ppt
 
Embedded Applications
Embedded ApplicationsEmbedded Applications
Embedded Applications
 
Damn Simics
Damn SimicsDamn Simics
Damn Simics
 
SR-IOV Introduce
SR-IOV IntroduceSR-IOV Introduce
SR-IOV Introduce
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
TWS 8.6 new features (from the 2013 European Tour)
TWS 8.6 new features (from the 2013 European Tour)TWS 8.6 new features (from the 2013 European Tour)
TWS 8.6 new features (from the 2013 European Tour)
 
리눅스 드라이버 #2
리눅스 드라이버 #2리눅스 드라이버 #2
리눅스 드라이버 #2
 
Release notes 3_d_v61
Release notes 3_d_v61Release notes 3_d_v61
Release notes 3_d_v61
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 

Plus de Anil Kumar Pugalia (20)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
System Calls
System CallsSystem Calls
System Calls
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Power of vi
Power of viPower of vi
Power of vi
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
System Calls
System CallsSystem Calls
System Calls
 
Timers
TimersTimers
Timers
 
Threads
ThreadsThreads
Threads
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Processes
ProcessesProcesses
Processes
 
Signals
SignalsSignals
Signals
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 

Dernier

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Dernier (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Introduction to Linux Drivers

  • 1. © 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Introduction to Linux Drivers
  • 2. 2© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? After this session, you would know W's 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
  • 3. 3© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. W's of Linux Drivers What 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?
  • 4. 4© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Functions of an OS Process / Time / Processor Management Memory Management Device I/O Management Storage Management Network Management
  • 5. 5© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux as an OS So, Linux also has the same structure Visually, can be shown as
  • 6. 6© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux Driver Ecosystem bash gvim X Server gcc firefox ` Process Management ssh Memory Management File Systems Device Control Networking Architecture Dependent Code Character Drivers & Friends Memory Manager Filesystem Layer Block Layer & Drivers Network Subsystem Interface Drivers Concurrency MultiTasking Virtual Memory Files & Dirs: The VFS Ttys & Device Access Connectivity CPU Memory Disks & CDs Consoles, etc Network Interfaces Hardware Protocol Layers like PCI, USB, I2C, RS232, ...
  • 7. 7© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Source Organization /usr/src/linux/ net drivers block fs mm init arch/<arch> char mtd/ide net pci ...usbserial include asm-<arch>linux kernel ipc lib scripts toolsscripts crypto firmware security sound ...
  • 8. 8© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. W's of a Module? Hot plug-n-play Driver Dynamically Loadable & Unloadable Linux – the first OS to have such a feature Later many followed suit Enables fast development cycle File: <module>.ko (Kernel Object) <module>.o wrapped with kernel signature Std Modules Path /lib/modules/<kernel version>/kernel/... Module Configuration: /etc/modprobe.conf
  • 9. 9© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Module Commands Typically needs root permission Resides in /sbin Operates over the kernel-module i/f Foundation of Driver Development Need to understand thoroughly
  • 10. 10© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Listing Modules Command: lsmod Fields: Module, Size, Used By Kernel Window: /proc/modules Are these listed modules static or dynamic?
  • 11. 11© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Loading Modules Command: insmod <module_file> Go to modules directory and into fs/vfat Try: insmod vfat.ko
  • 12. 12© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Unloading Modules Command: rmmod <module_name> Try: rmmod fat
  • 13. 13© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Auto Loading Modules Command: modprobe <module_name> Try: modprobe vfat
  • 14. 14© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Windows Through virtual filesystems /proc /sys Command: cat <window_file> System Logs: /var/log/messages Command: tail /var/log/messages dmesg | tail
  • 15. 15© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Other Useful Commands Disassemble: objdump -d <object_file> List symbols: nm <object_file>
  • 16. 16© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Command Summary lsmod insmod modprobe rmmod dmesg objdump nm
  • 17. 17© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The First Linux Driver
  • 18. 18© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Kernel's C Normal 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>/lib gcc need to be tuned to compile “Kernel C” Kernel C is a beautiful example of implementing object oriented code using pure C
  • 19. 19© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Module Constructor static int __init mfd_init(void) { ... return 0; } module_init(mfd_init);
  • 20. 20© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Module Destructor static void __exit mfd_exit(void) { ... } module_exit(mfd_exit);
  • 21. 21© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. printk – Kernel's printf Header: <linux/kernel.h> Arguments: Same as printf Format Specifiers: All as in printf, except float & double related Additionally, 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 */
  • 22. 22© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Module Constructor (revisited) static int __init mfd_init(void) { printk(KERN_INFO "mfd registered"); ... return 0; } module_init(mfd_init);
  • 23. 23© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Module Destructor (revisited) static void __exit mfd_exit(void) { printk(KERN_INFO "mfd deregistered"); ... } module_exit(mfd_exit);
  • 24. 24© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Other Basics & Ornaments Basic 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");
  • 25. 25© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Building the Module For building our driver, it needs The Kernel Headers for Prototypes The Kernel Functions for Functionality The Kernel Build System & the Makefile for Building Two 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
  • 26. 26© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Our Makefile ifeq (${KERNELRELEASE},) KERNEL_SOURCE := <kernel source directory path> PWD := $(shell pwd) default: $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) modules clean: $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) clean else obj-m += <module>.o endif
  • 27. 27© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Try out your First Linux Driver
  • 28. 28© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? W's 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
  • 29. 29© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?