SlideShare a Scribd company logo
(IN LINUX-KERNAL)
DEVICE DRIVER’S
Linux is, in simplest terms, an operating system
Linux is very similar to other operating
systems, such as windows, android and OS
x(mac).
Free and open-source software
Android uses the Linux kernel under the hood.
Because Linux is open-source, Google's
android developers could modify the Linux
kernel to fit their needs.
Linux gives the android developers a pre-built,
already maintained operating system kernel to
start with so they don’t have to write their own
kernel.
WHAT IS LINUX??
 A kernel is the lowest level of easily
replaceable software that interfaces with the
hardware in your computer.
 It is responsible for interfacing all of your
applications that are running in “user mode”
down to the physical hardware, and allowing
processes, known as servers, to get
information from each other using inter-
process communication (IPC).
WHAT DOES KERNAL DOES??
HERE COMES A DEVICE DRIVER
A device driver is a program that controls a particular
type of device that is attached to your computer.
 Black boxes to hide details of hardware
devices
 Use standardized calls
 Independent of the specific driver
 Main role is to Map standard calls to
device-specific operations
 Can be developed separately from the
rest of the kernel
 Plugged in at runtime when needed
DEVICE
DRIVER
WINDOWS
(DEVICE
DRIVERS )
LINUX
(MODULES)
Kernel model with
device driver
hierarchy.
Implements the mechanisms to access the hardware.
E.g., show a disk as an array of data blocks
Does not force particular policies on the user.
Support for synchronous/asynchronous operation
Be opened multiple times
Exploit the full capabilities of the hardware
Easier user model
Easier to write and maintain
To assist users with policies, release device drivers with user programs
THE ROLE OF THE DEVICE DRIVER
THAT’S ALL FOR TODAY….
ANY QUESTION??
SPLITIING THE ROLES OF KERNAL
PROCESS
MANAGEMENT
MEMORY
MANAGEMENT
FILE SYSTEMSDEVICE
CONTROL
NETWORKING
PROCESS
MANAGEMENT
 Creates, destroys processes
 Supports communication among processes
Signals, pipes, etc.
 Schedules how processes share the CPU
MEMORY
MANAGEMENT
 Managing memory by Virtual addressing
FILE SYSTEMS
DEVICE
CONTROL
NETWORKING
 Everything in UNIX can be treated as a file
 Linux supports multiple file systems
 Every system operation maps to a physical device
 Few exceptions: CPU, memory, etc.
 Handles packets
 Handles routing and network address resolution issues
A SPLIT VIEW OF
KERNAL
CLASSES OF DEVICES THAT USE MODULES
CHARACTER DEVICES
BLOCK DEVICES
NETWORK DEVICES
OTHERS
1
2
3
4
CHARACTER DEVICES
 Abstraction: a stream of bytes
 Examples
Text console (/dev/console)
Serial ports (/dev/ttyS0)
 Usually supports open, close, read,
write instructions
 Accessed sequentially (in most cases)
 Might not support file seeks
 Exception: frame grabbers
 Can access acquired image using
mmap or lseek
BLOCK DEVICES
 Abstraction: array of storage blocks
 However, applications can access a
block device in bytes
 Block and char devices differ only at
the kernel level
 A block device can host a file system
NETWORK DEVICES OTHERS
 Abstraction: data packets
 Send and receive packets
 Do not know about individual
connections
 Have unique names (e.g., eth0)
 Not in the file system
 Support protocols and streams
related to packet transmission
(i.e., no read and write)
 Examples that do not fit to
previous categories:
 USB
 SCSI
 FireWire
 I2O
 MTD
SECURITY ISSUES
Kernel modules present possibilities for both
System does rudimentary checks at module load time
It relies on limiting privilege to load modules
DAMAGES
DELIBARATE
INCIDENTAL
Hack, Virus, Log Files, Encryption, Logic Bomb
Something Happens By Chance, w/o Intention
SECURITY ISSUES
Driver writer must be on guard for security problems.
Do not define security policies, Provide mechanisms to enforce policies.
Be aware of operations that affect global resources.
Beware of bugs.
Treat input/parameters with utmost suspicion.
Uninitialized memory, Kernel memory should be zeroed before being made available
to a user. Otherwise, information leakage could result.
Passwords protected.
Avoid running kernels compiled by an untrusted friend
VERSION NUMBER’S
 Every software package used in Linux has a release number.
 You need a particular version of one package to run a particular version of another
package.
 Prepackaged distribution contains matching versions of various packages.
 Linux kernel version numbers:
<major>.<minor>.<release>
For example: 2.6.31
BUILDING MODULES
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void) {
printk(KERN_ALERT “Hello,
worldn”);
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT
“Goodbye, cruel worldn”);
}
module_init(hello_init);
module_exit(hello_exit);
The HELLO WORLD program
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void) {
printk(KERN_ALERT “Hello,
worldn”);
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT
“Goodbye, cruel worldn”);
}
module_init(hello_init);
module_exit(hello_exit);
This module bears
a free license
The ordering
matters sometimes
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void) {
printk(KERN_ALERT “Hello,
worldn”);
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT
“Goodbye, cruel worldn”);
}
module_init(hello_init);
module_exit(hello_exit);
No main function is used
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void) {
printk(KERN_ALERT “Hello,
worldn”);
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT
“Goodbye, cruel worldn”);
}
module_init(hello_init);
module_exit(hello_exit);
Invoked when the module
is loaded
Invoked when the module
is removed
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void) {
printk(KERN_ALERT “Hello,
worldn”);
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT
“Goodbye, cruel worldn”);
}
module_init(hello_init);
module_exit(hello_exit);
Micros to indicate which module
initialization and exit functions
to call
1) You need running kernel source code
2) Next go to your kernel module source
code directory and simply create the
Makefile file as follows
3) Compile module using make command
(module build can be done by any user)
4) Once module compiled successfully,
load it and run using insmod or
modprobe command.
Source code
Makefile
Compile
Load
+
run
$ tar -zxvf kernel* -C /usr/src
$ vi Makefile
$ make(complie)
# insmod HELLO.ko
EXAMPLE: HELLO.C MODULE
1. hello.c C source code
2. Create new Makefile
3. Save and close the file
4. Compile hello.c module($ make)
5. Become a root user (use su or sudo)
and load the module
6. Verify that module loaded:
7. See message in /var/log/message file:
8. Unload the module(# rmmod hello)
KERNEL MODULES VS. APPLICATIONS
 Applications:
Can access various functions in user-
level libraries (e.g., printf in C
library)
 Kernel modules:
• No user-level libraries
• printk is defined within the kernel
• Exported to modules
• Should include only header files defined within
the kernel source tree
LINKING MODULE TO A KERNEL
END OF CLASS..
ANY
QUESTION??
 The table contains the addresses of global
kernel items functions and variables that
are needed to implement modularized
drivers.
 When a module is loaded, any symbol
exported by the module becomes part of
the kernel symbol table.
 In the usual case, a module implements
its own functionality without the need to
export any symbols at all.
Example
alias eth0 e1000
Whenever eth0 is referenced, the kernel
module e1000 is loaded
IN MODULE HEADER FILES
USE THE FOLLOWING MACROS
EXPORT_SYMBOL(NAME);
EXPORT_SYMBOL_GPL(NAME);
Just about all module code includes
the following header files
<linux/module.h>
Symbols and functions
needed by modules
<linux/init.h>
Allows you to specify
initialization and cleanup
functions
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void) {
printk(KERN_ALERT “Hello,
worldn”);
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT
“Goodbye, cruel worldn”);
}
module_init(hello_init);
module_exit(hello_exit);
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual
BSD/GPL”);
static int hello_init(void) {
printk(KERN_ALERT
“Hello, worldn”);
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT
“Goodbye, cruel worldn”);
}
module_init(hello_init);
module_exit(hello_exit);
Initialization function: Registers any
facility, or functionality offered by the
module.
Syntax:
module_init(initialization_function);
Shut down: Unregisters various
functionalities and returns all resources
A facility is available once a register call is completed
Kernel can make calls to registered functions before the initialization function completes
Obtain and initialize all critical resources before calling the register function
Include moduleparam.h, stat.h
Need to use the following macros
module_param(name, type,
permission)
module_param_array(name, type,
num, permission)
“hello world” module to say hello to someone
a number of times
%/sbin/insmod ./hello.ko
someone=“Mom” times=2
Output:
Hello Mom
Hello Mom
ADVANTAGES
 The full C library can be linked in. The
programmer can run a conventional
debugger on the driver code without
having to go through contortions to
debug a running kernel.
 If a user-space driver hangs, you can
simply kill it.
 User memory is swappable, unlike kernel
memory.
 A well-designed driver program can still
allow concurrent access to a device.
DISADVANTAGES
 • Interrupts are not available in user
space.
 • Direct access to memory is possible if
only a privileged user can do that.
 • Access to I/O ports is available only
after calling
 • Response time is slower.
 • The most important devices can’t be
handled in user space, including, but not
limited to, network interfaces and block
devices.
Linux Device Driver’s

More Related Content

What's hot

Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
Rashila Rr
 
Introduction to Modern U-Boot
Introduction to Modern U-BootIntroduction to Modern U-Boot
Introduction to Modern U-Boot
GlobalLogic Ukraine
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
Emertxe Information Technologies Pvt Ltd
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
Emertxe Information Technologies Pvt Ltd
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
Emertxe Information Technologies Pvt Ltd
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
Linaro
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
Emertxe Information Technologies Pvt Ltd
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
mukul bhardwaj
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
Emertxe Information Technologies Pvt Ltd
 
Linux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platformLinux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platform
Emertxe Information Technologies Pvt Ltd
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
Wave Digitech
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
Macpaul Lin
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
guest547d74
 
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
Houcheng Lin
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
Satpal Parmar
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
NEEVEE Technologies
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
Abhishek Sagar
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
Shay Cohen
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
Anil Kumar Pugalia
 

What's hot (20)

Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
 
Introduction to Modern U-Boot
Introduction to Modern U-BootIntroduction to Modern U-Boot
Introduction to Modern U-Boot
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Linux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platformLinux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platform
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
 
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 or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 

Viewers also liked

Device Drivers
Device DriversDevice Drivers
Device Drivers
Suhas S R
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
Kushal Modi
 
linux device driver
linux device driverlinux device driver
linux device driver
Rahul Batra
 
Linux device drivers
Linux device drivers Linux device drivers
Android platform
Android platform Android platform
Android platform
Rashmi Warghade
 
Usb
UsbUsb
Computer Interfaces
Computer Interfaces Computer Interfaces
Computer Interfaces
Prasad Deshpande
 
Usb
UsbUsb
Pakaagee
PakaageePakaagee
Pakaagee
posh ksa
 
Why Drivers Stay with Fleets
Why Drivers Stay with FleetsWhy Drivers Stay with Fleets
Why Drivers Stay with Fleets
bmweber
 
The USB Generation
The USB GenerationThe USB Generation
The USB Generation
Jacques Warner
 
Usb
UsbUsb
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
mcganesh
 
Device drivers Introduction
Device drivers IntroductionDevice drivers Introduction
Device drivers Introduction
vijay selva
 
Linux kernel code
Linux kernel codeLinux kernel code
Linux kernel code
Ganesh Naik
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-sem
Sagun Baijal
 
Device Drivers in Linux
Device Drivers in LinuxDevice Drivers in Linux
Device Drivers in Linux
Shreyas MM
 
Breaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success StoryBreaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success Story
Sage Sharp
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
Alexandre Moreno
 
Linux Device Driver Training
Linux Device Driver TrainingLinux Device Driver Training
Linux Device Driver Training
Multisoft Virtual Academy
 

Viewers also liked (20)

Device Drivers
Device DriversDevice Drivers
Device Drivers
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Android platform
Android platform Android platform
Android platform
 
Usb
UsbUsb
Usb
 
Computer Interfaces
Computer Interfaces Computer Interfaces
Computer Interfaces
 
Usb
UsbUsb
Usb
 
Pakaagee
PakaageePakaagee
Pakaagee
 
Why Drivers Stay with Fleets
Why Drivers Stay with FleetsWhy Drivers Stay with Fleets
Why Drivers Stay with Fleets
 
The USB Generation
The USB GenerationThe USB Generation
The USB Generation
 
Usb
UsbUsb
Usb
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
 
Device drivers Introduction
Device drivers IntroductionDevice drivers Introduction
Device drivers Introduction
 
Linux kernel code
Linux kernel codeLinux kernel code
Linux kernel code
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-sem
 
Device Drivers in Linux
Device Drivers in LinuxDevice Drivers in Linux
Device Drivers in Linux
 
Breaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success StoryBreaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success Story
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
 
Linux Device Driver Training
Linux Device Driver TrainingLinux Device Driver Training
Linux Device Driver Training
 

Similar to Linux Device Driver’s

Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
murali_purushothaman
 
Linux device driver
Linux device driverLinux device driver
Linux device driver
chatsiri
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Tushar B Kute
 
Linux
LinuxLinux
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
Dharshana Kasun Warusavitharana
 
Device drivers tsp
Device drivers tspDevice drivers tsp
Device drivers tsp
Pradeep Kumar TS
 
Linux
LinuxLinux
Windows Architecture Explained by Stacksol
Windows Architecture Explained by StacksolWindows Architecture Explained by Stacksol
Windows Architecture Explained by Stacksol
Stacksol
 
Operating system
Operating systemOperating system
Operating system
Nasrin Borsha
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
Nalin Sharma
 
3CS LSP UNIT 1-1.pdf
3CS LSP UNIT 1-1.pdf3CS LSP UNIT 1-1.pdf
3CS LSP UNIT 1-1.pdf
DeepakKumar783815
 
Linux security
Linux securityLinux security
Linux security
trilokchandra prakash
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
Priyank Kapadia
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
Eddy Reyes
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
KunalKewat1
 
Docker dDessi november 2015
Docker dDessi november 2015Docker dDessi november 2015
Docker dDessi november 2015
Massimiliano Dessì
 
Nguyen lyhedieuhanh 14-15_hedieuhanhlinux
Nguyen lyhedieuhanh 14-15_hedieuhanhlinuxNguyen lyhedieuhanh 14-15_hedieuhanhlinux
Nguyen lyhedieuhanh 14-15_hedieuhanhlinux
Integrated Circuit Design Research & Education Center (ICDREC)
 
Fight with linux reverse
Fight with linux reverseFight with linux reverse
Fight with linux reverse
chao yang
 
Linux Virus
Linux VirusLinux Virus
Linux Virus
Akhil Kadangode
 
Linux
Linux Linux
Linux
Teja Babu
 

Similar to Linux Device Driver’s (20)

Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
Linux device driver
Linux device driverLinux device driver
Linux device driver
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
 
Linux
LinuxLinux
Linux
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
 
Device drivers tsp
Device drivers tspDevice drivers tsp
Device drivers tsp
 
Linux
LinuxLinux
Linux
 
Windows Architecture Explained by Stacksol
Windows Architecture Explained by StacksolWindows Architecture Explained by Stacksol
Windows Architecture Explained by Stacksol
 
Operating system
Operating systemOperating system
Operating system
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
3CS LSP UNIT 1-1.pdf
3CS LSP UNIT 1-1.pdf3CS LSP UNIT 1-1.pdf
3CS LSP UNIT 1-1.pdf
 
Linux security
Linux securityLinux security
Linux security
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
 
Docker dDessi november 2015
Docker dDessi november 2015Docker dDessi november 2015
Docker dDessi november 2015
 
Nguyen lyhedieuhanh 14-15_hedieuhanhlinux
Nguyen lyhedieuhanh 14-15_hedieuhanhlinuxNguyen lyhedieuhanh 14-15_hedieuhanhlinux
Nguyen lyhedieuhanh 14-15_hedieuhanhlinux
 
Fight with linux reverse
Fight with linux reverseFight with linux reverse
Fight with linux reverse
 
Linux Virus
Linux VirusLinux Virus
Linux Virus
 
Linux
Linux Linux
Linux
 

Recently uploaded

How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 

Recently uploaded (20)

How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 

Linux Device Driver’s

  • 2. Linux is, in simplest terms, an operating system Linux is very similar to other operating systems, such as windows, android and OS x(mac). Free and open-source software Android uses the Linux kernel under the hood. Because Linux is open-source, Google's android developers could modify the Linux kernel to fit their needs. Linux gives the android developers a pre-built, already maintained operating system kernel to start with so they don’t have to write their own kernel. WHAT IS LINUX??
  • 3.  A kernel is the lowest level of easily replaceable software that interfaces with the hardware in your computer.  It is responsible for interfacing all of your applications that are running in “user mode” down to the physical hardware, and allowing processes, known as servers, to get information from each other using inter- process communication (IPC). WHAT DOES KERNAL DOES??
  • 4. HERE COMES A DEVICE DRIVER A device driver is a program that controls a particular type of device that is attached to your computer.  Black boxes to hide details of hardware devices  Use standardized calls  Independent of the specific driver  Main role is to Map standard calls to device-specific operations  Can be developed separately from the rest of the kernel  Plugged in at runtime when needed DEVICE DRIVER WINDOWS (DEVICE DRIVERS ) LINUX (MODULES)
  • 5. Kernel model with device driver hierarchy.
  • 6. Implements the mechanisms to access the hardware. E.g., show a disk as an array of data blocks Does not force particular policies on the user. Support for synchronous/asynchronous operation Be opened multiple times Exploit the full capabilities of the hardware Easier user model Easier to write and maintain To assist users with policies, release device drivers with user programs THE ROLE OF THE DEVICE DRIVER
  • 7. THAT’S ALL FOR TODAY…. ANY QUESTION??
  • 8. SPLITIING THE ROLES OF KERNAL PROCESS MANAGEMENT MEMORY MANAGEMENT FILE SYSTEMSDEVICE CONTROL NETWORKING
  • 9. PROCESS MANAGEMENT  Creates, destroys processes  Supports communication among processes Signals, pipes, etc.  Schedules how processes share the CPU MEMORY MANAGEMENT  Managing memory by Virtual addressing
  • 10. FILE SYSTEMS DEVICE CONTROL NETWORKING  Everything in UNIX can be treated as a file  Linux supports multiple file systems  Every system operation maps to a physical device  Few exceptions: CPU, memory, etc.  Handles packets  Handles routing and network address resolution issues
  • 11. A SPLIT VIEW OF KERNAL
  • 12. CLASSES OF DEVICES THAT USE MODULES CHARACTER DEVICES BLOCK DEVICES NETWORK DEVICES OTHERS 1 2 3 4
  • 13. CHARACTER DEVICES  Abstraction: a stream of bytes  Examples Text console (/dev/console) Serial ports (/dev/ttyS0)  Usually supports open, close, read, write instructions  Accessed sequentially (in most cases)  Might not support file seeks  Exception: frame grabbers  Can access acquired image using mmap or lseek BLOCK DEVICES  Abstraction: array of storage blocks  However, applications can access a block device in bytes  Block and char devices differ only at the kernel level  A block device can host a file system
  • 14. NETWORK DEVICES OTHERS  Abstraction: data packets  Send and receive packets  Do not know about individual connections  Have unique names (e.g., eth0)  Not in the file system  Support protocols and streams related to packet transmission (i.e., no read and write)  Examples that do not fit to previous categories:  USB  SCSI  FireWire  I2O  MTD
  • 15. SECURITY ISSUES Kernel modules present possibilities for both System does rudimentary checks at module load time It relies on limiting privilege to load modules DAMAGES DELIBARATE INCIDENTAL Hack, Virus, Log Files, Encryption, Logic Bomb Something Happens By Chance, w/o Intention
  • 16. SECURITY ISSUES Driver writer must be on guard for security problems. Do not define security policies, Provide mechanisms to enforce policies. Be aware of operations that affect global resources. Beware of bugs. Treat input/parameters with utmost suspicion. Uninitialized memory, Kernel memory should be zeroed before being made available to a user. Otherwise, information leakage could result. Passwords protected. Avoid running kernels compiled by an untrusted friend
  • 17. VERSION NUMBER’S  Every software package used in Linux has a release number.  You need a particular version of one package to run a particular version of another package.  Prepackaged distribution contains matching versions of various packages.  Linux kernel version numbers: <major>.<minor>.<release> For example: 2.6.31
  • 18.
  • 19. BUILDING MODULES #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); static int hello_init(void) { printk(KERN_ALERT “Hello, worldn”); return 0; } static void hello_exit(void) { printk(KERN_ALERT “Goodbye, cruel worldn”); } module_init(hello_init); module_exit(hello_exit); The HELLO WORLD program
  • 20. #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); static int hello_init(void) { printk(KERN_ALERT “Hello, worldn”); return 0; } static void hello_exit(void) { printk(KERN_ALERT “Goodbye, cruel worldn”); } module_init(hello_init); module_exit(hello_exit); This module bears a free license The ordering matters sometimes
  • 21. #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); static int hello_init(void) { printk(KERN_ALERT “Hello, worldn”); return 0; } static void hello_exit(void) { printk(KERN_ALERT “Goodbye, cruel worldn”); } module_init(hello_init); module_exit(hello_exit); No main function is used
  • 22. #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); static int hello_init(void) { printk(KERN_ALERT “Hello, worldn”); return 0; } static void hello_exit(void) { printk(KERN_ALERT “Goodbye, cruel worldn”); } module_init(hello_init); module_exit(hello_exit); Invoked when the module is loaded Invoked when the module is removed
  • 23. #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); static int hello_init(void) { printk(KERN_ALERT “Hello, worldn”); return 0; } static void hello_exit(void) { printk(KERN_ALERT “Goodbye, cruel worldn”); } module_init(hello_init); module_exit(hello_exit); Micros to indicate which module initialization and exit functions to call
  • 24. 1) You need running kernel source code 2) Next go to your kernel module source code directory and simply create the Makefile file as follows 3) Compile module using make command (module build can be done by any user) 4) Once module compiled successfully, load it and run using insmod or modprobe command. Source code Makefile Compile Load + run
  • 25. $ tar -zxvf kernel* -C /usr/src $ vi Makefile $ make(complie) # insmod HELLO.ko EXAMPLE: HELLO.C MODULE 1. hello.c C source code 2. Create new Makefile 3. Save and close the file 4. Compile hello.c module($ make) 5. Become a root user (use su or sudo) and load the module 6. Verify that module loaded: 7. See message in /var/log/message file: 8. Unload the module(# rmmod hello)
  • 26. KERNEL MODULES VS. APPLICATIONS  Applications: Can access various functions in user- level libraries (e.g., printf in C library)  Kernel modules: • No user-level libraries • printk is defined within the kernel • Exported to modules • Should include only header files defined within the kernel source tree
  • 27. LINKING MODULE TO A KERNEL
  • 29.  The table contains the addresses of global kernel items functions and variables that are needed to implement modularized drivers.  When a module is loaded, any symbol exported by the module becomes part of the kernel symbol table.  In the usual case, a module implements its own functionality without the need to export any symbols at all. Example alias eth0 e1000 Whenever eth0 is referenced, the kernel module e1000 is loaded IN MODULE HEADER FILES USE THE FOLLOWING MACROS EXPORT_SYMBOL(NAME); EXPORT_SYMBOL_GPL(NAME);
  • 30. Just about all module code includes the following header files <linux/module.h> Symbols and functions needed by modules <linux/init.h> Allows you to specify initialization and cleanup functions #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); static int hello_init(void) { printk(KERN_ALERT “Hello, worldn”); return 0; } static void hello_exit(void) { printk(KERN_ALERT “Goodbye, cruel worldn”); } module_init(hello_init); module_exit(hello_exit);
  • 31. #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE(“Dual BSD/GPL”); static int hello_init(void) { printk(KERN_ALERT “Hello, worldn”); return 0; } static void hello_exit(void) { printk(KERN_ALERT “Goodbye, cruel worldn”); } module_init(hello_init); module_exit(hello_exit); Initialization function: Registers any facility, or functionality offered by the module. Syntax: module_init(initialization_function); Shut down: Unregisters various functionalities and returns all resources
  • 32. A facility is available once a register call is completed Kernel can make calls to registered functions before the initialization function completes Obtain and initialize all critical resources before calling the register function Include moduleparam.h, stat.h Need to use the following macros module_param(name, type, permission) module_param_array(name, type, num, permission) “hello world” module to say hello to someone a number of times %/sbin/insmod ./hello.ko someone=“Mom” times=2 Output: Hello Mom Hello Mom
  • 33.
  • 34. ADVANTAGES  The full C library can be linked in. The programmer can run a conventional debugger on the driver code without having to go through contortions to debug a running kernel.  If a user-space driver hangs, you can simply kill it.  User memory is swappable, unlike kernel memory.  A well-designed driver program can still allow concurrent access to a device. DISADVANTAGES  • Interrupts are not available in user space.  • Direct access to memory is possible if only a privileged user can do that.  • Access to I/O ports is available only after calling  • Response time is slower.  • The most important devices can’t be handled in user space, including, but not limited to, network interfaces and block devices.