<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://elinux.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://elinux.org/api.php?action=feedcontributions&amp;user=Ftheile&amp;feedformat=atom</id>
		<title>eLinux.org - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://elinux.org/api.php?action=feedcontributions&amp;user=Ftheile&amp;feedformat=atom"/>
		<link rel="alternate" type="text/html" href="http://elinux.org/Special:Contributions/Ftheile"/>
		<updated>2013-05-24T00:08:00Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.21alpha</generator>

	<entry>
		<id>http://elinux.org/RPi_Kernel_Compilation</id>
		<title>RPi Kernel Compilation</title>
		<link rel="alternate" type="text/html" href="http://elinux.org/RPi_Kernel_Compilation"/>
				<updated>2013-04-29T19:05:20Z</updated>
		
		<summary type="html">&lt;p&gt;Ftheile: cmd line fixed&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:RPi_Software}}&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
This page explains how to rebuild the kernel image for the RPi. There are two possible routes available: &lt;br /&gt;
# Compile on the Raspberry Pi itself&lt;br /&gt;
# Cross compile on another Linux system&lt;br /&gt;
&lt;br /&gt;
Both of these routes are covered below, however, you are strongly recommended to follow the cross compilation route. The low processing power of the RPi means that a local compile will take many hours.&lt;br /&gt;
&lt;br /&gt;
== Example Checklist/Roadmap ==&lt;br /&gt;
This section serves to hold a new user's hand just a bit more than some of the other more generic information below in the document. To get more information on the steps in the roadmap, search this page for additional details. It assumes you can navigate filesystems, move files across systems, and have a general understanding of compiling linux kernels, filesystems, partitions, and block devices.&lt;br /&gt;
&lt;br /&gt;
This series of steps yielded a successful custom/updated hardfp kernel to a stock Raspbian installation, cross compiled from an amd64 Debian system without regression on any kernel configuration options or requiring modified boot parameters. Be aware that in the worst case, you may need to overlay a stock set of kernel/modules/firmware on the Raspberry Pi if something fails. If you do not know how to do this, then a reimage of the SD card may be necessary. Assuming this is not an issue for your configuration, continue onward:&lt;br /&gt;
# Get the latest raspberrypi kernel source (https://github.com/raspberrypi/linux)&lt;br /&gt;
# Set an environment variable KERNEL_SRC to point to the location of the source ( e.g. KERNEL_SRC=/home/me/linux/ )&lt;br /&gt;
# Get the latest raspberrypi compiler (git clone https://github.com/raspberrypi/tools)&lt;br /&gt;
# Set an environment variable CCPREFIX to point to the location of tools ( e.g. CCPREFIX=/home/me/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi- )&lt;br /&gt;
# From the kernel clone location, clean the kernel source with &amp;quot;make mrproper&amp;quot;&lt;br /&gt;
# Pull the /proc/config.gz from the running Raspbian installation&lt;br /&gt;
# Prime kernel with the old config by running &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig&amp;quot;&lt;br /&gt;
# Modify the kernel config by either modifying the .config file or using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig&amp;quot;&lt;br /&gt;
# Build the new kernel by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make&amp;quot;&lt;br /&gt;
# Set an environment variable MODULES_TEMP to point to the location of the source ( e.g. MODULES_TEMP=/home/me/modules/ )&lt;br /&gt;
# Set aside the new kernel modules by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} make modules_install&amp;quot;&lt;br /&gt;
# From the tools clone location, in the mkimage directory, run &amp;quot;./imagetool-uncompressed.py ${KERNEL_SRC}/arch/arm/boot/zImage&amp;quot;&lt;br /&gt;
# Move the resulting kernel.img to the Raspberry Pi's /boot/ directory&lt;br /&gt;
# Package up the modules into an archive such that at the top level, the structure looks like this:&lt;br /&gt;
#* ./firmware&lt;br /&gt;
#* ./firmware/brcm&lt;br /&gt;
#* ./firmware/edgeport&lt;br /&gt;
#* ./firmware/emi26&lt;br /&gt;
#* ...&lt;br /&gt;
#* ./modules&lt;br /&gt;
#* ./modules/3.6.11+&lt;br /&gt;
#* ./modules/3.6.11+/kernel&lt;br /&gt;
#* ./modules/3.6.11+/kernel/lib&lt;br /&gt;
#* ./modules/3.6.11+/kernel/fs&lt;br /&gt;
#* ...&lt;br /&gt;
# Move the modules archive to the Raspberry Pi and extract them such that the aforementioned firmware and modules directories overwrite /lib/firmware and /lib/modules&lt;br /&gt;
# Get the latest raspberrypi firmware (git://github.com/raspberrypi/firmware.git)&lt;br /&gt;
# Transfer the following files from the firmware/boot directory to the Raspberry pi /boot directory:&lt;br /&gt;
#* bootcode.bin&lt;br /&gt;
#* fixup.dat&lt;br /&gt;
#* start.elf&lt;br /&gt;
# Transfer the firmware/hardfp/opt directory to the Raspberry pi /opt directory&lt;br /&gt;
# Reboot the Raspberry Pi&lt;br /&gt;
The Raspberry Pi should now boot with the newly configured/recompiled kernel.&lt;br /&gt;
&lt;br /&gt;
= Get the kernel source =&lt;br /&gt;
The kernel source should be downloaded from the [https://github.com/raspberrypi/linux RPI linux section on GitHub]. Although you could just compile the vanilla kernel from [http://www.kernel.org/ Kernel.org], it will not have the necessary drivers and modules for the Broadcom SoC on the RPi. You can however apply patches from the vanilla kernel to the RPi one - be prepared for potential compiler grumbles though!&lt;br /&gt;
&lt;br /&gt;
At the time of writing, three branches of interest are available:&lt;br /&gt;
* '''rpi-3.2.27''' - This is the version of the kernel currently used in Raspbian, but not exactly the same - Raspbian stock kernel image (the one available from the foundation's website) has a 3.2.27+ version marking. Please see [http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&amp;amp;t=26616 this post] for more details.&lt;br /&gt;
&lt;br /&gt;
* '''rpi-3.6-y''' - This is a development branch based on the current vanilla kernel( GIT rebased ) . It replaced the 3.2 development branch end marc 2013.&lt;br /&gt;
At the time of writing, the exact version is 3.6.11.&lt;br /&gt;
&lt;br /&gt;
* '''rpi-3.8-y''' - This is a Alpha development branch based on the current vanilla kernel( GIT rebased) . It will eventually replace the 3.6 branch. &lt;br /&gt;
At the time of writing, the exact version is 3.8.8 ( 22-04-2013 ).&lt;br /&gt;
&lt;br /&gt;
You can download the source directly using git. For the 3.2 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git init&lt;br /&gt;
git clone --depth 1 git://github.com/raspberrypi/linux.git&lt;br /&gt;
git checkout rpi-3.2.27&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the 3.6 Stable Code branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git init&lt;br /&gt;
git fetch git://github.com/raspberrypi/linux.git rpi-3.6.y:refs/remotes/origin/rpi-3.6.y&lt;br /&gt;
git checkout rpi-3.6.y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the 3.8 Development branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git init&lt;br /&gt;
git fetch git://github.com/raspberrypi/linux.git rpi-3.8.y:refs/remotes/origin/rpi-3.8.y&lt;br /&gt;
git checkout rpi-3.8.y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/linux/archive/rpi-3.2.27.tar.gz rpi-3.2.27] [https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz rpi-3.6.y][https://github.com/raspberrypi/linux/archive/rpi-3.8.y.tar.gz rpi-3.8.y]&lt;br /&gt;
&lt;br /&gt;
= Get a compiler =&lt;br /&gt;
Next, you will need to get a version of GCC in order to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== 1. On the RPi ==&lt;br /&gt;
&lt;br /&gt;
=== Raspbian ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get -y dist-upgrade&lt;br /&gt;
apt-get -y install gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -Syu&lt;br /&gt;
pacman -S gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OpenSuSE Linux ===&lt;br /&gt;
    Detailed OpenSuSE RPI 12.3 Image 20130407 + 3.8.8 kernel hack  tutorial witten  ( 22042013 updated ) &lt;br /&gt;
    see: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=87&amp;amp;t=40664&amp;amp;p=331953#p331953&lt;br /&gt;
    Kernel Compile takes ~22H on RPI Model B  due massive module compiles , Include all IP_VS , ARPD , Fuse-zfs  , Zram and more :-)   &lt;br /&gt;
&lt;br /&gt;
 This works as well for Debian , Fedora remix and others ( just package Install command differ )&lt;br /&gt;
 #     &lt;br /&gt;
 SuSE:  zypper install u-boot-tools sudo gcc automake autoconf bison gettext flex libncurses5 ncurses-devel&lt;br /&gt;
 Debian / Ubuntu : apt-get install ncurses-base libncurses5 ncurses-bin ncurses-term libncurses5-dev sudo gcc automake autoconf bison gettext flex&lt;br /&gt;
                   apt-get install uboot-mkimage uboot-envtools&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /usr/src&lt;br /&gt;
mkdir GIT; cd GIT; git init; D=`date +&amp;quot;%m-%d-%Y&amp;quot;`&lt;br /&gt;
git fetch git://github.com/raspberrypi/linux.git rpi-3.8.y:refs/remotes/origin/rpi-3.8.y&lt;br /&gt;
git checkout rpi-3.8.y&lt;br /&gt;
tar cpf rpi-3.8.y.$D.tar   rpi-3.8.y&lt;br /&gt;
&lt;br /&gt;
cd /usr/src&lt;br /&gt;
tar xpf  GIT/rpi-3.8.y.$D.tar&lt;br /&gt;
rm linux&lt;br /&gt;
ln -s linux-rpi-3.8.y linux&lt;br /&gt;
&lt;br /&gt;
cd /usr/src/linux&lt;br /&gt;
kversion=$(make -s kernelrelease)&lt;br /&gt;
cp linux/.config .config_$kversion&lt;br /&gt;
&lt;br /&gt;
cd /usr/src/&lt;br /&gt;
- get config-3.8.7.ipvs+krb5+arpd.tar.bz2 from the Tutorial:&lt;br /&gt;
wget http://www.raspberrypi.org/phpBB3/download/file.php?id=3174&lt;br /&gt;
- copy the .config to /usr/src/linux: &lt;br /&gt;
tar xpfj config-3.8.7.ipvs+krb5+arpd.tar.bz2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
make  the Kernel any go sleep :-)&lt;br /&gt;
 cd linux&lt;br /&gt;
 make oldconfig&lt;br /&gt;
 nohup make zImage dep modules &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Next day .. Install It.&lt;br /&gt;
cd /usr/src/linux&lt;br /&gt;
kversion=$(make -s kernelrelease)&lt;br /&gt;
echo $kversion&lt;br /&gt;
mkdir -p  /boot/$kversion&lt;br /&gt;
make ARCH=arm INSTALL_PATH=/boot/ install&lt;br /&gt;
cp System.map /boot/System.map-$kversion&lt;br /&gt;
cp System.map-$kversion /boot/System.map&lt;br /&gt;
make ARCH=arm modules_install INSTALL_MOD_PATH=/&lt;br /&gt;
make ARCH=arm INSTALL_PATH=/boot/ zinstall&lt;br /&gt;
cp .config /boot/config-$kversion&lt;br /&gt;
cp ./Module.symvers  /boot/symvers-$kversion&lt;br /&gt;
cp arch/arm/boot/Image /boot/kernel.img&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 2. Cross compiling from Linux ==&lt;br /&gt;
Please note that when cross-compiling, your compiler may not target the correct ARM processor by default. This will at best reduce performance, or worse, compile for a much newer processor resulting in illegal instructions in your code. The pre-built compiler or a custom-built compiler are recommended because of this. (For example, the latest GCC Linaro binary targets armv7-a by default, whereas the RPi requires armv6kz). It is possible to add extra compiler options to the &amp;lt;tt&amp;gt;HOSTCFLAGS&amp;lt;/tt&amp;gt; line in &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt;. The correct flags are shown on the [[RPi_Software#Compiler|software page]] - note that you may also need to add &amp;lt;tt&amp;gt;-marm&amp;lt;/tt&amp;gt; if your compiler produces Thumb code by default.&lt;br /&gt;
&lt;br /&gt;
=== Use the provided compiler ===&lt;br /&gt;
Download the pre-built bmc2708 compiler from the [https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi RPI tools section on GitHub].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/tools.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or you can download a tarball from the website using [https://github.com/raspberrypi/tools/archive/master.tar.gz this link].&lt;br /&gt;
&lt;br /&gt;
=== Custom-built Linaro GCC ===&lt;br /&gt;
See [[RPi_Linaro_GCC_Compilation|Linaro GCC Compilation]].&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install gcc-arm-linux-gnueabi make ncurses-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Gentoo Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crossdev -S -v -t arm-unknown-linux-gnueabi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Crossdev should create a cross-toolchain using the latest stable versions of the required packages.  If it fails, you can specify exact versions by removing the &amp;quot;-S&amp;quot; flag and adding the &amp;quot;--b&amp;quot;, &amp;quot;--g&amp;quot;, &amp;quot;--k&amp;quot; and &amp;quot;--l&amp;quot; flags. On 2012-05-06, &amp;lt;tt&amp;gt;cross -S -v -A gnueabi arm&amp;lt;/tt&amp;gt; works just fine.&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yaourt -S arm-linux-gnueabi-gcc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from OSX ==&lt;br /&gt;
=== Macports ===&lt;br /&gt;
The Kernel source requires a case-sensitive filesystem. If you do not have a HFS+ Case-sensitive partition that can be used, create a disk image with the appropriate format.&lt;br /&gt;
Ensure latest Xcode and command line tools are installed from [http://developer.apple.com/downloads Apple Developer Connection]&lt;br /&gt;
Install [http://guide.macports.org/#installing macports]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
port install arm-none-eabi-gcc&lt;br /&gt;
port install arm-none-eabi-binutils&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''If you get an error message that elf.h is missing'''&lt;br /&gt;
 sudo port install libelf &amp;amp;&amp;amp; sudo ln -s /opt/local/include/libelf /usr/include/libelf&lt;br /&gt;
From opensource.apple.com, download and copy [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elf.h?txt elf.h] and [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elftypes.h?txt elftypes.h] to /usr/include&lt;br /&gt;
&lt;br /&gt;
Edit elf.h and add&lt;br /&gt;
 #define R_386_NONE        0&lt;br /&gt;
 #define R_386_32          1&lt;br /&gt;
 #define R_386_PC32        2&lt;br /&gt;
 #define R_ARM_NONE        0&lt;br /&gt;
 #define R_ARM_PC24        1&lt;br /&gt;
 #define R_ARM_ABS32       2&lt;br /&gt;
 #define R_MIPS_NONE       0&lt;br /&gt;
 #define R_MIPS_16         1&lt;br /&gt;
 #define R_MIPS_32         2&lt;br /&gt;
 #define R_MIPS_REL32      3&lt;br /&gt;
 #define R_MIPS_26         4&lt;br /&gt;
 #define R_MIPS_HI16       5&lt;br /&gt;
 #define R_MIPS_LO16       6&lt;br /&gt;
'''If you get a &amp;quot;SEGMENT_SIZE is undeclared&amp;quot; error'''&lt;br /&gt;
open the Makefile and change the line:&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)&lt;br /&gt;
to&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux&lt;br /&gt;
&lt;br /&gt;
'''Complete script''' requires raspberrypi.config to be in the same folder that you execute from&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo port install arm-none-eabi-gcc&lt;br /&gt;
sudo port install arm-none-eabi-binutils&lt;br /&gt;
sudo port install libelf &amp;amp;&amp;amp; sudo ln -s /opt/local/include/libelf /usr/include/libelf&lt;br /&gt;
sudo curl http://opensource.apple.com/source/dtrace/dtrace-48/sys/elftypes.h?txt -o  /usr/include/elftypes.h&lt;br /&gt;
sudo curl http://opensource.apple.com/source/dtrace/dtrace-48/sys/elf.h?txt -o /usr/include/elf.h&lt;br /&gt;
#code to append to elf.h&lt;br /&gt;
echo &amp;quot;&lt;br /&gt;
#define R_386_NONE 0&lt;br /&gt;
#define R_386_32 1&lt;br /&gt;
#define R_386_PC32 2&lt;br /&gt;
#define R_ARM_NONE 0&lt;br /&gt;
#define R_ARM_PC24 1&lt;br /&gt;
#define R_ARM_ABS32 2&lt;br /&gt;
#define R_MIPS_NONE 0&lt;br /&gt;
#define R_MIPS_16 1&lt;br /&gt;
#define R_MIPS_32 2&lt;br /&gt;
#define R_MIPS_REL32 3&lt;br /&gt;
#define R_MIPS_26 4&lt;br /&gt;
#define R_MIPS_HI16 5&lt;br /&gt;
#define R_MIPS_LO16 6&amp;quot; &amp;gt; elf-append.h&lt;br /&gt;
sudo -s 'cat elf-append.h &amp;gt;&amp;gt; /usr/include/elf.h'&lt;br /&gt;
&lt;br /&gt;
#Make a case sensitive 3gb disk image, raspberrypi-kernel, and attach it&lt;br /&gt;
hdiutil create -size 10g -type SPARSEBUNDLE -nospotlight -volname raspberrypi-kernel -fs &amp;quot;Case-sensitive Journaled HFS+&amp;quot; -attach ./raspberrypi-kernel.dmg&lt;br /&gt;
cp raspberrypi.config /Volumes/raspberrypi-kernel/&lt;br /&gt;
mkdir /Volumes/raspberrypi-kernel/src&lt;br /&gt;
cd /Volumes/raspberrypi-kernel/src&lt;br /&gt;
&lt;br /&gt;
#get source, either 1. from zip (faster), or 2. from git&lt;br /&gt;
#1. from zip&lt;br /&gt;
curl https://codeload.github.com/raspberrypi/linux/zip/rpi-3.6.y -o ./rpi-3.6.y.zip&lt;br /&gt;
unzip rpi-3.6.y.zip&lt;br /&gt;
#2. from git (disabled)&lt;br /&gt;
#git init&lt;br /&gt;
#git fetch git://github.com/raspberrypi/linux.git rpi-3.6.y:refs/remotes/origin/rpi-3.6.y&lt;br /&gt;
#git checkout rpi-3.6.y&lt;br /&gt;
&lt;br /&gt;
cpu=$(sysctl hw.ncpu | awk '{print $2}')&lt;br /&gt;
cpup1=$((cpu+1))&lt;br /&gt;
&lt;br /&gt;
cd /Volumes/raspberrypi-kernel/src/linux-rpi-3.6.y/&lt;br /&gt;
export CCPREFIX=/opt/local/bin/arm-none-eabi-&lt;br /&gt;
cp /Volumes/raspberrypi-kernel/raspberrypi.config .config&lt;br /&gt;
make mrproper&lt;br /&gt;
#answer yes to all config options&lt;br /&gt;
yes &amp;quot;&amp;quot; | make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j$cpup1&lt;br /&gt;
#make ARCH=arm CROSS_COMPILE=${CCPREFIX} modules -j$cpup1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Yagarto ===&lt;br /&gt;
Download and install from [http://www.yagarto.de/#downloadmac here].&lt;br /&gt;
&lt;br /&gt;
= Perform the compilation =&lt;br /&gt;
Firstly, ensure your build directory is clean:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make mrproper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, in all cases, you will want to get a working kernel configuration to start from. You can get the one running on the RPi by typing the following (on the RPi):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zcat /proc/config.gz &amp;gt; .config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then copy &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; into your build directory.&lt;br /&gt;
&lt;br /&gt;
Alternatively, the default configuration is available in the downloaded kernel source in &amp;lt;tt&amp;gt;arch/arm/configs/bcmrpi_defconfig&amp;lt;/tt&amp;gt;. Just copy this to &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; in the build directory.&lt;br /&gt;
&lt;br /&gt;
From this point on, if you are cross-compiling, set an environment variable &amp;lt;tt&amp;gt;CCPREFIX&amp;lt;/tt&amp;gt; that points to the prefix of your compiler binary as each compiler will be named slightly differently.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CCPREFIX=/path/to/your/compiler/binary/prefix-of-binary-&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are building on the RPi, remove &amp;lt;tt&amp;gt;ARCH=arm CROSS_COMPILE=${CCPREFIX}&amp;lt;/tt&amp;gt; from each command.&lt;br /&gt;
&lt;br /&gt;
Ensure that your configuration file is up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If any configuration options have been added, you will be asked what set each option to. If you don't know the answer, just press enter to accept the default.&lt;br /&gt;
&lt;br /&gt;
Optionally, if you want to make changes to the configuration, run this next:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you are ready to build:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on a multi-core system, you can make the build faster by appending &amp;lt;tt&amp;gt;-j&amp;lt;N&amp;gt;&amp;lt;/tt&amp;gt; where &amp;lt;tt&amp;gt;&amp;lt;N&amp;gt;&amp;lt;/tt&amp;gt; is the number of cores on your system plus one (i.e. -j3 for 2 cores).&lt;br /&gt;
&lt;br /&gt;
Find something else to get on with while the compilation takes place. On an average PC with the default configuration, this should take about 15 minutes.&lt;br /&gt;
&lt;br /&gt;
The modules will be build with the following command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} modules&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Transfer the build =&lt;br /&gt;
The fully built kernel will be &amp;lt;tt&amp;gt;arch/arm/boot/Image&amp;lt;/tt&amp;gt;. Copy your new kernel file into the RPi boot partition, though preferably as a new file (such as &amp;lt;tt&amp;gt;kernel_new.img&amp;lt;/tt&amp;gt;) just in case it doesn't work. If you're building on the RPi, just copy the file to &amp;lt;tt&amp;gt;/boot&amp;lt;/tt&amp;gt;. If you use a different filename, edit &amp;lt;tt&amp;gt;config.txt&amp;lt;/tt&amp;gt; change the kernel line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel=kernel_new.img&lt;br /&gt;
#kernel=kernel.img&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you need to transfer the modules. Set an environment variable that points to a temporary module path.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export MODULES_TEMP=~/modules&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the build directory, run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} modules_install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The contents of this directory should then be copied into the RPi root directory. NOTE: If you have rebuilt the new kernel with exactly the same version as the one that's running, you'll need to remove the old modules first. Ideally this should be done offline by mounting the SD card on another system.&lt;br /&gt;
&lt;br /&gt;
Your RPi should now be ready to boot the new kernel. However, at this point it's recommended that you update your GPU firmware and libraries. '''This is required if you've just moved from 3.2 to 3.6 as the firmware interface has changed'''.&lt;br /&gt;
&lt;br /&gt;
= Get the firmware =&lt;br /&gt;
The firmware and boot files should be updated at the same time to ensure that your new kernel works properly. Again, two branches are available:&lt;br /&gt;
* '''master''' - This is the version of firmware currently used in Raspbian (i.e. it works with the 3.2 kernel).&lt;br /&gt;
* '''next''' - This is a development branch which provides a newer GPU firmware to work with the updated drivers in the 3.6 kernel.&lt;br /&gt;
&lt;br /&gt;
You can either download the source directly using git:&lt;br /&gt;
You can download the firmware directly using git. For the master branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/firmware.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the next branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/firmware.git next:refs/remotes/origin/next&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/firmware/archive/master.tar.gz master] [https://github.com/raspberrypi/firmware/archive/next.tar.gz next]&lt;br /&gt;
&lt;br /&gt;
= Transfer the firmware =&lt;br /&gt;
Firstly, update the required boot files in the RPi &amp;lt;tt&amp;gt;boot&amp;lt;/tt&amp;gt; directory with those you've downloaded. These are:&lt;br /&gt;
* bootcode.bin&lt;br /&gt;
* fixup.dat&lt;br /&gt;
* start.elf&lt;br /&gt;
&lt;br /&gt;
Next, you need to copy the VC libraries over. There are two copies of this: one for hard float and one for soft float. To find the correct one, run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
${CCPREFIX}gcc -v 2&amp;gt;&amp;amp;1 | grep hard&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If something prints out, and you can see &amp;lt;tt&amp;gt;--with-float=hard&amp;lt;/tt&amp;gt;, you need the hard float ones. NOTE: The current version of Raspbian uses hard float.&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;lt;tt&amp;gt;/opt/vc&amp;lt;/tt&amp;gt; directory from the RPi root, then:&lt;br /&gt;
* For hard float, copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the &amp;lt;tt&amp;gt;hardfp/opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory&lt;br /&gt;
* Otherwise copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the top-level &amp;lt;tt&amp;gt;opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory.&lt;br /&gt;
&lt;br /&gt;
= Test your build =&lt;br /&gt;
Power cycle your RPi and check the following:&lt;br /&gt;
* If you have the serial port on the GPIO expander wired up, you should see the kernel booting.&lt;br /&gt;
* The screen works - the kernel boots and you get a login prompt.&lt;br /&gt;
* The VC interface is working - if the 'OK' LED flashes regularly eight or so times every few seconds once the OS has booted, it's not. You can also test this by running &amp;lt;tt&amp;gt;vcgencmd measure_temp&amp;lt;/tt&amp;gt;. If it prints &amp;quot;VCHI initialization failed&amp;quot;, you have the a mismatch between the firmware, the VC libraries, and the kernel driver.&lt;br /&gt;
* Run &amp;lt;tt&amp;gt;uname -a&amp;lt;/tt&amp;gt; and check that your new kernel is the one that's running.&lt;br /&gt;
* Make sure you don't have any odd error messages during boot that may indicate a module isn't working properly. If you see &amp;lt;tt&amp;gt;missed completion of cmd 18&amp;lt;/tt&amp;gt; regarding DMA transfers to the SD card, you can safely ignore it.&lt;br /&gt;
&lt;br /&gt;
{{Template:Raspberry Pi}}&lt;br /&gt;
[[Category:RaspberryPi]]&lt;/div&gt;</summary>
		<author><name>Ftheile</name></author>	</entry>

	<entry>
		<id>http://elinux.org/RPi_Kernel_Compilation</id>
		<title>RPi Kernel Compilation</title>
		<link rel="alternate" type="text/html" href="http://elinux.org/RPi_Kernel_Compilation"/>
				<updated>2013-02-05T12:09:25Z</updated>
		
		<summary type="html">&lt;p&gt;Ftheile: /* Transfer the firmware */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:RPi_Software}}&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
This page explains how to rebuild the kernel image for the RPi. There are two possible routes available: &lt;br /&gt;
# Compile on the Raspberry Pi itself&lt;br /&gt;
# Cross compile on another Linux system&lt;br /&gt;
&lt;br /&gt;
Both of these routes are covered below, however, you are strongly recommended to follow the cross compilation route. The low processing power of the RPi means that a local compile will take many hours.&lt;br /&gt;
&lt;br /&gt;
== Example Checklist/Roadmap ==&lt;br /&gt;
This section serves to hold a new user's hand just a bit more than some of the other more generic information below in the document. To get more information on the steps in the roadmap, search this page for additional details. It assumes you can navigate filesystems, move files across systems, and have a general understanding of compiling linux kernels, filesystems, partitions, and block devices.&lt;br /&gt;
&lt;br /&gt;
This series of steps yielded a successful custom/updated hardfp kernel to a stock Raspbian installation, cross compiled from an amd64 Debian system without regression on any kernel configuration options or requiring modified boot parameters. Be aware that in the worst case, you may need to overlay a stock set of kernel/modules/firmware on the Raspberry Pi if something fails. If you do not know how to do this, then a reimage of the SD card may be necessary. Assuming this is not an issue for your configuration, continue onward:&lt;br /&gt;
# Get the latest raspberrypi kernel source (git://github.com/raspberrypi/linux.git)&lt;br /&gt;
# Set an environment variable KERNEL_SRC to point to the location of the source (e.g. KERNEL_SRC=/home/me/linux/)&lt;br /&gt;
# Get the latest raspberrypi compiler (git clone git://github.com/raspberrypi/tools.git)&lt;br /&gt;
# Set an environment variable CCPREFIX to point to the location of tools (e.g. CCPREFIX=/home/me/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-)&lt;br /&gt;
# From the kernel clone location, clean the kernel source with &amp;quot;make mrproper&amp;quot;&lt;br /&gt;
# Pull the /proc/config.gz from the running Raspbian installation&lt;br /&gt;
# Prime kernel with the old config by running &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig&amp;quot;&lt;br /&gt;
# Modify the kernel config by either modifying the .config file or using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig&amp;quot;&lt;br /&gt;
# Build the new kernel by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make&amp;quot;&lt;br /&gt;
# Set an environment variable MODULES_TEMP to point to the location of the source (e.g. MODULES_TEMP=/home/me/modules/)&lt;br /&gt;
# Set aside the new kernel modules by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} modules_install INSTALL_MOD_PATH=${MODULES_TEMP} make&amp;quot;&lt;br /&gt;
# From the tools clone location, in the mkimage directory, run &amp;quot;./imagetool-uncompressed.py ${KERNEL_SRC}/arch/arm/boot/zImage&amp;quot;&lt;br /&gt;
# Move the resulting kernel.img to the Raspberry Pi's /boot/ directory&lt;br /&gt;
# Package up the modules into an archive such that at the top level, the structure looks like this:&lt;br /&gt;
#* ./firmware&lt;br /&gt;
#* ./firmware/brcm&lt;br /&gt;
#* ./firmware/edgeport&lt;br /&gt;
#* ./firmware/emi26&lt;br /&gt;
#* ...&lt;br /&gt;
#* ./modules&lt;br /&gt;
#* ./modules/3.6.11+&lt;br /&gt;
#* ./modules/3.6.11+/kernel&lt;br /&gt;
#* ./modules/3.6.11+/kernel/lib&lt;br /&gt;
#* ./modules/3.6.11+/kernel/fs&lt;br /&gt;
#* ...&lt;br /&gt;
# Move the modules archive to the Raspberry Pi and extract them such that the aforementioned firmware and modules directories overwrite /lib/firmware and /lib/modules&lt;br /&gt;
# Get the latest raspberrypi firmware (git://github.com/raspberrypi/firmware.git)&lt;br /&gt;
# Transfer the following files from the firmware/boot directory to the Raspberry pi /boot directory:&lt;br /&gt;
#* bootcode.bin&lt;br /&gt;
#* fixup.dat&lt;br /&gt;
#* start.elf&lt;br /&gt;
# Transfer the firmware/hardfp/opt directory to the Raspberry pi /opt directory&lt;br /&gt;
# Reboot the Raspberry Pi&lt;br /&gt;
The Raspberry Pi should now boot with the newly configured/recompiled kernel.&lt;br /&gt;
&lt;br /&gt;
= Get the kernel source =&lt;br /&gt;
The kernel source should be downloaded from the [https://github.com/raspberrypi/linux RPI linux section on GitHub]. Although you could just compile the vanilla kernel from [http://www.kernel.org/ Kernel.org], it will not have the necessary drivers and modules for the Broadcom SoC on the RPi. You can however apply patches from the vanilla kernel to the RPi one - be prepared for potential compiler grumbles though!&lt;br /&gt;
&lt;br /&gt;
At the time of writing, two branches of interest are available:&lt;br /&gt;
* '''rpi-3.2.27''' - This is the version of the kernel currently used in Raspbian, but not exactly the same - Raspbian stock kernel image (the one available from the foundation's website) has a 3.2.27+ version marking. Please see [http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&amp;amp;t=26616 this post] for more details.&lt;br /&gt;
* '''rpi-3.6-y''' - This is a development branch based on the current vanilla kernel. It will eventually replace the 3.2 branch. At the time of writing, the exact version is 3.6.11.&lt;br /&gt;
&lt;br /&gt;
You can download the source directly using git. For the 3.2 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone --depth 1 git://github.com/raspberrypi/linux.git&lt;br /&gt;
git checkout rpi-3.2.27&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the 3.6 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/linux.git rpi-3.6.y:refs/remotes/origin/rpi-3.6.y&lt;br /&gt;
git checkout rpi-3.6.y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/linux/archive/rpi-3.2.27.tar.gz rpi-3.2.27] [https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz rpi-3.6.y]&lt;br /&gt;
&lt;br /&gt;
= Get a compiler =&lt;br /&gt;
Next, you will need to get a version of GCC in order to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== On the RPi ==&lt;br /&gt;
&lt;br /&gt;
=== Raspbian ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get -y dist-upgrade&lt;br /&gt;
apt-get -y install gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -Syu&lt;br /&gt;
pacman -S gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from Linux ==&lt;br /&gt;
Please note that when cross-compiling, your compiler may not target the correct ARM processor by default. This will at best reduce performance, or worse, compile for a much newer processor resulting in illegal instructions in your code. The pre-built compiler or a custom-built compiler are recommended because of this. (For example, the latest GCC Linaro binary targets armv7-a by default, whereas the RPi requires armv6kz). It is possible to add extra compiler options to the &amp;lt;tt&amp;gt;HOSTCFLAGS&amp;lt;/tt&amp;gt; line in &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt;. The correct flags are shown on the [[RPi_Software#Compiler|software page]] - note that you may also need to add &amp;lt;tt&amp;gt;-marm&amp;lt;/tt&amp;gt; if your compiler produces Thumb code by default.&lt;br /&gt;
&lt;br /&gt;
=== Use the provided compiler ===&lt;br /&gt;
Download the pre-built bmc2708 compiler from the [https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi RPI tools section on GitHub].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/tools.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or you can download a tarball from the website using [https://github.com/raspberrypi/tools/archive/master.tar.gz this link].&lt;br /&gt;
&lt;br /&gt;
=== Custom-built Linaro GCC ===&lt;br /&gt;
See [[RPi_Linaro_GCC_Compilation|Linaro GCC Compilation]].&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install gcc-arm-linux-gnueabi make ncurses-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Gentoo Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crossdev -S -v -t arm-unknown-linux-gnueabi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Crossdev should create a cross-toolchain using the latest stable versions of the required packages.  If it fails, you can specify exact versions by removing the &amp;quot;-S&amp;quot; flag and adding the &amp;quot;--b&amp;quot;, &amp;quot;--g&amp;quot;, &amp;quot;--k&amp;quot; and &amp;quot;--l&amp;quot; flags. On 2012-05-06, &amp;lt;tt&amp;gt;cross -S -v -A gnueabi arm&amp;lt;/tt&amp;gt; works just fine.&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yaourt -S arm-linux-gnueabi-gcc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from OSX ==&lt;br /&gt;
=== Macports ===&lt;br /&gt;
The Kernel source requires a case-sensitive filesystem. If you do not have a HFS+ Case-sensitive partition that can be used, create a disk image with the appropriate format.&lt;br /&gt;
Ensure latest Xcode and command line tools are installed from [http://developer.apple.com/downloads Apple Developer Connection]&lt;br /&gt;
Install [http://guide.macports.org/#installing macports]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
port install arm-none-eabi-gcc&lt;br /&gt;
port install arm-none-eabi-binutils&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''If you get an error message that elf.h is missing'''&lt;br /&gt;
 sudo port install libelf &amp;amp;&amp;amp; sudo ln -s /opt/local/include/libelf /usr/include/libelf&lt;br /&gt;
From opensource.apple.com, download and copy [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elf.h?txt elf.h] and [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elftypes.h?txt elftypes.h] to /usr/include&lt;br /&gt;
&lt;br /&gt;
Edit elf.h and add&lt;br /&gt;
 #define R_386_NONE        0&lt;br /&gt;
 #define R_386_32          1&lt;br /&gt;
 #define R_386_PC32        2&lt;br /&gt;
 #define R_ARM_NONE        0&lt;br /&gt;
 #define R_ARM_PC24        1&lt;br /&gt;
 #define R_ARM_ABS32       2&lt;br /&gt;
 #define R_MIPS_NONE       0&lt;br /&gt;
 #define R_MIPS_16         1&lt;br /&gt;
 #define R_MIPS_32         2&lt;br /&gt;
 #define R_MIPS_REL32      3&lt;br /&gt;
 #define R_MIPS_26         4&lt;br /&gt;
 #define R_MIPS_HI16       5&lt;br /&gt;
 #define R_MIPS_LO16       6&lt;br /&gt;
'''If you get a &amp;quot;SEGMENT_SIZE is undeclared&amp;quot; error'''&lt;br /&gt;
open the Makefile and change the line:&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)&lt;br /&gt;
to&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux&lt;br /&gt;
&lt;br /&gt;
=== Yagarto ===&lt;br /&gt;
Download and install from [http://www.yagarto.de/#downloadmac here].&lt;br /&gt;
&lt;br /&gt;
= Perform the compilation =&lt;br /&gt;
Firstly, ensure your build directory is clean:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make mrproper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, in all cases, you will want to get a working kernel configuration to start from. You can get the one running on the RPi by typing the following (on the RPi):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zcat /proc/config.gz &amp;gt; .config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then copy &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; into your build directory.&lt;br /&gt;
&lt;br /&gt;
Alternatively, the default configuration is available in the downloaded kernel source in &amp;lt;tt&amp;gt;arch/arm/configs/bcmrpi_defconfig&amp;lt;/tt&amp;gt;. Just copy this to &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; in the build directory.&lt;br /&gt;
&lt;br /&gt;
From this point on, if you are cross-compiling, set an environment variable &amp;lt;tt&amp;gt;CCPREFIX&amp;lt;/tt&amp;gt; that points to the prefix of your compiler binary as each compiler will be named slightly differently.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CCPREFIX=/path/to/your/compiler/binary/prefix-of-binary-&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are building on the RPi, remove &amp;lt;tt&amp;gt;ARCH=arm CROSS_COMPILE=${CCPREFIX}&amp;lt;/tt&amp;gt; from each command.&lt;br /&gt;
&lt;br /&gt;
Ensure that your configuration file is up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If any configuration options have been added, you will be asked what set each option to. If you don't know the answer, just press enter to accept the default.&lt;br /&gt;
&lt;br /&gt;
Optionally, if you want to make changes to the configuration, run this next:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you are ready to build:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on a multi-core system, you can make the build faster by appending &amp;lt;tt&amp;gt;-j&amp;lt;N&amp;gt;&amp;lt;/tt&amp;gt; where &amp;lt;tt&amp;gt;N&amp;lt;/tt&amp;gt; is the number of cores on your system plus one.&lt;br /&gt;
&lt;br /&gt;
Find something else to get on with while the compilation takes place. On an average PC with the default configuration, this should take about 15 minutes.&lt;br /&gt;
&lt;br /&gt;
= Transfer the build =&lt;br /&gt;
Copy your new &amp;lt;tt&amp;gt;kernel.img&amp;lt;/tt&amp;gt; file into the RPi boot partition, though preferably as a new file (such as &amp;lt;tt&amp;gt;kernel_new.img&amp;lt;/tt&amp;gt;) just in case it doesn't work. If you're building on the RPi, just copy the file to &amp;lt;tt&amp;gt;/boot&amp;lt;/tt&amp;gt;. If you use a different filename, edit &amp;lt;tt&amp;gt;config.txt&amp;lt;/tt&amp;gt; change the kernel line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel=kernel_new.img&lt;br /&gt;
#kernel=kernel.img&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you need to transfer the modules. Set an environment variable that points to a temporary module path.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export MODULES_TEMP=~/modules&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the build directory, run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} modules_install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The contents of this directory should then be copied into the RPi root directory. NOTE: If you have rebuilt the new kernel with exactly the same version as the one that's running, you'll need to remove the old modules first. Ideally this should be done offline by mounting the SD card on another system.&lt;br /&gt;
&lt;br /&gt;
Your RPi should now be ready to boot the new kernel. However, at this point it's recommended that you update your GPU firmware and libraries. '''This is required if you've just moved from 3.2 to 3.6 as the firmware interface has changed'''.&lt;br /&gt;
&lt;br /&gt;
= Get the firmware =&lt;br /&gt;
The firmware and boot files should be updated at the same time to ensure that your new kernel works properly. Again, two branches are available:&lt;br /&gt;
* '''master''' - This is the version of firmware currently used in Raspbian (i.e. it works with the 3.2 kernel).&lt;br /&gt;
* '''next''' - This is a development branch which provides a newer GPU firmware to work with the updated drivers in the 3.6 kernel.&lt;br /&gt;
&lt;br /&gt;
You can either download the source directly using git:&lt;br /&gt;
You can download the firmware directly using git. For the master branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/firmware.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the next branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/firmware.git next:refs/remotes/origin/next&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/firmware/archive/master.tar.gz master] [https://github.com/raspberrypi/firmware/archive/next.tar.gz next]&lt;br /&gt;
&lt;br /&gt;
= Transfer the firmware =&lt;br /&gt;
Firstly, update the required boot files in the RPi &amp;lt;tt&amp;gt;boot&amp;lt;/tt&amp;gt; directory with those you've downloaded. These are:&lt;br /&gt;
* bootcode.bin&lt;br /&gt;
* fixup.dat&lt;br /&gt;
* start.elf&lt;br /&gt;
&lt;br /&gt;
Next, you need to copy the VC libraries over. There are two copies of this: one for hard float and one for soft float. To find the correct one, run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
${CCPREFIX}gcc -v 2&amp;gt;&amp;amp;1 | grep hard&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If something prints out, and you can see &amp;lt;tt&amp;gt;--with-float=hard&amp;lt;/tt&amp;gt;, you need the hard float ones. NOTE: The current version of Raspbian uses hard float.&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;lt;tt&amp;gt;/opt/vc&amp;lt;/tt&amp;gt; directory from the RPi root, then:&lt;br /&gt;
* For hard float, copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the &amp;lt;tt&amp;gt;hardfp/opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory&lt;br /&gt;
* Otherwise copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the top-level &amp;lt;tt&amp;gt;opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory.&lt;br /&gt;
&lt;br /&gt;
= Test your build =&lt;br /&gt;
Power cycle your RPi and check the following:&lt;br /&gt;
* If you have the serial port on the GPIO expander wired up, you should see the kernel booting.&lt;br /&gt;
* The screen works - the kernel boots and you get a login prompt.&lt;br /&gt;
* The VC interface is working - if the 'OK' LED flashes regularly eight or so times every few seconds once the OS has booted, it's not. You can also test this by running &amp;lt;tt&amp;gt;vcgencmd measure_temp&amp;lt;/tt&amp;gt;. If it prints &amp;quot;VCHI initialization failed&amp;quot;, you have the a mismatch between the firmware, the VC libraries, and the kernel driver.&lt;br /&gt;
* Run &amp;lt;tt&amp;gt;uname -a&amp;lt;/tt&amp;gt; and check that your new kernel is the one that's running.&lt;br /&gt;
* Make sure you don't have any odd error messages during boot that may indicate a module isn't working properly. If you see &amp;lt;tt&amp;gt;missed completion of cmd 18&amp;lt;/tt&amp;gt; regarding DMA transfers to the SD card, you can safely ignore it.&lt;br /&gt;
&lt;br /&gt;
{{Template:Raspberry Pi}}&lt;br /&gt;
[[Category:RaspberryPi]]&lt;/div&gt;</summary>
		<author><name>Ftheile</name></author>	</entry>

	<entry>
		<id>http://elinux.org/RPi_Kernel_Compilation</id>
		<title>RPi Kernel Compilation</title>
		<link rel="alternate" type="text/html" href="http://elinux.org/RPi_Kernel_Compilation"/>
				<updated>2013-02-05T12:03:56Z</updated>
		
		<summary type="html">&lt;p&gt;Ftheile: /* Transfer the build */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:RPi_Software}}&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
This page explains how to rebuild the kernel image for the RPi. There are two possible routes available: &lt;br /&gt;
# Compile on the Raspberry Pi itself&lt;br /&gt;
# Cross compile on another Linux system&lt;br /&gt;
&lt;br /&gt;
Both of these routes are covered below, however, you are strongly recommended to follow the cross compilation route. The low processing power of the RPi means that a local compile will take many hours.&lt;br /&gt;
&lt;br /&gt;
== Example Checklist/Roadmap ==&lt;br /&gt;
This section serves to hold a new user's hand just a bit more than some of the other more generic information below in the document. To get more information on the steps in the roadmap, search this page for additional details. It assumes you can navigate filesystems, move files across systems, and have a general understanding of compiling linux kernels, filesystems, partitions, and block devices.&lt;br /&gt;
&lt;br /&gt;
This series of steps yielded a successful custom/updated hardfp kernel to a stock Raspbian installation, cross compiled from an amd64 Debian system without regression on any kernel configuration options or requiring modified boot parameters. Be aware that in the worst case, you may need to overlay a stock set of kernel/modules/firmware on the Raspberry Pi if something fails. If you do not know how to do this, then a reimage of the SD card may be necessary. Assuming this is not an issue for your configuration, continue onward:&lt;br /&gt;
# Get the latest raspberrypi kernel source (git://github.com/raspberrypi/linux.git)&lt;br /&gt;
# Set an environment variable KERNEL_SRC to point to the location of the source (e.g. KERNEL_SRC=/home/me/linux/)&lt;br /&gt;
# Get the latest raspberrypi compiler (git clone git://github.com/raspberrypi/tools.git)&lt;br /&gt;
# Set an environment variable CCPREFIX to point to the location of tools (e.g. CCPREFIX=/home/me/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-)&lt;br /&gt;
# From the kernel clone location, clean the kernel source with &amp;quot;make mrproper&amp;quot;&lt;br /&gt;
# Pull the /proc/config.gz from the running Raspbian installation&lt;br /&gt;
# Prime kernel with the old config by running &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig&amp;quot;&lt;br /&gt;
# Modify the kernel config by either modifying the .config file or using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig&amp;quot;&lt;br /&gt;
# Build the new kernel by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make&amp;quot;&lt;br /&gt;
# Set an environment variable MODULES_TEMP to point to the location of the source (e.g. MODULES_TEMP=/home/me/modules/)&lt;br /&gt;
# Set aside the new kernel modules by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} modules_install INSTALL_MOD_PATH=${MODULES_TEMP} make&amp;quot;&lt;br /&gt;
# From the tools clone location, in the mkimage directory, run &amp;quot;./imagetool-uncompressed.py ${KERNEL_SRC}/arch/arm/boot/zImage&amp;quot;&lt;br /&gt;
# Move the resulting kernel.img to the Raspberry Pi's /boot/ directory&lt;br /&gt;
# Package up the modules into an archive such that at the top level, the structure looks like this:&lt;br /&gt;
#* ./firmware&lt;br /&gt;
#* ./firmware/brcm&lt;br /&gt;
#* ./firmware/edgeport&lt;br /&gt;
#* ./firmware/emi26&lt;br /&gt;
#* ...&lt;br /&gt;
#* ./modules&lt;br /&gt;
#* ./modules/3.6.11+&lt;br /&gt;
#* ./modules/3.6.11+/kernel&lt;br /&gt;
#* ./modules/3.6.11+/kernel/lib&lt;br /&gt;
#* ./modules/3.6.11+/kernel/fs&lt;br /&gt;
#* ...&lt;br /&gt;
# Move the modules archive to the Raspberry Pi and extract them such that the aforementioned firmware and modules directories overwrite /lib/firmware and /lib/modules&lt;br /&gt;
# Get the latest raspberrypi firmware (git://github.com/raspberrypi/firmware.git)&lt;br /&gt;
# Transfer the following files from the firmware/boot directory to the Raspberry pi /boot directory:&lt;br /&gt;
#* bootcode.bin&lt;br /&gt;
#* fixup.dat&lt;br /&gt;
#* start.elf&lt;br /&gt;
# Transfer the firmware/hardfp/opt directory to the Raspberry pi /opt directory&lt;br /&gt;
# Reboot the Raspberry Pi&lt;br /&gt;
The Raspberry Pi should now boot with the newly configured/recompiled kernel.&lt;br /&gt;
&lt;br /&gt;
= Get the kernel source =&lt;br /&gt;
The kernel source should be downloaded from the [https://github.com/raspberrypi/linux RPI linux section on GitHub]. Although you could just compile the vanilla kernel from [http://www.kernel.org/ Kernel.org], it will not have the necessary drivers and modules for the Broadcom SoC on the RPi. You can however apply patches from the vanilla kernel to the RPi one - be prepared for potential compiler grumbles though!&lt;br /&gt;
&lt;br /&gt;
At the time of writing, two branches of interest are available:&lt;br /&gt;
* '''rpi-3.2.27''' - This is the version of the kernel currently used in Raspbian, but not exactly the same - Raspbian stock kernel image (the one available from the foundation's website) has a 3.2.27+ version marking. Please see [http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&amp;amp;t=26616 this post] for more details.&lt;br /&gt;
* '''rpi-3.6-y''' - This is a development branch based on the current vanilla kernel. It will eventually replace the 3.2 branch. At the time of writing, the exact version is 3.6.11.&lt;br /&gt;
&lt;br /&gt;
You can download the source directly using git. For the 3.2 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone --depth 1 git://github.com/raspberrypi/linux.git&lt;br /&gt;
git checkout rpi-3.2.27&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the 3.6 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/linux.git rpi-3.6.y:refs/remotes/origin/rpi-3.6.y&lt;br /&gt;
git checkout rpi-3.6.y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/linux/archive/rpi-3.2.27.tar.gz rpi-3.2.27] [https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz rpi-3.6.y]&lt;br /&gt;
&lt;br /&gt;
= Get a compiler =&lt;br /&gt;
Next, you will need to get a version of GCC in order to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== On the RPi ==&lt;br /&gt;
&lt;br /&gt;
=== Raspbian ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get -y dist-upgrade&lt;br /&gt;
apt-get -y install gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -Syu&lt;br /&gt;
pacman -S gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from Linux ==&lt;br /&gt;
Please note that when cross-compiling, your compiler may not target the correct ARM processor by default. This will at best reduce performance, or worse, compile for a much newer processor resulting in illegal instructions in your code. The pre-built compiler or a custom-built compiler are recommended because of this. (For example, the latest GCC Linaro binary targets armv7-a by default, whereas the RPi requires armv6kz). It is possible to add extra compiler options to the &amp;lt;tt&amp;gt;HOSTCFLAGS&amp;lt;/tt&amp;gt; line in &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt;. The correct flags are shown on the [[RPi_Software#Compiler|software page]] - note that you may also need to add &amp;lt;tt&amp;gt;-marm&amp;lt;/tt&amp;gt; if your compiler produces Thumb code by default.&lt;br /&gt;
&lt;br /&gt;
=== Use the provided compiler ===&lt;br /&gt;
Download the pre-built bmc2708 compiler from the [https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi RPI tools section on GitHub].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/tools.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or you can download a tarball from the website using [https://github.com/raspberrypi/tools/archive/master.tar.gz this link].&lt;br /&gt;
&lt;br /&gt;
=== Custom-built Linaro GCC ===&lt;br /&gt;
See [[RPi_Linaro_GCC_Compilation|Linaro GCC Compilation]].&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install gcc-arm-linux-gnueabi make ncurses-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Gentoo Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crossdev -S -v -t arm-unknown-linux-gnueabi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Crossdev should create a cross-toolchain using the latest stable versions of the required packages.  If it fails, you can specify exact versions by removing the &amp;quot;-S&amp;quot; flag and adding the &amp;quot;--b&amp;quot;, &amp;quot;--g&amp;quot;, &amp;quot;--k&amp;quot; and &amp;quot;--l&amp;quot; flags. On 2012-05-06, &amp;lt;tt&amp;gt;cross -S -v -A gnueabi arm&amp;lt;/tt&amp;gt; works just fine.&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yaourt -S arm-linux-gnueabi-gcc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from OSX ==&lt;br /&gt;
=== Macports ===&lt;br /&gt;
The Kernel source requires a case-sensitive filesystem. If you do not have a HFS+ Case-sensitive partition that can be used, create a disk image with the appropriate format.&lt;br /&gt;
Ensure latest Xcode and command line tools are installed from [http://developer.apple.com/downloads Apple Developer Connection]&lt;br /&gt;
Install [http://guide.macports.org/#installing macports]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
port install arm-none-eabi-gcc&lt;br /&gt;
port install arm-none-eabi-binutils&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''If you get an error message that elf.h is missing'''&lt;br /&gt;
 sudo port install libelf &amp;amp;&amp;amp; sudo ln -s /opt/local/include/libelf /usr/include/libelf&lt;br /&gt;
From opensource.apple.com, download and copy [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elf.h?txt elf.h] and [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elftypes.h?txt elftypes.h] to /usr/include&lt;br /&gt;
&lt;br /&gt;
Edit elf.h and add&lt;br /&gt;
 #define R_386_NONE        0&lt;br /&gt;
 #define R_386_32          1&lt;br /&gt;
 #define R_386_PC32        2&lt;br /&gt;
 #define R_ARM_NONE        0&lt;br /&gt;
 #define R_ARM_PC24        1&lt;br /&gt;
 #define R_ARM_ABS32       2&lt;br /&gt;
 #define R_MIPS_NONE       0&lt;br /&gt;
 #define R_MIPS_16         1&lt;br /&gt;
 #define R_MIPS_32         2&lt;br /&gt;
 #define R_MIPS_REL32      3&lt;br /&gt;
 #define R_MIPS_26         4&lt;br /&gt;
 #define R_MIPS_HI16       5&lt;br /&gt;
 #define R_MIPS_LO16       6&lt;br /&gt;
'''If you get a &amp;quot;SEGMENT_SIZE is undeclared&amp;quot; error'''&lt;br /&gt;
open the Makefile and change the line:&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)&lt;br /&gt;
to&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux&lt;br /&gt;
&lt;br /&gt;
=== Yagarto ===&lt;br /&gt;
Download and install from [http://www.yagarto.de/#downloadmac here].&lt;br /&gt;
&lt;br /&gt;
= Perform the compilation =&lt;br /&gt;
Firstly, ensure your build directory is clean:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make mrproper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, in all cases, you will want to get a working kernel configuration to start from. You can get the one running on the RPi by typing the following (on the RPi):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zcat /proc/config.gz &amp;gt; .config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then copy &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; into your build directory.&lt;br /&gt;
&lt;br /&gt;
Alternatively, the default configuration is available in the downloaded kernel source in &amp;lt;tt&amp;gt;arch/arm/configs/bcmrpi_defconfig&amp;lt;/tt&amp;gt;. Just copy this to &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; in the build directory.&lt;br /&gt;
&lt;br /&gt;
From this point on, if you are cross-compiling, set an environment variable &amp;lt;tt&amp;gt;CCPREFIX&amp;lt;/tt&amp;gt; that points to the prefix of your compiler binary as each compiler will be named slightly differently.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export CCPREFIX=/path/to/your/compiler/binary/prefix-of-binary-&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are building on the RPi, remove &amp;lt;tt&amp;gt;ARCH=arm CROSS_COMPILE=${CCPREFIX}&amp;lt;/tt&amp;gt; from each command.&lt;br /&gt;
&lt;br /&gt;
Ensure that your configuration file is up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If any configuration options have been added, you will be asked what set each option to. If you don't know the answer, just press enter to accept the default.&lt;br /&gt;
&lt;br /&gt;
Optionally, if you want to make changes to the configuration, run this next:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you are ready to build:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on a multi-core system, you can make the build faster by appending &amp;lt;tt&amp;gt;-j&amp;lt;N&amp;gt;&amp;lt;/tt&amp;gt; where &amp;lt;tt&amp;gt;N&amp;lt;/tt&amp;gt; is the number of cores on your system plus one.&lt;br /&gt;
&lt;br /&gt;
Find something else to get on with while the compilation takes place. On an average PC with the default configuration, this should take about 15 minutes.&lt;br /&gt;
&lt;br /&gt;
= Transfer the build =&lt;br /&gt;
Copy your new &amp;lt;tt&amp;gt;kernel.img&amp;lt;/tt&amp;gt; file into the RPi boot partition, though preferably as a new file (such as &amp;lt;tt&amp;gt;kernel_new.img&amp;lt;/tt&amp;gt;) just in case it doesn't work. If you're building on the RPi, just copy the file to &amp;lt;tt&amp;gt;/boot&amp;lt;/tt&amp;gt;. If you use a different filename, edit &amp;lt;tt&amp;gt;config.txt&amp;lt;/tt&amp;gt; change the kernel line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel=kernel_new.img&lt;br /&gt;
#kernel=kernel.img&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you need to transfer the modules. Set an environment variable that points to a temporary module path.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export MODULES_TEMP=~/modules&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the build directory, run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} modules_install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The contents of this directory should then be copied into the RPi root directory. NOTE: If you have rebuilt the new kernel with exactly the same version as the one that's running, you'll need to remove the old modules first. Ideally this should be done offline by mounting the SD card on another system.&lt;br /&gt;
&lt;br /&gt;
Your RPi should now be ready to boot the new kernel. However, at this point it's recommended that you update your GPU firmware and libraries. '''This is required if you've just moved from 3.2 to 3.6 as the firmware interface has changed'''.&lt;br /&gt;
&lt;br /&gt;
= Get the firmware =&lt;br /&gt;
The firmware and boot files should be updated at the same time to ensure that your new kernel works properly. Again, two branches are available:&lt;br /&gt;
* '''master''' - This is the version of firmware currently used in Raspbian (i.e. it works with the 3.2 kernel).&lt;br /&gt;
* '''next''' - This is a development branch which provides a newer GPU firmware to work with the updated drivers in the 3.6 kernel.&lt;br /&gt;
&lt;br /&gt;
You can either download the source directly using git:&lt;br /&gt;
You can download the firmware directly using git. For the master branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/firmware.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the next branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/firmware.git next:refs/remotes/origin/next&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/firmware/archive/master.tar.gz master] [https://github.com/raspberrypi/firmware/archive/next.tar.gz next]&lt;br /&gt;
&lt;br /&gt;
= Transfer the firmware =&lt;br /&gt;
Firstly, update the required boot files in the RPi &amp;lt;tt&amp;gt;boot&amp;lt;/tt&amp;gt; directory with those you've downloaded. These are:&lt;br /&gt;
* bootcode.bin&lt;br /&gt;
* fixup.dat&lt;br /&gt;
* start.elf&lt;br /&gt;
&lt;br /&gt;
Next, you need to copy the VC libraries over. There are two copies of this: one for hard float and one for soft float. To find the correct one, run the following command (substituting the program name for your compiler binary as required):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arm-none-linux-gnueabi-gcc -v 2&amp;gt;&amp;amp;1 | grep hard&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If something prints out, and you can see &amp;lt;tt&amp;gt;--with-float=hard&amp;lt;/tt&amp;gt;, you need the hard float ones. NOTE: The current version of Raspbian uses hard float.&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;lt;tt&amp;gt;/opt/vc&amp;lt;/tt&amp;gt; directory from the RPi root, then:&lt;br /&gt;
* For hard float, copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the &amp;lt;tt&amp;gt;hardfp/opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory&lt;br /&gt;
* Otherwise copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the top-level &amp;lt;tt&amp;gt;opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory.&lt;br /&gt;
&lt;br /&gt;
= Test your build =&lt;br /&gt;
Power cycle your RPi and check the following:&lt;br /&gt;
* If you have the serial port on the GPIO expander wired up, you should see the kernel booting.&lt;br /&gt;
* The screen works - the kernel boots and you get a login prompt.&lt;br /&gt;
* The VC interface is working - if the 'OK' LED flashes regularly eight or so times every few seconds once the OS has booted, it's not. You can also test this by running &amp;lt;tt&amp;gt;vcgencmd measure_temp&amp;lt;/tt&amp;gt;. If it prints &amp;quot;VCHI initialization failed&amp;quot;, you have the a mismatch between the firmware, the VC libraries, and the kernel driver.&lt;br /&gt;
* Run &amp;lt;tt&amp;gt;uname -a&amp;lt;/tt&amp;gt; and check that your new kernel is the one that's running.&lt;br /&gt;
* Make sure you don't have any odd error messages during boot that may indicate a module isn't working properly. If you see &amp;lt;tt&amp;gt;missed completion of cmd 18&amp;lt;/tt&amp;gt; regarding DMA transfers to the SD card, you can safely ignore it.&lt;br /&gt;
&lt;br /&gt;
{{Template:Raspberry Pi}}&lt;br /&gt;
[[Category:RaspberryPi]]&lt;/div&gt;</summary>
		<author><name>Ftheile</name></author>	</entry>

	<entry>
		<id>http://elinux.org/RPi_Kernel_Compilation</id>
		<title>RPi Kernel Compilation</title>
		<link rel="alternate" type="text/html" href="http://elinux.org/RPi_Kernel_Compilation"/>
				<updated>2013-01-22T20:28:39Z</updated>
		
		<summary type="html">&lt;p&gt;Ftheile: closing brace, quotation mark&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:RPi_Software}}&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
This page explains how to rebuild the kernel image for the RPi. There are two possible routes available: &lt;br /&gt;
# Compile on the Raspberry Pi itself&lt;br /&gt;
# Cross compile on another Linux system&lt;br /&gt;
&lt;br /&gt;
Both of these routes are covered below, however, you are strongly recommended to follow the cross compilation route. The low processing power of the RPi means that a local compile will take many hours.&lt;br /&gt;
&lt;br /&gt;
== Example Checklist/Roadmap ==&lt;br /&gt;
This section serves to hold a new user's hand just a bit more than some of the other more generic information below in the document. To get more information on the steps in the roadmap, search this page for additional details. It assumes you can navigate filesystems, move files across systems, and have a general understanding of compiling linux kernels, filesystems, partitions, and block devices.&lt;br /&gt;
&lt;br /&gt;
This series of steps yielded a successful custom/updated hardfp kernel to a stock Raspbian installation, cross compiled from an amd64 Debian system without regression on any kernel configuration options or requiring modified boot parameters. Be aware that in the worst case, you may need to overlay a stock set of kernel/modules/firmware on the Raspberry Pi if something fails. If you do not know how to do this, then a reimage of the SD card may be necessary. Assuming this is not an issue for your configuration, continue onward:&lt;br /&gt;
# Get the latest raspberrypi kernel source (git://github.com/raspberrypi/linux.git)&lt;br /&gt;
# Set an environment variable KERNEL_SRC to point to the location of the source (e.g. KERNEL_SRC=/home/me/linux/)&lt;br /&gt;
# Get the latest raspberrypi compiler (git clone git://github.com/raspberrypi/tools.git)&lt;br /&gt;
# Set an environment variable CCPREFIX to point to the location of tools (e.g. CCPREFIX=/home/me/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-)&lt;br /&gt;
# From the kernel clone location, clean the kernel source with &amp;quot;make mrproper&amp;quot;&lt;br /&gt;
# Pull the /proc/config.gz from the running Raspbian installation&lt;br /&gt;
# Prime kernel with the old config by running &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig&amp;quot;&lt;br /&gt;
# Modify the kernel config by either modifying the .config file or using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig&amp;quot;&lt;br /&gt;
# Build the new kernel by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make&amp;quot;&lt;br /&gt;
# Set an environment variable MODULES_TEMP to point to the location of the source (e.g. MODULES_TEMP=/home/me/modules/)&lt;br /&gt;
# Set aside the new kernel modules by using &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} modules_install INSTALL_MOD_PATH=${MODULES_TEMP} make&amp;quot;&lt;br /&gt;
# From the tools clone location, in the mkimage directory, run &amp;quot;./imagetool-uncompressed.py ${KERNEL_SRC}/arch/arm/boot/zImage&amp;quot;&lt;br /&gt;
# Move the resulting kernel.img to the Raspberry Pi's /boot/ directory&lt;br /&gt;
# Package up the modules into an archive such that at the top level, the structure looks like this:&lt;br /&gt;
#* ./firmware&lt;br /&gt;
#* ./firmware/brcm&lt;br /&gt;
#* ./firmware/edgeport&lt;br /&gt;
#* ./firmware/emi26&lt;br /&gt;
#* ...&lt;br /&gt;
#* ./modules&lt;br /&gt;
#* ./modules/3.6.11+&lt;br /&gt;
#* ./modules/3.6.11+/kernel&lt;br /&gt;
#* ./modules/3.6.11+/kernel/lib&lt;br /&gt;
#* ./modules/3.6.11+/kernel/fs&lt;br /&gt;
#* ...&lt;br /&gt;
# Move the modules archive to the Raspberry Pi and extract them such that the aforementioned firmware and modules directories overwrite /lib/firmware and /lib/modules&lt;br /&gt;
# Get the latest raspberrypi firmware (git://github.com/raspberrypi/firmware.git)&lt;br /&gt;
# Transfer the following files from the firmware/boot directory to the Raspberry pi /boot directory:&lt;br /&gt;
#* bootcode.bin&lt;br /&gt;
#* fixup.dat&lt;br /&gt;
#* start.elf&lt;br /&gt;
# Transfer the firmware/hardfp/opt directory to the Raspberry pi /opt directory&lt;br /&gt;
# Reboot the Raspberry Pi&lt;br /&gt;
The Raspberry Pi should now boot with the newly configured/recompiled kernel.&lt;br /&gt;
&lt;br /&gt;
= Get the kernel source =&lt;br /&gt;
The kernel source should be downloaded from the [https://github.com/raspberrypi/linux RPI linux section on GitHub]. Although you could just compile the vanilla kernel from [http://www.kernel.org/ Kernel.org], it will not have the necessary drivers and modules for the Broadcom SoC on the RPi. You can however apply patches from the vanilla kernel to the RPi one - be prepared for potential compiler grumbles though!&lt;br /&gt;
&lt;br /&gt;
At the time of writing, two branches of interest are available:&lt;br /&gt;
* '''rpi-3.2.27''' - This is the version of the kernel currently used in Raspbian, but not exactly the same - Raspbian stock kernel image (the one available from the foundation's website) has a 3.2.27+ version marking. Please see [http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&amp;amp;t=26616 this post] for more details.&lt;br /&gt;
* '''rpi-3.6-y''' - This is a development branch based on the current vanilla kernel. It will eventually replace the 3.2 branch. At the time of writing, the exact version is 3.6.11.&lt;br /&gt;
&lt;br /&gt;
You can download the source directly using git. For the 3.2 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/linux.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the 3.6 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/linux.git rpi-3.6.y:refs/remotes/origin/rpi-3.6.y&lt;br /&gt;
git checkout rpi-3.6.y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/linux/archive/rpi-3.2.27.tar.gz rpi-3.2.27] [https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz rpi-3.6.y]&lt;br /&gt;
&lt;br /&gt;
= Get a compiler =&lt;br /&gt;
Next, you will need to get a version of GCC in order to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== On the RPi ==&lt;br /&gt;
&lt;br /&gt;
=== Raspbian ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get -y dist-upgrade&lt;br /&gt;
apt-get -y install gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -Syu&lt;br /&gt;
pacman -S gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from Linux ==&lt;br /&gt;
Please note that when cross-compiling, your compiler may not target the correct ARM processor by default. This will at best reduce performance, or worse, compile for a much newer processor resulting in illegal instructions in your code. The pre-built compiler or a custom-built compiler are recommended because of this. (For example, the latest GCC Linaro binary targets armv7-a by default, whereas the RPi requires armv6kz). It is possible to add extra compiler options to the &amp;lt;tt&amp;gt;HOSTCFLAGS&amp;lt;/tt&amp;gt; line in &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt;. The correct flags are shown on the [[RPi_Software#Compiler|software page]] - note that you may also need to add &amp;lt;tt&amp;gt;-marm&amp;lt;/tt&amp;gt; if your compiler produces Thumb code by default.&lt;br /&gt;
&lt;br /&gt;
=== Use the provided compiler ===&lt;br /&gt;
Download the pre-built bmc2708 compiler from the [https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi RPI tools section on GitHub].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/tools.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or you can download a tarball from the website using [https://github.com/raspberrypi/tools/archive/master.tar.gz this link].&lt;br /&gt;
&lt;br /&gt;
=== Custom-built Linaro GCC ===&lt;br /&gt;
See [[RPi_Linaro_GCC_Compilation|Linaro GCC Compilation]].&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install gcc-arm-linux-gnueabi make ncurses-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Gentoo Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crossdev -S -v -t arm-unknown-linux-gnueabi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Crossdev should create a cross-toolchain using the latest stable versions of the required packages.  If it fails, you can specify exact versions by removing the &amp;quot;-S&amp;quot; flag and adding the &amp;quot;--b&amp;quot;, &amp;quot;--g&amp;quot;, &amp;quot;--k&amp;quot; and &amp;quot;--l&amp;quot; flags. On 2012-05-06, &amp;lt;tt&amp;gt;cross -S -v -A gnueabi arm&amp;lt;/tt&amp;gt; works just fine.&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yaourt -S arm-linux-gnueabi-gcc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from OSX ==&lt;br /&gt;
=== Macports ===&lt;br /&gt;
The Kernel source requires a case-sensitive filesystem. If you do not have a HFS+ Case-sensitive partition that can be used, create a disk image with the appropriate format.&lt;br /&gt;
Ensure latest Xcode and command line tools are installed from [http://developer.apple.com/downloads Apple Developer Connection]&lt;br /&gt;
Install [http://guide.macports.org/#installing macports]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
port install arm-none-eabi-gcc&lt;br /&gt;
port install arm-none-eabi-binutils&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''If you get an error message that elf.h is missing'''&lt;br /&gt;
 sudo port install libelf &amp;amp;&amp;amp; sudo ln -s /opt/local/include/libelf /usr/include/libelf&lt;br /&gt;
From opensource.apple.com, download and copy [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elf.h?txt elf.h] and [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elftypes.h?txt elftypes.h] to /usr/include&lt;br /&gt;
&lt;br /&gt;
Edit elf.h and add&lt;br /&gt;
 #define R_386_NONE        0&lt;br /&gt;
 #define R_386_32          1&lt;br /&gt;
 #define R_386_PC32        2&lt;br /&gt;
 #define R_ARM_NONE        0&lt;br /&gt;
 #define R_ARM_PC24        1&lt;br /&gt;
 #define R_ARM_ABS32       2&lt;br /&gt;
 #define R_MIPS_NONE       0&lt;br /&gt;
 #define R_MIPS_16         1&lt;br /&gt;
 #define R_MIPS_32         2&lt;br /&gt;
 #define R_MIPS_REL32      3&lt;br /&gt;
 #define R_MIPS_26         4&lt;br /&gt;
 #define R_MIPS_HI16       5&lt;br /&gt;
 #define R_MIPS_LO16       6&lt;br /&gt;
'''If you get a &amp;quot;SEGMENT_SIZE is undeclared&amp;quot; error'''&lt;br /&gt;
open the Makefile and change the line:&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)&lt;br /&gt;
to&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux&lt;br /&gt;
&lt;br /&gt;
=== Yagarto ===&lt;br /&gt;
Download and install from [http://www.yagarto.de/#downloadmac here].&lt;br /&gt;
&lt;br /&gt;
= Perform the compilation =&lt;br /&gt;
Firstly, ensure your build directory is clean:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make mrproper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, in all cases, you will want to get a working kernel configuration to start from. You can get the one running on the RPi by typing the following (on the RPi):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zcat /proc/config.gz &amp;gt; .config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then copy &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; into your build directory.&lt;br /&gt;
&lt;br /&gt;
Alternatively, the default configuration is available in the downloaded kernel source in &amp;lt;tt&amp;gt;arch/arm/configs/bcmrpi_defconfig&amp;lt;/tt&amp;gt;. Just copy this to &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; in the build directory.&lt;br /&gt;
&lt;br /&gt;
From this point on, if you are cross-compiling, please substitute &amp;lt;tt&amp;gt;&amp;lt;your_compiler&amp;gt;&amp;lt;/tt&amp;gt; with your compiler binary prefix (e.g. &amp;lt;tt&amp;gt;arm-bcm2708hardfp-linux-gnueabi-&amp;lt;/tt&amp;gt;) as each compiler will be named slightly differently. If you are building on the RPi, remove &amp;lt;tt&amp;gt;ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt;&amp;lt;/tt&amp;gt; from each command.&lt;br /&gt;
&lt;br /&gt;
Ensure that your configuration file is up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt; oldconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If any configuration options have been added, you will be asked what set each option to. If you don't know the answer, just press enter to accept the default.&lt;br /&gt;
&lt;br /&gt;
Optionally, if you want to make changes to the configuration, run this next:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt; menuconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you are ready to build:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on a multi-core system, you can make the build faster by appending &amp;lt;tt&amp;gt;-j&amp;lt;N&amp;gt;&amp;lt;/tt&amp;gt; where &amp;lt;tt&amp;gt;N&amp;lt;/tt&amp;gt; is the number of cores on your system plus one.&lt;br /&gt;
&lt;br /&gt;
Find something else to get on with while the compilation takes place. On an average PC with the default configuration, this should take about 15 minutes.&lt;br /&gt;
&lt;br /&gt;
= Prepare the image file =&lt;br /&gt;
Because of the way the memory addresses are arranged in the Broadcom SoC, you will need to prepare the compiled image for use. &lt;br /&gt;
&lt;br /&gt;
If you haven't got the tools directory from the Git repo, please do so now:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/tools.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or you can download a tarball from the website using [https://github.com/raspberrypi/tools/archive/master.tar.gz this link].&lt;br /&gt;
&lt;br /&gt;
In the tools set, there is a folder called &amp;lt;tt&amp;gt;mkimage&amp;lt;/tt&amp;gt;. Enter this directory, then run the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./imagetool-uncompressed.py &amp;lt;your_kernel_build_directory&amp;gt;/arch/arm/boot/zImage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will output a file called &amp;lt;tt&amp;gt;kernel.img&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Transfer the build =&lt;br /&gt;
Copy your new &amp;lt;tt&amp;gt;kernel.img&amp;lt;/tt&amp;gt; file into the RPi boot partition, though preferably as a new file (such as &amp;lt;tt&amp;gt;kernel_new.img&amp;lt;/tt&amp;gt;) just in case it doesn't work. If you're building on the RPi, just copy the file to &amp;lt;tt&amp;gt;/boot&amp;lt;/tt&amp;gt;. If you use a different filename, edit &amp;lt;tt&amp;gt;config.txt&amp;lt;/tt&amp;gt; change the kernel line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel=kernel_new.img&lt;br /&gt;
#kernel=kernel.img&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you need to transfer the modules. In the build directory, run the following (substituting &amp;lt;tt&amp;gt;&amp;lt;modules_path&amp;gt;&amp;lt;/tt&amp;gt; for a folder somewhere (e.g. &amp;lt;tt&amp;gt;~/modules&amp;lt;/tt&amp;gt;):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt; INSTALL_MOD_PATH=&amp;lt;modules_path&amp;gt; modules_install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The contents of this directory should then be copied into the RPi root directory. NOTE: If you have rebuilt the new kernel with exactly the same version as the one that's running, you'll need to remove the old modules first. Ideally this should be done offline by mounting the SD card on another system.&lt;br /&gt;
&lt;br /&gt;
Your RPi should now be ready to boot the new kernel. However, at this point it's recommended that you update your GPU firmware and libraries. '''This is required if you've just moved from 3.2 to 3.6 as the firmware interface has changed'''.&lt;br /&gt;
&lt;br /&gt;
= Get the firmware =&lt;br /&gt;
The firmware and boot files should be updated at the same time to ensure that your new kernel works properly. Again, two branches are available:&lt;br /&gt;
* '''master''' - This is the version of firmware currently used in Raspbian (i.e. it works with the 3.2 kernel).&lt;br /&gt;
* '''next''' - This is a development branch which provides a newer GPU firmware to work with the updated drivers in the 3.6 kernel.&lt;br /&gt;
&lt;br /&gt;
You can either download the source directly using git:&lt;br /&gt;
You can download the firmware directly using git. For the master branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/firmware.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the next branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/firmware.git next:refs/remotes/origin/next&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/firmware/archive/master.tar.gz master] [https://github.com/raspberrypi/firmware/archive/next.tar.gz next]&lt;br /&gt;
&lt;br /&gt;
= Transfer the firmware =&lt;br /&gt;
Firstly, update the required boot files in the RPi &amp;lt;tt&amp;gt;boot&amp;lt;/tt&amp;gt; directory with those you've downloaded. These are:&lt;br /&gt;
* bootcode.bin&lt;br /&gt;
* fixup.dat&lt;br /&gt;
* start.elf&lt;br /&gt;
&lt;br /&gt;
Next, you need to copy the VC libraries over. There are two copies of this: one for hard float and one for soft float. To find the correct one, run the following command (substituting the program name for your compiler binary as required):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arm-none-linux-gnueabi-gcc -v 2&amp;gt;&amp;amp;1 | grep hard&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If something prints out, and you can see &amp;lt;tt&amp;gt;--with-float=hard&amp;lt;/tt&amp;gt;, you need the hard float ones. NOTE: The current version of Raspbian uses hard float.&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;lt;tt&amp;gt;/opt/vc&amp;lt;/tt&amp;gt; directory from the RPi root, then:&lt;br /&gt;
* For hard float, copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the &amp;lt;tt&amp;gt;hardfp/opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory&lt;br /&gt;
* Otherwise copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the top-level &amp;lt;tt&amp;gt;opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory.&lt;br /&gt;
&lt;br /&gt;
= Test your build =&lt;br /&gt;
Power cycle your RPi and check the following:&lt;br /&gt;
* If you have the serial port on the GPIO expander wired up, you should see the kernel booting.&lt;br /&gt;
* The screen works - the kernel boots and you get a login prompt.&lt;br /&gt;
* The VC interface is working - if the 'OK' LED flashes regularly eight or so times every few seconds once the OS has booted, it's not. You can also test this by running &amp;lt;tt&amp;gt;vcgencmd measure_temp&amp;lt;/tt&amp;gt;. If it prints &amp;quot;VCHI initialization failed&amp;quot;, you have the a mismatch between the firmware, the VC libraries, and the kernel driver.&lt;br /&gt;
* Run &amp;lt;tt&amp;gt;uname -a&amp;lt;/tt&amp;gt; and check that your new kernel is the one that's running.&lt;br /&gt;
* Make sure you don't have any odd error messages during boot that may indicate a module isn't working properly. If you see &amp;lt;tt&amp;gt;missed completion of cmd 18&amp;lt;/tt&amp;gt; regarding DMA transfers to the SD card, you can safely ignore it.&lt;br /&gt;
&lt;br /&gt;
{{Template:Raspberry Pi}}&lt;br /&gt;
[[Category:RaspberryPi]]&lt;/div&gt;</summary>
		<author><name>Ftheile</name></author>	</entry>

	<entry>
		<id>http://elinux.org/User:Ftheile</id>
		<title>User:Ftheile</title>
		<link rel="alternate" type="text/html" href="http://elinux.org/User:Ftheile"/>
				<updated>2013-01-19T15:31:58Z</updated>
		
		<summary type="html">&lt;p&gt;Ftheile: added some infos about me.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Frank, I live in Germany and I get my Raspberry PI in Nov. 2012.&lt;br /&gt;
I've not done so much with it right now, but I'm interested in the Linux kernel and in embedded systems.&lt;br /&gt;
&lt;br /&gt;
I hope I can learn something from it.&lt;/div&gt;</summary>
		<author><name>Ftheile</name></author>	</entry>

	<entry>
		<id>http://elinux.org/Talk:RPi_Kernel_Compilation</id>
		<title>Talk:RPi Kernel Compilation</title>
		<link rel="alternate" type="text/html" href="http://elinux.org/Talk:RPi_Kernel_Compilation"/>
				<updated>2013-01-19T15:27:00Z</updated>
		
		<summary type="html">&lt;p&gt;Ftheile: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page could use a re-organization. Currently, most of the page is concerned with cross-platform compilation, with a lot of duplication in the kernel build step. I propose a breakdown thus:&lt;br /&gt;
&lt;br /&gt;
* Overview&lt;br /&gt;
* Getting the toolchain for cross-compilation (if needed)&lt;br /&gt;
* Configuring the kernel&lt;br /&gt;
: with special emphasis on built-in vs. modular drivers&lt;br /&gt;
* Building the kernel&lt;br /&gt;
* Installing the kernel&lt;br /&gt;
&lt;br /&gt;
Another possibility is to give cross-compilation its own page, to cover toolchain acquisition for different host platforms. Given that the RPi isn't the only embedded to use ARM CPU's, such a page could serve the same purpose for [[Processors#ARM|several ARM platforms]]. (For that matter, each CPU on such a page could have its own section on toolchain acquisition.) Then, the &amp;quot;kernel compilation&amp;quot; page could deal more succinctly with process of configuring and building the kernel for the RPi platform.&lt;br /&gt;
&lt;br /&gt;
[[User:Gus3|Gus3]]&lt;br /&gt;
&lt;br /&gt;
Note: zImage not supported by the last loader, officially confirmed! Only the uncompressed kernel image is supported.&lt;br /&gt;
&lt;br /&gt;
Just a quick note from an amateur: The cross compilation description includes building everything under /opt.  I build everything for myself under ~/opt, which seems both easier and safer.&lt;br /&gt;
&lt;br /&gt;
[[User:jakartadean|jakartadean]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I'm a newbie and had a problem running the pre-compiled tools (arm-bcm2708hardfp-linux-gnueabi-*) on my 64-bit host (Xubuntu 12.10). Installing ia32-libs on the host fixed the problem.&lt;br /&gt;
&lt;br /&gt;
Is it OK to add this somewhere?&lt;br /&gt;
&lt;br /&gt;
[[User:Ftheile|Ftheile]] ([[User talk:Ftheile|talk]])&lt;/div&gt;</summary>
		<author><name>Ftheile</name></author>	</entry>

	<entry>
		<id>http://elinux.org/RPi_Kernel_Compilation</id>
		<title>RPi Kernel Compilation</title>
		<link rel="alternate" type="text/html" href="http://elinux.org/RPi_Kernel_Compilation"/>
				<updated>2013-01-19T13:10:20Z</updated>
		
		<summary type="html">&lt;p&gt;Ftheile: typo fixed&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:RPi_Software}}&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
This page explains how to rebuild the kernel image for the RPi. There are two possible routes available: &lt;br /&gt;
# Compile on the Raspberry Pi itself&lt;br /&gt;
# Cross compile on another Linux system&lt;br /&gt;
&lt;br /&gt;
Both of these routes are covered below, however, you are strongly recommended to follow the cross compilation route. The low processing power of the RPi means that a local compile will take many hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example Checklist/Roadmap ==&lt;br /&gt;
This section serves to hold a new user's hand just a bit more than some of the other more generic information below in the document. To get more information on the steps in the roadmap, search this page for additional details. It assumes you can navigate filesystems, move files across systems, and have a general understanding of compiling linux kernels, filesystems, partitions, and block devices.&lt;br /&gt;
&lt;br /&gt;
This series of steps yielded a successful custom/updated hardfp kernel to a stock Raspbian installation, cross compiled from an amd64 Debian system without regressing on any kernel configuration options or requiring modified boot parameters:&lt;br /&gt;
# Get the latest raspberrypi kernel source (git://github.com/raspberrypi/linux.git)&lt;br /&gt;
# Set an environment variable KERNEL_SRC to point to the location of the source (e.g. KERNEL_SRC=/home/me/linux/)&lt;br /&gt;
# Get the latest raspberrypi compiler (git clone git://github.com/raspberrypi/tools.git)&lt;br /&gt;
# Set an environment variable CCPREFIX to point to the location of tools/ (e.g. CCPREFIX=/home/me/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-&amp;quot;&lt;br /&gt;
# From the kernel clone location, clean the kernel source with a &amp;quot;make mrproper&amp;quot;&lt;br /&gt;
# Pull the /proc/config.gz from the running Raspbian installation&lt;br /&gt;
# Prime kernel with the old config by running &amp;quot;ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig&amp;quot;&lt;br /&gt;
# Modify the kernel config by either modifying the .config file or using &amp;quot;make ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig&amp;quot;&lt;br /&gt;
# Build the new kernel by using &amp;quot;make ARCH=arm CROSS_COMPILE=${CCPREFIX} make&amp;quot;&lt;br /&gt;
# Set an environment variable MODULES_TEMP to point to the location of the source (e.g. MODULES_TEMP=/home/me/modules/)&lt;br /&gt;
# Set aside the new kernel modules by using &amp;quot;make ARCH=arm CROSS_COMPILE=${CCPREFIX} modules_install INSTALL_MOD_PATH=${MODULES_TEMP}&amp;quot;&lt;br /&gt;
# From the tools clone location, in the mkimage directory, run &amp;quot;./imagetool-uncompressed.py ${KERNEL_SRC}/arch/arm/boot/zImage&amp;quot;&lt;br /&gt;
# Move the resulting kernel.img to the Raspberry Pi's /boot/ directory&lt;br /&gt;
# Package up the modules into an archive such that at the top level, the structure looks like this:&lt;br /&gt;
#* ./firmware&lt;br /&gt;
#* ./firmware/brcm&lt;br /&gt;
#* ./firmware/edgeport&lt;br /&gt;
#* ./firmware/emi26&lt;br /&gt;
#* ...&lt;br /&gt;
#* ./modules&lt;br /&gt;
#* ./modules/3.6.11+&lt;br /&gt;
#* ./modules/3.6.11+/kernel&lt;br /&gt;
#* ./modules/3.6.11+/kernel/lib&lt;br /&gt;
#* ./modules/3.6.11+/kernel/fs&lt;br /&gt;
#* ...&lt;br /&gt;
# Move the modules archive to the Raspberry Pi and extract them such that the aforementioned firmware and modules directories overwrite /lib/firmware and /lib/modules&lt;br /&gt;
# Get the latest raspberrypi firmware (git://github.com/raspberrypi/firmware.git)&lt;br /&gt;
# Transfer the following files from the firmware/boot directory to the Raspberry pi /boot directory:&lt;br /&gt;
#* bootcode.bin&lt;br /&gt;
#* fixup.dat&lt;br /&gt;
#* start.elf&lt;br /&gt;
# Transfer the firmware/hardfp/opt directory to the Raspberry pi /opt directory&lt;br /&gt;
# Reboot the Raspberry Pi&lt;br /&gt;
&lt;br /&gt;
= Get the kernel source =&lt;br /&gt;
The kernel source should be downloaded from the [https://github.com/raspberrypi/linux RPI linux section on GitHub]. Although you could just compile the vanilla kernel from [http://www.kernel.org/ Kernel.org], it will not have the necessary drivers and modules for the Broadcom SoC on the RPi. You can however apply patches from the vanilla kernel to the RPi one - be prepared for potential compiler grumbles though!&lt;br /&gt;
&lt;br /&gt;
At the time of writing, two branches of interest are available:&lt;br /&gt;
* '''rpi-3.2.27''' - This is the version of the kernel currently used in Raspbian, but not exactly the same - Raspbian stock kernel image (the one available from the foundation's website) has a 3.2.27+ version marking. Please see [http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&amp;amp;t=26616 this post] for more details.&lt;br /&gt;
* '''rpi-3.6-y''' - This is a development branch based on the current vanilla kernel. It will eventually replace the 3.2 branch. At the time of writing, the exact version is 3.6.11.&lt;br /&gt;
&lt;br /&gt;
You can download the source directly using git. For the 3.2 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/linux.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the 3.6 branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/linux.git rpi-3.6.y:refs/remotes/origin/rpi-3.6.y&lt;br /&gt;
git checkout rpi-3.6.y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/linux/archive/rpi-3.2.27.tar.gz rpi-3.2.27] [https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz rpi-3.6.y]&lt;br /&gt;
&lt;br /&gt;
= Get a compiler =&lt;br /&gt;
Next, you will need to get a version of GCC in order to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== On the RPi ==&lt;br /&gt;
&lt;br /&gt;
=== Raspbian ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get -y dist-upgrade&lt;br /&gt;
apt-get -y install gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -Syu&lt;br /&gt;
pacman -S gcc make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from Linux ==&lt;br /&gt;
Please note that when cross-compiling, your compiler may not target the correct ARM processor by default. This will at best reduce performance, or worse, compile for a much newer processor resulting in illegal instructions in your code. The pre-built compiler or a custom-built compiler are recommended because of this. (For example, the latest GCC Linaro binary targets armv7-a by default, whereas the RPi requires armv6kz). It is possible to add extra compiler options to the &amp;lt;tt&amp;gt;HOSTCFLAGS&amp;lt;/tt&amp;gt; line in &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt;. The correct flags are shown on the [[RPi_Software#Compiler|software page]] - note that you may also need to add &amp;lt;tt&amp;gt;-marm&amp;lt;/tt&amp;gt; if your compiler produces Thumb code by default.&lt;br /&gt;
&lt;br /&gt;
=== Use the provided compiler ===&lt;br /&gt;
Download the pre-built bmc2708 compiler from the [https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi RPI tools section on GitHub].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/tools.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or you can download a tarball from the website using [https://github.com/raspberrypi/tools/archive/master.tar.gz this link].&lt;br /&gt;
&lt;br /&gt;
=== Custom-built Linaro GCC ===&lt;br /&gt;
See [[RPi_Linaro_GCC_Compilation|Linaro GCC Compilation]].&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install gcc-arm-linux-gnueabi make ncurses-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Gentoo Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
crossdev -S -v -t arm-unknown-linux-gnueabi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Crossdev should create a cross-toolchain using the latest stable versions of the required packages.  If it fails, you can specify exact versions by removing the &amp;quot;-S&amp;quot; flag and adding the &amp;quot;--b&amp;quot;, &amp;quot;--g&amp;quot;, &amp;quot;--k&amp;quot; and &amp;quot;--l&amp;quot; flags. On 2012-05-06, &amp;lt;tt&amp;gt;cross -S -v -A gnueabi arm&amp;lt;/tt&amp;gt; works just fine.&lt;br /&gt;
&lt;br /&gt;
=== Arch Linux ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yaourt -S arm-linux-gnueabi-gcc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cross compiling from OSX ==&lt;br /&gt;
=== Macports ===&lt;br /&gt;
The Kernel source requires a case-sensitive filesystem. If you do not have a HFS+ Case-sensitive partition that can be used, create a disk image with the appropriate format.&lt;br /&gt;
Ensure latest Xcode and command line tools are installed from [http://developer.apple.com/downloads Apple Developer Connection]&lt;br /&gt;
Install [http://guide.macports.org/#installing macports]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
port install arm-none-eabi-gcc&lt;br /&gt;
port install arm-none-eabi-binutils&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''If you get an error message that elf.h is missing'''&lt;br /&gt;
 sudo port install libelf &amp;amp;&amp;amp; sudo ln -s /opt/local/include/libelf /usr/include/libelf&lt;br /&gt;
From opensource.apple.com, download and copy [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elf.h?txt elf.h] and [http://opensource.apple.com/source/dtrace/dtrace-48/sys/elftypes.h?txt elftypes.h] to /usr/include&lt;br /&gt;
&lt;br /&gt;
Edit elf.h and add&lt;br /&gt;
 #define R_386_NONE        0&lt;br /&gt;
 #define R_386_32          1&lt;br /&gt;
 #define R_386_PC32        2&lt;br /&gt;
 #define R_ARM_NONE        0&lt;br /&gt;
 #define R_ARM_PC24        1&lt;br /&gt;
 #define R_ARM_ABS32       2&lt;br /&gt;
 #define R_MIPS_NONE       0&lt;br /&gt;
 #define R_MIPS_16         1&lt;br /&gt;
 #define R_MIPS_32         2&lt;br /&gt;
 #define R_MIPS_REL32      3&lt;br /&gt;
 #define R_MIPS_26         4&lt;br /&gt;
 #define R_MIPS_HI16       5&lt;br /&gt;
 #define R_MIPS_LO16       6&lt;br /&gt;
'''If you get a &amp;quot;SEGMENT_SIZE is undeclared&amp;quot; error'''&lt;br /&gt;
open the Makefile and change the line:&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)&lt;br /&gt;
to&lt;br /&gt;
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux&lt;br /&gt;
&lt;br /&gt;
=== Yagarto ===&lt;br /&gt;
Download and install from [http://www.yagarto.de/#downloadmac here].&lt;br /&gt;
&lt;br /&gt;
= Perform the compilation =&lt;br /&gt;
Firstly, ensure your build directory is clean:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make mrproper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, in all cases, you will want to get a working kernel configuration to start from. You can get the one running on the RPi by typing the following (on the RPi):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zcat /proc/config.gz &amp;gt; .config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then copy &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; into your build directory.&lt;br /&gt;
&lt;br /&gt;
Alternatively, the default configuration is available in the downloaded kernel source in &amp;lt;tt&amp;gt;arch/arm/configs/bcmrpi_defconfig&amp;lt;/tt&amp;gt;. Just copy this to &amp;lt;tt&amp;gt;.config&amp;lt;/tt&amp;gt; in the build directory.&lt;br /&gt;
&lt;br /&gt;
From this point on, if you are cross-compiling, please substitute &amp;lt;tt&amp;gt;&amp;lt;your_compiler&amp;gt;&amp;lt;/tt&amp;gt; with your compiler binary prefix (e.g. &amp;lt;tt&amp;gt;arm-bcm2708hardfp-linux-gnueabi-&amp;lt;/tt&amp;gt;) as each compiler will be named slightly differently. If you are building on the RPi, remove &amp;lt;tt&amp;gt;ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt;&amp;lt;/tt&amp;gt; from each command.&lt;br /&gt;
&lt;br /&gt;
Ensure that your configuration file is up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt; oldconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If any configuration options have been added, you will be asked what set each option to. If you don't know the answer, just press enter to accept the default.&lt;br /&gt;
&lt;br /&gt;
Optionally, if you want to make changes to the configuration, run this next:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt; menuconfig&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you are ready to build:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on a multi-core system, you can make the build faster by appending &amp;lt;tt&amp;gt;-j&amp;lt;N&amp;gt;&amp;lt;/tt&amp;gt; where &amp;lt;tt&amp;gt;N&amp;lt;/tt&amp;gt; is the number of cores on your system plus one.&lt;br /&gt;
&lt;br /&gt;
Find something else to get on with while the compilation takes place. On an average PC with the default configuration, this should take about 15 minutes.&lt;br /&gt;
&lt;br /&gt;
= Prepare the image file =&lt;br /&gt;
Because of the way the memory addresses are arranged in the Broadcom SoC, you will need to prepare the compiled image for use. &lt;br /&gt;
&lt;br /&gt;
If you haven't got the tools directory from the Git repo, please do so now:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/tools.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or you can download a tarball from the website using [https://github.com/raspberrypi/tools/archive/master.tar.gz this link].&lt;br /&gt;
&lt;br /&gt;
In the tools set, there is a folder called &amp;lt;tt&amp;gt;mkimage&amp;lt;/tt&amp;gt;. Enter this directory, then run the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./imagetool-uncompressed.py &amp;lt;your_kernel_build_directory&amp;gt;/arch/arm/boot/zImage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will output a file called &amp;lt;tt&amp;gt;kernel.img&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Transfer the build =&lt;br /&gt;
Copy your new &amp;lt;tt&amp;gt;kernel.img&amp;lt;/tt&amp;gt; file into the RPi boot partition, though preferably as a new file (such as &amp;lt;tt&amp;gt;kernel_new.img&amp;lt;/tt&amp;gt;) just in case it doesn't work. If you're building on the RPi, just copy the file to &amp;lt;tt&amp;gt;/boot&amp;lt;/tt&amp;gt;. If you use a different filename, edit &amp;lt;tt&amp;gt;config.txt&amp;lt;/tt&amp;gt; change the kernel line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel=kernel_new.img&lt;br /&gt;
#kernel=kernel.img&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you need to transfer the modules. In the build directory, run the following (substituting &amp;lt;tt&amp;gt;&amp;lt;modules_path&amp;gt;&amp;lt;/tt&amp;gt; for a folder somewhere (e.g. &amp;lt;tt&amp;gt;~/modules&amp;lt;/tt&amp;gt;):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make ARCH=arm CROSS_COMPILE=&amp;lt;your_compiler&amp;gt; INSTALL_MOD_PATH=&amp;lt;modules_path&amp;gt; modules_install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The contents of this directory should then be copied into the RPi root directory. NOTE: If you have rebuilt the new kernel with exactly the same version as the one that's running, you'll need to remove the old modules first. Ideally this should be done offline by mounting the SD card on another system.&lt;br /&gt;
&lt;br /&gt;
Your RPi should now be ready to boot the new kernel. However, at this point it's recommended that you update your GPU firmware and libraries. '''This is required if you've just moved from 3.2 to 3.6 as the firmware interface has changed'''.&lt;br /&gt;
&lt;br /&gt;
= Get the firmware =&lt;br /&gt;
The firmware and boot files should be updated at the same time to ensure that your new kernel works properly. Again, two branches are available:&lt;br /&gt;
* '''master''' - This is the version of firmware currently used in Raspbian (i.e. it works with the 3.2 kernel).&lt;br /&gt;
* '''next''' - This is a development branch which provides a newer GPU firmware to work with the updated drivers in the 3.6 kernel.&lt;br /&gt;
&lt;br /&gt;
You can either download the source directly using git:&lt;br /&gt;
You can download the firmware directly using git. For the master branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://github.com/raspberrypi/firmware.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and for the next branch:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch git://github.com/raspberrypi/firmware.git next:refs/remotes/origin/next&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download a tarball from the website using these links: [https://github.com/raspberrypi/firmware/archive/master.tar.gz master] [https://github.com/raspberrypi/firmware/archive/next.tar.gz next]&lt;br /&gt;
&lt;br /&gt;
= Transfer the firmware =&lt;br /&gt;
Firstly, update the required boot files in the RPi &amp;lt;tt&amp;gt;boot&amp;lt;/tt&amp;gt; directory with those you've downloaded. These are:&lt;br /&gt;
* bootcode.bin&lt;br /&gt;
* fixup.dat&lt;br /&gt;
* start.elf&lt;br /&gt;
&lt;br /&gt;
Next, you need to copy the VC libraries over. There are two copies of this: one for hard float and one for soft float. To find the correct one, run the following command (substituting the program name for your compiler binary as required):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arm-none-linux-gnueabi-gcc -v 2&amp;gt;&amp;amp;1 | grep hard&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If something prints out, and you can see &amp;lt;tt&amp;gt;--with-float=hard&amp;lt;/tt&amp;gt;, you need the hard float ones. NOTE: The current version of Raspbian uses hard float.&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;lt;tt&amp;gt;/opt/vc&amp;lt;/tt&amp;gt; directory from the RPi root, then:&lt;br /&gt;
* For hard float, copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the &amp;lt;tt&amp;gt;hardfp/opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory&lt;br /&gt;
* Otherwise copy &amp;lt;tt&amp;gt;vc&amp;lt;/tt&amp;gt; from the top-level &amp;lt;tt&amp;gt;opt&amp;lt;/tt&amp;gt; directory into &amp;lt;tt&amp;gt;/opt&amp;lt;/tt&amp;gt; in the RPi root directory.&lt;br /&gt;
&lt;br /&gt;
= Test your build =&lt;br /&gt;
Power cycle your RPi and check the following:&lt;br /&gt;
* If you have the serial port on the GPIO expander wired up, you should see the kernel booting.&lt;br /&gt;
* The screen works - the kernel boots and you get a login prompt.&lt;br /&gt;
* The VC interface is working - if the 'OK' LED flashes regularly eight or so times every few seconds once the OS has booted, it's not. You can also test this by running &amp;lt;tt&amp;gt;vcgencmd measure_temp&amp;lt;/tt&amp;gt;. If it prints &amp;quot;VCHI initialization failed&amp;quot;, you have the a mismatch between the firmware, the VC libraries, and the kernel driver.&lt;br /&gt;
* Run &amp;lt;tt&amp;gt;uname -a&amp;lt;/tt&amp;gt; and check that your new kernel is the one that's running.&lt;br /&gt;
* Make sure you don't have any odd error messages during boot that may indicate a module isn't working properly. If you see &amp;lt;tt&amp;gt;missed completion of cmd 18&amp;lt;/tt&amp;gt; regarding DMA transfers to the SD card, you can safely ignore it.&lt;br /&gt;
&lt;br /&gt;
{{Template:Raspberry Pi}}&lt;br /&gt;
[[Category:RaspberryPi]]&lt;/div&gt;</summary>
		<author><name>Ftheile</name></author>	</entry>

	</feed>