Cross Compiling: Difference between revisions
mNo edit summary |
mNo edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
[[Category: | [[Category:OtherOS]] | ||
=Cross Compiling= | =Cross Compiling= | ||
Line 18: | Line 18: | ||
To know how many cores you have available use : | To know how many cores you have available use : | ||
{{keyboard|content=grep -c '^processor' /proc/cpuinfo}} | {{keyboard|content=<syntaxhighlight lang="bash">grep -c '^processor' /proc/cpuinfo</syntaxhighlight>}} | ||
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. | ||
Line 24: | Line 24: | ||
Example for a quadcore system : | Example for a quadcore system : | ||
{{keyboard|content=ct-ng build.4 | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
CONCURRENCY_LEVEL=4}} | ct-ng build.4 | ||
CONCURRENCY_LEVEL=4 | |||
</syntaxhighlight>}} | |||
Line 31: | Line 33: | ||
Install required packages : | Install required packages : | ||
{{keyboard|content=sudo apt-get install build-essential gawk bison flex automake libtool cvs lzma ncurses-dev texinfo patch g++ gcj mercurial git-core}} | {{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>}} | ||
Add the enviromental variable to bash : | Add the enviromental variable to bash : | ||
{{keyboard|content=sudo vi /etc/bash.bashrc}} | {{keyboard|content=<syntaxhighlight lang="bash">sudo vi /etc/bash.bashrc</syntaxhighlight>}} | ||
or | or | ||
{{keyboard|content=vi /home/user/.bashrc}} | {{keyboard|content=<syntaxhighlight lang="bash">vi /home/user/.bashrc</syntaxhighlight>}} | ||
Add the following lines at the end of the file : | Add the following lines at the end of the file : | ||
{{keyboard|content=export PATH="${PATH}:/home/user/crosstool/bin/" | {{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 PATH="${PATH}:/home/user/x-tools/powerpc64-unknown-linux-gnu/bin/" | ||
export CONCURRENCY_LEVEL=#number}} | export CONCURRENCY_LEVEL=#number | ||
</syntaxhighlight>}} | |||
Create directories and compile crosstool : | Create directories and compile crosstool : | ||
{{keyboard|content=mkdir /home/user/crosstool | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
mkdir /home/user/crosstool | |||
mkdir /home/user/kernel | mkdir /home/user/kernel | ||
mkdir -p /home/user/toolchain/powerpc | mkdir -p /home/user/toolchain/powerpc | ||
Line 54: | Line 59: | ||
cd crosstool-ng | cd crosstool-ng | ||
./configure --prefix=/home/user/crosstool | ./configure --prefix=/home/user/crosstool | ||
make && make install}} | make && make install | ||
</syntaxhighlight>}} | |||
* /home/user/crosstool-ng/ -> '''crosstool-ng sources''' | * /home/user/crosstool-ng/ -> '''crosstool-ng sources''' | ||
Line 92: | Line 98: | ||
Go to that directory and apply the patch : | Go to that directory and apply the patch : | ||
{{keyboard|content=cd /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/scripts/build | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
patch < important.patch}} | cd /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/scripts/build | ||
patch < important.patch | |||
</syntaxhighlight>}} | |||
===Creating a cross compiler toolchain for ppc64=== | ===Creating a cross compiler toolchain for ppc64=== | ||
Line 99: | Line 107: | ||
Download graf_chokolo's kernel : | Download graf_chokolo's kernel : | ||
{{keyboard|content=cd /home/user/kernel | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
cd /home/user/kernel | |||
git clone git://git.gitbrew.org/ps3/ps3linux/linux-2.6.git | git clone git://git.gitbrew.org/ps3/ps3linux/linux-2.6.git | ||
tar -zcvf linux-2.6.tar.gz linux-2.6/}} | tar -zcvf linux-2.6.tar.gz linux-2.6/ | ||
</syntaxhighlight>}} | |||
Copy the sample configuration file and modify it : | Copy the sample configuration file and modify it : | ||
{{keyboard|content=cp /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/samples/powerpc64-unknown-linux-gnu/* /home/user/toolchain/powerpc/ | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
cp /home/user/crosstool/lib/ct-ng-yourcrosstoolversion/samples/powerpc64-unknown-linux-gnu/* /home/user/toolchain/powerpc/ | |||
cd /home/user/toolchain/powerpc/ | cd /home/user/toolchain/powerpc/ | ||
mv crosstool.config .config | mv crosstool.config .config | ||
cd /home/user/toolchain/powerpc/ | cd /home/user/toolchain/powerpc/ | ||
ct-ng menuconfig}} | ct-ng menuconfig | ||
</syntaxhighlight>}} | |||
I've added graf_chokolos kernel : | I've added graf_chokolos kernel : | ||
Line 121: | Line 133: | ||
Start from scratch and configure the toolchain the way you want : | Start from scratch and configure the toolchain the way you want : | ||
{{keyboard|content=cd /home/user/toolchain/powerppc/ | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
ct-ng menuconfig}} | cd /home/user/toolchain/powerppc/ | ||
ct-ng menuconfig | |||
</syntaxhighlight>}} | |||
Compile ppc64 toolchain : | Compile ppc64 toolchain : | ||
{{keyboard|content=unset LD_LIBRARY_PATH LIBRARY_PATH CPATH | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
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.#number | ||
</syntaxhighlight>}} | |||
'''Wait for some time until it finishes compiling''' | '''Wait for some time until it finishes compiling''' | ||
Line 135: | Line 151: | ||
===Testing if your toolchain works properly=== | ===Testing if your toolchain works properly=== | ||
{{keyboard|content= | {{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>}} | |||
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 144: | Line 161: | ||
Download openssl sources | Download openssl sources | ||
{{keyboard|content=wget http://www.openssl.org/source/openssl-0.9.8g.tar.gz}} | {{keyboard|content=<syntaxhighlight lang="bash">wget http://www.openssl.org/source/openssl-0.9.8g.tar.gz</syntaxhighlight>}} | ||
unpack the sources : | unpack the sources : | ||
{{keyboard|content=tar -zxvf openssl-0.9.8g.tar.gz}} | {{keyboard|content=<syntaxhighlight lang="bash">tar -zxvf openssl-0.9.8g.tar.gz</syntaxhighlight>}} | ||
Go to openssl source path : | Go to openssl source path : | ||
{{keyboard|content=cd openssl-0.9.8g/}} | {{keyboard|content=<syntaxhighlight lang="bash">cd openssl-0.9.8g/</syntaxhighlight>}} | ||
Change the following lines in the Makefile : | Change the following lines in the Makefile : | ||
Line 163: | Line 180: | ||
Finally : | Finally : | ||
{{keyboard|content=make}} | {{keyboard|content=<syntaxhighlight lang="bash">make</syntaxhighlight>}} | ||
Line 179: | Line 196: | ||
Finally : | Finally : | ||
{{keyboard|content=make}} | {{keyboard|content=<syntaxhighlight lang="bash">make</syntaxhighlight>}} | ||
You can find graf_chokolo tools and scripts here : | You can find graf_chokolo tools and scripts here : | ||
Line 188: | Line 205: | ||
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 : | ||
{{keyboard|content=cd /home/user/kernel | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
cd /home/user/kernel | |||
tar xfvz linux-2.6.tar.gz | tar xfvz linux-2.6.tar.gz | ||
cd linux-2.6}} | cd linux-2.6 | ||
</syntaxhighlight>}} | |||
It is a good measure to clean the source directory : | It is a good measure to clean the source directory : | ||
{{keyboard|content=make clean | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
make-kpkg clean}} | make clean | ||
make-kpkg clean | |||
</syntaxhighlight>}} | |||
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 : | ||
{{keyboard|content=export ARCH=powerpc | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
export CONCURRENCY_LEVEL=4}} | export ARCH=powerpc | ||
export CONCURRENCY_LEVEL=4 | |||
</syntaxhighlight>}} | |||
Use graf_chokolo config file : | Use graf_chokolo config file : | ||
{{keyboard|content=cp ps3_linux_config .config | {{keyboard|content=<syntaxhighlight lang="bash"> | ||
make oldconfig}} | cp ps3_linux_config .config | ||
make oldconfig | |||
</syntaxhighlight>}} | |||
You can customize your by using make menuconfig. | You can customize your by using make menuconfig. | ||
Line 211: | Line 235: | ||
Now lets compile and package our kernel : | Now lets compile and package our kernel : | ||
{{keyboard|content=make-kpkg --arch=powerpc --cross-compile=powerpc64-unknown-linux-gnu- --rootcmd=fakeroot --initrd --append-to-version=-graf kernel_image kernel_source kernel_headers}} | {{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> |
Latest revision as of 17:57, 15 September 2021
Cross Compiling[edit | edit source]
This page shows how to cross compile for CellBE/ppc64
Gentoo[edit | edit source]
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[edit | edit source]
Know your host System[edit | edit source]
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[edit | edit source]
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/ -> crosstool-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[edit | edit source]
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[edit | edit source]
save the following file as """important.patch""" in home/user/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[edit | edit source]
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/user/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[edit | edit source]
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[edit | edit source]
Download openssl sources
wget http://www.openssl.org/source/openssl-0.9.8g.tar.gz
unpack the sources :
tar -zxvf openssl-0.9.8g.tar.gz
Go to openssl source path :
cd openssl-0.9.8g/
Change the following lines in the Makefile :
INSTALLTOP= /home/user/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 CC= powerpc64-unknown-linux-gnu-gcc AR= powerpc64-unknown-linux-gnu-ar $(ARFLAGS) r RANLIB= powerpc64-unknown-linux-gnu-ranlib
Finally :
make
Cross compiling graf_chokolo's tools[edit | edit source]
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[edit | edit source]
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