Compilation-croisée

[pdf]download as a pdf fileCompilation-croisée.[/pdf]

1) Répertoire de travail :

[~] ➔ mkdir -p RASPBERRYPI/CompilationCroisee/toolchain
[~] ➔ cd RASPBERRYPI/CompilationCroisee/toolchain/

2) Téléchargement de Crosstool :

[~/RASPBERRYPI/CompilationCroisee/toolchain] ➔ wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.17.0.tar.bz2
[~/RASPBERRYPI/CompilationCroisee/toolchain] ➔ tar xvfj crosstool-ng-1.17.0.tar.bz2 
[~/RASPBERRYPI/CompilationCroisee/toolchain] ➔ cd crosstool-ng-1.17.0/

3) Installation des paquetages de compilation :

[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ sudo apt-get install bison cvs flex gperf texinfo automake libtool gawk

4) Configuration :

[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ mkdir -p ~/RASPBERRYPI/crosstool-ng
[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ ./configure --prefix=/home/util01/RASPBERRYPI/crosstool-ng

5) Compilation :

[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ make
[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ make install
[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ export PATH=$PATH:/home/util01/RASPBERRYPI/crosstool-ng/bin/

6) Configuiration de l’environnement :

[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ mkdir -p /home/util01/RASPBERRYPI/CompilationCroisee/staging
[~/RASPBERRYPI/CompilationCroisee/toolchain/crosstool-ng-1.17.0] ➔ cd /home/util01/RASPBERRYPI/CompilationCroisee/staging
[~/RASPBERRYPI/CompilationCroisee/staging] ➔ ct-ng menuconfig

Menu de configuration :

- Paths and misc options
	- Try features marked as EXPERIMENTAL : *
		- (${HOME}/x-tools/${CT_TARGET}) Prefix directory (NEW) : ${HOME}/RASPBERRYPI/x-tools/${CT_TARGET}

- Target options
	- Target Architecture (alpha) : arm
	- Endianness : Little endian
	- Bitness : 32-bit

- Operating System
	- Target OS (bare-metal) : Linux
	
- Binaries utilities 
	- binutils version (2.22 (EXPERIMENTAL)) : 2.21.1a

- C compiler
	- Show Linaro versions (EXPERIMENTAL) : *
		- gcc version (linaro-4.7-2012.10 (EXPERIMENTAL)) : linaro-4.7-2012.10 (EXPERIMENTAL

7) Compilation :

[~/RASPBERRYPI/CompilationCroisee/staging] ➔ ct-ng build
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20130124.195411
[INFO ]  Building environment variables
...
[INFO ]  Installing final compiler
[INFO ]  Installing final compiler: done in 604.49s (at 54:56)
[INFO ]  =================================================================
[INFO ]  Cleaning-up the toolchain's directory
[INFO ]    Stripping all toolchain executables
[INFO ]  Cleaning-up the toolchain's directory: done in 1.60s (at 54:57)
[INFO ]  Build completed at 20130124.204908
[INFO ]  (elapsed: 54:57.28)
[INFO ]  Finishing installation (may take a few seconds)...

8) Vérification :

[~/RASPBERRYPI/CompilationCroisee/staging] ➔ ls -l /home/util01/RASPBERRYPI/x-tools/arm-unknown-linux-gnueabi/
total 488
dr-xr-xr-x 5 util01 util01   4096 24 janv. 20:03 arm-unknown-linux-gnueabi
dr-xr-xr-x 2 util01 util01   4096 24 janv. 20:49 bin
-r--r--r-- 1 util01 util01 468690 24 janv. 20:49 build.log.bz2
dr-xr-xr-x 2 util01 util01   4096 24 janv. 20:48 include
dr-xr-xr-x 4 util01 util01   4096 24 janv. 20:48 lib
dr-xr-xr-x 3 util01 util01   4096 24 janv. 20:48 libexec
dr-xr-xr-x 2 util01 util01   4096 24 janv. 20:49 share
[~/RASPBERRYPI/CompilationCroisee/staging] ➔ cd /home/util01/RASPBERRYPI/x-tools/arm-unknown-linux-gnueabi/bin
[~/RASPBERRYPI/x-tools/arm-unknown-linux-gnueabi/bin] ➔ ls
arm-unknown-linux-gnueabi-addr2line     arm-unknown-linux-gnueabi-gprof
arm-unknown-linux-gnueabi-ar            arm-unknown-linux-gnueabi-ld
arm-unknown-linux-gnueabi-as            arm-unknown-linux-gnueabi-ld.bfd
arm-unknown-linux-gnueabi-cc            arm-unknown-linux-gnueabi-ldd
arm-unknown-linux-gnueabi-c++filt       arm-unknown-linux-gnueabi-nm
arm-unknown-linux-gnueabi-cpp           arm-unknown-linux-gnueabi-objcopy
arm-unknown-linux-gnueabi-ct-ng.config  arm-unknown-linux-gnueabi-objdump
arm-unknown-linux-gnueabi-elfedit       arm-unknown-linux-gnueabi-populate
arm-unknown-linux-gnueabi-gcc           arm-unknown-linux-gnueabi-ranlib
arm-unknown-linux-gnueabi-gcc-4.7.3     arm-unknown-linux-gnueabi-readelf
arm-unknown-linux-gnueabi-gcc-ar        arm-unknown-linux-gnueabi-size
arm-unknown-linux-gnueabi-gcc-nm        arm-unknown-linux-gnueabi-strings
arm-unknown-linux-gnueabi-gcc-ranlib    arm-unknown-linux-gnueabi-strip
arm-unknown-linux-gnueabi-gcov

9) Post-configuration :


[~/RASPBERRYPI/x-tools/arm-unknown-linux-gnueabi/bin] ➔ export PATH=$PATH:/home/util01/RASPBERRYPI/x-tools/arm-unknown-linux-gnueabi/bin

10) Compilation d’un programme de test :

[~/RASPBERRYPI/x-tools/arm-unknown-linux-gnueabi/bin] ➔ cd /home/util01/RASPBERRYPI/

Ouvrir :

bonjourlemonde.c

Ajouter :

#include 
int main() {
        printf("Bonjour tout le monde !\n");
        return 0;
} 
[~/RASPBERRYPI] ➔ arm-unknown-linux-gnueabi-gcc bonjourlemonde.c -o bonjourlemonde
[~/RASPBERRYPI] ➔ ls -l bonjour*
-rwxr-xr-x 1 util01 util01 5375 24 janv. 23:57 bonjourlemonde
-rw-r--r-- 1 util01 util01   83 24 janv. 23:57 bonjourlemonde.c

11) Copier l’exécutable sur le RPi :

[~/RASPBERRYPI] ➔ scp bonjourlemonde pi@192.168.1.12:/home/pi

12) Exécuter le programme sur le RPi :

pi@framboisepi ~ $ ./bonjourlemonde
Bonjour tout le monde !
pi@framboisepi ~ $ 

13) Liens :

http://www.kitware.fr/blog/home/post/426
http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *