#Compiling Linux Kernel 3.12.x

<span class="abstract">
This article illustrates how to generate a bootable <b>Linux Kernel</b> image for Aria G25
</span>

##What do you need:

###Hardware required:

* a PC with Linux <b>Ubuntu 13.10</b> installed to cross compile the Kernel
* One of these Acme boards:
	* [AriaG25 SoM](/aria) with a minimal [hardware wired](/ariag25_wirings)
* a >2 GByte microSD card
* a [Debug Port Interface](/DPI)

###Software toolchain to install on your Linux PC:

* @article='arm9_toolchain'

###Kernel sources:

Download and save in your home directory the Linux Kernel sources you need from this page:

* [www.kernel.org](http://www.kernel.org)

Select the [tar.xz] format.

##Kernel source cross-compilation step by step:

Untar the Kernel sources by typing:

<pre class="minicom">
~$ <b>tar xvfJ linux-x.xx.x.tar.xz</b>
...
</pre>

<span class="smallnotes">Changing of course the <b>x.xx.x</b> part with the release version :-)</span>


Move inside the just created folder:

<pre class="minicom">
~$ <b>cd linux-x.xx.x</b>
~/linux-x.xx.x$
</pre>

###Download the default Kernel configuration file

Download our basic configuration file. It contains a basic set 
of kernel drivers and features to get starting. Select 
the file for your board and save it into <b>arch/arm/configs</b>:

* Aria G25 or Terra Board  
  * [at91-ariag25_defconfig](./at91-ariag25_defconfig)

Now create the <b>.config</b> working file by typing:

<pre class="minicom">
~/linux-3.xx.x$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- at91-ariag25_defconfig</b>
...
#
# configuration written to .config
#
</pre>

<span class="smallnotes">
A file called **.config** is created inside the Linux sources root directory. 
All the changes you will do using **make menuconfig** will be saved on this file so, 
if you want to create your own default kernel configuration, simple copy the new **.config** 
you obtain file in <b>arch/arm/configs</b> with a custom name like **at91-myconfiguration**.
</span>

###Download e generate the device tree file

"<i>The Device Tree is a data structure for describing hardware. Rather than hard 
coding every detail of a device into an operating system, many aspect of the hardware 
can be described in a data structure that is passed to the operating system at boot 
time.</i>"

When you compile a Device Tree File (.dts) you will obtain a Device Three 
Blob file (.dtb) to save in the first partition of your bootable microSD 
card together with Linux Kernel image.

Download and save our basic Device Tree Source file for your board 
in <b>arch/arm/boot/dts</b>:

* Aria G25 or Terra Board  
  * [at91-ariag25.dts](./at91-ariag25.dts)

Generate the Device Tree Blob file by typing:

<pre class="minicom">
~/linux-x.xx.x$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- at91-ariag25.dtb</b>
...
</pre>

###Customize the default Linux Kernel configuration:

If you need to customize the Kernel configuration or just taking a look
to the drivers and features activated type:

<pre class="minicom">
~/linux-x.xx.x$ <b>make ARCH=arm menuconfig</b>
</pre>

and navigate inside the Kernel configuration using the arrow keys and 
following the help provided by the menuconfig interface.

###Kernel compilation

To compile the Linux Kernel sources and generate a binary 
image file to place in your bootable microSD card type:

<pre class="minicom">
~/linux-x.xx.x$ <b>make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage</b>
...
  UIMAGE  arch/arm/boot/uImage
Image Name:   Linux-x.xx.x
Created:      ...
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    ...
Load Address: 20008000
Entry Point:  20008000
  Image arch/arm/boot/uImage is ready
</pre>

On a mid-power PC the whole source compilation requires about 5 minutes. 

###Copying the binary files generated in the bootable microSD

Copy on a [bootable and formatted microSD](/microsd_format) the Linux **uImage** file 
renaming it in <b>image.bin</b> and the Device Tree Blog file **at91-ariag25.dtb**
in the first <b>FAT32</b> partition:

<pre class="minicom">
~/linux-x.xx.x$ <b>cp arch/arm/boot/dts/at91-ariag25.dtb /media/$USER/KERNEL/at91-ariag25.dtb</b>
~/linux-x.xx.x$ <b>cp arch/arm/boot/uImage /media/$USER/KERNEL/image.bin</b>
</pre>

<span class="smallnotes">If you are using an Ubuntu release older than 13.10 remove **$USER** in the 
path</span>

###Compile the Kernel modules

The image generated contains the Linux Kernel and all the built-in 
device drivers (option <b>[*]</b> in menuconfig) compiled with it.

Al the drivers compiled as external modules (option <b>[M]</b> in menuconfig)
need to be compiled and saved in the rootfs <b>/lib</b> directory on the second 
partition of the microSD. To compile them type:

<pre class="minicom">
~/linux-x.xx.x$ <b>make modules -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-</b>
...
~/linux-x.xx.x$ <b>make modules_install INSTALL_MOD_PATH=./modules ARCH=arm</b>
...
</pre>

Copy the kernel modules on the microSD:

<pre class="minicom">
~/linux-x.xx.x$ <b>sudo rsync -avc modules/lib/. /media/$USER/rootfs/lib/.</b>
</pre>

At the first access to the board command line update the module 
dependencies by typing this command:

<pre class="minicom">
~# <b>depmod -a</b>
</pre>

#rootfs contents

##Use the new Kernel with **Aria R5** microSD contents (Debian 6.0 Lenny)

To use the current Aria R5 rootfs contents with this Kernel version simply change these files:

In **/etc/fstab** changes:

<pre class="minicom">
proc /proc proc none 0 0
</pre>

in

<pre class="minicom">
proc /proc proc defaults 0 0
</pre>

In **/etc/network/interfaces** add after the lines:

<pre class="minicom">
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
</pre>

the line:

<pre class="minicom">
hwaddress ether 00:01:04:1b:2C:1F
</pre>

Using the MAC address you want to set for the Aria G25 ethernet port.

##Use the new Kernel with EmDebian 7.2 Wheezy Grip 

Follow this article:

* @article='emdebian_grip' 

# Related links

* [Kernel.org](http://kernel.org)
* [Linux changes](http://kernelnewbies.org/LinuxChanges)
* [Linux Kernel mailing list archives](https://lkml.org/)
* [Kernel documentation for device trees](http://lxr.linux.no/linux+v3.12.8/Documentation/devicetree/)

