<?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>nanoANT &#187; Linux</title>
	<atom:link href="http://www.nanoant.com/category/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.nanoant.com</link>
	<description>Yet another self-employee site &#38; blog</description>
	<lastBuildDate>Mon, 24 Jan 2011 17:18:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Compiling kernel IEGD 10.x module for any Linux distribution</title>
		<link>http://www.nanoant.com/linux/compiling-kernel-iegd-10x-module-for-any-linux-distribution</link>
		<comments>http://www.nanoant.com/linux/compiling-kernel-iegd-10x-module-for-any-linux-distribution#comments</comments>
		<pubDate>Fri, 19 Feb 2010 13:23:55 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[IEGD]]></category>
		<category><![CDATA[Intel]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://www.nanoant.com/?p=354</guid>
		<description><![CDATA[Intel has put great effort to put complete open-source drivers into recent kernels for its devices. Only device that is clearly missing there is GMA500 (aka Poulsbo, aka US15 chipset, aka Atom Z5xx family). This is understood as it does relay on Imagination Technologies PowerVR core licensed out by Intel to produce GMA500, so most [...]]]></description>
			<content:encoded><![CDATA[<p><em><a href="http://www.nanoant.com/wp/wp-content/uploads/2010/02/atom1.gif"><img class="alignright size-full wp-image-377" title="Intel Atom" src="http://www.nanoant.com/wp/wp-content/uploads/2010/02/atom1.gif" alt="" width="81" height="100" /></a>Intel</em> has put great effort to put complete open-source drivers into recent kernels for its devices. Only device that is clearly missing there is <em>GMA500</em> (aka <em>Poulsbo,</em> aka <em>US15</em> chipset, aka <em>Atom Z5xx</em> family). This is understood as it does relay on I<em>magination Technologies PowerVR</em> core licensed out by <em>Intel</em> to produce <em>GMA500</em>, so most of the driver parts cannot go open-source as it would imply of violation of some agreement between <em>ImgTec</em> and <em>Intel</em>.<br />
<span id="more-354"></span></p>
<p>Fortunately Intel provides binary driver set called <a href="http://edc.intel.com/Software/Downloads/IEGD/">Intel® Embedded Graphics Driver</a> (<em>IEGD</em>) supporting all embedded video chipsets, containing binary form of video driver libraries for latest <em>Xorg</em>, <em>OpenGL</em> and <em>VA</em>.</p>
<p>While most of the work you need to do is to have <tt>IEGD_10_3_Linux.tgz</tt> file (in case of <em>IEGD 10.3</em>) extracted onto the target box and to copy various <tt>.so</tt> files in proper places (follow <em>IEGD</em> documentation). Yet there is one more complicated thing extra &#8211; <em>IEGD Kernel Module</em> (<em>IKM</em>) <tt>iegd_mod.ko</tt> that has to be compiled out of the source shipped with <em>IEGD</em>.</p>
<h2>Linux Kernel module</h2>
<p><em>IEGD</em> documentation clearly states that only few distributions are supported by this driver, and those are i.e. <em>Fedora 8</em> &amp; <em>10</em>, some older <em>Ubuntu 8.x</em> and finally <em>Moblin</em>. But what about others, such as <em>Debian</em>, newer <em>Ubuntu</em>. You think you are unlucky running other distro? You shall understand word &#8220;supported&#8221; here as &#8220;tested&#8221;.</p>
<p>Reading the documentation, in all cases your are supposed to enter <tt>IKM</tt> folder of extracted drivers and launch <tt>install.sh</tt> script. This script shall compile and install without any hassle IKM on &#8220;supported&#8221; distributions. Surprisingly trying that on your distribution even it is not supported may work too! With one important exception it produces bogus driver that will crash your kernel.</p>
<h2>Finding the proper way for your distribution</h2>
<p>This recipe will save some few hours upto few days of struggling with fancy errors trying to compile and run the IKM module on your system <img src='http://www.nanoant.com/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Investigating the driver and <tt>install.sh</tt> first thing to notice is that it checks you <em>Kernel</em> version, it also takes (false) assumption that your are running one of the &#8220;supported&#8221; distros, so i.e <tt>2.6.27</tt> may mean Fedora version of the <tt>2.6.27</tt> <em>Kernel</em> not any <tt>2.6.27</tt> kernel.</p>
<p><em>Linux</em> distributions have this fancy characteristic that they usually come with heavily patched kernel, so when you take <tt>2.6.xx</tt> driver module from one distro and try to run it on the same version kernel on the other distro it will likely crash your kernel. Why? Incompatible ABI.</p>
<p>What <em>Intel</em> (<em>Tungsten?</em>) did in <em>IKM</em> is prepared <tt>IKM/val</tt> subfolder with headers <strong>extracted</strong> from several kernel sources of &#8220;supported&#8221; distributions. And what <tt>install.sh</tt> does, it tries to guess which one of <tt>DRM</tt> and <tt>AGP</tt> kernel module headers placed in that subfolder are OK for your <em>Kernel</em>.</p>
<p>In case you are running on the &#8220;unsupported&#8221; distribution the answer in 95% cases is <strong>NONE</strong>! Even you will be able to compile the <tt>iegd_mod.ko</tt> using <tt>Makefile</tt> produced by <tt>install.sh</tt> the module will crash you kernel as soon you will try to use it. Since your kernel has incompatible ABI (different structures) with the ABI provided inside <tt>IKM/val</tt> subfolder.</p>
<h2>Preparing for compilation of <em>IKM</em> for your own kernel</h2>
<p>If you are running &#8220;unsupported&#8221; distribution you should avoid then using headers in <tt>IKM/val</tt> subfolder. The right way is to take <tt>AGP</tt> and <tt>DRM</tt> headers out of your running kernel sources (you don&#8217;t have to compile the whole kernel of course).</p>
<p>So go to <tt>IEGD_10_3_Linux</tt> folder and launch:</p>
<pre>sudo apt-get install linux-headers-x.y.zz
apt-get source linux-image-x.y.zz</pre>
<p>Where <tt>x.y.zz</tt> is your running kernel version. (Use your own distro command to grab kernel source if you don&#8217;t run on <em>Debian</em> or <em>Ubuntu</em>)</p>
<p>This will install kernel headers and scripts to build kernel modules and also produce <tt>linux-x.y.zz</tt> folder containing source code of your running <em>Kernel</em>. The whole trick if to place (replace) <tt>Makefile</tt> in <tt>IKM</tt> folder as below:</p>
<pre class="textmate-source"><span class="source source_makefile"><span class="variable variable_other variable_other_makefile">KERNELVER ?= $(shell uname -r)</span>
<span class="variable variable_other variable_other_makefile">KERNELDIR ?= /lib/modules/$(KERNELVER)/build</span>
<span class="variable variable_other variable_other_makefile">INSTALLDIR ?= /lib/modules/$(KERNELVER)/kernel/drivers/char/agp</span>
<span class="variable variable_other variable_other_makefile">PWD ?= $(realpath .)</span>

EXTRA_CFLAGS += -I$(PWD)/include
EXTRA_CFLAGS += -I$(PWD)/../linux-$(KERNELVER)/drivers/char/agp
EXTRA_CFLAGS += -I/lib/modules/$(KERNELVER)/build/include/drm

<span class="meta meta_function meta_function_makefile"><span class="entity entity_name entity_name_function entity_name_function_makefile">all:</span> clean modules</span>

<span class="meta meta_function meta_function_makefile"><span class="entity entity_name entity_name_function entity_name_function_makefile">modules:</span>
</span>	@echo $(PWD)
	@$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

<span class="meta meta_function meta_function_makefile"><span class="entity entity_name entity_name_function entity_name_function_makefile">install:</span>
</span>	install -o root -g root -m 755 -d $(INSTALLDIR)
	install -o root -g root -m 744 iegd_mod.ko $(INSTALLDIR)
	/sbin/depmod -a

<span class="meta meta_function meta_function_makefile"><span class="entity entity_name entity_name_function entity_name_function_makefile">uninstall:</span>
</span>	rm -rf $(INSTALLDIR)/iegd_mod.ko
	/sbin/depmod -a

<span class="meta meta_function meta_function_makefile"><span class="entity entity_name entity_name_function entity_name_function_makefile">clean:</span>
</span>	@rm -f *.o iegd*.ko iegd*.mod.c iegd*.o agp/*.o drm/*.o Module.symvers
	@rm -fr .intel* .tmp* .*.cmd agp/.*.cmd drm/.*.cmd

obj-m := iegd_mod.o
iegd_mod-objs := agp/pci.o agp/global.o agp/drv_alm.o agp/drv_nap.o agp/drv_plb.o agp/drv_cmn.o agp/drv_gn4.o drm/iegd_drv.o drm/iegd_interface.o drm/iegd_interface_265.o drm/iegd_interface_2611.o drm/iegd_interface_2615.o drm/iegd_interface_2624.o drm/psb_irq.o</span></pre>
<p>You don&#8217;t need to launch <tt>install.sh</tt> at all. Just paste the file as above.</p>
<p>As you see now, this <tt>Makefile</tt> references to <tt>../linux-$(KERNELVER)</tt> for your running <em>Kernel</em> source <tt>AGP</tt> &amp; <tt>DRM</tt> headers. Yet however you may still need to do few tweaks in your <tt>Makefile</tt>, see notes below:</p>
<p><strong>Note (1)</strong> In case you are running older kernel, <tt>/lib/modules/$(KERNELVER)/build/include/drm </tt>may not exist, then <tt>$(PWD)/../linux-$(KERNELVER)/drivers/char/drm </tt>should be right path to put in the <tt>Makefile</tt> instead.</p>
<p><strong>Note (2)</strong> The <em>Kernel</em> source code folder you downloaded (i.e. via <tt>apt-get source</tt>) may not actually match exactly <tt>linux-$(KERNELVER)</tt>, so you may change that <tt>EXTRA_CFLAGS</tt> setting manually:</p>
<ul>
<li>In case of <em>Ubuntu</em> `<tt>uname -r</tt>` is <tt>2.6.31-19-generic</tt> while the extracted source folder name has no <tt>-generic</tt> suffix and it is just <tt>linux-2.6.31-19</tt>.</li>
<li>In case of <em>Debian</em> `<tt>uname -r</tt>` is <tt>2.6.26-21</tt> while the extracted source folder name is <tt>linux-2.6-2.6.26-21</tt>. Weird huh?</li>
</ul>
<h3>Final fixes before compilation</h3>
<p>There is a file still missing if you try now to `<tt>make</tt>`. It is file that exists in <tt>IKM/val/agp</tt> but does not exist in your <tt>$(PWD)/../linux-$(KERNELVER)/drivers/char/agp</tt>. It is called <tt>interface_abs.h</tt>.</p>
<p>Wonder why the heck it is NOT in <tt>IKM/include</tt>!? This is a little lack of consequence from <em>Intel</em> here.</p>
<p>Anyway just copy <tt>interface_abs.h</tt> into <tt>IKM/include</tt> out of <tt>IKM/val/agp/agpm0vmob2</tt> if you are running on &gt;= 2.6.30 <em>Kernel</em> or from <tt>IKM/val/agp/agpm0v103</tt> otherwise. The only difference between <tt>interface_abs.h</tt> from <tt>agpm0vmob2</tt> and <tt>agpm0v103</tt> is one macro definition.</p>
<p>Finally we need two little extra fixes.</p>
<p><strong>(1)</strong> Trying to compile on <em>Debian Lenny</em> we will get many nasty errors from kernel headers for <tt>IKM/drm/iegd_interface.c</tt>. Moving <tt>igd_abs.h</tt> inclusion in this source file little down fixes the issue. Edit <tt>IKM/drm/iegd_interface.c</tt> as below:</p>
<pre> #include "iegd.h"
<strong>-#include "igd_abs.h"</strong>
 #include "drmP.h"
 #include "drm.h"

<strong>+#include "igd_abs.h"</strong>
 #include "iegd_drm.h"
 #include "iegd_drv.h"
 #include "psb_intregs.h"</pre>
<p><strong>(2)</strong> <tt>IKM/drm/iegd_drv.c</tt> tries to include <tt>linux/config.h</tt> at the very begining of the file. This is not actually necessary, and anyway does not exist, so you may comment that out:</p>
<pre><strong>-#include &lt;linux/config.h&gt;
+/* #include &lt;linux/config.h&gt; */</strong></pre>
<h3>Compiling at last</h3>
<p>Now you are ready to so `<tt>make</tt>` and `<tt>sudo make install</tt>`. This time  <tt>iegd_mod.ko</tt> should be ABI compatible with your kernel.</p>
<p>I have tested this method on <em>Debian 5.0 Lenny</em> and <em>Ubuntu 9.10 Karmic Koala</em>.</p>
<p>To ensure everything works fine after driver installation try:</p>
<pre>sudo modprobe iegd_mod</pre>
<p>And try to go into <tt>IKM/agp</tt> and compile and run <tt>agp_test.c</tt>:</p>
<pre>gcc -o agp_test agp_test.c
sudo ./agp_test</pre>
<p>Next try the same with <tt>IKM/drm</tt> compiling and running <tt>drm_test.c</tt>.</p>
<p>If those two test won&#8217;t fail and won&#8217;t blow your kernel it means you have fully working <em>IEGD</em> module on your own <em>Linux</em> distro.</p>
<h3>Notes for users of old psb-modules or psb-kernel-source Ubuntu package</h3>
<p>Older <em>psb-modules</em> and <em>psb-kernel-source</em> <em>Ubuntu</em> packages install their own incompatible <tt>drm.ko</tt> module at <tt>/lib/modules/`uname -r`/updates/char/drm</tt>.</p>
<p>Check <tt>find /lib/modules/`uname -r` -type f -name 'drm*'</tt> you should have only one: <tt>/lib/modules/`uname -r`/kernel/drivers/gpu/drm/drm.ko</tt></p>
<p>In case if you find other <tt>drm.ko</tt>, probably in <tt>updates/char/drm</tt> delete it. That one came from <em>psb-kernel-source</em> and is causing you a trouble. You may ensure you got only valid <tt>drm.ko</tt> reinstalling your kernel image with:</p>
<p><tt>apt-get install --reinstall linux-image-`uname -r`</tt></p>
<h2>Notes for curious</h2>
<p>The difference of <tt>Makefile</tt> of mine and <tt>Makefile</tt> produced of <tt>install.sh</tt> is the beginning:</p>
<pre class="textmate-source"><span class="source source_makefile"><span class="variable variable_other variable_other_makefile">KERNELVER ?= $(shell uname -r)</span>
<span class="variable variable_other variable_other_makefile">KERNELDIR ?= /lib/modules/$(KERNELVER)/build</span>
<span class="variable variable_other variable_other_makefile">INSTALLDIR ?= /lib/modules/$(KERNELVER)/kernel/drivers/char/agp</span>
<span class="variable variable_other variable_other_makefile">PWD ?= $(realpath .)</span>

EXTRA_CFLAGS += -I$(PWD)/include
EXTRA_CFLAGS += -I$(PWD)/../linux-$(KERNELVER)/drivers/char/agp
EXTRA_CFLAGS += -I/lib/modules/$(KERNELVER)/build/include/drm</span></pre>
<p>If you try to run <tt>install.sh</tt> <tt>EXTRA_CFLAGS</tt> will include two of <tt>IKM/val</tt> folders which contain some <em>Kernel</em> source extracted header definitions that are likely not compatible with your <em>Kernel</em>.</p>
<p>I use also <tt>PWD ?= $(realpath .</tt>) here instead of <tt>PWD ?= $(shell pwd)</tt> because with some <em>Linux</em> headers versions $(shell pwd) resolves to /lib/modules path not the path where IKM sources are.</p>
<h2>Notes for <em>Intel</em></h2>
<p>It would be nice for next <em>IEGD</em> release if <em>IKM</em> source tree would be made for readable and clear:</p>
<ol>
<li><tt>IKM/val</tt> should be renamed to <tt>IKM/kernel-headers</tt> (what the heck &#8220;val&#8221; means here ?!) and this should be noted somewhere in docs that files here are NOT made by <em>Intel</em> but extracted of &#8220;supported&#8221; <em>Linux</em> distributions <em>Kernel</em> sources</li>
<li><tt>interface_abs.h</tt> should moved away from <tt>IKM/val</tt> (<tt>IKM/kernel-headers</tt>) to avoid confusion (with point 1) and placed into <tt>IKM/includes</tt> (and there should be <tt>#ifdef</tt> for this one macro that makes it different for across 2.6.30)</li>
<li><tt>IKM/drm/iegd_interface.c</tt> should be fixed as described above (moving <tt>iegd_abs.h</tt> inclusion little bit down).</li>
<li><tt>IKM/drm/iegd_drv.c</tt> inclusion of <tt>&lt;include/config.h&gt;</tt> is not necessary, may be removed.</li>
<li>Finally <tt>install.sh</tt> should contain case when running on &#8220;unsupported&#8221; distribution.<br />
So it shall make SURE if running on &#8220;supported&#8221; distributions and then and only then use files from <tt>IKM/kernel-headers</tt>, OTHERWISE ask for a path for your own <em>Linux</em> distribution <em>Kernel</em> source&#8217;s to find a path for your own <tt>kernel/drivers/char/agp</tt> and <tt>kernel/drivers/char/drm</tt> (<tt>include/drm</tt>) i.e. by showing:</p>
<pre>Your Linux distribution and Kernel version was untested, however you may try to compile and run driver on your own risk.
Please provide your running kernel sources extracted i.e. on Debian or Ubuntu using apt-get source linux-image-2.6-686:
[path to your kernel]:</pre>
</li>
</ol>
<h3>Fell free to post your comments and problems with method presented here below using comment form!</h3>
]]></content:encoded>
			<wfw:commentRss>http://www.nanoant.com/linux/compiling-kernel-iegd-10x-module-for-any-linux-distribution/feed</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
	</channel>
</rss>

