Building a Kernel for Edison

From Intel Edison Wiki
Jump to: navigation, search


This was by far the toughest challenge yet on the Edison. According to this blog:

http://habrahabr.ru/post/254247/

It is possible to run a newer kernel (in this case 4.1) on the Edison. So far, - and I know this is going to sound silly - I don't know if I succeeded. What I do know is that I have not succeeded in getting console output from this kernel, and without that console output it is virtually impossible to debug.

A rather less ambitious approach would be to initially use the original Intel Edison kernel, which is version 3.10.17. This kernel is very very old by now, but since it works it is at least a way to get OpenWrt up and running.

Github

All efforts on this page are tracked here:

https://github.com/bright-things/ionic/tree/edison/target/linux/edison

Using the buildroot

Building a complete OpenWrt takes a while. The following commands might come in handy.

First step is to select "edison" as a target.

 make menuconfig

and select "edison" as target system.

Menuconfig.png

From now on, the following commands will work.

First command is to take a kernel.org kernel and apply patches. From the root:

 make target/linux/{clean,prepare} V=s QUILT=1

Second command - build the kernel:

 make target/linux/install V=s

Everything in one go:

 make target/linux/{clean,install} V=s

Take I: Original Intel Edison kernel in OpenWrt

Rather than trying to get an up-to-date kernel running in OpenWrt, a first attempt would be to try to port the Intel Edison kernel build to the OpenWrt built root.

Edison is at the time of wring using kernel 3.10.17 and it supplies a patch and a default config

The default config is easy to deal with - simply drop it in target/linux/config-3.10.17.

The completely insane patch file (150k lines or thereabouts) is a different matter. Yes it could probably be applied using OpenWrt's Quilt system, however, for maintenance reasons it would probably be more productive to chop it into individual patch files. I hacked together a quick bash/awk script to do the chopping:

#!/bin/bash

if [ -z "$1" -o -z "$2" ]; then
        echo "Usage: generate <original patch file> <target directory>"
        exit 1
fi

if [ ! -f "$1" ]; then
        echo "Input file $1 does not exist"
        exit 2
fi

if [ ! -d "$2" ]; then
        echo "Output directory $2 does not exist or it is not a directory"
        exit 3
fi

cat "$1" | awk --assign "OUTDIR=$2" '

BEGIN {
        printf("Starting....\n");

        printf("  Output directory: %s\n", OUTDIR);

        STATE = 0;
        PATCH_NO = 0;
}
/^diff / {
        PATCH_NO = PATCH_NO + 1;

        PATCH_FILE = gensub(/^.*\//, "", "g", $4);
        PATCH_FILE = gensub(/\..*$/, "", "g", PATCH_FILE);

        PATCH_FILE = sprintf("%s/%03i-%s.patch", OUTDIR, PATCH_NO, PATCH_FILE);

        printf("  Found new patch: %s\n", PATCH_FILE);
        STATE = 1;
}
{
        if ( STATE == 1) {
                printf("%s\n", $0) >>PATCH_FILE
        }
}
END {
        printf("....Finished\n");
}

Running this script in target/linux/edison like this:

$ ./generate /tmp/upstream_to_edison.patch patches-3.10.17/

resulted in no less than 475 different patch files in patches-3.10.17.

A little tweaking of the config file, the resulting kernel was building cleanly on OpenWrt using:

 make target/linux/install V=s

And replacing /boot/vmlinux on a running Edison showed that the kernel starts up and produces console output.

This kernel did not allow a complete boot of the Edison, but I didn't bother to nail down the missing parts.

Take II: Proper 3.18 kernel

Unfortunately the current version of OpenWrt require features that are not available in kernel 3.10, which pretty much leaves two options:

  1. Bring patches up to kernel 3.18 level, or
  2. Patch OpenWrt to live with a 3.10 kernel

While the second option probably wouldn't be too hard it would be hard to maintain in the long run. The first option is a lot better long term.