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
 ReworkThings
 Improve performance
 Fix a Problem
 Add Support for New Device
 Add 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 libssl
libncurses 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 mouse
is hotpluged
New uevent
Load usbhid
module
Create
New 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 kernel
Get module info
Load a new module
Insert module from file
Remove a module
Check Dependency of module
Udev daemon Control
Prints Message buffer of Kernel
Shreyas MM www.shreyasmm.com
Shreyas MM www.shreyasmm.com

Device Drivers in Linux

  • 1.
  • 2.
    Introduction • A newKernel 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 ?
  • 3.
    Introduction Here are whatgoes on each new Kernel release  ReworkThings  Improve performance  Fix a Problem  Add Support for New Device  Add New Feature
  • 4.
    Example Support for LogitechWireless Keyboard and Mouse
  • 5.
    Kernel Modules • Kernelsupports most of the Devices • Devices Drivers are implemented as Kernel modules • Kernel modules are not part of Core Kernel
  • 6.
    Kernel Modules • Kernelmodules are loaded only when they are required • Eg – Kernel module usbhid is loaded when USB Mouse is Attached • Kernel Modules have .ko extension
  • 7.
    Compiling Kernel FromSource ~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 libssl libncurses libncurses-devel # make menuconfig
  • 8.
    Compiling Kernel FromSource Here we have option to support Devices based on Vendor, products Eg – we can completely Disable support for usb devices itself
  • 9.
    Compiling Kernel FromSource # 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
  • 10.
    Kernel • Kernel sendsuevent when new device is plugged • We can load Kernel modules with modprobe # modprobe hid-generic
  • 11.
    Udev • Udev isdaemon • 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
  • 12.
    What happens whenUSB Mouse or device is Plugged ? udevd USB mouse is hotpluged New uevent Load usbhid module Create New device node /dev/input/mouse1 Application Application & Hardware interact via device file & module 1 5 4 3 2
  • 13.
    Some Commands forModule Management # lsmod # modinfo # modprobe # insmod # rmmod # depmod # udevadm # dmesg List of modules loaded in kernel Get module info Load a new module Insert module from file Remove a module Check Dependency of module Udev daemon Control Prints Message buffer of Kernel
  • 14.
  • 15.