Editing Cross Compiling

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
[[Category:OtherOS]]
=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 11: 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)


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


===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


{{keyboard|content=<syntaxhighlight lang="bash">grep -c '^processor' /proc/cpuinfo</syntaxhighlight>}}
<prep>
grep -c '^processor' /proc/cpuinfo
</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 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>
{{keyboard|content=<syntaxhighlight lang="bash">
ct-ng build.4
ct-ng build.4
CONCURRENCY_LEVEL=4
CONCURRENCY_LEVEL=4
</syntaxhighlight>}}
</pre>




===Installing Cross Tool===
===Installing Cross Tool===


Install required packages :
Install required packages
{{keyboard|content=<syntaxhighlight lang="bash">sudo apt-get install build-essential gawk bison flex automake libtool cvs lzma ncurses-dev texinfo patch g++ gcj mercurial git-core</syntaxhighlight>}}
<pre>
sudo apt-get install build-essential gawk bison flex automake libtool cvs lzma ncurses-dev texinfo patch g++ gcj
</pre>


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


* /home/user/crosstool-ng/ -> '''crosstool-ng sources'''
* /home/user/crosstool-ng-1.10.0/ -> '''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 68: Line 54:
* /home/user/toolchain/x-tools/ -> '''generated toolchain'''
* /home/user/toolchain/x-tools/ -> '''generated toolchain'''
* /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
<pre>
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===
===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
 
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====


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


<pre>
<pre>
Line 96: Line 91:
</pre>
</pre>


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


{{keyboard|content=<syntaxhighlight lang="bash">
<pre>
cd /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/scripts/build
cd /home/usr/crosstool/lib/ct-ng-1.10.0/scripts/build
patch < important.patch
patch < important.patch
</syntaxhighlight>}}
</pre>


===Creating a cross compiler toolchain for ppc64===
===Creating a cross compiler toolchain for ppc64===


Download graf_chokolo's kernel :
Download graf_chokolo's kernel


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


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


{{keyboard|content=<syntaxhighlight lang="bash">
<pre>
cp /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/samples/powerpc64-unknown-linux-gnu/* /home/user/toolchain/powerpc/
cp /home/usr/crosstool/lib/ct-ng-1.10.0/samples/powerpc64-unknown-linux-gnu/* /home/usr/toolchain/powerpc/
cd /home/user/toolchain/powerpc/
cd /home/usr/toolchain/powerpc/
mv crosstool.config .config
mv crosstool.config .config
cd /home/user/toolchain/powerpc/
cd /home/usr/toolchain/powerpc/
ct-ng menuconfig
ct-ng menuconfig
</syntaxhighlight>}}
</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 131: Line 125:
----
----


Start from scratch and configure the toolchain the way you want :
Start from scratch and configure the toolchain the way you want  
 
<pre>
{{keyboard|content=<syntaxhighlight lang="bash">
cd /home/user/toolchain/powerppc/
cd /home/user/toolchain/powerppc/
ct-ng menuconfig
ct-ng menuconfig
</syntaxhighlight>}}
</pre>


Compile ppc64 toolchain :
Compile ppc64 toolchain


{{keyboard|content=<syntaxhighlight lang="bash">
<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.#number
ct-ng build
</syntaxhighlight>}}
</pre>


'''Wait for some time until it finishes compiling'''
'''Wait for some time until it finishes compiling'''
Line 150: Line 143:


===Testing if your toolchain works properly===
===Testing if your toolchain works properly===
 
<pre>
{{keyboard|content=<syntaxhighlight lang="bash">
export PATH="${PATH}:/home/user/x-tools/powerpc64-unknown-linux-gnu/bin/"
export PATH="${PATH}:/home/user/x-tools/powerpc64-unknown-linux-gnu/bin/"
powerpc64-unknown-linux-gnuspe-gcc test.c -o test
powerpc64-unknown-linux-gnuspe-gcc test.c -o test
</syntaxhighlight>}}
</pre>


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


Download openssl sources
Download openssl sources
{{keyboard|content=<syntaxhighlight lang="bash">wget http://www.openssl.org/source/openssl-0.9.8g.tar.gz</syntaxhighlight>}}
<pre>
wget http://www.openssl.org/source/openssl-0.9.8g.tar.gz
</pre>


unpack the sources :
unpack the sources
{{keyboard|content=<syntaxhighlight lang="bash">tar -zxvf openssl-0.9.8g.tar.gz</syntaxhighlight>}}
<pre>
tar xvjf openssl-0.9.8g.tar.gz
</pre>


Go to openssl source path :
Go to openssl source path
{{keyboard|content=<syntaxhighlight lang="bash">cd openssl-0.9.8g/</syntaxhighlight>}}
<pre>
cd openssl-0.9.8g/
</pre>


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


<pre>
<pre>
INSTALLTOP= /home/user/x-tools/powerpc64-unknown-linux-gnu/powerpc64-unknown-linux-gnu/sysroot/usr
INSTALLTOP=/x-tools/powerpc64-unknown-linux-gnu/powerpc64-unknown-linux-gnu/sysroot/usr
OPENSSLDIR= /home/user/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
CC= powerpc64-unknown-linux-gnu-gcc
AR= powerpc64-unknown-linux-gnu-ar $(ARFLAGS) r
AR=xpowerpc64-unknown-linux-gnu-ar $(ARFLAGS) r
RANLIB= powerpc64-unknown-linux-gnu-ranlib
RANLIB= powerpc64-unknown-linux-gnu-ranlib
</pre>
</pre>


Finally :
Finally  
{{keyboard|content=<syntaxhighlight lang="bash">make</syntaxhighlight>}}


<pre>
make
</pre>


===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 194: Line 193:
</pre>
</pre>


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


{{keyboard|content=<syntaxhighlight lang="bash">make</syntaxhighlight>}}
http://git.dukio.com/gitweb.cgi


You can find graf_chokolo tools and scripts here :
===Compiling graf_chokolo's kernel===


http://git-hacks.com/linux-ps3
Set the following environmental variables


===Compiling graf_chokolo's kernel and making a deb package===
If you haven't already
<pre>
export
</pre>


Go to the directory where you saved your kernel, untar it and go to the kernel source directory :
the cross compile environmental variables
{{keyboard|content=<syntaxhighlight lang="bash">
<pre>
cd /home/user/kernel
CROSS_COMPILE=powerpc64-unknown-linux-gnu-
tar xfvz linux-2.6.tar.gz
ARCH=powerpc
cd linux-2.6
</pre>
</syntaxhighlight>}}


It is a good measure to clean the source directory :
Finally
{{keyboard|content=<syntaxhighlight lang="bash">
make clean
make-kpkg clean
</syntaxhighlight>}}


Export set ARCH=powerpc
<pre>
And set the right number of concurrent jobs to be done this is used to improve the building time :
make
 
</pre>
{{keyboard|content=<syntaxhighlight lang="bash">
export ARCH=powerpc
export CONCURRENCY_LEVEL=4
</syntaxhighlight>}}
 
Use graf_chokolo config file :
{{keyboard|content=<syntaxhighlight lang="bash">
cp ps3_linux_config .config
make oldconfig
</syntaxhighlight>}}
 
You can customize your by using make menuconfig.
 
Now lets compile and package our kernel :
 
{{keyboard|content=<syntaxhighlight lang="bash">make-kpkg --arch=powerpc --cross-compile=powerpc64-unknown-linux-gnu- --rootcmd=fakeroot --initrd --append-to-version=-graf kernel_image kernel_source kernel_headers</syntaxhighlight>}}
 
 
 
 
{{Linux}}<noinclude>[[Category:Main]]</noinclude>
Please note that all contributions to PS3 Developer wiki are considered to be released under the GNU Free Documentation License 1.2 (see PS3 Developer wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)