Above average nerdiness

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

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 <ix2-200>
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

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.

23 responses to “Compiling kernels for the Marvell Kirkwood SoC under Ubuntu 11.10

  1. Alan January 8, 2012 at 1:36 am

    oops posted in the wrong place.

    How are u getting on with compileing the ix2-200 kernel. iv been trying to compile a 3.0, 3.1 3.any kernel realy myself with support for the buttons on the ix2-200 i even tried the origional kernel which i cannt get to compile either.

  2. marco February 1, 2012 at 7:01 am

    Dear nigelr,

    I followed your guide and installed Debian on my ix2-200. I had to fight a little with some bad blocks in NAND, but now the machine is booting from Flash.
    My question is about the “few alterations to the kernel” for leds and buttons support. I took a look to the config file: it seems to me that led support is built as module; I wasn’t able to find any entry recalling the buttons.

    Any clue?



    • nigelr February 1, 2012 at 10:30 pm

      Hi Marco

      To make the LEDs and button work I had to modify parts of the kernel, specifically the setup file used for ARM platforms to configure these sorts of things. I’ll post a patch that includes in the next day or two.

      Once that’s done, you just need a few options in the config file enabled to be able to control LEDs and use the button.


  3. Alan April 18, 2012 at 2:05 am

    how did you get the crypto dev module to work iv been trying and it just wont build for me? it keeps saying things are missing when i type make like this:

    from /root/cryptodev-linux-1.4/ioctl.c:36:
    /usr/src/linux-headers-3.3.2-ix2-200/arch/arm/include/asm/timex.h:15:24: fatal error: mach/timex.h: No such file or directory
    compilation terminated

    • nigelr April 18, 2012 at 8:51 pm

      I got it to work by using the same environment and other settings from my kernel post and editing the Makefile to set the source to a specific directory. I then had to copy the files around like I do with the kernel rather than use a package, but it works fine.

      • Alan April 18, 2012 at 9:48 pm

        sounds a lil confusing but would i be right in saying basically you build it on the same computer you build the kernel then your basically copying the built cryptodev source to the nas and install?

        i got it to build on my linux computer (x86_64 though) by just untaring the latest cryptodev source and hitting make. but trying to build it on the nas keeps giving errors of missing files.

        do you use the actual kernel source directory to build it or the headers directory?
        and by editing the makefile do you mean changing the uname -r where it gets the source directory automatically to say /usr/src/kernel3.xsource

        sorry to annoy you with a bunch of questions.

  4. Alan April 18, 2012 at 11:30 pm

    not entirely sure how but i got the /dev/crypto now following your way to build the kernel (for the most part). did you have to do anything special with openssl or anything to get it to use the new crypto dev?

    • nigelr April 20, 2012 at 8:21 pm

      Yep, I had to recompile the debian package with the right patch. You also need to limit what ciphers are used i.e. only aes-cbc is recommended and accelerated by cesa.

      • Alan April 22, 2012 at 12:59 am

        yeah i managed to get it all to work i ended up with about 8 engines in openssl though and maybe i was doin sumthing wrong but even after copying the files into place it didnt “JUST WORK” think i still needed to do depmod and modprobe cryptodev i think not to sure it was a bit of a roundabout way but got it working.

        what sort of numbers are you getting outa the test just out of curiosity? im getting:

        Nas:# openssl speed -evp aes-128-cbc
        Doing aes-128-cbc for 3s on 16 size blocks: 74346 aes-128-cbc’s in 0.13s
        Doing aes-128-cbc for 3s on 64 size blocks: 72781 aes-128-cbc’s in 0.10s
        Doing aes-128-cbc for 3s on 256 size blocks: 53998 aes-128-cbc’s in 0.05s
        Doing aes-128-cbc for 3s on 1024 size blocks: 37544 aes-128-cbc’s in 0.04s
        Doing aes-128-cbc for 3s on 8192 size blocks: 7805 aes-128-cbc’s in 0.01s
        OpenSSL 1.0.1 14 Mar 2012
        built on: Wed Apr 18 22:47:54 IST 2012
        options:bn(64,32) rc4(ptr,char) des(idx,cisc,16,long) aes(partial) idea(int) blowfish(ptr)
        The ‘numbers’ are in 1000s of bytes per second processed.
        type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
        aes-128-cbc 9150.28k 46579.84k 276469.76k 961126.40k 6393856.00k

        i also i updated your patch for the 3.3 kernel. with that im not sure but do we need just that 1 changed line for them to work? the way i did it i just changed all the lines in the mpp.h file that appear in your patch back to match all the ones that appear in your origional patch and created a new patch but it works on source and debian source. i currently have the 3.3.2 kernel on mine.

      • nigelr April 24, 2012 at 9:48 pm

        That’s about the same performance as I get. The reason my patch doesn’t apply any more in the latest kernels is that someone has actually fixed up that part properly by specifying which SoCs actually have that GPIO configured. That means that my change to mpp.h is not required, so I’ll generate a new patch with out that part.

  5. Alan April 25, 2012 at 8:14 am

    cool so basically half the changes that are needed to support the ix2-200 have been mainlined?

    • nigelr April 25, 2012 at 1:16 pm

      A tiny fraction perhaps 🙂

      The proper way of doing this would be to create a separate setup file and kernel configuration parameters for the ix2-200 instead of changing rd88f6281-setup.c. This should be fairly straight forward to do, but I’m not sure how useful it will be to get this into the mainline.

  6. Alan April 27, 2012 at 1:58 am

    ha well half of what your patch modifies anyway. and it would save us having to rebuild and patch every new kernel. i remember when i was putting debian on a goflex net there was a patch that did just that it created a new setup file for the goflex net and all the needed changes.

    i never realy looked into the setup files though so i wonder would there be any other advantages to having an ix2-200 setup file.

    and iv just found ubuntu arm install images so i might give that a shot for fun to see how it works on the ix2-200 without the desktop gui of course.

    • nigelr April 29, 2012 at 2:20 pm

      The only advantage is that OpenRD users can still use the original setup file, which is crucial from the kernel maintainers point of view. Last time I looked at Ubuntu they were only releasing binaries for ARMv7, which won’t work on Kirkwoods with their ARMv5 cores. Where are you getting them from?

      • Alan May 4, 2012 at 3:43 am

        yeah your right they dont work on the ix2-200 it keeps resetting the cpu after loading the install images. i got them from somewhere on the ubuntu site so must be the same ones you were thinking of. i used to have an address for a site that had basically a list of devices and their support staus in the linux kernel. i think it would be handy to have it mainlined especialy if your someone like me who likes to have the latest and greatest kernel and the like.

  7. Abhishek Sudhakaran March 18, 2013 at 11:43 pm

    where is the patch for the kirkwood soc driver ?
    Is it already in the mainstream kernel?

  8. itzurabhi March 20, 2013 at 9:08 am

    Ok.Thanks for the info guys…Is there any examples/docs that can help me with bare metal programming on this chip ? I’ve looked around in google but it seems most people dont use this chip that way except kernel dev’s/u-boot dev’s?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: