Building an ARM GCC Toolchain from Source
Step by step guide on building a GCC cross-compilation toolchain from source on Windows and LinuxWhile we'd strongly recommend starting with one of the precompiled GNU GCC toolchains available for A
While we'd strongly recommend starting with one of the precompiled GNU GCC toolchains available for ARM such as CodeSourcery G++ Lite orYagarto (see Setting up a GCC Development Environment for the Cortex M0/M3 for more information), using a precompiled toolchain leaves you at the mercy of someone else's whims and fancies about what features to include, what libraries to use, etc. Depending on precompiled toolchains also means that you're depending on their authors to regularly update them when new releases of GCC become available.
This tutorial came to life precisely because of a situation like that: GCC 4.5.0 is the first version to have official support for the ARM Cortex-M0 core, but unfortunately all the precompiled toolchains at the time this article was written were still based on GCC 4.4.x. Roel Verdult (from libnfc.org) came to the rescue and provided this step-by-step tutorial on building GCC from source in both Linux and Windows for us. If you need to build your own toolchain as well, this tutorial should at least get you well on your way.
Linux
Building GCC under Linux requires less steps than in Windows since a number of required packages are typically already installed on most Linux distributions or they can be easily installed from pre-compiled binaries. GCC compile times are also generally a lot faster under Linux than in Windows, which is helpful for packages as 'large' as a custom GNU GCC for ARM toolchain. That said ... the entire build process will probably still take about an hour on most machines.
This tutorial was written and tested for Ubuntu 10.10, but should be easily adaptable to most modern Linux distributions. The build script currently builds GCC 4.5.2, Binutils 2.21, Newlib 1.19 and GDB 7.2.
Step 1: Install build tools and packages
From the command-prompt, enter the following command:sudo apt-get update sudo apt-get install build-essential sudo apt-get install libmpc-dev sudo apt-get install zlib1g-dev sudo apt-get install texinfo sudo apt-get install libncurses5-dev
Step 2: Build the GCC Toolchain
Download summon-arm-toolchain.tar.gz, decompress it and run it using the following commands:wget http://www.microbuilder.eu/Files/Tutorials/summon-arm-toolchain.tar.gz tar -xvzf summon-arm-toolchain.tar.gz sh summon-arm-toolchain.sh ~/ arm-none-eabi
Step 3: Add the GCC Toolchain to PATH
Next you need to add the location of the compiled binaries to your path variable with the following command:$ echo "PATH=$PATH:~/arm-none-eabi/bin" >> .bashrcNote: You will need to restart the console for these changes to take effect.
Windows
Building GCC under Windows is a little bit more complicated than in Linux, since a number of packages need to be installed beforehand. This guide will help you install and configure the required software packages to be able to build a GCC cross-compiling toolchain for ARM.
Step 1: Install MinGW and MSYS Base System
Before you can do anything useful, you will need to download Minimalist GNU for Windows (MinGW) andMSYS Base System with GNU Utilities (MSYS), both of which are available from theMinGW SourceForge download page. You can also download the files directly with the following links (which were the most recent versions at the publication of this article, 19 April 2010):
- Direct Download: Minimalist GNU for Windows (MinGW) 5.1.6
- Direct Download: MSYS Base System with GNU Utilities 1.0.11
Step 2: Download GNU wget
Next you need to download wget (a non-interactive network retriever) using the link below, and place the executable file in the "msys\1.0\bin" folder:
- Direct Download: wget
Step 3: Load the MSYS Environment and Start Building
Next you need to start the MSYS environment by selecting "Start -> Programs -> MinGW -> MSYS -> MSYS" in the start menu. (The menu options may vary slightly depending on which version of Windows you are using, and how you're start menu is configured.). This UNIX console will be used to build the necessary packages as well as the GNU GCC ARM Toolchain:
Mount MinGW in MSYS
To access MinGW from MSYS, you will need to configure MSYS to associate "/mingw" with the MinGW installation path (presumably "c:\mingw" if you used the default settings during installation). This can be done with the following command:mount c:/mingw /mingw
Build GMP (GNU Multiple Precision Arithmetic Library)
$ wget ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.gz $ tar -xvzf gmp-5.0.1.tar.gz $ cd gmp-5.0.1 $ ./configure --prefix=/mingw $ make $ make install $ cd ..
Build MPFR (Multi-Precision Floating Point Library)
$ wget http://www.mpfr.org/mpfr-current/mpfr-2.4.2.tar.gz $ tar -xvzf mpfr-2.4.2.tar.gz $ cd mpfr-2.4.2 $ ./configure --prefix=/mingw $ make $ make install $ cd ..
Build MPC (Multi-Precision Complex Arithmetic Library)
$ wget http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz $ tar -xvzf mpc-0.8.1.tar.gz $ cd mpc-0.8.1 $ ./configure --prefix=/mingw $ make $ make install $ cd ..
Step 4: Build GNU GCC ARM Toolchain
Last, you need to download a simple script file that will handle the compilation of the GNU GCC ARM Toolchain (GCC 4.5.0, Newlib 1.18.0, GDB 7.1 and Binutils 2.20.1). Download the following file, and unzip it in the "<drive>:\msys\1.0\home\<username>\" folder:
- Direct Download: GCC Build Script
Build GNU GCC
$ sh summon-arm-toolchain.sh ~ arm-none-eabi
Step 5: Adding the Environment Variables in Windows
In order to access the newly built GCC toolchain from the command-prompt, you will need to add the appropriate paths to the Windows "path". You can do this using the following steps:
- Right-click on My Computer and select Properties from the popup-menu
- Switch to the Advanced tab
- From there, select the Environment Variables button at the bottom
- Find the Path system variable and click the Edit button
"Path" Environment Variables
C:\msys\1.0\home\<username>\arm-none-eabi\bin;C:\msys\1.0\bin\
更多推荐
所有评论(0)