device drivers in linux

15
Shreyas MM www.shreyasmm.com

Upload: shreyas-mm

Post on 22-Jan-2018

821 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Device Drivers in Linux

Shreyas MM www.shreyasmm.com

Page 2: Device Drivers in Linux

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

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

Example

Support for Logitech Wireless Keyboard and Mouse

Page 5: Device Drivers in Linux

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

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

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

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

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

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

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

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

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

Shreyas MM www.shreyasmm.com

Page 15: Device Drivers in Linux

Shreyas MM www.shreyasmm.com