Cross compiling a 64-bit PowerPC Linux Kernel

From PowerPC Kernel Archives

To build your own 64-bit toolchain and/or Linux kernel, follow the instructions below. If you just want a working kernel, try one of the ones available at ppckernel.org.

Building a 64-bit toolchain with crosstool

These instructions show how to build a 64-bit toolchain using crosstool. This toolchain will not be biarch, meaning you won't be able to use it to build both 32-bit and 64-bit userspace binaries with the same toolchain. You will, however, be able to build both 32-bit and 64-bit kernels. If you already have a working 64-bit toolchain available, you can skip to the next section.

wget http://kegel.com/crosstool/crosstool-0.43.tar.gz
tar xzf crosstool-0.43.tar.gz
cd crosstool-0.43
  • By default, crosstool-0.43 will build a gcc-4.1.0 toolchain. gcc-4.1.0, however, does not correctly build the kernel, so we need to change crosstool's configuration before continuing. Open demo-powerpc-970.sh in your favorite editor and comment out the last line, like so:
#eval `cat powerpc-970.dat gcc-4.1.0-glibc-2.3.6-tls.dat` sh all.sh --notest

Now, uncomment (or add if it doesn't yet exist) one of the following known working configurations:

eval `cat powerpc-970.dat gcc-3.4.2-glibc-2.3.3.dat` sh all.sh --notest
eval `cat powerpc-970.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest
eval `cat powerpc-970.dat gcc-4.1.1-glibc-2.3.6.dat` sh all.sh --notest

This is not an all-inclusive list. If you know of other working configurations, please add them here. Alternatively, you can make a copy of the file gcc-4.1.1-glibc-2.3.6.dat, change the GCC version number to the latest available, and then specify that file in demo-powerpc-970.sh. As of this writing, the latest GCC version is 4.1.2 and this method builds a working toolchain. You will need GCC 4.x.x to build the latest kernels.

  • Next, save demo-powerpc-970.sh, return to your shell, create the destination directory for your toolchain, and start the build process:
sudo mkdir -p /opt/crosstool
sudo chown $USER /opt/crosstool
./demo-powerpc-970.sh

(You should not be building crosstool as root.)

Building the toolchain may take quite awhile, depending on the speed of your machine. If it completes successfully, you should be ready to build a kernel.

Building a 64-bit PowerPC Linux kernel (2.4)

(Still need to test this.)

Building a 64-bit PowerPC Linux kernel (2.6)

Cross compiling a 2.6 Linux kernel is easy, but the ppc/powerpc ambiguity can confuse the process slightly.

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.4.tar.bz2 
tar xjf linux-2.6.20.4.tar.bz2
cd linux-2.6.20.4
  • Now, start the build process, making sure to replace the gcc and glibc version numbers with those of your toolchain and the config file with your config of choice:
PATH=${PATH}:/opt/crosstool/gcc-3.x.x-glibc-2.3.x/powerpc64-unknown-linux-gnu/bin
make ARCH=powerpc CROSS_COMPILE=powerpc64-unknown-linux-gnu- g5_defconfig
make ARCH=powerpc CROSS_COMPILE=powerpc64-unknown-linux-gnu-
  • Alternatively, you can create an alias for make to facilitate building 64-bit kernels (and add it to your .bashrc):
PATH=${PATH}:/opt/crosstool/gcc-3.x.x-glibc-2.3.x/powerpc64-unknown-linux-gnu/bin
alias make64='make ARCH=powerpc CROSS_COMPILE=powerpc64-unknown-linux-gnu-'
make64 g5_defconfig
make64

It is crucial that you specify ARCH=powerpc and not ARCH=ppc, as otherwise the build will fail. This also holds true if you want to use your 64-bit toolchain to build a 32-bit kernel.