<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KP Solutions &#187; compile</title>
	<atom:link href="http://www.kpsolution.com/blog/category/compile/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kpsolution.com/blog</link>
	<description>Solutions for Day to Day Technical Problems</description>
	<lastBuildDate>Wed, 14 Sep 2011 19:05:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to create a simple linux device driver</title>
		<link>http://www.kpsolution.com/blog/linux/how-to-create-a-simple-linux-device-driver/11/</link>
		<comments>http://www.kpsolution.com/blog/linux/how-to-create-a-simple-linux-device-driver/11/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 18:19:47 +0000</pubDate>
		<dc:creator>Ketan Patel</dc:creator>
				<category><![CDATA[compile]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.kpsolution.com/blog/linux/how-to-create-a-simple-linux-device-driver/11/</guid>
		<description><![CDATA[Here, I would show you how to create a simple linux driver that does nothing! This just a demo to show you how to compile, install and remove the device driver. Before we get started, you need to make sure &#8230; <a href="http://www.kpsolution.com/blog/linux/how-to-create-a-simple-linux-device-driver/11/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here, I would show you how to create a simple linux driver that does nothing! This just a demo to show you how to compile, install and remove the device driver.</p>
<p>Before we get started, you need to make sure that you have the kernel source installed. The following instructions will guide you through the steps to install the kernel source for RedHat Enterprice 4 (RHEL4). Issue the following command to get the kernel source.<strong>up2date &#8211;get-source kernel</strong></p>
<p>This would dump the kernel-&lt;version&gt;.src.rpm in the <strong>/var/spool/up2date</strong> folder. Then you must install the source using the following command.</p>
<p><strong>rpm -Uvh kernel-&lt;version&gt;.src.rpm</strong></p>
<p>This would install the kernel source in the <strong>/usr/src/redhat</strong>. You need to change the directory to <strong>/usr/src/redhat/SPECS/</strong> and issue the following command.</p>
<p><strong>rpmbuild -bp &#8211;target=&lt;arch&gt; kernel-2.6.spec</strong> where &lt;<strong>arch</strong>&gt; is the desired target architecture.</p>
<p>Then copy the configuration file from the <strong>/usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9/configs/kernel-&lt;version&gt;.config </strong>to<strong><br />
/usr/src/redhat/BUILD/.config</strong><br />
<span></span></p>
<p><span><span class="command">Then issue the following command </span></span></p>
<p><span><span class="command"></span><strong class="command">make oldconfig</strong></span></p>
<p>Build all the modules before you could compile your linux device drivers.</p>
<p><strong>make modules</strong></p>
<p>Now that we have the proper kernel source and modules compiled, create a file &#8216;nothing.c&#8217; as follows:</p>
<p><em>#include &lt;linux/module.h&gt;</p>
<p>MODULE_LICENSE(&#8220;DUAL BSD/GPL&#8221;);</em></p>
<p>and save it your home folder <strong>~/nothing/nothing.c</strong></p>
<p>In ~/nothing, create Makefile as follows:</p>
<pre class="screen"><tt><tt class="computeroutput">obj-m    := nothing.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:</tt></tt></pre>
<pre class="screen"><tt><tt class="computeroutput">   $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules</tt></tt></pre>
<p>Change directory to &#8216;<strong>~/nothing</strong>&#8216; and then issue the &#8216;<strong>make</strong>&#8216; command, this will create the &#8216;nothing.ko&#8217; file in the current folder.</p>
<p>You can load the module in the kernel space using the following command.</p>
<p><strong>insmod nothing.ko</strong></p>
<p>and remove the module using the command.</p>
<p><strong>rmmod nothing</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kpsolution.com/blog/linux/how-to-create-a-simple-linux-device-driver/11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

