Building a custom kernel
Building a custom kernel is one of those things that looks daunting at first, but really isn't that hard after you do it a few times. It is worthwhile to learn to build a custom kernel especially for a developer kit like the Sheeva Plug because eventually, you'll need functions that are offered by the new kernel.
At lot of information I've used to build the custom kernel is from here. You may want to browse to that location if you could not find the information you need here.
Deciding on the kernel
The first thing you need to decide when building a custom kernel is which kernel you want to use. There are 3 that I know of:
- 18.104.22.168 (Feroceon) - This is the kernel that came with the Sheeva Plug, the source and the patches comes with the development kit.
- 2.6.30-rc1 (Orion) - This is Marvell's kernel tree and is maintained by Marvell. You get this from Marvell's GIT repository.
- 2.6.30-rc3 (kernel.org) - This is the Linux's mainline kernel development tree. At lot of Marvell's changes have already made it to this tree. The difference between this tree and Orion is the different updates that are available. Meaning that Orion will likely see more updates/fixes that are specific to the Sheeva Plug. While the kernel.org tree will likely see updates/fixes to other parts of the kernel such as driver support some new USB gadget. I expect that when 2.6.30 is finally released, the 2 trees will merge.
Choosing between the different kernels depends on your level of comfort with running the latest and greatest. 2.6.30-rc* is still a development branch and is a kernel under test. Although the kernel should work, it is not bug free. As an example, the current Orion tree has a bug in the MMC detection where it prints out
mmc0: error -110 whilst initialising SD card
on the serial console when you plug in a SDHC memory card into the SD slot. A patch is available to fix the problem, but this illustrates the differences between a tested (Feorceon) kernel and a development kernel.
Getting the Feroceon tree
The 22.214.171.124 Feroceon tree is in the development CD that came with the Sheeva Plug. You can get it online as well here. You can get Marvell's instructions File:SheevaPlug Development Kit - Configuring the kernel with LSP for KW A0 based device-Rev1.1.pdf. Download SheevaPlug_LSP.zip from Marvell and unzip. You should then see 2 subdirectories LSP - Image and LSP - Sources. The image is the same as what was loaded in the Sheeva Plug. The sources directory contains the kernel source. The instructions from Marvell is a oddly worded, but essentially you need to untar linux-126.96.36.199.tar.bz2 and unzip linux-feroceon_4_2_7_KW.zip. Both will untar/unzip into their own directories, then, copy all the files from linux-feroceon_4_2_7_KW to linux-188.8.131.52. After that, you can follow Marvell's instructions make mrproper, make mv88f6281_defconfig and make uImage.
Getting the Orion tree
To get the Orion tree from Marvell, you'll need git. Clone the Orion repository with:
git clone git://git.marvell.com/orion.git
After a few minutes, you should see the orion directory that holds the kernel tree.
Getting the tree from kernel.org
The 2.6.30 is not yet released, the source is found under the test folder. You can use wget, which is the easiest way to get the kernel tree.
You can also use the git repository if you want the working copy.
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
The working copy is nice because it has snapshots of any previous released versions back to 2.6.12-rc2 and of course it has the latest, greatest, most cutting edge coded checked into mainline. If you download and build from this tree, you will end up with a 2.6.30-rc4 kernel. If you want to use the slightly less sharp version 2.6.30-rc3, type this in the linux-2.6 directory.
git checkout v2.6.30-rc3
Fixing U-Boot to load the Orion/Mainline kernel
The Current U-Boot only loads the Feroceon build kernel correctly. So if tried to boot an Orion or Mainline kernel, you will get the following error message:
Error: unrecognized/unsupported machine ID (r1 = 0x0000020f). Available machine support: ID (hex) NAME 00000690 Marvell DB-88F6281-BP Development Board 00000691 Marvell RD-88F6192-NAS Development Board 00000682 Marvell RD-88F6281 Reference Board 00000831 Marvell SheevaPlug Reference Board 0000085b QNAP TS-119/TS-219 Please check your kernel config and/or bootloader.
So if you plan to boot the Orion or Mainline kernel, you need to type the following at the U-Boot prompt.
setenv arcNumber 2097 setenv mainlineLinux yes saveenv
You must save the environments otherwise the kernel will not boot.
Cross-compiling is another one those things that sounds hard but really isn't, so don't let the term scare you. It is a lot faster to cross-compile and that's a big plus if you plan to compile a lot.
Advantages of cross-compiling:
- Compile time is a lot faster. It takes about 5 minutes to cross-compile the kernel on a decent desktop compare to about 70 minutes on the Sheeva Plug.
- Lots of storage. You don't have to worry about storage on the Sheeva Plug on a desktop.
- Kernel debugging. You can't build a new kernel if the one you build doesn't boot. So you'll need to have access to the cross-compiler anyway.
Setup the cross-compiler
You can either use the cross-compiler supply on the developer CD, or download it from Marvell's website under Host Software Support Package. You can also download Code Sourcery's ARM compiler for the x86 here. Any one of them will work fine. After you download the cross-compiler you want, unzip it and put the cross-compiler and kernel tree that you got earlier in this directory structure.
/sheeva | +-/sheeva/orion +-/sheeva/arm-2008q3
Your directories will be different depending on which cross-compiler/kernel. But the structure should be the same.
Getting U-Boot's mkimage
Before you can compile the kernel, you need a tool call mkimage from U-Boot so that the kernel image can be packaged into something U-Boot understands. The file is inside the U-Boot source package from Marvell, download and unzip. Copy mkimage to somewhere in your path and set the executable bit:
cp ./SheevaPlug_U-Boot/Tools/mkimage /usr/bin chmod +x /usr/bin/mkimage
Cross-compile the kernel
Now you're ready to compile the kernel. Go to the kernel source directory (orion, in my case) and type:
make ARCH=arm kirkwood_defconfig
That will load the default kirkwood kernel config. You can then do a
make ARCH=arm menuconfig
If you want to change any settings. If you have trouble with menuconfig, it is likely you didn't install developers libraries for ncurses. So do a
apt-get install libncurses5-dev
When you're happy with the config, start the build with:
make -j4 ARCH=arm CROSS_COMPILE=../arm-2008q3/bin/arm-none-eabi- uImage
The finish product is located in /sheeva/orion/arch/arm/boot/uImage.
You'll need to build modules that goes along with this kernel, even if you didn't select any modules in the kernel config.
make -j4 ARCH=arm CROSS_COMPILE=../arm-2008q3/bin/arm-none-eabi- modules
Then install the modules into a temporary directory:
make -j4 ARCH=arm CROSS_COMPILE=../arm-2008q3/bin/arm-none-eabi- INSTALL_MOD_PATH=.. modules_install
The modules and the dependency list will be install in the /sheeva/lib directory.
Installing the kernel and modules
Copy uImage to the Sheeva Plug and burn it into the flash. If you're like me, and use a external HDD to boot the uImage, replace the old uImage with the new one. As for the modules, copy all the files under /sheeva/lib to the Sheeva Plug's /lib.
Compile locally on the Sheeva Plug
Cross-compile might be fast, but there are still some advantages to compiling locally on the Sheeva Plug.
Advantages of compiling locally
- Everything is on the Sheeva Plug instead of a separate development computer. Keep in mind that all the cross-compile tools only run in Linux. So you'll need to build a separate Linux machine if you only have Windows. Remember, the Sheeva Plug is already a separate Linux machine, so why build another one?
- make modules_install works like it should. Cross-compile requires you to install the modules to a separate directory and then copy it to the Sheeva Plug. It is an extra step.
Personally I have both working, but I tend to compile on the Sheeva Plug because I don't really mind the wait. I like the idea of keeping the source I used to build the kernel I'm running on the same system. That way, I could always recompile the kernel if I need to. Also, I have an external HDD as my main storage and lots of space to hold different kernel versions (in case the one I build is bad).
Setup the compiler
This is an easy one, on the Sheeva Plug, type:
apt-get install build-essential libncurses5-dev
Also download and unpack your kernel of choice.
Getting U-Boot's mkimage
This is the hard one, because you can't use the mkimage from Marvell directly. So you'll have to compile it from source. Get the Marvell U-Boot source with:
Unpack the file, change directory to SheevaPlug_U-Boot. In this directory you should see U-Boot - Sources, you'll need to rename the sources directory so it doesn't have whites spaces in there. Otherwise the U-Boot build will fail. I renamed it to U-Boot-Sources. Go into U-Boot-Sources, unpack u-boot-1.1.4.tar.bz2 and u-boot-3.4.16.zip. Copy the contents of the u-boot-3.4.16 directory into u-boot-1.1.4 and replace the old files. Then go to the u-boot-1.1.4 directory and type:
make rd88f6281Sheevaplug_config make tools cp tools/mkimage /usr/local/bin
If you don't feel like going through the process of compiling your own mkimage, you can download the one I've already made here.
Compile the kernel
Once all the tools are installed, changed to the kernel source directory and compile the kernel with the follow:
make kirkwood_defconfig; make uImage; make modules; make modules_install
Copy uImage to the boot directory or burn it into the flash.
Did you find this page useful?