Nobiscuit

Above average nerdiness

Monthly Archives: November 2011

Compiling kernels for the Marvell Kirkwood SoC under Ubuntu 11.10

I’ve been doing a few alterations to the kernel to support the ix2-200 LEDs, buttons, i2c sensor etc. and so I needed a fast and reliable way of compiling the kernel. I can do this directly under Ubuntu 11.10 using the arm cross compiler:

apt-get install gcc-4.6-arm-linux-gnueabi

Once that’s installed, I can just use the following environment settings to build as per the usual kernel build process:

export CFLAGS="-march=armv5te -mfloat-abi=soft -marm"
export CROSS_COMPILE="arm-linux-gnueabi-"
export ARCH="arm"

I use git to track the latest kernels, and I suggest you do too since it makes keeping up to date quite easy. This means that the first step is to retrieve the kernel sources like so:

git pull git.kernel.org:/pub/scm/linux/kernel/git/stable/linux-stable.git

Once this is complete, just checkout the version you want to use. I’d recommend the 3.0.x series, since that works well for me under Debian 6.0. The latest as of this writing is 3.0.26 and as of 3.0.13, the issues with mv_cesa have been fixed.

cd linux-stable
git checkout v3.0.26

At this point you can apply patches and copy a previously prepared config, such as from my earlier post

patch -p1 < 0001-Modified-rd88f6281-setup-to-support-iomega-ix2-200.patch
cp ~/path/to/config .config

I use a standard set of environment variables for when I’m compiling a kernel:

export LOCALVERSION="" # don't append a special version string the kernel (but you can if you like)
export INSTALL_MOD_PATH=../modules # install the kernel modules in a special directory outside of the kernel structure

The next step is to setup the configuration by running make oldconfig.

make oldconfig

If you’re using the 3.0.x series and the configuration as above you probably won’t be asked any questions, but you’ll need to figure out the answer yourself if you do. The next step is to actually compile the kernel:

make -j8 uImage
make -j8 modules
make modules_install

Once these are done, I tar up the modules directory and then copy all the required files to the target.

tar -czf ../modules.tar.gz ../modules
scp ../modules.tar.gz <ix2-200>:
scp System.map <ix2-200>:System.map-3.0.26
scp .config <ix2-200>:config-3.0.26
scp arch/arm/boot/uImage <ix2-200>:uImage-3.0.26

Once that’s done, I ssh to the ix2-200 and copy the files to the right place (as root):

cp /home/user/*-3.0.26 /boot
tar xzf modules.tar.gz
cp -r modules/lib /

I can now create the initial RAM disk and convert it to uboot format:

update-initramfs -v -c -k 3.0.26
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs -d initrd.img-3.0.26 uInitrd-3.0.26

Now, if if I’m feeling brave, I will just write it to flash and reboot but I would suggest having a known good uImage/uInitrd sitting on a USB drive somewhere in case it goes wrong:

flash_eraseall /dev/mtd0
flash_eraseall /dev/mtd1
nandwrite -p /dev/mtd0 /boot/uImage-3.0.26
nandwrite -p /dev/mtd1 /boot/uInitrd-3.0.26
reboot

Other notes:

  • At some point I’d like to get packaging automated so that I can just install a .deb like other howtos do.
  • I haven’t included the steps to use the cryptodev module, which I use for giving accelerating SSH via a modified openssl.
  • There are some packages in debian-backports that I think are required to make Debian 6.0 fully support modern kernels. I haven’t looked that closely as to what exactly might not work, but I haven’t run into any problems either.
Advertisements