<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Embedded-Linux-Device-Driver%2FC3%2FFile-Operations-on-a-Device%2FEnglish</id>
		<title>Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Embedded-Linux-Device-Driver%2FC3%2FFile-Operations-on-a-Device%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;action=history"/>
		<updated>2026-05-13T15:46:52Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;diff=54041&amp;oldid=prev</id>
		<title>Nancyvarkey at 08:21, 15 October 2020</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;diff=54041&amp;oldid=prev"/>
				<updated>2020-10-15T08:21:36Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;amp;diff=54041&amp;amp;oldid=53858&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Nancyvarkey</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;diff=53858&amp;oldid=prev</id>
		<title>Nancyvarkey at 10:08, 28 September 2020</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;diff=53858&amp;oldid=prev"/>
				<updated>2020-09-28T10:08:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;amp;diff=53858&amp;amp;oldid=53839&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Nancyvarkey</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;diff=53839&amp;oldid=prev</id>
		<title>Nirmala Venkat: Created page with &quot; {| style=&quot;border-spacing:0;&quot; | style=&quot;border:1pt solid #000000;padding:0.176cm;&quot;| '''Visual cue :''' | style=&quot;border:1pt solid #000000;padding:0.176cm;&quot;| '''Narration :'''  |...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Embedded-Linux-Device-Driver/C3/File-Operations-on-a-Device/English&amp;diff=53839&amp;oldid=prev"/>
				<updated>2020-09-22T11:36:17Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot; {| style=&amp;quot;border-spacing:0;&amp;quot; | style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &amp;#039;&amp;#039;&amp;#039;Visual cue :&amp;#039;&amp;#039;&amp;#039; | style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &amp;#039;&amp;#039;&amp;#039;Narration :&amp;#039;&amp;#039;&amp;#039;  |...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
{| style=&amp;quot;border-spacing:0;&amp;quot;&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| '''Visual cue :'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| '''Narration :'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 1 :&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Welcome to the spoken tutorial on '''File Operations on a Device.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 2 :&lt;br /&gt;
Learning objectives:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| In this tutorial, we will learn how to&lt;br /&gt;
&lt;br /&gt;
* Implement the basic''' file operations '''such as '''open() '''and''' close()''' on a '''device'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 3:&lt;br /&gt;
&lt;br /&gt;
System Requirements:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| To record this tutorial, I am using,&lt;br /&gt;
&lt;br /&gt;
* '''VirtualBox''' version '''5.2.'''&lt;br /&gt;
* '''Ubuntu Linux 18.04 LTS''' operating system.&lt;br /&gt;
* '''Linux kernel '''version''' 5.0.0-31 generic '''and&lt;br /&gt;
* '''gedit text editor'''&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 4 :&lt;br /&gt;
&lt;br /&gt;
Prerequisites:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| To follow this tutorial, you should be familiar with:&lt;br /&gt;
&lt;br /&gt;
* '''C programming language '''and&lt;br /&gt;
* Basics of''' Linux kernel'''&lt;br /&gt;
&lt;br /&gt;
If not, then go through the '''C/C++''' and '''Linux''' spoken tutorials on this website.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Point to the '''folder''' and''' file''' in '''desktop'''&lt;br /&gt;
&lt;br /&gt;
Point to the '''files.'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Go to the '''DeviceDriver '''folder on the desktop.&lt;br /&gt;
&lt;br /&gt;
Here I have created a new directory''' '''as '''FileOperations.'''&lt;br /&gt;
&lt;br /&gt;
In this directory, I have saved a '''simple_driver dot c driver file, Makefile and user.c.'''&lt;br /&gt;
&lt;br /&gt;
I’ll use these files''' '''for demonstration.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 5:&lt;br /&gt;
&lt;br /&gt;
'''Code files:'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| * The files used in this tutorial are available in the '''Code Files '''link on this tutorial page.&lt;br /&gt;
* Please download and extract them&lt;br /&gt;
* Make a copy and then use them while practising&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 6:&lt;br /&gt;
&lt;br /&gt;
About new_device&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| We have already registered and created a device called '''new_device '''in the earlier tutorial.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will perform file operations such as '''open''' and '''close''' on''' new_device.'''&lt;br /&gt;
&lt;br /&gt;
We will use a user program called '''user.c '''to access this device.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Open the '''terminal'''&lt;br /&gt;
&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Open the '''terminal''' by pressing '''ALT+Ctrl+T '''keys simultaneously.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''cd Desktop/DeviceDriver/FileOperations'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Go to the directory '''FileOperations '''as shown here.&lt;br /&gt;
&lt;br /&gt;
Press '''Enter '''key after every command'''.'''&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''gedit simple_driver.c'''&lt;br /&gt;
&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type''' gedit space simple_driver dot c.'''&lt;br /&gt;
&lt;br /&gt;
I have used the same''' '''file''' simple_driver dot c '''which we used earlier.&lt;br /&gt;
&lt;br /&gt;
Here, I have implemented the basic file functions for the device '''new_device.'''&lt;br /&gt;
&lt;br /&gt;
Using these''' '''functions users can perform the '''open '''and '''close''' '''operations '''on a '''device'''.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Let me explain the code.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight '''&amp;lt;nowiki&amp;gt;#include&amp;lt;linux/fs.h&amp;gt;&amp;lt;/nowiki&amp;gt;''' and&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;nowiki&amp;gt;#include&amp;lt;linux/cdev.h&amp;gt;&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''cdev.h'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''struct cdev.'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| We have to include these '''header files '''to perform file''' '''related operations.&lt;br /&gt;
&lt;br /&gt;
The''' cdev dot h header '''file is used to create the''' character device structure.'''&lt;br /&gt;
&lt;br /&gt;
The '''cdev structure''' is used to describe '''character devices''' in the''' Linux kernel.'''&lt;br /&gt;
&lt;br /&gt;
Here,''' my_cdev''' represents our '''device cdev structure''' in the '''kernel. '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Now let us see how to implement the '''device file operations.''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight :&lt;br /&gt;
&lt;br /&gt;
'''struct file_operations structure'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| * '''File operations''' are defined in the''' kernel''' as the instance of '''struct file_operation.'''&lt;br /&gt;
* This is the most important structure of a driver defined in the '''fs dot h file.'''&lt;br /&gt;
* Each field of this '''structure '''is a '''function pointer.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight''' struct file_operations structure'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''mydevice_open '''and '''mydevice_release'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Here, I have defined the''' file_operations structure '''for our '''device.'''&lt;br /&gt;
&lt;br /&gt;
We will implement two functions''' mydevice_open '''and''' mydevice_release '''in a driver.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight''' function declarations.'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| You have to declare the prototypes of these '''functions '''at the start of the '''driver.'''&lt;br /&gt;
&lt;br /&gt;
You can get these '''functions '''declarations from the '''fs dot h header file'''.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Now let us see the''' kernels functions''' used to implement the file operations.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight '''void cdev_init()'''&lt;br /&gt;
&lt;br /&gt;
Highlight''' cdev'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''fops'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| The '''cdev_init() function''' is used to initialize the members of the '''cdev structure.'''&lt;br /&gt;
&lt;br /&gt;
'''cdev''' specifies a''' '''pointer to the''' cdev structure''' to initialize.&lt;br /&gt;
&lt;br /&gt;
'''fops''' specifies a''' '''pointer to device '''file operation structure.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight '''init_function()'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''cdev_init(&amp;amp;my_cdev, &amp;amp;fops)'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''my_cdev''' and '''fops.'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| In the '''init_function''', we have already created a device '''new_device '''and its '''class.'''&lt;br /&gt;
&lt;br /&gt;
After that we have to initialize the '''cdev structure '''of a device as shown here.&lt;br /&gt;
&lt;br /&gt;
It will establish a connection between '''cdev structure '''and '''file_operations.'''&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight '''int cdev_add()'''&lt;br /&gt;
&lt;br /&gt;
Highlight''' p'''&lt;br /&gt;
Highlight '''dev'''&lt;br /&gt;
Highlight '''count'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| '''cdev_add()''' adds a '''cdev''' to the system to complete the registration of a device.&lt;br /&gt;
&lt;br /&gt;
It returns a negative error code on failure.&lt;br /&gt;
&lt;br /&gt;
'''p '''specifies the cdev structure for the device.&lt;br /&gt;
&lt;br /&gt;
'''dev''' specifies a device number.&lt;br /&gt;
&lt;br /&gt;
'''count '''specifies''' '''a number of consecutive minor numbers corresponding to this device.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight '''cdev_add()'''&lt;br /&gt;
&lt;br /&gt;
Highlight my_cdev&lt;br /&gt;
&lt;br /&gt;
Highlight the''' device_destroy(cl,device_num),'''&lt;br /&gt;
&lt;br /&gt;
'''class_destroy(cl), unregister_chrdev_region(device_num,1);'''&lt;br /&gt;
&lt;br /&gt;
Highlight''' printk'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| I used this '''function''' to add the '''cdev structure''' of '''new_device '''as shown here.&lt;br /&gt;
&lt;br /&gt;
If the registration fails then we have to destroy a '''device''' and its '''class. '''&lt;br /&gt;
&lt;br /&gt;
Also unregister the device from the system as shown here.&lt;br /&gt;
&lt;br /&gt;
This '''printk''' message will show the successful execution of the '''cdev_add()''' '''function'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight''' mydevice_open()'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''printk''' message&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Now we will learn how to implement the''' device file '''functions'''.'''&lt;br /&gt;
&lt;br /&gt;
Here, I have defined the '''open''' function with a '''printk''' message. &lt;br /&gt;
&lt;br /&gt;
'''mydevice_open() '''function gets executed when the user program opens the device.&lt;br /&gt;
&lt;br /&gt;
This''' printk''' message will display in the '''kernel log level.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight''' mydevice_release()'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''printk message'''&lt;br /&gt;
&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Similarly, I have defined the '''release '''function with a '''printk''' message. &lt;br /&gt;
&lt;br /&gt;
'''mydevice_release() function''' gets executed when the '''user''' '''program''' closes the device.&lt;br /&gt;
&lt;br /&gt;
This '''printk''' message will display in the''' kernel log level'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Let us see the '''exit function '''of a driver.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| '''void cdev_del (struct cdev * cdev)'''&lt;br /&gt;
&lt;br /&gt;
Highlight''' cdev'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| '''cdev_del() function''' will remove a''' cdev structure '''of a '''device '''from the kernel.&lt;br /&gt;
&lt;br /&gt;
'''cdev '''specifies the '''cdev''' structure to be removed.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight '''cdev_del()'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Here, we remove the '''cdev structure '''of a '''new_device '''before removing its''' '''file'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Now let us write the program to perform the file operations on the '''device file.'''&lt;br /&gt;
&lt;br /&gt;
Save and close the file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''gedit user.c.'''&lt;br /&gt;
&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type '''gedit user dot c.'''&lt;br /&gt;
&lt;br /&gt;
Here, I have created a simple''' user program''' which will open and close the '''device.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Highlight''' open() function'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''printf'''&lt;br /&gt;
&lt;br /&gt;
Highlight '''close() function'''&lt;br /&gt;
&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| The '''open() system call '''will internally call the''' open function''' of '''new_device '''from its driver.&lt;br /&gt;
&lt;br /&gt;
'''printf function''' will print the message if the '''open function''' fails to open the '''new_device.'''&lt;br /&gt;
&lt;br /&gt;
'''close() system call''' will internally call the '''close function '''of a''' new_device''' from its driver.&lt;br /&gt;
&lt;br /&gt;
Save and close the''' '''file'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''gedit Makefile '''&lt;br /&gt;
&lt;br /&gt;
Save the''' Makefile '''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Let us create a '''Makefile''' to '''compile''' a '''driver.'''&lt;br /&gt;
&lt;br /&gt;
Type''' gedit space Makefile.'''&lt;br /&gt;
&lt;br /&gt;
Type this '''code''' in a '''Makefile '''or you can use the downloaded '''Makefile.'''&lt;br /&gt;
&lt;br /&gt;
Save and close the file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type''' sudo su'''&lt;br /&gt;
&lt;br /&gt;
Type &amp;gt;&amp;gt; '''make all'''&lt;br /&gt;
&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Let us '''compile''' the '''driver.'''&lt;br /&gt;
Type''' sudo su '''and''' password''' to be a superuser.&lt;br /&gt;
Type '''make space all.'''&lt;br /&gt;
&lt;br /&gt;
Clear the screen.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt;''' insmod simple_driver.ko'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Now let us load the '''driver '''into the''' kernel.'''&lt;br /&gt;
&lt;br /&gt;
For that, type '''insmod space simple_driver dot ko.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''clear'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Clear the screen'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''dmesg | grep simple_driver'''&lt;br /&gt;
&lt;br /&gt;
Highlight the output&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Let us see the loaded '''printk '''messages from the '''initialisation function.'''&lt;br /&gt;
&lt;br /&gt;
Type '''dmesg space pipe space grep space simple_driver.'''&lt;br /&gt;
&lt;br /&gt;
Here, you can see the''' cdev structure''' of a '''new_device '''registered successfully.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt;''' clear'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Clear the screen'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''gcc -c user. c'''&lt;br /&gt;
&lt;br /&gt;
Type &amp;gt;&amp;gt;''' gcc -o user user.o.'''&lt;br /&gt;
&lt;br /&gt;
Type &amp;gt;&amp;gt;''' ./user'''&lt;br /&gt;
&lt;br /&gt;
Highlight output&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Now let us compile the '''user.c file'''&lt;br /&gt;
&lt;br /&gt;
Type '''gcc space hyphen c space user dot c''' &lt;br /&gt;
&lt;br /&gt;
Then type''' gcc space hyphen o space user space user dot o'''&lt;br /&gt;
&lt;br /&gt;
Now to execute the program type '''dot slash user.'''&lt;br /&gt;
&lt;br /&gt;
Here, it indicates that the '''new_device '''opened successfully.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt;''' clear'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Clear the screen'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''dmesg | grep simple_driver'''&lt;br /&gt;
&lt;br /&gt;
Highlight the '''respective messages'''&lt;br /&gt;
&lt;br /&gt;
Type &amp;gt;&amp;gt;''' clear'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type the command as shown here.&lt;br /&gt;
&lt;br /&gt;
The output shows that '''open '''and''' close''' '''functions '''of the driver are executed successfully.&lt;br /&gt;
&lt;br /&gt;
It indicates that the '''new_device''' is opened and closed by the '''user program.'''&lt;br /&gt;
&lt;br /&gt;
Clear the '''screen.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type''' rmmod simple_driver.ko'''&lt;br /&gt;
&lt;br /&gt;
Type '''dmesg | grep simple_driver'''&lt;br /&gt;
&lt;br /&gt;
Highlight the '''output'''&lt;br /&gt;
&lt;br /&gt;
Type &amp;gt;&amp;gt;''' clear'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Now let us unload the '''driver.'''&lt;br /&gt;
&lt;br /&gt;
Type '''rmmod space simple_driver dot ko'''&lt;br /&gt;
&lt;br /&gt;
To see the unloaded '''printk '''messages type this '''dmesg '''command.&lt;br /&gt;
&lt;br /&gt;
It indicates that the''' cdev structure '''of a '''new_device '''removed from the '''kernel. '''&lt;br /&gt;
&lt;br /&gt;
Clear the screen.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Type &amp;gt;&amp;gt; '''make clean'''&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Let us remove the '''object files''' created after the compilation'''.'''&lt;br /&gt;
&lt;br /&gt;
Type '''make space clean.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| &lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| With this, we come to the end of this tutorial. Let us summarize.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 7:&lt;br /&gt;
&lt;br /&gt;
Summary:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| In this tutorial, we learnt how to&lt;br /&gt;
&lt;br /&gt;
* Implement the basic''' file operations '''such as '''open() '''and''' close''' on a device.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 8 :&lt;br /&gt;
&lt;br /&gt;
Assignment : &lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| As an assignment,&lt;br /&gt;
&lt;br /&gt;
# Open the '''simple driver.c file.'''&lt;br /&gt;
# Write the different '''printk''' messages in the open and close functions.&lt;br /&gt;
# Compile and load the''' driver.'''&lt;br /&gt;
# Compile and execute the''' user program.'''&lt;br /&gt;
# Use '''dmesg command '''to check whether the device is opened or not.&lt;br /&gt;
# Unload the driver from the''' kernel.'''&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 9 :&lt;br /&gt;
&lt;br /&gt;
About Spoken Tutorial Project:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| * The video at the following link summarizes the Spoken Tutorial project.&lt;br /&gt;
&lt;br /&gt;
* Please download and watch it.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 10:&lt;br /&gt;
&lt;br /&gt;
Spoken Tutorial workshops:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| The''' Spoken Tutorial Project''' Team:&lt;br /&gt;
&lt;br /&gt;
* conducts workshops and&lt;br /&gt;
* gives certificates.&lt;br /&gt;
&lt;br /&gt;
For more details, please write to us.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 11:&lt;br /&gt;
&lt;br /&gt;
Forum questions:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| * Please post your timed queries in this forum.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 12 :&lt;br /&gt;
&lt;br /&gt;
Forum for specific questions:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| * Do you have any general or technical questions on Embedded Linux Device Driver?&lt;br /&gt;
* Please visit the FOSSEE forum and post your question.&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 13 :&lt;br /&gt;
&lt;br /&gt;
Acknowledgment:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| The Spoken Tutorial Project is funded by MHRD, Government of India.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| Slide 14:&lt;br /&gt;
&lt;br /&gt;
Thank you slide:&lt;br /&gt;
| style=&amp;quot;border:1pt solid #000000;padding:0.176cm;&amp;quot;| This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay. &lt;br /&gt;
&lt;br /&gt;
This is Mayuri Panchakshari signing off.&lt;br /&gt;
&lt;br /&gt;
Thanks for watching.&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Nirmala Venkat</name></author>	</entry>

	</feed>