Device Drivers in Linux
-
Upload
shreyas-mm -
Category
Technology
-
view
823 -
download
1
Transcript of Device Drivers in Linux
Shreyas MM www.shreyasmm.com
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 ?
Introduction
Here are what goes on each new Kernel release
Rework Things Improve performance Fix a ProblemAdd Support for New DeviceAdd New Feature
Example
Support for Logitech Wireless Keyboard and Mouse
Kernel Modules
• Kernel supports most of the Devices
• Devices Drivers are implemented as Kernel modules
• Kernel modules are not part of Core Kernel
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
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
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
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
Kernel
• Kernel sends uevent when new device is plugged
• We can load Kernel modules with modprobe
# modprobe hid-generic
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
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
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
Shreyas MM www.shreyasmm.com
Shreyas MM www.shreyasmm.com