Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
259 views

Assignments For Device Drivers Programming in Linux

The document provides rules and instructions for assignments in a Linux Device Drivers module. It states that students must maintain a single journal document to log their daily activities and learnings for each assignment. The journal will be evaluated and used to award marks. Students must not copy others' work and should discuss assignments together but not copy directly. Daily journaling of assignments is required to receive full marks. There is an optional bonus question at the end.

Uploaded by

Sahil Khan
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views

Assignments For Device Drivers Programming in Linux

The document provides rules and instructions for assignments in a Linux Device Drivers module. It states that students must maintain a single journal document to log their daily activities and learnings for each assignment. The journal will be evaluated and used to award marks. Students must not copy others' work and should discuss assignments together but not copy directly. Daily journaling of assignments is required to receive full marks. There is an optional bonus question at the end.

Uploaded by

Sahil Khan
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Assignments for Linux Device Drivers module

Rules for solving the assignments


1. Maintain a journal (Word document) for your day to day activities in the lab (only 1 document).
2. The journal will be evaluated at the end of the module and assignment marks will be awarded
based on your personal findings
3. As you attempt the assignments, you will have to journal your learnings for each day and each
assignment in the journal your journal
4. Do not copy or use somebody else's journal. The content will be processed through a
plagiarism software and if you are caught copying, assignment marks will be deducted.
5. Each student will maintain his individual journal and will not share his work with other students.
6. You are free to discuss amongst yourselves, refer to material from other sources but make
sure that you are not copying from others.
7. Journal daily. Each day carries marks. Failure to do so will reduce your marks
8. There is a Bonus Question in the final section. Refer to the section Ultimate Bonus for a
challenge

Contents
Introduction to Module Programming and Device Drivers ......................................................................3
Lab Objectives ......................................................................................................................................3
Assignments..........................................................................................................................................3
Introduction to Character Drivers..............................................................................................................4
Lab Objectives.......................................................................................................................................4
Assignments..........................................................................................................................................4
Advanced Character Drivers......................................................................................................................5
Lab Objectives.......................................................................................................................................5
Assignments..........................................................................................................................................5
Concurrency & Race Conditions...............................................................................................................6
Lab Objectives.......................................................................................................................................6
Assignments..........................................................................................................................................6
Time, Delays and Deferred Execution.......................................................................................................8
Lab Objectives.......................................................................................................................................8
Assignments..........................................................................................................................................8
Communication with Hardware and Interrupt Handling...........................................................................9
Lab Objectives.......................................................................................................................................9
Assignments..........................................................................................................................................9
Additional Topics.....................................................................................................................................10
Debugging Techniques........................................................................................................................10
Kernel Linked Lists.............................................................................................................................10
Adding A system Call..........................................................................................................................10
Embedded Linux.................................................................................................................................10
USB Drivers........................................................................................................................................10
Ultimate Bonus.........................................................................................................................................11

Introduction to Module Programming and Device Drivers


Lab Objectives
1. Acquaint yourselves with required commands/utilities that will be encountered when writing a
kernel module
2. Compile and run your first Kernel Module
3. Pass runtime parameters to modules
4. Understand the Kernel Symbol Table
5. Write a Makefile for compiling the Kernel Module
Assignments
1. Explore the following utilities and comment on them in your journals
1. lsmod
2. insmod
3. rmmod
4. modprobe
5. Makefile for compiling the module
6. dmesg
7. cat /proc/modules
In a sentence, journal the significance of each of the above utilities
2. Write a simple module which would print I am in init module when the module is inserted &
I am in cleanup module when it is removed? Perform lsmod before inserting the module
and after inserting the module Record your observations in the journal.
3. Read about the module_param() macro and write a simple Add module which takes
parameters at module loading time and prints the sum of the numbers in init module and
cleanup module. Can you pass a structure to the kernel module containing your name, age,
batch and subject? Record your learnings in the journal
4. Write two modules, Add and Average. Add exports a function add() which takes 2 arguments
and returns the sum of those 2 numbers. Average calls the function add() to perform an
average operation. Execute these modules using
1. insmod
2. modprobe
Record your observations in your journal

Introduction to Character Drivers


Lab Objectives
1. Acquaint yourselves with required utilities & concepts that will be encountered when writing a
character device driver
2. Develop a template for a Character Driver providing functionality like Open, Read, Write and
Close
3. Transact data between an application written in user space and a character driver, written in
the kernel space
4. Develop a driver serving multiple applications
Assignments
1. Explore the following utilities
1. mknod
2. cat /proc/devices
3. /dev from the linux file system
In one sentence, explain the above utilities in your journals
2. Review and differentiate between the following concepts and journal in a few sentences
1. dev_t data type, MAJOR(), MINOR (), MKDEV()
2. register_chrdev_region(), alloc_chrdev_region()
3. struct file_operations, struct file, struct inode, struct cdev
3. Build a skeletal Character Diver that registers and unregisters itself with the kernel. Comment
in your journals, what is displayed when cat /proc/devices is executed before and after
loading the driver.
4. Execute the above program using alloc_chrdev_region function. Record your observations
5. Write a Character Driver, which implements the open and close methods/functionality. Write an
application which opens and closes the driver. Print out some information in the open and
close methods of the driver. Record the tail of dmesg in your journals
6. Write a Character Driver which implements the open, read, write and close methods/functions.
An application in user space should open the driver and perform the 4 operations. When the
application performs the read operation on the driver, stored data should be transferred to the
application and printed in user space. Similarly, when the application writes data, the driver
should display it in dmesg.
7. Write a Character Driver that registers 4 Device Numbers (Major & Minor pairs). Create 4
device nodes in /dev by the names Add, Sub, Mul, Div which correspond to addition
functionality, subtraction functionality and so on. There should be 4 applications in the user
space, each calling, one of the 4 device nodes and implementing call to functions open, read,
write and close. The Character Driver should implement 8 functions by names Add_read,
Add_write, Sub_read, Sub_write and so on. At run time, based on the application being
executed in user space, the read & write functions should be wired ie, when the add program is
executed in user space, the character driver should function as an addition driver and collect
the arguments passed during the application's write, calculate the sum and return the sum to
the application's read. Similar logic applies for other applications as well.

Advanced Character Drivers


Lab Objectives
1. Explore the mechanism of sending and receiving control information to and from a device
driver
2. Implement schemes for blocking a user space application until the requested amount of data is
not available
Assignments
1. Review the following concepts and journal in a few sentences
1. Magic Numbers and their composition
2. Exclusive Waits
Journal your learnings in one or two sentences
2. There is a serial device which provides the control operations namely SET_BAUD,
SET_PARITY, SET_STOP_BITS, FLUSH_BUFFERS, READ_DEVICE_CONFIGURATION.
Create the Magic Numbers for these operations such that they are unique over the whole
system. Journal your understanding
3. Using the Magic Numbers above, write a Character driver that implements the IOCTL method
to handle the above mentioned control operations. Develop a user space application which
opens the driver and performs the above operations. How will you pass a structure of
configuration information using IOCTL. Journal your options
4. Write a Character Driver that implements a Blocking operation between read and write
methods. In the user space, develop two applications, one should only read and the other
should only write. Both the applications should open the driver simultaneously. The read
application should not complete execution until the write application finishes. The data read in
the read application is provided by the write application. Use Wait Queues to stall the read
process until write completes. Journal what you have learnt and the scenarios in whichwait
queues are significant in Device Driver development

Concurrency & Race Conditions


Lab Objectives
1. To understand various terminologies used when dealing with concurrency and race conditions
2. To explore various kernel constructs/mechanisms available for handling concurrency and
identify the scenarios where each construct may be employed. The constructs which will be
investigated are
1. Semaphores & Reader-Write Semaphores
2. Spinlocks & Reader-Writer Spinlocks
3. Signaling using Completions
4. Sequential Locks
5. Atomic Variables
3. To familiarize ourselves with the synchronization constructs available in the kernel by
developing various drivers using them
Assignments
1. There are 3 applications A1, A2 and A3 in the user space. A1 and A2 are writing data to the
kernel buffer and A3 is consuming the data. While A1 writes data from 1 to 10, A2 writes data
from 51-60. A3 has to read all the 20 bytes of data without losing any. Implement this
requirement using a Character Driver such that all three applications are using the same driver
and are executing simultaneously. There is only one global buffer in the kernel space.
Implement this requirement using semaphores. Depict your logic in your journals
2. There are three applications A1, A2 and A3 in the user space. A1 is randomly generating
numbers in the range 1 to 100. A2 and A3 are responsible to consume the numbers being
generated by A1 such that A2 consumes all even numbers while A3 consumes all odd
numbers. All the applications open the same driver to perform this operation and the data is
stored in one global data buffer. Synchronize the operations such that there is no data
overwriting and data is rightly printed out. Journal your logic
3. Implement Assignment 1 such that each write is followed by a read and vice versa. No two
writes should happen one after the other and no two reads should happen one after the other.
Journal your logic
4. Implement Assignment 2 such that applications A2 and A3 are executed alternately with A1. Is
there a change in the logic? Journal your understanding
5. Familiarize yourselves with the spinlock technique by executing Assignment 1 using spinlocks.
Record the application differences between semaphores and spinlocks. Where will you use a
spinlock and where will you use a semaphore.
6. There is a user space process which spawns 5 threads T1, T2, T3, T4, T5. Each of the threads
T1 to T4 populate a global buffer in the kernel space with their IDS and their time of execution.
T5 should gain access to the global buffer only after all the other threads have completed
execution. Which is the best mechanism to provide this synchronization? Comment in your
journals
7. There are 2 applications (A1 & A2) in user space. A1 tries to increment a variable and A2 tries
to decrement this variable, which is maintained by the kernel driver. Using atomic variables,
synchronize this action such that no data is lost. Journal the output

8. For all the synchronization mechanisms you have learnt so far, write where each finds its
application in driver development.

Time, Delays and Deferred Execution


Lab Objectives
1.
2.
3.
4.

Investigate various mechanisms available in the kernel for maintaining time


Use kernel timers to achieve fixed delays, specifying the exact time
Understand deferred execution and its importance in Interrupt Management, using tasklets
To defer execution of a kernel thread using Work Queues

Assignments
1. Implement a sleep function in the driver using the jiffies variable. The user space application
should call ioctl function with a command requesting a delay. The amount of delay in seconds
can be passed as command value to ioctl. The driver should use jiffies and provide this delay.
During the delay, the application may be put onto the wait queue and woken up after the delay
has expired. Print out the time difference in the user space application. Journal the result,
defining the logic used
2. Write a driver which returns the current time to the user space application when the ioctl
function is called.
3. Write a driver, which executes a function to print the time in the kernel, every second. The
function is initiated when read is called by application A1. When application A2 executes, the
periodicity of execution should be modified to 2 seconds. Application A3 will stop the function
from executing. Journal your results
4. Explore the tasklet API and write a driver which defers the execution of a function to a later
moment. Print the time difference between scheduling the tasklet and its actual execution.
Repeat this experiment using the high priority variant of the tasklet API and record the
differences. Journal your learnings.

Communication with Hardware and Interrupt Handling


Lab Objectives
1. Explore the functions that enable data transfer between the driver and hardware devices
2. To gain access to the parallel port hardware by requesting for the I/O memory and Interrupt
allocations
3. Understand Interrupts and the Linux implementation of Interrupt Handling
4. Write a handler for the parallel port
5. Probe the parallel port to generate interrupts and handle the interrupts
Assignments
1. Probe the parallel port and find out the IRQ number of the hardware.
2. Using the seven segment display board given to you, develop a parallel port driver that prints
the number transferred by the application program onto the device.

Additional Topics
Debugging Techniques
1. Explore the Oops message and try to find out the error using the message?
2. Configure and Compile the UML (User Mode Linux) and try simple Driver programs in UML ?
3. Explore KDB, KGDB and set up a debugging environment for linux device drivers.
Kernel Linked Lists
1. Implement a Linked list inside the kernel and perform the following operations on th list
1. Add a entry to the list
2. Add a entry to the tail of the list
3. Delete a entry from the list
4. Removes a entry from a list and adds to another list
5. Removes a entry from a list and adds to the tail of another list
6. Traversing the list
Do the above program using the IOCTL commands for the user application?
Adding A system Call
1. Add your own system call to linux by defining a function to provide system time as a string
Embedded Linux
1. Configure and Compile the New Kernel for ARM processor and generate initrd for the same
run the system with the new compiled kernel and do all Device Drivers programs in that kernel.
USB Drivers
1. Explore the USB subsystem and write a driver to probe a device.

Ultimate Bonus
1. Write a driver for the Serial Port using data sheet, 16550. The driver should implement all the
mechanisms and constructs covered in the Device Drivers lectures and should communicate
with the hardware using Interrupts. Proper mechanisms for buffer management should be
performed in the driver and it should support concurrent access. If this is completed according
to required specifications, you will be exempt for appearing in the lab exam and will be
awarded highest marks. You may begin from the 2 nd week of the module and complete it within
5 working days. Partially completed drivers will not be accepted.

You might also like