Chaitu Tech Bits

How To Cross Compiling The Linux Kernel for ARM9 ( Mini2440 ) Step By Step

Friday, February 18, 2011

In this tutorial, I'll quickly show you how easy it is to compile a kernel for the mini2440. If you haven't already installed git, you should do so now. In Ubuntu, you simply install the package git-core. 


Setting up Your Toolchain

Follow the instructions from this tutorial. 
http://billforums.station51.net/viewtopic.php?f=4&t=9



Obtaining the Correct Kernel Sources


In order for you to get a kernel thats patched for all the hardware on your Mini2440, you need to get the kernel sources from the correct place. While it's possible to simply go and download a kernel directly from kernel.org and cross compile it, you won't get the patches included with that for all the hardware on the Mini2440. 


Create a directory for your source tree and change to it and use git to clone the repository.

Code:
$ mkdir mini2440-kernel
$ git clone git://repo.or.cz/linux-2.6/mini2440.git
$ cd mini2440


You should now be in the top directory with the kernel source. 

Compiling Your Kernel

The first step in compiling is to create the default configuration file. 

Code:
$ CROSS_COMPILE=/usr/local/arm-2008q3/bin/arm-none-linux-gnueabi- ARCH=arm make mini2440_defconfig

This creates the default configuration file for the mini2440. I'll show you later how to modify this.

Now you simply run make.

Code:
$ CROSS_COMPILE=/usr/local/arm-2008q3/bin/arm-none-linux-gnueabi- ARCH=arm make


When this is complete. Your kernel is compiled. 

Now we need to create a uImage.

Code:
$ CROSS_COMPILE=/usr/local/arm-2008q3/bin/arm-none-linux-gnueabi- ARCH=arm make uImage


Your uImage for booting your device is in arch/arm/boot and you can copy that to your SD card, or NFS directory or NAND.

Installing Kernel Modules To Your Filesystem

It's very simply to install modules into your filesystem for the mini. Let's say your SD card has your filesystem for the mini2440, and it's mounted in /mnt

Code:
$ CROSS_COMPILE=/usr/local/arm-2008q3/bin/arm-none-linux-gnueabi- ARCH=arm INSTALL_MOD_PATH=/mnt make modules_install


[/i]
Customizing Your Kernel Configuration

There are two ways you can customize your kernel source. If you know what you're doing you can use your favorite editor to edit a file called .config in the kernel source root. But the easiest, and in my opinion, the best way, is to use the built in menu configuration tool. For this you'll need to have ncurses installed on your system.

Code:
$ CROSS_COMPILE=/usr/local/arm-2008q3/bin/arm-none-linux-gnueabi- ARCH=arm make menuconfig


Every time you make any change to this, you should clean your source tree and recompile.

Cleaning your source tree

Code:
$ CROSS_COMPILE=/usr/local/arm-2008q3/bin/arm-none-linux-gnueabi- ARCH=arm make clean


This will simply clean the tree of binaries and compiled object files etc but leaves the config intact. If you want to clean it completely and erase the config to start fresh you can do a distclean.

Code:
$ CROSS_COMPILE=/usr/local/arm-2008q3/bin/arm-none-linux-gnueabi- ARCH=arm make distclean


You'll notice I left the cross_compile and arch variables in there so that clean knows what to remove. It probably uses wildcards to clean, but better safe that sorry. 

Final Thoughts

It's pretty simple to compile a kernel and knowing this will help you to stay current. OpenEmbedded builds a kernel as well but this source tree used here is much better. 

Be careful what change in the config. Changing too many things at once without really knowing what you're doing might cause your kernel to not work as you want. If you just feel like experimenting, that's fine, but if you're in a production environment and just want something that works, be careful what you do. 

I hope this tutorial has helped you understand the basics of cross compiling a kernel. If you have any questions, please feel free to ask.


credits goes to bill sargent :)
Share/Bookmark

Related Posts Plugin for WordPress, Blogger...