#Compiling Linux Kernel 3.18.14

<img src="./tuxcase_small.jpg">

This article illustrates how to generate a bootable <b>Linux Kernel</b> 
image usable on the following Acme Systems SoM:

* [Arietta G25](/arietta)
* [Aria G25](/aria)

###Hardware requirements:

* a PC with Ubuntu Linux (tested with version 15.04) to cross compile the Kernel
* an Acme board with Atmel MPU inside
* a microSD card
* a [Debug Port Interface](/DPI)

###Software requirements

* @article='arm9_toolchain'

##Step-by-step Kernel cross-compilation procedure:

Download and save in your home directory the Linux Kernel sources:

* [linux-3.18.14.tar.xz](https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.14.tar.xz)

Extract the Kernel sources from the compressed file by typing:

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

Move inside the new folder:

<pre class="minicom">
~$ <b>cd linux-3.18.14</b>
~/linux-3.18.14$
</pre>

###Set the basic Kernel configuration

<div class="accordion">

<h3>Arietta</h3>
<div markdown="1">

Download [acme-arietta_defconfig](./acme-arietta_defconfig) in <b>arch/arm/configs</b>
then type to use it:

<pre class="minicom">
~/linux-3.18.14$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-arietta_defconfig</b>
...
# configuration written to .config
</pre>

</div>

<h3>Aria</h3>
<div markdown="1">

Download [acme-aria_defconfig](./acme-aria_defconfig) in <b>arch/arm/configs</b>
then type to use it:

<pre class="minicom">
~/linux-3.18.14$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria_defconfig</b>
...
# configuration written to .config
</pre>

</div>


</div>

###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-3.18.14$ <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.

###Compile the Device Tree Blob file

<div class="accordion">



<h3>Arietta</h3>
<div markdown="1">

Download [acme-arietta.dts](./acme-arietta.dts) in <b>arch/arm/boot/dts</b>
then type to use it:

<pre class="minicom">
~/linux-3.18.14$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-arietta.dtb</b>
...
</pre>
</div>


<h3>Aria</h3>
<div markdown="1">

Download [acme-aria.dts](./acme-aria.dts) in <b>arch/arm/boot/dts</b>
then type to use it:

<pre class="minicom">
~/linux-3.18.14$ <b>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria.dtb</b>
...
</pre>

</div>
</div>


###Compile the Kernel image

Compile the Linux Kernel sources and generate a binary 
image file to save in the first partition of microSD card.

<div class="accordion">


<h3>Arietta</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage</b>
...
  Image arch/arm/boot/zImage is ready
</pre>
</div>

<h3>Aria</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage</b>
...
  Image arch/arm/boot/zImage is ready
</pre>
</div>


</div>

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

###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-3.18.14$ <b>make modules -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-</b>
...
~/linux-3.18.14$ <b>make modules_install INSTALL_MOD_PATH=./modules ARCH=arm</b>
...
</pre>

#Copy the boot files into the first microSD partition

##Method 1 - Direct write on microSD

Insert a [formatted microSD](/microsd_format) in your Linux PC and copy 
on it the files directly:

Write the Linux Kernel image and Device tree blog files in the first microSD
partition:

<div class="accordion">


<h3>Arietta</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>cp arch/arm/boot/dts/acme-arietta.dtb /media/$USER/KERNEL</b>
~/linux-3.18.14$ <b>cp arch/arm/boot/zImage /media/$USER/KERNEL</b>
</pre>

</div>

<h3>Aria</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>cp arch/arm/boot/dts/acme-aria.dtb /media/$USER/KERNEL/at91-ariag25.dtb</b>
~/linux-3.18.14$ <b>cp arch/arm/boot/zImage /media/$USER/KERNEL</b>
</pre>

</div>


</div>

Write the Kernel modules in the rootfs (second microSD partition):

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

##Method 2 - Remote writing via ssh 

Use this method if you have a working board accessible via LAN

Write the Linux Kernel image and Device tree blog files in the first microSD
partition:

<div class="accordion">


<h3>Arietta</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>scp arch/arm/boot/dts/acme-arietta.dtb root@192.168.10.10:/boot</b>
~/linux-3.18.14$ <b>scp arch/arm/boot/zImage root@192.168.10.10:/boot</b>
</pre>

</div>

<h3>Aria</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>scp arch/arm/boot/dts/acme-aria.dtb root@ariag25.local:/media/mmc_p1/at91-ariag25.dtb</b>
~/linux-3.18.14$ <b>scp arch/arm/boot/zImage root@ariag25.local:/media/mmc_p1</b>
</pre>

</div>


</div>


Write the Kernel modules in the rootfs (second microSD partition):

<div class="accordion">


<h3>Arietta</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>rsync -avc modules/lib/. root@192.168.10.10:/lib/.</b>
</pre>

</div>

<h3>Aria</h3>
<div markdown="1">

<pre class="minicom">
~/linux-3.18.14$ <b>rsync -avc modules/lib/. root@ariag25.local:/lib/.</b>
</pre>

</div>

</div>


<span class="smallnotes">
If this command doesn't work verify if rsync in installed on your board. Use <b>apt-get install rsync</b>.
</span>


##After the first boot

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>

#Use the new Kernel with Debian "Wheezy" rootfs 

* @article='debian_wheezy' 

# Related links

* [Linux changes](http://kernelnewbies.org/LinuxChanges)
* [Linux Kernel mailing list archives](https://lkml.org/)
* [Kernel documentation](http://lxr.linux.no/linux+v3.18.14/Documentation)
