Home NAS (Advanced) • Crosscompiling your own kernel

Crosscompiling your own kernel

 - 

In this post I’ll show you the steps necessary to build your own custom kernel to run on your NAS. In this post i only show to build it for Orion and Kirkwood LaCie devices, as i own these myself and know how to build it for them. I also use Ubuntu 32-bit to prepare and build the software on.

Note to 64-bit users:
The toolchain used here is 32-bit. If you want to crosscompile the kernel on a 64-bit machine you’ll need one extra package:
apt-get install ia32-libs
This will install the 32-bit shared libraries needed for building 32-bit apps on 64-bit systems.

First we need to prepare thing, which will consist of downloading the kernel source, ARM toolchain and necessary packages needed to build:

First we’ll install the necessary packages needed to build:
apt-get install uboot-mkimage build-essential libncurses5-dev

Navigate to your home directory (cd ~/) and lets start building!

Then we need to download the required software, starting with the kernel (as of writing, the current stable version is 3.8.4).
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.8.4.tar.xz

Unpack the kernel:
tar vxf linux-3.84.tar.xz

Download the ARM Toolchain:
wget http://www.arm-blog/dls/arm-2012.09-64-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

Unpack the toolchain:
tar vxjf arm-2012.09-64-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

Then we need to create the kernel modules directory, create a dir called kernelmodules:
mkdir kernelmodules

Set some environment variables to enhance the building process:
export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabi-
export PATH=~/arm-2012.09/bin/:${PATH}
export INSTALL_MOD_PATH=~/kernelmodules

Dive in the kernel source directory:
cd linux-3.8.4

For Orion devices do the following to configure the kernel for that board:
make mrproper
make orion5x_defconfig

For Kirkwood devices do the following to configure the kernel for that board:
make mrproper
make kirkwood_defconfig

The rest of the steps are the same for both boards, continue to customize the kernel (you will enter a menu where you add extra modules for your kernel, like extra filesystem support):
make menuconfig

Optionally you can save the configuration file you just created with menuconfig, when leaving menuconfig you have saved the config in the current directory as:
.config
If you make a copy of that file to a safe location you can use that configuration file again whenever you need to build a new kernel for the device the config is created for, this can be helpful if there are kernel updates or you want to extend or slim down the config.

Once you have set the options and modules you want and saved your configuration, you can start building the uImage needed by uBoot:
make uImage

If you have a multicore processor you may append the number of cores to the make instruction, this will greatly speed up the compile process, so if you have a quadcore system you can make the image with:
make uImage -j4

When the build is complete there will be a file called uImage in arch/arm/boot/, copy that file to your homedir:
cp arch/arm/boot/uImage ../

Now build your kernel modules:
make modules

If you have a multicore processor you may append the number of cores to the make instruction, this will greatly speed up the compile process, so if you have a quadcore system you can make the modules with:
make modules -j4

And install them (will be in ~/kernelmodules):
make modules_install

Create a tarball with your modules in it, so you can deploy them on your new to boot system:
cd ~/kernelmodules
tar vczf kernelmodules.tgz *
mv kernelmodules.tgz ../

That’s it! Now you have built your own ARM kernel with the latest kernel sources available. For LaCie based NAS devices the kernel can be booted in 2 ways, that’s the secret partition (/dev/sda6 or 7) using dd of creating a ext3 filesystem on those partitions with uImage in the following directory: /snaps/00/boot/, but I will get back to you for this in the next round. You can also boot this via the uBoot console using TFTP.

Author:Jeffrey Langerak

48 responses to “Crosscompiling your own kernel”

  • Chris 08-02-2011 at 07:01 Reply 

    I followed your instructions exactly, even cut&paste to avoid any typos.
    I get to “make proper” and get this error:
    chris@ubuntu:~/linux-2.6.37$ make mrproper
    make: arm-none-eabi-gcc: Command not found

    Is there a typo in your instructions or am I missing a module?

    Thanks!


    • langerak 08-02-2011 at 21:45 Reply 

      Hi! Have you set the environment options as well? What version of ubuntu are you using? You can also check if in the 2010.09 folder is arm-none-eabi-gcc? Also make sure you are running as root!
      On ubuntu you can be root with “sudo su -“.


  • Chris 09-02-2011 at 04:44 Reply 

    Hi!

    I did set the environment options.
    I am using Ubuntu 10.10
    Under arm-2010.09 folder there is an arm-none-linux-gnueabi but *NOT* an arm-none-eabi-gcc folder.
    I was not using sudo. I will try that now.


  • Chris 09-02-2011 at 04:48 Reply 

    running as sudo did not make a difference 🙁


  • Chris 09-02-2011 at 05:05 Reply 

    This is one of your environment variables:
    export PATH=~/arm-2010.09/bin/:${PATH}

    I do not have a bin directory under arm-2010.09


    • Chris 09-02-2011 at 05:15 Reply 

      Ignore last comment. I am going senile.

      I deleted all of it and reinstalled from beginning, with all parts done as root. Same error.


      • langerak 09-02-2011 at 12:10 Reply 

        You are right, but i found the solution, with the newer toolchain the prefix has been changed, i’ve updated the post and the fix is:
        export CROSS_COMPILE=arm-none-linux-gnueabi-

        Try it! 🙂


  • Chris 09-02-2011 at 16:49 Reply 

    re-tried. Used the new EXPORT command.

    Same result 🙁


    • langerak 09-02-2011 at 16:54 Reply 

      Can you paste the contents of your arm-2010.09 folder? Because i have recreated the setup on a fresh machine and that worked for me with the new CROSS_COMPILE variable.


Leave a Reply

Your email address will not be published. Required fields are marked*

*

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.