Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Character Device Drivers in deep
Rating: 4.2 out of 5(154 ratings)
1,546 students

Character Device Drivers in deep

Linux Kernel Programming - Character Device Drivers
Created byLinux Trainer
Last updated 10/2020
English
English [Auto],

What you'll learn

  • Write character device driver from scratch
  • Understand the various file operations provided by character driver

Course content

6 sections • 88 lectures • 4h 20m total length
  • Introduction to character device drivers3:36

    Explore how a device driver integrates code parts—user space access and hardware communication—treats devices as files and uses character devices for byte-wise data with system calls like open and read.

  • List Character and Block Devices2:28

    Learn to differentiate character and block device files and identify real-world examples like serial ports, console terminals, hard disks, and ramdisks through device file types.

  • Steps in Registering a character driver0:41
  • Device Number = Major + Minor3:32

    Learn how the name-based connection between a user application and the device file contrasts with major and minor numbers, where the major identifies the driver and the minor distinguishes devices.

  • How to choose a device number1:58

    Major numbers are statically assigned and documented by government sources, showing used device numbers; the lecture contrasts static and dynamic assignment and explains how dynamic mode allocates the last number.

  • Data type for device number dev_t0:50
  • Example of MAJOR,MINOR,MKDEV macros3:27

    Explore a simple example using the major, minor, and mkdev macros to create and dissect a device number, print the major and minor values, and verify them by extraction.

  • /proc/devices file1:03

    Explore the /proc/devices file to see the devices currently present on the system, including their major numbers and names. The content is shown in two sections.

  • Static Allocation of Device Numbers1:36

    Examine static and dynamic allocation of major and minor device numbers in character device drivers, and why dynamic allocation helps avoid conflicts.

  • Example of static allocation of device numbers2:26

    Explore the static allocation of device numbers for character device drivers, illustrating default values and how explicit IDs are assigned and verified within the system.

  • Test cases on Previous Example1:58

    Explore test cases on a previous example within character device drivers. Examine arguments discussed in the caption to understand how the topic unfolds.

  • What happens if i try to register same major number1:39

    Explore what happens when two character device drivers register the same major number, and why dynamic allocation prevents conflicts unlike static allocation.

  • What happens if i try to register same name1:36

    The lecture explores a reverse case of registering the same name in character device drivers, showing successful registration when major numbers differ, using usb and uspi as examples.

  • Registering Maximum Minor Numbers3:27

    Explain how one major number supports multiple minor numbers via the magic number, with 126 majors and minor numbers starting at zero or ten, illustrating registration and overflow.

  • What is Maximum Major Number3:02

    Explain how the kernel enforces an artificial limit on major numbers via the Major_Max macro. Show that the maximum major number is 511 and that allocations like 095 are blocked.

  • Dynamic Allocation of Device Number0:48

    Examine dynamic allocation of device numbers to replace static locations, address allocation parameters such as minimum numbers and device counts, and minimize conflicts.

  • Example of dynamic allocation of device number1:54
  • Calling alloc_chrdev_region in loop4:12

    Explore how alloc_chrdev_region is called in a loop to allocate dynamic major numbers, revealing two segments, end-of-segment values (234 and 384), and why the region fills and requires a reboot.

  • Manual Device Node Creation3:54
  • Automatic Device Node Creation - class_create4:02
  • Automatic Device Node Creation - device_create2:48

    Explore automatic device node creation using device_create in character device drivers, covering major and minor numbers, device class creation, and clean removal of devices.

  • Example of automatic device node creation1:54

    This example demonstrates automatic device node creation, using a device number and a name, and discusses allocation and creation steps.

  • Quiz 1

Requirements

  • Should be able to write/compile/load/unload Hello World Linux Kernel Modules

Description

Updated on Oct 10: Added Downloads section

What will you learn from this course?

  • Introduction to character drivers

  • What is device number and device file

  • Allocating device number - statically and dynamically

  • Creating device file - Manually(mknod) and automatically (udev)

  • Registering character device and its file operation with Kernel

  • Copying data from user space to kernel space and vice versa

  • Understanding the various structures - struct file and struct inode

  • Implementation of open, release, read, write, llseek, ioctl file operations

  • How to create multiple device nodes and add support for private data

  • Flow of write system call from kernel system call entry point to driver write file operations

  • Handling all the error cases in ioctl implementation

  • Sending a signal to user space from kernel space

  • Various access control mechanisms and capabilities

  • Misc Driver

API's covered in this course:

  • MAJOR

  • MINOR

  • MKDEV

  • register_chrdev_region

  • alloc_chrdev_region

  • class_create

  • device_create

  • class_destroy

  • device_destroy

  • unregister_chrdev_region

  • imajor

  • iminor

  • copy_from_user

  • copy_to_user

  • put_user

  • get_user

  • print_dev_t

  • format_dev_t

  • strnlen_user

  • container_of

  • access_ok

Commands used in this course:

  • mknod

  • udevadm monitor

Who this course is for:

  • Developers interested in learning Linux Kernel Programming