Mainline Kernel Howto

This articles describes how you can compile and use the Linux mainline kernel. For work done and to do read Linux mainlining effort please.

Prerequisites

 * An initramfs image (for example generated using buildroot)
 * An ARM toolchain
 * U-boot supporting device tree (if unsure, use a fresh build from the sunxi branch of u-boot-sunxi)

Supported boards
As of 3.12, the boards and SoC supported are:
 * A10
 * Cubieboard
 * Melee A1000
 * Mini X-plus
 * Hackberry


 * A10s
 * A10s-olinuxino


 * A13
 * A13-olinuxino


 * A20
 * A20-olinuxino
 * Cubieboard2


 * A31
 * A31 EVK

For boards using these SoCs, adding a new device tree should be trivial.

Stable releases
The stable releases are released by Linus Torvalds. Since Linux 3.8, the Allwinner support is added gradually. It is still quite sparse, but we are making good progress. This is probably what you should choose if you are looking for stability.

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

Patches merged in the next stable release
There is also a sunxi-next branch maintained with all the inclusions that have been accepted, merged and will included in the next stable release. If you want to do some development, it's probably the best pick.

git clone git://github.com/mripard/linux.git -b sunxi-next

Patches not yet merged in the next release
You can find a sunxi-devel branch on linux-sunxi. This branch contains functional patches that are currently being reviewed on the kernel lists. If you want to do bleeding-edge mainline testing, this should probably be your pick. Please do not use this branch for development, as it is frequently rebased and the code is likely to change.

git clone git://github.com/linux-sunxi/linux-sunxi.git -b sunxi-devel

Configuration
ARCH=arm make sunxi_defconfig ARCH=arm make menuconfig

Once there, fill the option General Setup / Initramfs source file(s) with a path to your initramfs image.

Compilation
ARCH=arm CROSS_COMPILE= LOADADDR=0x40008000 make uImage dtbs

After the compilation ended, you should have generated both the uImage in arch/arm/boot, and a device tree blob in arch/arm/boot/dts.

This device tree blob (or simply dtb) gives to the kernel the description of the hardware it's currently running on. In its goal, it's pretty similar to the FEX scripts that Allwinner uses, yet far more generic. It allows to compile a single kernel image that will run on several platforms.

Identify the dtb file for you board in arch/arm/boot/dts. You will need it in the next step.

Kernel Loading
Now copy the relevant dtb and uImage somewhere that you can load it from on your board, like a tftp server, a SD Card, etc.

Once you get to the U-boot prompt, stop the autoboot, and load the kernel image and device tree into memory making sure the will not overlap.

Depending on where you store it, you will have something like fatload mmc 0 0x46000000 uImage fatload mmc 0 0x49000000 .dtb

Warning: Before giving control to the kernel the U-Boot will move the loaded binaries to some different addresses and ignore the fact, the kernel needs much more space for extracting itselt. This causes a dtb to be overwritten and failure to boot. This of course should be fixed in U-Boot but a workaround for now is to set fdt_high: env set fdt_high ffffffff Once it's loaded into memory, you only need to tell U-Boot to boot the kernel using bootm 0x 0x 0x if initramfs is built into the uImage, you just use "-" as a placeholder for its address. Taking all this into account your bootm might look like bootm 0x46000000 - 0x49000000

The kernel should start booting up to a shell.

Have fun.

=See also=
 * Possible setups for hacking on mainline
 * Notes on Linux Kernel configuration