device drivers in linux
TRANSCRIPT
![Page 1: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/1.jpg)
Shreyas MM www.shreyasmm.com
![Page 2: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/2.jpg)
Introduction
• A new Kernel comes out every 2 - 3 months
Current – 4.3
Next Release – 4.4 LTS ( Jan – Feb 2016 )
• What do you think there is so much to work on Kernel ?
![Page 3: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/3.jpg)
Introduction
Here are what goes on each new Kernel release
Rework Things Improve performance Fix a ProblemAdd Support for New DeviceAdd New Feature
![Page 4: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/4.jpg)
Example
Support for Logitech Wireless Keyboard and Mouse
![Page 5: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/5.jpg)
Kernel Modules
• Kernel supports most of the Devices
• Devices Drivers are implemented as Kernel modules
• Kernel modules are not part of Core Kernel
![Page 6: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/6.jpg)
Kernel Modules
• Kernel modules are loaded only when they are required
• Eg – Kernel module usbhid is loaded when USB Mouse is Attached
• Kernel Modules have .ko extension
![Page 7: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/7.jpg)
Compiling Kernel From Source
~sudo su
# cd /usr/src
# curl https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.3.tar.xz
# tar –xvJf linux-4.3.tar.xz
# cd linux-4.3
# apt-get update
# apt-get install build-essentials openssh-server libssllibncurses libncurses-devel
# make menuconfig
![Page 8: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/8.jpg)
Compiling Kernel From Source
Here we have option to support Devices based on Vendor, products
Eg – we can completely Disable support for usb devices itself
![Page 9: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/9.jpg)
Compiling Kernel From Source
# make
# make modules
# make modules_install
# make install
# reboot
# uname –r
4.3
Compile main Kernel
Compile Kernel Modules
Install Kernel Modules - /lib/modules/4.3/
Install New Kernel - /boot
|->vmlinuz-4.3
|->System.map-4.3
|->vmlinuz-4.3
|->initrd.img-4.3
|->config-4.3
New Grub Entries are automatically created
![Page 10: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/10.jpg)
Kernel
• Kernel sends uevent when new device is plugged
• We can load Kernel modules with modprobe
# modprobe hid-generic
![Page 11: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/11.jpg)
Udev
• Udev is daemon
• Udev is Device Manager for Linux Kernel
• Udev Operates in User Space
• Udev listens to Kernel uevents via netlink socket
• Primarily Manages Device Nodes in /dev
Device nodes are special files that allow application to interface device drivers
![Page 12: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/12.jpg)
What happens when USB Mouse or device is Plugged ?
udevd
USB mouseis hotpluged
New uevent
Load usbhidmodule
CreateNew device node
/dev/input/mouse1
Application
Application & Hardware interact
via device file & module
1 5
4
3
2
![Page 13: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/13.jpg)
Some Commands for Module Management
# lsmod
# modinfo
# modprobe
# insmod
# rmmod
# depmod
# udevadm
# dmesg
List of modules loaded in kernelGet module infoLoad a new moduleInsert module from fileRemove a moduleCheck Dependency of moduleUdev daemon ControlPrints Message buffer of Kernel
![Page 14: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/14.jpg)
Shreyas MM www.shreyasmm.com
![Page 15: Device Drivers in Linux](https://reader037.vdocuments.us/reader037/viewer/2022102617/58ecc14b1a28ab25188b46d9/html5/thumbnails/15.jpg)
Shreyas MM www.shreyasmm.com