#Compiling Linux Kernel 2.6.38 for FOX Board G20 and Netus G20

<div class="text-success lead">
This article illustrates how get and patch the Linux Kernel version 2.6.38 sources 
and generate a working binary image bootable from the FOX Board G20.
</div>

##Requirements

*  a PC with Linux an [ARM cross compiler](/arm9_toolchain) installed. In this article I've used an <b>Ubuntu 11.10</b>
*  a 1GB or greater microSD card 
*  a [FOX Board G20](/FOXG20) with [AcmeBoot](/acmeboot) installed
*  a [Debug Port Interface](/DPI)
*  an Internet access

#Download the source tree without revision history

This is the faster way to download the already patched sources without the whole Linux commit history:

* [acme-2.6.38.zip](https://github.com/tanzilli/foxg20-linux-2.6.38/archive/acme-2.6.38.zip) 

#Download the source tree with the complete revision history

This is the slowest way to download the sources because it includes the whole Linux commit history and each patch applied by Acme. 
To follow this way you have to install [Git](http://git-scm.com/) on your Linux PC.

Open a terminal session and type:

<pre class="minicom">
$ git clone git://github.com/tanzilli/foxg20-linux-2.6.38.git
...
$ cd foxg20-linux-2.6.38
</pre>

Using **gitk** take a look to the patches applied by Acme Systems on the Linux Kernel Vanilla 2.6.38 
to obtain a working image for the [FOX Board G20](/FOXG20) by typing:

<pre class="minicom">
$ gitk
</pre>

You can see all the commit also via web 
on [https://github.com/tanzilli/foxg20-linux-2.6.38/commits/acme-2.6.38](https://github.com/tanzilli/foxg20-linux-2.6.38/commits/acme-2.6.38).

#Configuring your Kernel

Set the default Kernel configuration used by Acme to generate its default bootable microSD.

<pre class="minicom">
$ make foxg20_defconfig
</pre>

Access the Kernel configuration and make your changes (if you have any changes to make) typing:

<pre class="minicom">
$ make menuconfig
</pre>

#Kernel compilation

To launch the Kernel compilation type:

<pre class="minicom">
$ make -j8
...
</pre>

The <b>j8</b> option is to build the kernel in a multithreaded way.

<i>"It is best to give a number to the -j option that corresponds to twice the number of processors in the system". (From pag.26 of Linux in a Nutshell by Greg Kroah-Hartman)
</i>

When finished you will find a new <b>uImage</b> file containing the bootable Kernel image in binary format. This file has to be copied on the first FAT16 partition of your microSD card as described next.

##Place the new Kernel image on the bootable microSD: Method 1

*  Insert the FOX microSD card on your Linux PC
*  once /media/kernel folder copy on ite the file uImage
*  copy your module tree from ./foxg20-modules/lib to /media/rootfs/lib
*  unmount /media/kernel and /media/rootfs
*  transfer the microSD card back to your FOX Board G20
*  start your FOX Board G20 to see your new kernel in action!
*  don't forget to type the command depmod -a on the FOX Board command line to build the modules dependencies files

##Place the new Kernel image on the bootable microSD: Method 2

If you have a FOX Board already running you can store the Kernel image on the bootable micro SD remotely by following this article: @article='foxg20_uimage_update'.

#Kernel modules compilation

To compile the Kernel modules type:

<pre class="minicom">
$ make modules -j8
$ make modules_install
</pre>

Note that modules are not installed but copied to the foxg20-modules sub-directory. If you don't want old modules you've built before, instead of that last line do:

<pre class="minicom">
$ rm -rf ./foxg20-modules
$ make modules_install
</pre>

##Install the modules inside the FOX Board 

Copy your module tree from your build machine's foxg20-modules/lib to the FOX Board G20 rootfs:

<pre class="minicom">
$ rsync -avc foxg20-modules/lib/. root@192.168.1.90:/lib/.
</pre>

If this doesn't work install rsync on the FOX with the command:

<pre class="minicom">
$ apt-get install rsync
</pre>

Back to the FOX Board G20 terminal and update the module dependencies:

<pre class="minicom">
$ depmod -a
</pre>

Finally reboot the FOX Board G20 to load the new Kernel.


