[Experiment content]
Use the crosstool-0.43.tar.gz script toolkit to create your own cross compiler. The compiler can compile U-boot, Linux kernel, and applications. This experiment aims to help readers learn how to compile and create a cross compiler. In actual development, most of them select compiled and tested cross compilers Based on the Compilation goal.
[Lab environment]
1. ubuntu7.10/8.10/9.10 release
2. linux-2.6.14 Kernel
3. fs2410 Platform
Lab procedure]
Crosstool is a script program developed by Dan Keel, an American (graduated from the National Institute of Technology in lifonia) to automatically compile and test GCC and glibc of different matching versions. : Bytes.
Note: Generally, Super Users (Root) are not used in the system. When Super User Permissions are required, use sudo to temporarily improve user permissions. When compiling crosstool, it is strongly required not to use the root user to avoid disastrous consequences. |
Lab steps:
(1) If your current user is a Super User (Root), Log On As a normal user,
First install the following software package in the system: sudo apt-Get install build-essential automake Autoconf bison flex libtool
Sudo apt-Get install libncurses5-dev (or: sudo apt-Get install ncurses-Dev)
Note: In ubuntu 8.10, the default installed GCC version is 4.3.2, with this version of compilation will be wrong, it is not recommended to choose we need to select the gcc-4.1.3, but do not need to uninstall the gcc-4.3.2 in Ubuntu 8.10 don't go to the gcc-4.1.3 source code to compile (download the source code compilation will find more problems ), just enter sudo apt-Get install gcc-4.1 installation on the terminal and then sudo RM/usr/bin/GCC (delete GCC, it's just a soft link file to the gcc-4.3.2) sudo ln-S/usr/bin/gcc-4.1 /Usr/bin/GCC (create a soft link from GCC to the gcc-4.1) If you run LS-La/bin/sh and see that the link is Dash, run the following command Sudo dpkg-reconfigure DASH: Select No to delete dash. If no change is made, an error will occur during compilation. |
(2) Create a working directory and copy the related software package $ mkdir/home // downloads. Copy the required toolkit to the downloads directory.
The toolkit used is as follows (the gcc-3.4.5-glibc-2.3.6.dat has instructions, if your Linux environment can access the Internet, the installation script used later will automatically download the required package ):
Gcc-3.4.5.tar.gz glibc-2.3.6.tar.gz linux-2.6.14.tar.gz crosstool-0.43.tar.gz
Binutils-2.15.tar.gz glibc-linuxthreads-2.3.3.tar.gz linux-libc-headers-2.6.12.0.tar.bz2 gdb-6.5.tar.bz2
Copy them to/home/farsight/downloads:
(3) decompress the software package and enter the directory to view important script files. $ CD downloads $ tar-zxvf Co., crosstool-0.43.tar.gz $ CD crosstool-0.43
There are many. Sh scripts and. dat configuration files in this directory. Each supported processor has its corresponding scripts. If you choose demo-arm-softfloat.sh is to establish the target to support soft floating point arm cross compilation tool chain.
(4) $ Vim demo-arm-softfloat.sh
#! /Bin/sh
# This script has one line for each known working toolchain
# For this architecture. uncomment the one you want.
# Generated by generate-demo.pl from buildlogs/all.dats.txt
Set-ex
Tarballs_dir = $ home/downloads // indicates the directory where the downloaded source code is stored.
Result_top = $ home/crosstool // indicates the directory where the generated toolchain is stored.
Export tarballs_dir result_top
Gcc_languages = "C, C ++" // indicates the language supported by the toolchain to be generated
Export gcc_ages
# Really, you shoshould do the mkdir before running this,
# And chown/opt/crosstool to yourself so you don't need to run as root.
Mkdir-p $ result_top
# Eval 'cat arm-softfloat.dat gcc-2.95.3-glibc-2.1.3.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.2.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.5.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.2.3-glibc-2.2.5.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.2.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.5.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.2.5.dat 'sh all. Sh -- notest
# Eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.5.dat 'sh all. Sh -- notest
Eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat 'sh all. Sh -- notest -- GDB
# Select this line in this experiment, and add -- GDB later to enable production debugging tools
Echo done.
// Indicates that you want to select the version number of the toolchain! "#" Starts the annotation function! Select a row!
TIPS: If an error occurs during compilation, You can execute it again. /demo-arm-softfloat.sh before eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat 'sh all. sh -- notest -- add -- nounpack at the end of GDB, which means that the installation package is not re-decompressed, so that the installation process continues without overwriting the previous compilation results. |
The final modified file is as follows:
#! /Bin/sh # This script has one line for each known working toolchain # For this architecture. uncomment the one you want. # Generated by generate-demo.pl from buildlogs/all.dats.txt Set-ex Tarballs_dir = $ home/downloads Result_top = $ home/crosstool Export tarballs_dir result_top Gcc_ages = "C, C ++" Export gcc_ages # Really, you shoshould do the mkdir before running this, # And chown/opt/crosstool to yourself so you don't need to run Root. Mkdir-p $ result_top # Eval 'cat arm-softfloat.dat gcc-2.95.3-glibc-2.1.3.dat 'sh all. sh -- Notest # Eval 'cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.2.dat 'sh all. sh -- Notest # Eval 'cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.5.dat 'sh all. sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.2.3-glibc-2.2.5.dat 'sh all. Sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2.dat 'sh all. Sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2-tls.dat 'sh all. Sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.2.dat 'sh all. Sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.5.dat 'sh all. Sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2.dat 'sh all. Sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2-tls.dat 'sh all. Sh -- Notest # Eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.2.5.dat 'sh all. Sh -- Notest # eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.5.dat 'sh all. Sh -- Notest Eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat 'sh all. Sh -- Notest -- GDB Echo done. |
Demo-arm-softfloat.sh this script is executing the eval 'cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat 'sh all. Sh-notest this batch file during execution. Open this file
(5) $ Vim gcc-3.4.5-glibc-2.3.6.dat
Binutils_dir = binutils-2.15
Gcc_dir = gcc-3.4.5
Glibc_dir = glibc-2.3.6
Linux_dir = linux-2.6.8
Linux_sanitized_header_dir = linux-libc-headers-2.6.12.0
Glibcthreads_filename = glibc-linuxthreads-2.3.6
Since the cross compiler is compiled 2.6.14 kernel, So modify linux_dir = linux-2.6.14 In addition, we need to add GDB debugging function, in linux_dir this line after add a line: gdb_dir = gdb-6.5
The final modification is as follows:
Binutils_dir = binutils-2.15 Gcc_dir = gcc-3.4.5 Glibc_dir = glibc-2.3.6 Linux_dir = linux-2.6.14 Gdb_dir = gdb-6.5 Linux_sanitized_header_dir = linux-libc-headers-2.6.12.0 Glibcthreads_filename = glibc-linuxthreads-2.3.6 |
(6) Vim arm-softfloat.dat
Kernelconfig = 'pwd'/arm. config
Target = arm-softfloat-Linux-GNU
Target_cflags = "-o"
Gcc_extra_config = "-- with-float = soft"
Glibc_extra_config = "-- without-FP"
The final modification is as follows:
Kernelconfig = 'pwd'/arm. config Target = arm-softfloat-Linux-GNU (this name can be changed to yours. Prefix name of the desired cross-tool chain) Target_cflags = "-o" Gcc_extra_config = "-- with-float = soft" Glibc_extra_config = "-- without-FP" |
At this time, you can execute the compilation script.
(7) $./The demo-arm-softfloat.sh is compiled after more than 1 hour.
Note: 1. If it is compiled on ubuntu7.10, the compilation will fail (this is generated during the compilation process, so it cannot be solved in advance. About 30 minutes) Modify build/ARM-softfloat-Linux-GNU/gcc-3.4.5-glibc-2.3.6/build-glibc/CSU/version-info.h at this time Changed: "Compiled on a Linux> 2.6.20-15-generic <System on 2008-01-30. \ n" "Available extensions: \ n" "\ N" "GNU libio by Per bothner \ n" "Crypt add-on version 2.1 by Michael gglad and others \ n" Linuxthreads-0.10 by Xavier Leroy \ n" "BIND-8.2.3-T5B \ n" "Libthread_db work attached sored by Alpha processor Inc \ n" "Nis (YP)/NIS + NSS modules 0.19 by Thorsten Kuk \ n" Execute again. /demo-arm-softfloat.sh before, please arm-softfloat.dat in eval 'cat gcc-3.4.5-glibc-2.3.6.dat 'sh all. sh -- notest -- add -- nounpack at the end of GDB, which means that the installation package is not re-decompressed, so that the installation process continues without overwriting the previous compilation results. Execute again: /Demo-arm-softfloat.sh (About 50 minutes) 2. the following error occurs during the compilation of the toolchain./demo-arm-softflaot.sh on ubuntu9.10: * ** "These critical programs are missing or too old" as LD The solution is as follows: Modify the following file: Vi./build/ARM-softfloat-Linux-GNU/gcc-3.4.5-glibc-2.3.6/glibc-2.3.6/configure + 4425 Set 4419 test-n "$ critic_missing" & {echo "$ as_me: $ lineno: Error: 4420 *** these critical programs are missing or too old: $ critic_missing 4421 *** check the install file for required versions. "> & 5 4422 echo "$ as_me: Error: 4423 *** these critical programs are missing or too old: $ critic_missing 4424 *** check the install file for required versions. "> & 2 ;} {(Exit 1); Exit 1 ;};} Changed: 4419 test-n "$ critic_missing" & {echo "$ as_me: $ lineno: Error: 4420 *** these critical programs are missing or too old: $ critic_missing 4421 *** check the install file for required versions. "> & 5 4422 echo "$ as_me: Error: 4423 *** these critical programs are missing or too old: $ critic_missing 4424 *** check the install file for required versions. "> & 2 ;} # {(Exit 1); Exit 1 ;}; } Execute again. /demo-arm-softfloat.sh before, please arm-softfloat.dat in eval 'cat gcc-3.4.5-glibc-2.3.6.dat 'sh all. sh -- notest -- add -- nounpack at the end of GDB, which means that the installation package is not re-decompressed, so that the installation process continues without overwriting the previous compilation results. Execute again: /Demo-arm-softfloat.sh |
(8) You need to set the environment variable $ export Path =/opt/crosstool/gcc-3.4.5-glibc-2.3.6/ARM-Linux-GNU/bin before using it to compile the kernel: $ PATH $ source/etc/profile is above the environment variable set on the current terminal, if you want to add to the system environment variable, add the following line before export path in/etc/profile:
# Sudo VI/etc/profile (enter the root password)
Path =/opt/crosstool/gcc-3.4.5-glibc-2.3.6/ARM-Linux-GNU/bin: $ PATH export path
After saving and exiting Vi, you can restart the system or run the following command in the terminal window:
#
$ Source/etc/profile
(9) Now we can use this cross compiler to conduct the experiment.
(10) Compile the kernel [select to do]
Set kernel makefile
$ CD kernel/linux-2.6.14
$ Vim makefile
Ensure
Arch? = Arm
Cross_compile? = Arm-softfloat-Linux-GNU-
This compiler can be used to compile the kernel at this time, but other content will be involved in the kernel compilation experiment. This content will be linked to the system porting experiment.
Note: After compilation, you can run the following command to modify the original settings sudo RM/usr/bin/gccsudo ln-S/usr/bin/gcc-4.3/usr/bin/gccsudo dpkg-reconfigure dash to select Yes again restore sh to dash |