N1200 How To Recompile Kernel In Gentoo

Introduction
This guide covers building a kernel natively in Gentoo 2008.0 for the N1200. If you have followed the NAS-Central N1200 Gentoo installation guide you will already have all the sources and utilities necessary to recompile your kernel already installed. If you are using another distribution then you will need to ensure the mkimage utility from u-boot is installed alongside the usual utilities you would compile a kernel with.

Although the source is included in the distribution you may obtain it separately - see the N1200 kernel support page for more information. Note that this guide does not cover or work for the manufacturer supplied kernel sources.

Clean And Configure The Kernel
First it is necessary to make sure our sources are clean:

cd /usr/src/linux make mrproper

Following this you will need to copy the included config back into the root of the kernel sources. We left it in /usr/src for you:

cp ../config-linux-2.6.27-foonas-git .config make menuconfig

While you are configuring the kernel try to add the features you need as modules. Unfortunately we have a maximum kernel size (covered later) so you may need to change or remove parts of this configuration if you can not add them as modules. Also of course, be careful not to remove features needed to allow the device to function.

If you like you can disable obvious functionality that you know you will not be using - this may save you significant compile time.

Resulting Files
The product of this build are your kernel modules and the same kernel in various different formats. It is very important that you use the right one. Look in arch/powerpc/boot and you will see the file cuImage.thecus_n1200 - this is the file you must flash to your kernel mtd partition. If this file is not there then something went wrong and you should not flash any other file.

Check Kernel Size
You must check the resulting kernel size following the build. If the kernel file is bigger than 1703936 bytes then it will not be possible to flash your kernel onto the mtd kernel partition. If you kernel is larger you can tftp boot it, but you probably do not want this behavior permanently. It is up to you to check this.

Flash Kernel
Now that you have booted back to Gentoo successfully with your new kernel check that mtd3 is the kernel mtd:

cat /proc/mtd

You should see output similar to:

dev:   size   erasesize  name mtd0: 00040000 00020000 "u-boot" mtd1: 00040000 00020000 "u-boot config" mtd2: 00100000 00020000 "user" mtd3: 001a0000 00020000 "kernel" mtd4: 004e0000 00020000 "ramdisk"

Now change directory to where the kernel is and install it to the N1200s flash:

cd /usr/src/linux/arch/powerpc/boot dd if=cuImage.thecus_n1200 of=/dev/mtdblock3 bs=1k