Cross Compiling: Difference between revisions

From PS3 Developer wiki
Jump to navigation Jump to search
(Improved the instructions to build the kernel and create a deb pakage)
No edit summary
Line 1: Line 1:
=Cross Compiling=
=Cross Compiling=


This page shows how to cross compile for CellBE/ppc64  
This page shows how to cross compile for CellBE/ppc64




Line 10: Line 10:
Client: http://www.gentoo.org/doc/en/cross-compiling-distcc.xml (Because it's much better written than anything I could do)
Client: http://www.gentoo.org/doc/en/cross-compiling-distcc.xml (Because it's much better written than anything I could do)


== Ubuntu/Debian ==
== Debian/Debian-based ==


===Know your host System===
===Know your host System===
To be improve the building time it is a good Idea to know how many cores your processor has and have that number of concurrent jobs
To be improve the building time it is a good idea to know how many cores your processor has and have that number of concurrent jobs.


to know how many cores you have available use
To know how many cores you have available use :


<prep>
<pre>
grep -c '^processor' /proc/cpuinfo
grep -c '^processor' /proc/cpuinfo
</pre>
</pre>


This will be used later on while building the toolchain ct-ng build.#number of cores and while compiling export CONCURRENCY_LEVEL=#number of cores
This will be used later on while building the toolchain ct-ng build.#number of cores and while compiling export CONCURRENCY_LEVEL=#number of cores.
 
Example for a quadcore system :


Example for a quadcore system
<pre>
<pre>
ct-ng build.4
ct-ng build.4
Line 32: Line 33:
===Installing Cross Tool===
===Installing Cross Tool===


Install required packages
Install required packages :
 
<pre>
<pre>
sudo apt-get install build-essential gawk bison flex automake libtool cvs lzma ncurses-dev texinfo patch g++ gcj
sudo apt-get install build-essential gawk bison flex automake libtool cvs lzma ncurses-dev texinfo patch g++ gcj mercurial git-core
</pre>
</pre>


Create directories and compile crosstool
Add the enviromental variable to bash :
 
<pre>
sudo vi /etc/bash.bashrc
 
or
 
vi /home/user/.bashrc
</pre>
 
Add the following lines at the end of the file :
 
export PATH="${PATH}:/home/user/crosstool/bin/"
export PATH="${PATH}:/home/user/x-tools/powerpc64-unknown-linux-gnu/bin/"
export CONCURRENCY_LEVEL=#number
 
Create directories and compile crosstool :
 
<pre>
<pre>
mkdir /home/user/crosstool
mkdir /home/user/crosstool
mkdir /home/user/kernel
mkdir /home/user/kernel
mkdir -p /home/user/toolchain/powerpc
mkdir -p /home/user/toolchain/powerpc
tar xvjf crosstool-ng-1.10.0.tar.bz2
hg clone http://crosstool-ng.org/hg/crosstool-ng
cd crosstool-ng-1.10.0/
cd crosstool-ng
./configure --prefix=/home/user/crosstool/
./configure --prefix=/home/user/crosstool/
make && make install
make && make install
</pre>
</pre>


* /home/user/crosstool-ng-1.10.0/ -> '''crostool-ng sources'''
* /home/user/crosstool-ng/ -> '''crostool-ng sources'''
* /home/user/crosstool/ -> '''Crosstool install directory with binaries'''
* /home/user/crosstool/ -> '''Crosstool install directory with binaries'''
* /home/user/toolchain/ -> '''Directory where the binary will be installed'''
* /home/user/toolchain/ -> '''Directory where the binary will be installed'''
Line 55: Line 74:
* /home/user/kernel -> '''Place were graf_chokolo's linux kernel tarball will be saved'''
* /home/user/kernel -> '''Place were graf_chokolo's linux kernel tarball will be saved'''


Add the enviromental variable to bash
===Patching crosstool===


<pre>
NOTE : MAYBE THIS PATCHING STEP IS USELESS WITH LASTEST CROSSTOOL-NG REVISION
sudo gedit /etc/bash.bashrc
</pre>
 
Add the following lines at the end of the file
 
"export PATH="${PATH}:/home/user/crosstool/bin/"
"export PATH="${PATH}:/home/user/x-tools/powerpc64-unknown-linux-gnu/bin/"


===Patching crosstool===
For some reason, the compiler removes the symbolic links for lib64.


For some reason, the compiler removes the symbolic links for lib64
The following patch corrects this behaviour allowing the toolchain to work properly without further modifications.
 
The following patch corrects this behaviour allowing the toolchain to work properly without further modifications


====Required Patch====
====Required Patch====
Line 91: Line 101:
</pre>
</pre>


Go to that directory and apply the patch
Go to that directory and apply the patch :


<pre>
<pre>
cd /home/usr/crosstool/lib/ct-ng-1.10.0/scripts/build
cd /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/scripts/build
patch < important.patch
patch < important.patch
</pre>
</pre>
Line 100: Line 110:
===Creating a cross compiler toolchain for ppc64===
===Creating a cross compiler toolchain for ppc64===


Download graf_chokolo's kernel
Download graf_chokolo's kernel :


<pre>
<pre>
cd /home/user/kernel
cd /home/user/kernel
wget -O linux-2.6.tar.gz http://git.dukio.com/gitweb.cgi?p=linux-2.6\;a=snapshot\;h=HEAD\;sf=tgz
git clone git://git.gitbrew.org/ps3/ps3linux/linux-2.6.git
tar -zcvf linux-2.6.tar.gz linux-2.6/
</pre>
</pre>


Copy the sample configuration file and modify it
Copy the sample configuration file and modify it :


<pre>
<pre>
cp /home/usr/crosstool/lib/ct-ng-1.10.0/samples/powerpc64-unknown-linux-gnu/* /home/usr/toolchain/powerpc/
cp /home/usr/crosstool/lib/ct-ng-yourcrosstoolversion/samples/powerpc64-unknown-linux-gnu/* /home/user/toolchain/powerpc/
cd /home/usr/toolchain/powerpc/
cd /home/user/toolchain/powerpc/
mv crosstool.config .config
mv crosstool.config .config
cd /home/usr/toolchain/powerpc/
cd /home/user/toolchain/powerpc/
ct-ng menuconfig
ct-ng menuconfig
</pre>
</pre>


I've added graf_chokolos kernel  
I've added graf_chokolos kernel :


*Operating System -> Linux Kernel version -> custom tarball
*Operating System -> Linux Kernel version -> custom tarball
Line 125: Line 136:
----
----


Start from scratch and configure the toolchain the way you want  
Start from scratch and configure the toolchain the way you want :
 
<pre>
<pre>
cd /home/user/toolchain/powerppc/
cd /home/user/toolchain/powerppc/
Line 131: Line 143:
</pre>
</pre>


Compile ppc64 toolchain
Compile ppc64 toolchain :


<pre>
<pre>
unset LD_LIBRARY_PATH LIBRARY_PATH CPATH
unset LD_LIBRARY_PATH LIBRARY_PATH CPATH
export LD_LIBRARY_PATH LIBRARY_PATH CPATH
export LD_LIBRARY_PATH LIBRARY_PATH CPATH
ct-ng build
ct-ng build.#number
</pre>
</pre>


Line 157: Line 169:
</pre>
</pre>


unpack the sources
unpack the sources :
 
<pre>
<pre>
tar xvjf openssl-0.9.8g.tar.gz
tar xvjf openssl-0.9.8g.tar.gz
</pre>
</pre>


Go to openssl source path
Go to openssl source path :
 
<pre>
<pre>
cd openssl-0.9.8g/
cd openssl-0.9.8g/
</pre>
</pre>


Change the following lines in the Makefile
Change the following lines in the Makefile :


<pre>
<pre>
Line 177: Line 191:
</pre>
</pre>


Finally  
Finally :


<pre>
<pre>
Line 184: Line 198:


===Cross compiling graf_chokolo's tools===
===Cross compiling graf_chokolo's tools===
Make sure you have a working toolchain and openssl installed
Make sure you have a working toolchain and openssl installed


Comment the current compiler and add your cross compiler in our case "powerpc64-unknown-linux-gnu-gcc"
Comment the current compiler and add your cross compiler in our case "powerpc64-unknown-linux-gnu-gcc" :


<pre>
<pre>
Line 193: Line 208:
</pre>
</pre>


finally
Finally :
 
<pre>
<pre>
make
make
</pre>
</pre>
you can find graf_chokolo tools and scripts here


http://git.dukio.com/gitweb.cgi
You can find graf_chokolo tools and scripts here :
 
http://git-hacks.com/linux-ps3


===Compiling graf_chokolo's kernel and making a deb package===
===Compiling graf_chokolo's kernel and making a deb package===


Go to the directory where you saved your kernel, untar it and go to the kernel source directory
Go to the directory where you saved your kernel, untar it and go to the kernel source directory :
 
<pre>
<pre>
cd /home/user/kernel
cd /home/user/kernel
Line 210: Line 228:
</pre>
</pre>


It is a good measure to clean the source directory
It is a good measure to clean the source directory :
 
<pre>
<pre>
make clean
make clean
Line 217: Line 236:


Export set ARCH=powerpc
Export set ARCH=powerpc
And set the right number of concurrent jobs to be done this is used to improve the building time.
And set the right number of concurrent jobs to be done this is used to improve the building time :


<pre>
<pre>
Line 225: Line 244:




Use graf_chokolo config file
Use graf_chokolo config file :
 
<pre>
<pre>
cp ps3_linux_config .config
cp ps3_linux_config .config
Line 231: Line 251:
</pre>
</pre>


You can customize your by using make menuconfig
You can customize your by using make menuconfig.


Now lets compile and package our kernel
Now lets compile and package our kernel :


<pre>
<pre>
make-kpkg --arch=powerpc --cross-compile=powerpc64-unknown-linux-gnu- --rootcmd=fakeroot --initrd --append-to-version=-graf kernel_image kernel_source kernel_headers
make-kpkg --arch=powerpc --cross-compile=powerpc64-unknown-linux-gnu- --rootcmd=fakeroot --initrd --append-to-version=-graf kernel_image kernel_source kernel_headers
</pre>
</pre>

Revision as of 16:43, 10 May 2011

Cross Compiling

This page shows how to cross compile for CellBE/ppc64


Gentoo

Server: Emerge distcc crossdev & env-update & source /etc/profile & crossdev -t powerpc64-unknown-linux-gnu

Client: http://www.gentoo.org/doc/en/cross-compiling-distcc.xml (Because it's much better written than anything I could do)

Debian/Debian-based

Know your host System

To be improve the building time it is a good idea to know how many cores your processor has and have that number of concurrent jobs.

To know how many cores you have available use :

grep -c '^processor' /proc/cpuinfo

This will be used later on while building the toolchain ct-ng build.#number of cores and while compiling export CONCURRENCY_LEVEL=#number of cores.

Example for a quadcore system :

ct-ng build.4
CONCURRENCY_LEVEL=4


Installing Cross Tool

Install required packages :

sudo apt-get install build-essential gawk bison flex automake libtool cvs lzma ncurses-dev texinfo patch g++ gcj mercurial git-core

Add the enviromental variable to bash :

sudo vi /etc/bash.bashrc

or

vi /home/user/.bashrc

Add the following lines at the end of the file :

export PATH="${PATH}:/home/user/crosstool/bin/" export PATH="${PATH}:/home/user/x-tools/powerpc64-unknown-linux-gnu/bin/" export CONCURRENCY_LEVEL=#number

Create directories and compile crosstool :

mkdir /home/user/crosstool
mkdir /home/user/kernel
mkdir -p /home/user/toolchain/powerpc
hg clone http://crosstool-ng.org/hg/crosstool-ng
cd crosstool-ng
./configure --prefix=/home/user/crosstool/
make && make install
  • /home/user/crosstool-ng/ -> crostool-ng sources
  • /home/user/crosstool/ -> Crosstool install directory with binaries
  • /home/user/toolchain/ -> Directory where the binary will be installed
  • /home/user/toolchain/powerpc/ -> Crosstool files generated in this tutorial for powerpc
  • /home/user/toolchain/x-tools/ -> generated toolchain
  • /home/user/kernel -> Place were graf_chokolo's linux kernel tarball will be saved

Patching crosstool

NOTE : MAYBE THIS PATCHING STEP IS USELESS WITH LASTEST CROSSTOOL-NG REVISION

For some reason, the compiler removes the symbolic links for lib64.

The following patch corrects this behaviour allowing the toolchain to work properly without further modifications.

Required Patch

save the following file as """important.patch""" in home/usr/crosstool/lib/ct-ng-1.10.0/scripts/build

diff --git a/scripts/build/internals.sh b/scripts/build/internals.sh
--- a/scripts/build/internals.sh
+++ b/scripts/build/internals.sh
@@ -157,8 +157,6 @@
     # the standard lib/ dirs, so we can get rid of the symlinks
     for d in                            \
         "${CT_PREFIX_DIR}"              \
-        "${CT_SYSROOT_DIR}"             \
-        "${CT_SYSROOT_DIR}/usr"         \
         "${CT_PREFIX_DIR}/${CT_TARGET}" \
     ; do
         CT_DoExecLog ALL rm -f "${d}/lib32"

Go to that directory and apply the patch :

cd /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/scripts/build
patch < important.patch

Creating a cross compiler toolchain for ppc64

Download graf_chokolo's kernel :

cd /home/user/kernel
git clone git://git.gitbrew.org/ps3/ps3linux/linux-2.6.git
tar -zcvf linux-2.6.tar.gz linux-2.6/

Copy the sample configuration file and modify it :

cp /home/usr/crosstool/lib/ct-ng-yourcrosstoolversion/samples/powerpc64-unknown-linux-gnu/* /home/user/toolchain/powerpc/
cd /home/user/toolchain/powerpc/
mv crosstool.config .config
cd /home/user/toolchain/powerpc/
ct-ng menuconfig

I've added graf_chokolos kernel :

  • Operating System -> Linux Kernel version -> custom tarball
  • Operating System -> Path to custom tarball -> /home/user/kernel/linux-2.6.tar.gz

or


Start from scratch and configure the toolchain the way you want :

cd /home/user/toolchain/powerppc/
ct-ng menuconfig

Compile ppc64 toolchain :

unset LD_LIBRARY_PATH LIBRARY_PATH CPATH
export LD_LIBRARY_PATH LIBRARY_PATH CPATH
ct-ng build.#number

Wait for some time until it finishes compiling


Testing if your toolchain works properly

export PATH="${PATH}:/home/user/x-tools/powerpc64-unknown-linux-gnu/bin/"
powerpc64-unknown-linux-gnuspe-gcc test.c -o test

More info: http://www.ibm.com/developerworks/linux/tutorials/l-embedded-distro/section3.html

Cross compiling openssl

Download openssl sources

wget http://www.openssl.org/source/openssl-0.9.8g.tar.gz

unpack the sources :

tar xvjf openssl-0.9.8g.tar.gz

Go to openssl source path :

cd openssl-0.9.8g/

Change the following lines in the Makefile :

INSTALLTOP=/x-tools/powerpc64-unknown-linux-gnu/powerpc64-unknown-linux-gnu/sysroot/usr
OPENSSLDIR=/x-tools/powerpc64-unknown-linux-gnu/powerpc64-unknown-linux-gnu/sysroot/usru
CC= powerpc64-unknown-linux-gnu-gcc
AR=xpowerpc64-unknown-linux-gnu-ar $(ARFLAGS) r
RANLIB= powerpc64-unknown-linux-gnu-ranlib

Finally :

make

Cross compiling graf_chokolo's tools

Make sure you have a working toolchain and openssl installed

Comment the current compiler and add your cross compiler in our case "powerpc64-unknown-linux-gnu-gcc" :

#CC=gcc
CC=powerpc64-unknown-linux-gnu-gcc

Finally :

make

You can find graf_chokolo tools and scripts here :

http://git-hacks.com/linux-ps3

Compiling graf_chokolo's kernel and making a deb package

Go to the directory where you saved your kernel, untar it and go to the kernel source directory :

cd /home/user/kernel
tar xfvz linux-2.6.tar.gz
cd linux-2.6

It is a good measure to clean the source directory :

make clean
make-kpkg clean

Export set ARCH=powerpc And set the right number of concurrent jobs to be done this is used to improve the building time :

export ARCH=powerpc
export CONCURRENCY_LEVEL=4


Use graf_chokolo config file :

cp ps3_linux_config .config
make oldconfig

You can customize your by using make menuconfig.

Now lets compile and package our kernel :

make-kpkg --arch=powerpc --cross-compile=powerpc64-unknown-linux-gnu- --rootcmd=fakeroot --initrd --append-to-version=-graf kernel_image kernel_source kernel_headers