Difference between revisions of "Embedded Linux Device Driver"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " Most '''embedded hardware''' requires some type of software initialization and management. The software that directly interfaces with and controls this hardware is called a '...")
 
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
  
 
There are various types of '''drivers''' present in Linux such as Character, Block, Network and USB drivers. Furthermore, these bus device drivers can be of various types depending on the buses like USB drivers, PCI drivers, SBus drivers, HDMI drivers, I2C drivers, Uart drivers and a lot more.
 
There are various types of '''drivers''' present in Linux such as Character, Block, Network and USB drivers. Furthermore, these bus device drivers can be of various types depending on the buses like USB drivers, PCI drivers, SBus drivers, HDMI drivers, I2C drivers, Uart drivers and a lot more.
 
  
 
The Spoken Tutorial Effort for '''Embedded Linux Device Driver '''has been contributed by '''Mayuri Panchakshari '''and '''Usha Viswanathan''' from FOSSEE team and '''Nirmala Venkat '''from Spoken tutorial team.
 
The Spoken Tutorial Effort for '''Embedded Linux Device Driver '''has been contributed by '''Mayuri Panchakshari '''and '''Usha Viswanathan''' from FOSSEE team and '''Nirmala Venkat '''from Spoken tutorial team.
 
The domain review of this series is done by '''Prof.Kumar Appaiah '''from '''IIT Bombay'''.
 
The domain review of this series is done by '''Prof.Kumar Appaiah '''from '''IIT Bombay'''.
 
  
 
'''Learners''': BE/BTech students from Computer science, Information Technology, Electronics, Electronics and communication department and professionals from embedded system and Linux OS system programming.
 
'''Learners''': BE/BTech students from Computer science, Information Technology, Electronics, Electronics and communication department and professionals from embedded system and Linux OS system programming.
  
  
_TOC__
+
__TOC__
  
==Basic Level
+
==Basic Level==
 
#Installation of Linux kernel packages
 
#Installation of Linux kernel packages
 
#*Installation of gcc compiler
 
#*Installation of gcc compiler
Line 76: Line 74:
  
 
==Intermediate Level==
 
==Intermediate Level==
 +
#Registering a Character Device Number
 +
#*About device file
 +
#*About serial character device files
 +
#*Major and minor numbers of a device
 +
#*Internal representation of device number
 +
#*About fs.h file
 +
#*About alloc_chrdev_region() function
 +
#*Major and Minor macros
 +
#*About Unregister_chrdev_region()function
 +
#*Working of the above functions
 +
#*Compile the driver
 +
#*Display the output of major and minor number of my_device
 +
#Creating a New Character Device
 +
#*About Class and its device
 +
#*About device.h file
 +
#*Declare a class structure for a new device
 +
#*Create a class using the kernels function in the sysfs
 +
#*About device_create() function
 +
#*About class_destroy() function
 +
#*About device_destroy() function
 +
#*Working of the above functions
 +
#*Compile the driver
 +
#*Display the output of new device created
 +
#File Operations on a Device
 +
#*File operations such as open and close on a device
 +
#*About cdev.h header file
 +
#*About struct file_operations
 +
#*About mydevice_open() and mydevice_release() function
 +
#*About cdev_init()and cdev_add() function
 +
#*About cdev_del() function
 +
#*Working of the above function
 +
#*Executing the file operations with a user program
 +
#*Compile the driver
 +
#*Display the output message of open and close of a new device
 +
#Kernel Memory Allocation
 +
#*About Kernal Memory Allocation
 +
#*kmalloc() and vmalloc() functions
 +
#*About slab.h file
 +
#*Parameters of kmalloc() function
 +
#*About GFP_ATOMIC flag
 +
#*About kfree() function
 +
#*Working of the above functions
 +
#*Executing the file operations with a user program
 +
#*Compile the driver
 +
#*Display the output of kmalloc()function
 +
#Data Transfer between User and Kernel Space
 +
#*Copy data from the kernel space to the user space and vice versa
 +
#*read() and write() functions
 +
#*About uaccess.h file
 +
#*Add the protocols of read() and write() functions
 +
#*About copy_from_user() function
 +
#*About copy_to_user() function
 +
#*User program to write and read data from a device
 +
#*Executing the user program
 +
#*Compile the driver and the user program
 +
#*Display the output of data transfer
 +
#Input and Output Control
 +
#*About Input/Output control
 +
#*ioctl()- Example
 +
#*About ioctl.h file
 +
#*About macros used in the ioctl functions
 +
#*Write and Read Macros and its parameters
 +
#*ioctl function and its parameters
 +
#*Copy_from_user, Copy_to_user functions
 +
#*User program to send and receive integer data to/from the driver
 +
#*Compile and executing the user program
 +
#*Display the output of data transfer
 +
#Kernel Synchronization
 +
#*About Synchronization mechanism
 +
#*Synchronization techniques provided by Linux kernel
 +
#*Binary semaphore technique
 +
#*About semaphore.h file
 +
#*About sema_init function and its parameters
 +
#*About down_interruptible() function
 +
#*User program to write and read  data from a device
 +
#*Executing the user program
 +
#*Compile the driver and the user program
 +
#*Display the output of synchronization
 +
#Interrupt Handling
 +
#*About interrupt handler
 +
#*interrupt.h kernel header file
 +
#*Declaration of IRQ line number
 +
#*About request_irq function and its parameters
 +
#*Important flags that can be used by request_irq function
 +
#*Trigger a software interrupt using the int instruction
 +
#*User program to open and close a device
 +
#*Executing the user program
 +
#*Compile the driver and the user program
 +
#*Display the output of interrupt handler

Latest revision as of 19:22, 1 March 2021

Most embedded hardware requires some type of software initialization and management. The software that directly interfaces with and controls this hardware is called a device driver. It is used to control a particular type of device which is connected to a system.

The Device drivers takes a special role in the Linux kernel. It is the interface between the hardware device and the application or the operating system.When we connect a device to a Linux system then we need to install the driver for that particular device to be operational. Some drivers will automatically load as soon as we connect that device to the system.

Most of the Linux device drivers can be loaded into the kernel on demand when they are needed and unloaded when they are no longer being used. There is no need to restart the system after driver is loaded or unloaded.

There are various types of drivers present in Linux such as Character, Block, Network and USB drivers. Furthermore, these bus device drivers can be of various types depending on the buses like USB drivers, PCI drivers, SBus drivers, HDMI drivers, I2C drivers, Uart drivers and a lot more.

The Spoken Tutorial Effort for Embedded Linux Device Driver has been contributed by Mayuri Panchakshari and Usha Viswanathan from FOSSEE team and Nirmala Venkat from Spoken tutorial team. The domain review of this series is done by Prof.Kumar Appaiah from IIT Bombay.

Learners: BE/BTech students from Computer science, Information Technology, Electronics, Electronics and communication department and professionals from embedded system and Linux OS system programming.


Basic Level

  1. Installation of Linux kernel packages
    • Installation of gcc compiler
    • How to check gcc compiler installation?
    • How to check the kernel version of the system?
    • Install the kernel header files
    • uname -r command
    • Various details of the kernel headers
    • Check the kernal version
    • lsmod command
    • Commands that shows the kernel’s modules
    • About character device, block devices, network devices
  2. Simple Loadable Module
    • What is a kernal module?
    • Sample program for a module
    • About the header files used in the module
    • About GNU Public License
    • About the functions, macros used in the module
    • How to compile the code?
    • Create a Makefile
    • Clean the generated object file
    • Various information about a module
    • Compilation of the module
  3. Loading and Unloading a Module
    • Loading a module using insmod tool
    • Check the loaded module in the kernel
    • Pipe command
    • dmesg command
    • How to unload a module from the kernel
    • Check the unloaded module in the kernel
    • depmod command
    • modprobe command
    • About ELF file
    • objdump command
  4. Exporting Symbols from a Module
    • What is Symbol?
    • Program to Export the symbols from a module
    • Program to Import the symbols in a module
    • About EXPORT_SYMBOL and EXPORT_SYMBOL_GPL macros
    • About Makefile to compile the export and import modules
    • depmod command to recognize the newly added module
    • Load the modules into the kernel
    • Checking the successful loading
    • Unload the modules from the kernel
    • Checking the successful unloading
  5. Passing Parameters to a Module
    • About moduleparam.h file
    • module_param() macro and its parameters
    • module file permissions in S_I format
    • module_param_array macro
    • Working of the above macros
    • About Makefile
    • Compile the module
    • Load the module to see the output
    • Display the parameter passed to a module
    • Unload the module from the kernel

Intermediate Level

  1. Registering a Character Device Number
    • About device file
    • About serial character device files
    • Major and minor numbers of a device
    • Internal representation of device number
    • About fs.h file
    • About alloc_chrdev_region() function
    • Major and Minor macros
    • About Unregister_chrdev_region()function
    • Working of the above functions
    • Compile the driver
    • Display the output of major and minor number of my_device
  2. Creating a New Character Device
    • About Class and its device
    • About device.h file
    • Declare a class structure for a new device
    • Create a class using the kernels function in the sysfs
    • About device_create() function
    • About class_destroy() function
    • About device_destroy() function
    • Working of the above functions
    • Compile the driver
    • Display the output of new device created
  3. File Operations on a Device
    • File operations such as open and close on a device
    • About cdev.h header file
    • About struct file_operations
    • About mydevice_open() and mydevice_release() function
    • About cdev_init()and cdev_add() function
    • About cdev_del() function
    • Working of the above function
    • Executing the file operations with a user program
    • Compile the driver
    • Display the output message of open and close of a new device
  4. Kernel Memory Allocation
    • About Kernal Memory Allocation
    • kmalloc() and vmalloc() functions
    • About slab.h file
    • Parameters of kmalloc() function
    • About GFP_ATOMIC flag
    • About kfree() function
    • Working of the above functions
    • Executing the file operations with a user program
    • Compile the driver
    • Display the output of kmalloc()function
  5. Data Transfer between User and Kernel Space
    • Copy data from the kernel space to the user space and vice versa
    • read() and write() functions
    • About uaccess.h file
    • Add the protocols of read() and write() functions
    • About copy_from_user() function
    • About copy_to_user() function
    • User program to write and read data from a device
    • Executing the user program
    • Compile the driver and the user program
    • Display the output of data transfer
  6. Input and Output Control
    • About Input/Output control
    • ioctl()- Example
    • About ioctl.h file
    • About macros used in the ioctl functions
    • Write and Read Macros and its parameters
    • ioctl function and its parameters
    • Copy_from_user, Copy_to_user functions
    • User program to send and receive integer data to/from the driver
    • Compile and executing the user program
    • Display the output of data transfer
  7. Kernel Synchronization
    • About Synchronization mechanism
    • Synchronization techniques provided by Linux kernel
    • Binary semaphore technique
    • About semaphore.h file
    • About sema_init function and its parameters
    • About down_interruptible() function
    • User program to write and read data from a device
    • Executing the user program
    • Compile the driver and the user program
    • Display the output of synchronization
  8. Interrupt Handling
    • About interrupt handler
    • interrupt.h kernel header file
    • Declaration of IRQ line number
    • About request_irq function and its parameters
    • Important flags that can be used by request_irq function
    • Trigger a software interrupt using the int instruction
    • User program to open and close a device
    • Executing the user program
    • Compile the driver and the user program
    • Display the output of interrupt handler

Contributors and Content Editors

Nirmala Venkat