Difference between revisions of "Raspberry Pi Kernel Compilation"

From eLinux.org
Jump to: navigation, search
(From a foreign machine)
(re order)
Line 1: Line 1:
 
{{Template:RPi_Software}}
 
{{Template:RPi_Software}}
 
 
 
= Overview =
 
= Overview =
 
 
First, you are going to get and build the linux kernel and its modules using a suitable compiler (a "cross-compiler" if you aren't building it on the same hardware you will be running it on) and then you are going to create a kernel image from the uncompressed kernel (Image) to place on the sd, along with the modules you build alongside it.
 
First, you are going to get and build the linux kernel and its modules using a suitable compiler (a "cross-compiler" if you aren't building it on the same hardware you will be running it on) and then you are going to create a kernel image from the uncompressed kernel (Image) to place on the sd, along with the modules you build alongside it.
 
+
= From the Raspberry pi =
See below for the various guides to get and compile a suitable kernel for your RPi, and then create a kernel.img according to the steps at the end.
+
== Firmware ==
 
+
 
+
= Firmware =
+
 
+
== From the Raspberry pi ==
+
 
+
 
  cd /opt
 
  cd /opt
 
  git clone --depth 1 git://github.com/raspberrypi/firmware.git
 
  git clone --depth 1 git://github.com/raspberrypi/firmware.git
Line 19: Line 10:
 
  cd /opt
 
  cd /opt
 
  rm -r firmware
 
  rm -r firmware
 
+
== Kernel compilation ==
== From a foreign machine ==
+
=== Debian pre-build===
 
+
apt-get update
 +
apt-get -y dist-upgrade
 +
apt-get -y install git gcc make tmux
 +
=== Arch Linux pre-build===
 +
pacman -Syu
 +
pacman -S git gcc make tmux
 +
=== Common ===
 +
cd /opt
 +
mkdir raspberrypi
 +
cd raspberrypi
 +
git clone --depth 1 git://github.com/raspberrypi/linux.git
 +
cd linux
 +
zcat /proc/config.gz > .config
 +
#optional#make menuconfig
 +
tmux new -s make
 +
nice make; nice make modules
 +
[Ctrl]+[B],[D]
 +
############## … 5 hours later ...
 +
tmux a -t m
 +
[Ctrl]+[D]
 +
cp arch/arm/boot/Image /boot/kernel.img
 +
make ARCH=arm modules_install INSTALL_MOD_PATH=/
 +
cd /opt
 +
rm -r raspberrypi
 +
shutdown -r now;
 +
= From a foreign machine =
 +
== Firmware ==
 
  cd /opt
 
  cd /opt
 
  git clone git://github.com/raspberrypi/firmware.git
 
  git clone git://github.com/raspberrypi/firmware.git
 
  cd firmware/boot
 
  cd firmware/boot
 
  scp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf <user>@<host>:/boot/
 
  scp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf <user>@<host>:/boot/
 
+
After the first time:
after the first time:
+
 
  cd /opt/firmware
 
  cd /opt/firmware
 
  git pull
 
  git pull
 
  cd boot
 
  cd boot
 
  scp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf <user>@<host>:/boot/
 
  scp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf <user>@<host>:/boot/
 
+
== Kernel compilation ==
= Kernel compilation =
+
You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.
 
+
=== Ubunt ===
You can compile the kernel on the board itself, but because of the limited resources it will take a lot of time. Alternatively you can crosscompile the kernel on another machine running Linux, Windows or OS X.
+
  apt-get install git gcc-arm-linux-gnueabi make ncurses-dev
 
+
  cd /opt
== Compiling on the Raspberry pi itself ==
+
 
+
=== Debian ===
+
 
+
  apt-get update;
+
apt-get -y dist-upgrade;
+
apt-get -y install git tmux;
+
cd /opt/;
+
mkdir raspberrypi;
+
cd raspberrypi;
+
git clone --depth 1 https://github.com/raspberrypi/linux.git;
+
cd linux;
+
zcat /proc/config.gz > .config;
+
tmux new -s make;
+
nice make; nice make modules;
+
[Ctrl]+[B],[D]
+
############## … 5 hours later ...
+
tmux a -t m;
+
[Ctrl]+[D]
+
cp arch/arm/boot/Image /boot/kernel.img;
+
make ARCH=arm modules_install INSTALL_MOD_PATH=/
+
  cd ../;
+
git clone --depth 1 https://github.com/raspberrypi/firmware/;
+
cd firmware/boot;
+
cp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf /boot/;
+
shutdown -r now;
+
 
+
=== Arch Linux ===
+
 
+
==== getting the compiler ====
+
You will need GIT to clone the kernel source tree from GitHub, compiler (gcc) and GNU Make:
+
pacman -S git gcc make
+
 
+
(NOTE: git might be omitted if you decide to download sources in compressed format; this is far faster)
+
 
+
==== getting the sources ====
+
 
+
create a directory where you can work on  the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.
+
 
+
 
  mkdir raspberrypi
 
  mkdir raspberrypi
 
  cd raspberrypi  
 
  cd raspberrypi  
  git clone https://github.com/raspberrypi/linux.git
+
  git clone git://github.com/raspberrypi/linux.git
(NOTE: git might fail due to memory constraints; in this case creation of swap file might help. Be warned - this takes ages! To omit the revision history and reduce the download, you can add "--depth 1" to the end of the git clone command.)
+
 
+
Alternatively, download ZIP or TAR.GZ version of the sources from:
+
https://github.com/raspberrypi/linux/downloads
+
unpack and enter the extracted directory (this is your kernel directory - its sources to be precise)
+
 
+
==== configuring the kernel ====
+
Next, the kernel options are configured.  Either copy the cut down Raspberry Pi .config file from the kernel source configs directory:
+
cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
+
 
+
Or alternatively, to use the configuration from a currently running Raspberry Pi image, connect to the target and extract the .config file.  Then copy the resultant .config file into the Linux kernel source root directory:
+
zcat /proc/config.gz > .config
+
cp .config <path to linux source root directory>
+
 
+
If needed - manual/additional configuration:
+
make menuconfig
+
 
+
==== compile the kernel ====
+
make
+
 
+
(NOTE: this will take around 6h; You might find GNU Screen useful)
+
 
+
== Cross compiling on a foreign machine==
+
 
+
=== Ubuntu Linux ===
+
 
+
==== getting the compiler ====
+
 
+
On Ubuntu Oneiric getting the arm cross compiler can be as easy as:
+
+
sudo apt-get install gcc-arm-linux-gnueabi make
+
sudo apt-get install git-core  #jhauser14905 -- might as well state the obvious, you need git installed! -- it's git-core on ubuntu. --REW
+
sudo apt-get install ncurses-dev  #MatthewEveritt -- Had to install this to use menuconfig.
+
 
+
 
+
(TODO: Is this the right one? More packages required? I did this a while ago! TODO: Other distributions?)
+
 
+
==== getting the sources ====
+
 
+
create a directory where you can work on  the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.
+
 
+
mkdir raspberrypi
+
cd raspberrypi
+
git clone https://github.com/raspberrypi/linux.git
+
 
  cd linux
 
  cd linux
 
==== compiling ====
 
 
Next, the kernel options are configured.  Either copy the cut down Raspberry Pi .config file from the kernel source configs directory:
 
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 
Or alternatively, to use the configuration from a currently running Raspberry Pi image, connect to the target and extract the .config file.  Then copy the resultant .config file into the Linux kernel source root directory:
 
zcat /proc/config.gz > .config
 
cp .config <path to linux source root directory>
 
 
Configure the kernel with the copied .config file by running oldconfig:
 
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
 
+
  #optional#make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
If manual/additional configuration of kernel options are needed run menuconfig:
+
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
+
 
+
Then build the kernel:
+
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
 
You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.
 
 
If you get the error messages that arm-linux-gnueabi-gcc cannot be found when running make, run the following command:
 
 
sudo apt-get install gcc-arm-linux-gnueabi
 
 
 
=== Gentoo Linux ===
 
=== Gentoo Linux ===
 
 
==== getting the compiler ====
 
==== getting the compiler ====
 
 
Build the cross toolchain:
 
Build the cross toolchain:
 
  crossdev -S -v -t arm-unknown-linux-gnueabi
 
  crossdev -S -v -t arm-unknown-linux-gnueabi
 
 
theBuell: on 2012-05-06, cross -S -v -A gnueabi arm works just fine
 
theBuell: on 2012-05-06, cross -S -v -A gnueabi arm works just fine
  
 
This command 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 "-S" flag and adding the "--b", "--g", "--k" and "--l" flags. For the exact usage refer to the crossdev manpage. A good starting point for figuring out the right versions are those which are stable for the arm architecture.
 
This command 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 "-S" flag and adding the "--b", "--g", "--k" and "--l" flags. For the exact usage refer to the crossdev manpage. A good starting point for figuring out the right versions are those which are stable for the arm architecture.
 
 
==== getting the sources ====
 
==== getting the sources ====
 
 
create a directory where you can work on  the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.  
 
create a directory where you can work on  the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.  
 
 
  mkdir raspberrypi
 
  mkdir raspberrypi
 
  cd raspberrypi  
 
  cd raspberrypi  
 
  git clone https://github.com/raspberrypi/linux.git
 
  git clone https://github.com/raspberrypi/linux.git
 
  cd linux
 
  cd linux
 
 
==== compiling ====
 
==== compiling ====
 
 
Next you have to configure the kernel:
 
Next you have to configure the kernel:
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
 
 
Then building the kernel:
 
Then building the kernel:
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
 
 
You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.
 
You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.
 
 
=== Arch Linux ===
 
=== Arch Linux ===
 
 
==== getting the compiler ====
 
==== getting the compiler ====
 
You will need GIT to clone the kernel source tree from GitHub:
 
You will need GIT to clone the kernel source tree from GitHub:
 
  pacman -S git
 
  pacman -S git
 
 
Build the cross toolchain:
 
Build the cross toolchain:
 
arm-linux-gnueabi-gcc is on the AUR. If you use yaourt:
 
arm-linux-gnueabi-gcc is on the AUR. If you use yaourt:
 
 
  yaourt -S arm-linux-gnueabi-gcc
 
  yaourt -S arm-linux-gnueabi-gcc
 
 
Yaourt is recommended as it will build all dependencies.
 
Yaourt is recommended as it will build all dependencies.
 
 
==== getting the sources ====
 
==== getting the sources ====
 
 
create a directory where you can work on  the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.  
 
create a directory where you can work on  the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.  
 
 
  mkdir raspberrypi
 
  mkdir raspberrypi
 
  cd raspberrypi  
 
  cd raspberrypi  
 
  git clone https://github.com/raspberrypi/linux.git
 
  git clone https://github.com/raspberrypi/linux.git
 
  cd linux
 
  cd linux
 
 
==== compiling ====
 
==== compiling ====
 
 
Next you have to configure the kernel:
 
Next you have to configure the kernel:
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
 
 
Then building the kernel:
 
Then building the kernel:
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
 
  make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k
 
 
You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.
 
You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.
 
=== Windows ===
 
 
TODO
 
 
 
=== OS X ===
 
=== OS X ===
 
+
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.
==== getting the compiler ====
+
Ensure latest Xcode and command line tools are installed from [http://developer.apple.com/downloads Apple Developer Connection]  
Ensure latest Xcode and command line tools are installed from [http://developer.apple.com/downloads Apple Developer Connection] then
+
==== Yagarto ====
Downoad and install an GNU ARM toolchain such as [http://www.yagarto.de/#downloadmac yagarto]
+
Downoad and install an GNU ARM toolchain such as [http://www.yagarto.de/#downloadmac yagarto].
 
+
==== Macports ====
Another option is the MacPorts arm-none-eabi-*:
+
[http://guide.macports.org/#installing macports]
 
+
ARM gcc:
+
 
+
 
  port install arm-none-eabi-gcc
 
  port install arm-none-eabi-gcc
 
binutils:
 
 
 
  port install arm-none-eabi-binutils
 
  port install arm-none-eabi-binutils
 
+
==== Common ====
==== getting the sources ====
+
  cd /opt
 
+
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 then clone the repository into the mounted image.
+
 
+
Otherwise, create a directory where you can work on the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.
+
 
+
 
  mkdir raspberrypi
 
  mkdir raspberrypi
 
  cd raspberrypi  
 
  cd raspberrypi  
  git clone https://github.com/raspberrypi/linux.git
+
  git clone git://github.com/raspberrypi/linux.git
 
  cd linux
 
  cd linux
 
==== compiling ====
 
 
Next you have to configure the kernel: (the running kernel config can be found in <code>/proc/config.gz</code> on your RPi)
 
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 
  cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
 +
==== Yagarto ====
 
  make ARCH=arm CROSS_COMPILE=/path/to/yagarto/bin/arm-none-eabi- oldconfig
 
  make ARCH=arm CROSS_COMPILE=/path/to/yagarto/bin/arm-none-eabi- oldconfig
 
+
make ARCH=arm CROSS_COMPILE=/path/to/yagarto/bin/arm-none-eabi- -k
or if you used the MacPorts
+
==== Macports ====
 
  make ARCH=arm CROSS_COMPILE=/opt/local/bin/arm-none-eabi- oldconfig
 
  make ARCH=arm CROSS_COMPILE=/opt/local/bin/arm-none-eabi- oldconfig
 
Then building the kernel:
 
make ARCH=arm CROSS_COMPILE=/path/to/yagarto/bin/arm-none-eabi- -k
 
 
or if you used the MacPorts
 
 
  make ARCH=arm CROSS_COMPILE=/opt/local/bin/arm-none-eabi- -k
 
  make ARCH=arm CROSS_COMPILE=/opt/local/bin/arm-none-eabi- -k
 
You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on. (Don't use these for the oldconfig option because it messes up the input and output).
 
 
 
'''If you get an error message that elf.h is missing'''
 
'''If you get an error message that elf.h is missing'''
 
install [http://guide.macports.org/#installing macports]
 
install libelf and symlink to /usr/libelf:
 
 
  sudo port install libelf && sudo ln -s /opt/local/include/libelf /usr/include/libelf
 
  sudo port install libelf && sudo ln -s /opt/local/include/libelf /usr/include/libelf
 
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
 
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
 
 
Edit elf.h and add
 
Edit elf.h and add
 
  #define R_386_NONE        0
 
  #define R_386_NONE        0
Line 282: Line 141:
 
  #define R_MIPS_HI16      5
 
  #define R_MIPS_HI16      5
 
  #define R_MIPS_LO16      6
 
  #define R_MIPS_LO16      6
 
 
'''If you get a "SEGMENT_SIZE is undeclared" error'''
 
'''If you get a "SEGMENT_SIZE is undeclared" error'''
 
 
open the Makefile and change the line:
 
open the Makefile and change the line:
 
 
  NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
 
  NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
 
 
to
 
to
 
 
  NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux
 
  NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux
 
+
== Transferring The Build ==
=== Transferring The Build ===
+
 
+
 
Then you have to transfer this img file to the /boot directory and install the compiled modules. Unfortunately the compiled modules are not in a single place, there are two options of installing them.
 
Then you have to transfer this img file to the /boot directory and install the compiled modules. Unfortunately the compiled modules are not in a single place, there are two options of installing them.
  
Line 304: Line 156:
 
  make install
 
  make install
 
  make modules_install
 
  make modules_install
 
 
If you got "Permission denied" when doing <code>cd linux</code>, try:
 
If you got "Permission denied" when doing <code>cd linux</code>, try:
 
  sudo sh -c "cd linux ; make modules_install"
 
  sudo sh -c "cd linux ; make modules_install"
 
 
If that is not an option, you can also install the modules into a temporary folder:
 
If that is not an option, you can also install the modules into a temporary folder:
 
  mkdir /tmp/modules
 
  mkdir /tmp/modules
 
  make ARCH=arm modules_install INSTALL_MOD_PATH=/tmp/modules
 
  make ARCH=arm modules_install INSTALL_MOD_PATH=/tmp/modules
 
 
Now you have to copy the contents of that directory to /lib/modules on the SD card.
 
Now you have to copy the contents of that directory to /lib/modules on the SD card.
 
  scp linux/arch/arm/boot/Image <user>@<host>:/boot/kernel.img
 
  scp linux/arch/arm/boot/Image <user>@<host>:/boot/kernel.img
 
  scp -r /tmp/modules/* <user>@<host>://lib/modules/
 
  scp -r /tmp/modules/* <user>@<host>://lib/modules/
 
 
Once you've done those two steps, you are ready to put the SD card in and try booting your new system!
 
Once you've done those two steps, you are ready to put the SD card in and try booting your new system!
 
 
=References=  
 
=References=  
 
<references/>
 
<references/>
 
 
{{Template:Raspberry Pi}}
 
{{Template:Raspberry Pi}}
 
[[Category:RaspberryPi]]
 
[[Category:RaspberryPi]]

Revision as of 07:40, 9 August 2012

Back to the Hub.


Software & Distributions:

Software - an overview.

Distributions - operating systems and development environments for the Raspberry Pi.

Kernel Compilation - advice on compiling a kernel.

Performance - measures of the Raspberry Pi's performance.

Programming - programming languages that might be used on the Raspberry Pi.

Overview

First, you are going to get and build the linux kernel and its modules using a suitable compiler (a "cross-compiler" if you aren't building it on the same hardware you will be running it on) and then you are going to create a kernel image from the uncompressed kernel (Image) to place on the sd, along with the modules you build alongside it.

From the Raspberry pi

Firmware

cd /opt
git clone --depth 1 git://github.com/raspberrypi/firmware.git
cd firmware/boot
cp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf /boot/
cd /opt
rm -r firmware

Kernel compilation

Debian pre-build

apt-get update
apt-get -y dist-upgrade
apt-get -y install git gcc make tmux

Arch Linux pre-build

pacman -Syu
pacman -S git gcc make tmux

Common

cd /opt
mkdir raspberrypi
cd raspberrypi
git clone --depth 1 git://github.com/raspberrypi/linux.git
cd linux
zcat /proc/config.gz > .config
#optional#make menuconfig
tmux new -s make
nice make; nice make modules
[Ctrl]+[B],[D]
############## … 5 hours later ...
tmux a -t m
[Ctrl]+[D]
cp arch/arm/boot/Image /boot/kernel.img
make ARCH=arm modules_install INSTALL_MOD_PATH=/
cd /opt
rm -r raspberrypi
shutdown -r now;

From a foreign machine

Firmware

cd /opt
git clone git://github.com/raspberrypi/firmware.git
cd firmware/boot
scp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf <user>@<host>:/boot/

After the first time:

cd /opt/firmware
git pull
cd boot
scp arm128_start.elf arm192_start.elf arm224_start.elf bootcode.bin loader.bin start.elf <user>@<host>:/boot/

Kernel compilation

You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.

Ubunt

apt-get install git gcc-arm-linux-gnueabi make ncurses-dev
cd /opt
mkdir raspberrypi
cd raspberrypi 
git clone git://github.com/raspberrypi/linux.git
cd linux
cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
#optional#make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k

Gentoo Linux

getting the compiler

Build the cross toolchain:

crossdev -S -v -t arm-unknown-linux-gnueabi

theBuell: on 2012-05-06, cross -S -v -A gnueabi arm works just fine

This command 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 "-S" flag and adding the "--b", "--g", "--k" and "--l" flags. For the exact usage refer to the crossdev manpage. A good starting point for figuring out the right versions are those which are stable for the arm architecture.

getting the sources

create a directory where you can work on the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.

mkdir raspberrypi
cd raspberrypi 
git clone https://github.com/raspberrypi/linux.git
cd linux

compiling

Next you have to configure the kernel:

cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig

Then building the kernel:

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k

You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.

Arch Linux

getting the compiler

You will need GIT to clone the kernel source tree from GitHub:

pacman -S git

Build the cross toolchain: arm-linux-gnueabi-gcc is on the AUR. If you use yaourt:

yaourt -S arm-linux-gnueabi-gcc

Yaourt is recommended as it will build all dependencies.

getting the sources

create a directory where you can work on the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.

mkdir raspberrypi
cd raspberrypi 
git clone https://github.com/raspberrypi/linux.git
cd linux

compiling

Next you have to configure the kernel:

cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig

Then building the kernel:

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k

You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on.

OS X

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. Ensure latest Xcode and command line tools are installed from Apple Developer Connection

Yagarto

Downoad and install an GNU ARM toolchain such as yagarto.

Macports

macports

port install arm-none-eabi-gcc
port install arm-none-eabi-binutils

Common

cd /opt
mkdir raspberrypi
cd raspberrypi 
git clone git://github.com/raspberrypi/linux.git
cd linux
cp arch/arm/configs/bcmrpi_cutdown_defconfig .config

Yagarto

make ARCH=arm CROSS_COMPILE=/path/to/yagarto/bin/arm-none-eabi- oldconfig
make ARCH=arm CROSS_COMPILE=/path/to/yagarto/bin/arm-none-eabi- -k

Macports

make ARCH=arm CROSS_COMPILE=/opt/local/bin/arm-none-eabi- oldconfig
make ARCH=arm CROSS_COMPILE=/opt/local/bin/arm-none-eabi- -k

If you get an error message that elf.h is missing

sudo port install libelf && sudo ln -s /opt/local/include/libelf /usr/include/libelf

copy elf.h and elftypes.h to /usr/include Edit elf.h and add

#define R_386_NONE        0
#define R_386_32          1
#define R_386_PC32        2
#define R_ARM_NONE        0
#define R_ARM_PC24        1
#define R_ARM_ABS32       2
#define R_MIPS_NONE       0
#define R_MIPS_16         1
#define R_MIPS_32         2
#define R_MIPS_REL32      3
#define R_MIPS_26         4
#define R_MIPS_HI16       5
#define R_MIPS_LO16       6

If you get a "SEGMENT_SIZE is undeclared" error open the Makefile and change the line:

NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)

to

NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux

Transferring The Build

Then you have to transfer this img file to the /boot directory and install the compiled modules. Unfortunately the compiled modules are not in a single place, there are two options of installing them.

Boot your RaspberryPi and mount the linux directory over the network using sshfs:

cd /mnt
mkdir linux
sshfs <user>@<host>:<path/to/linux> linux
cd linux
make install
make modules_install

If you got "Permission denied" when doing cd linux, try:

sudo sh -c "cd linux ; make modules_install"

If that is not an option, you can also install the modules into a temporary folder:

mkdir /tmp/modules
make ARCH=arm modules_install INSTALL_MOD_PATH=/tmp/modules

Now you have to copy the contents of that directory to /lib/modules on the SD card.

scp linux/arch/arm/boot/Image <user>@<host>:/boot/kernel.img
scp -r /tmp/modules/* <user>@<host>://lib/modules/

Once you've done those two steps, you are ready to put the SD card in and try booting your new system!

References