為什么要用交叉編譯器?
交叉編譯通俗地講就是在一種平台上編譯出能運行在體系結構不同的另一種平台上的程序,
比如在PC平台(X86 CPU)上編譯出能運行在以ARM為內核的CPU平台上的程序,編譯得到的程序在X86 CPU平台上是不能運行的,必須放到ARM CPU平台上才能運行,雖然兩個平台用的都是Linux系統。
arm交叉編譯器
交叉編譯工具鏈是一個由編譯器、連接器和解釋器組成的綜合開發環境,交叉編譯工具鏈主要由binutils、gcc和glibc三個部分組成。
有時出於減小 libc 庫大小的考慮,也可以用別的 c 庫來代替 glibc,例如 uClibc、dietlibc 和 newlib。
建立交叉編譯工具鏈是一個相當復雜的過程,如果不想自己經歷復雜繁瑣的編譯過程,
網上有一些編譯好的可用的交叉編譯工具鏈可以下載,但就以學習為目的來說讀者有必要學習自己制作一個交叉編譯工具鏈(目前來看,對於初學者沒有太大必要自己交叉編譯一個工具鏈)。
分類和說明: 從授權上,分為免費授權版和付費授權版。
免費版目前有三大主流工具商提供,
- GNU(提供源碼,自行編譯制作)
- Codesourcery
- Linora (提供源碼,和已經編譯好的release binrary)
收費版有ARM原廠提供的armcc、IAR提供的編譯器等等,因為這些價格都比較昂貴,不適合學習用戶使用,所以不做講述。
arm-linux-gnueabihf-gcc(32-bit Armv7 Cortex-A, hard-float, little-endian )
是由 Linaro 公司基於GCC推出的的ARM交叉編譯工具。
可用於交叉編譯ARMv7(32位)系統中所有環節的代碼,包括裸機程序、u-boot、Linux kernel、filesystem和App應用程序。
armv8l-linux-gnueabihf(32-bit Armv8 Cortex-A, hard-float, little-endian )
是由 Linaro 公司基於GCC推出的的ARM交叉編譯工具。
可用於交叉編譯ARMv8(32位)系統中所有環節的代碼,包括裸機程序、u-boot、Linux kernel、filesystem和App應用程序。
aarch64-linux-gnu-gcc(64-bit Armv8 Cortex-A, little-endian )
是由 Linaro 公司基於GCC推出的的ARM交叉編譯工具。
可用於交叉編譯ARMv8 64位目標中的裸機程序、u-boot、Linux kernel、filesystem和App應用程序。
名稱 | 描述 | 詳情 |
---|---|---|
ABI | 二進制應用程序接口(Application Binary Interface (ABI) for the ARM Architecture) | 在計算機中, 應用二進制接口描述了應用程序(或者其他類型)和操作系統之間或其他應用程序的低級接口 |
EABI | 嵌入式ABI (Embedded Application Binary Interface) | 嵌入式應用二進制接口指定了文件格式、數據類型、寄存器使用、堆積組織優化和在一個嵌入式軟件中的參數的標准約定. 開發者使用自己的匯編語言也可以使用 EABI 作為與兼容的編譯器生成的匯編語言的接口 |
ABI的定義
ABI描述應用程序與操作系統、應用程序與庫、應用程序的組成部分之間的低層接口。ABI允許編譯好的目標代碼在使用兼容ABI的系統中無需改動就能運行。
兩者主要區別是,ABI是運行在x86,x64平台, EABI是嵌入式平台上(如ARM,MIPS,android, iOS等)。
linaro
Linaro,一間非營利性質的開放源代碼軟件工程公司,主要的目標在於開發不同半導體公司系統單芯片(SoC)平台的共通軟件,以促進消費者及廠商的福祉。針對於各個成員推出的 ARM系統單芯片(SoC),它開發了ARM開發工具、Linux內核以及Linux發行版(包括 Android 及 Ubuntu)的主要自動建構系統。
由ARM、飛思卡爾、IBM、Samsung、ST-Ericsson 及德州儀器 (TI)等半導體廠商聯合,在2010年3月成立。2010年6月在台北對外宣布這個消息。預計在2010年11月,推出第一版以ARM Cortex-A 為核心的 SoC 進行效能優化的軟件工具
除了推出交叉編譯器還推出修改的linux和安卓內核等包
Ubuntu源中的交叉編譯器即使用linaro下載編譯的交叉編譯器
下載 https://releases.linaro.org/components/toolchain/binaries/latest/
ELDK的下載
http://www.denx.de/en/News/WebHome
-> ftp://ftp.denx.de/pub/eldk/5.3/
-> ftp://ftp.denx.de/pub/eldk/5.3/iso/
中有各種的,基於arm的eldk,比如:
eldk-5.3-armv4t.iso
eldk-5.3-armv5te.iso
eldk-5.3-armv6.iso
eldk-5.3-armv6.iso
eldk-5.3-armv7a-hf.iso
eldk-5.3-armv7a.iso
下載下來,解壓后,去運行安裝腳本后,就可以使用了
Codesourcery
Codesourcery 推出的產品叫 Sourcery G++ Lite Edition, 其中基於 command-line 的編譯器是免費的, 在官網上可以下載, 而其中包含的 IDE 和 debug 工具是收費的, 當然也有30天試用版本的.
目前 CodeSourcery 已經由明導國際(Mentor Graphics)收購, 所以原本的網站風格已經全部變為 Mentor 樣式, 但是 Sourcery G++ Lite Edition 同樣可以注冊后免費下載.
Codesourcery一直是在做 ARM 目標 GCC 的開發和優化, 它的 ARM GCC 在目前在市場上非常優秀, 很多 patch 可能還沒被 gcc 接受, 所以還是應該直接用它的(而且他提供 Windows 下[mingw交叉編譯的]和Linux下的二進制版本, 比較方便; 如果不是很有時間和興趣, 不建議下載 src 源碼包自己編譯, 很麻煩, Codesourcery給的 shell 腳本很多時候根本沒辦法直接用, 得自行提取關鍵的部分手工執行, 又費精力又費時間, 如果想知道細節, 其實不用自己編譯一遍, 看看他是用什么步驟構建的即可, 如果你對交叉編譯器感興趣的話.
FriednlyARM友善之臂
arm9之家 http://www.arm9home.net/
論壇 http://www.friendlyarm.net/forum/topic/5203
命名規則
對應分別是 :
arch [-vendor] [-os] [-(gnu)eabi]
規則 描述
arch 體系架構, 如ARM, MIPS
vendor 工具鏈提供商
os 目標操作系統
eabi 嵌入式應用二進制接口(Embedded Application Binary Interface)
https://developer.arm.com/embedded
Getting started
Starting with the basics, find all of the resources you will need here.
Keil Application Notes
Keil MDK Device List
Keil Discussion Forum
Keil Knowledge Base
Keil MDK User's Guides
Latest Mbed news and releases
Learning Platform for Cortex-M
Migrating from 8051 to Cortex Microcontrollers
User Guides: Cortex-M4, Cortex-M3, Cortex-M0+ and Cortex-M0
Choosing a Board
Find the right development platform for your project and minimize project setup time.
Keil board list for Arm Cortex-M
Arm Cortex-M7
Arm Cortex-M4
Arm Cortex-M3
Arm Cortex-M0
Arm V2M-MPS2
Developing with Mbed
snapdragon boards
Latest Linux Targeted Binary Toolchain Releases
linaro downloads
arm版本 | 硬件型號 | |||
---|---|---|---|---|
arm-linux-gnueabihf | 32-bit Armv7 Cortex-A, hard-float, little-endian | Release-Notes | Binaries | Source |
armv8l-linux-gnueabihf | 32-bit Armv8 Cortex-A, hard-float, little-endian | Release-Notes | Binaries | Source |
aarch64-linux-gnu | 64-bit Armv8 Cortex-A, little-endian | Release-Notes | Binaries | Source |
Latest Bare-Metal Targeted Binary Toolchain Releases (也可以認為是MCU,不跑操作系統)
arm版本 | 硬件型號 | |||
---|---|---|---|---|
arm-eabi | 32-bit Armv7 Cortex-A, soft-float, little-endian | Release-Notes | Binaries | Source |
aarch64-elf | 64-bit Armv8 Cortex-A, little-endian | Release-Notes | Binaries | Source |
GNU Toolchain for Arm processors
Open source GNU tools for Arm processors: GNU compiler (GCC), binutils, GNU debugger (GDB) and newlib
1> ## GNU toolchain for the A-profile architecture
- Application and Linux kernel development
- Support for Arm Cortex-A family
- Monthly updates to QEMU, GDB, and various versions of GCC
- Freely available from Linaro
- Community support
Download GNU Toolchain for the A-profile architecture
GNU Toolchain for the A-profile architecture
The GNU Toolchain for the Cortex-A Family are integrated and validated packages featuring the GCC compiler, libraries and other GNU tools necessary for software development on devices based on the Arm Cortex-A processors or the Arm A-profile architecture. The toolchains are available for cross-compilation on Microsoft Windows and Linux host operating systems.
These toolchains are based on Free Software Foundation's (FSF) GNU Open source tools.
2> ## GNU toolchain for embedded processors
- Bare-metal development
- Support for Arm Cortex-R and Cortex-M families
- GCC, binutils, GDB and newlib
- Freely available from Arm
- Community support
GNU Arm Embedded Toolchain
Pre-built GNU toolchain for Arm Cortex-M and Cortex-R processors
The GNU Arm Embedded toolchains are integrated and validated packages featuring the Arm Embedded GCC compiler, libraries and other GNU tools necessary for bare-metal software development on devices based on the Arm Cortex-M and Cortex-R processors. The toolchains are available for cross-compilation on Microsoft Windows, Linux and Mac OS X host operating systems.
These toolchains are based on Free Software Foundation's (FSF) GNU Open source tools and newlib.
These toolchains support Arm Cortex-M0, Cortex-M0+, Cortex-M3, Cortex-M4, Cortex-M7, Cortex-M23, Cortex-M33, Cortex-R4, Cortex-R5, Cortex-R7, Cortex-R8 and Cortex-R52 processors.
The toolchains support code generation for non-OS or 'bare-metal' environments. These toolchains are based on Free Software Foundation's (FSF) GNU Open source tools and newlib.
GNU C/C++ Compiler
You can find the sources to Arm Embedded GCC under svn://gcc.gnu.org/svn/gcc/branches/ARM/. All contributions are made to trunk and patches are cherry-picked on a need basis to the Arm embedded branches.
Binutils
You can find the sources to Arm Embedded Binutils under git://sourceware.org/git/binutils-gdb.git. All embedded branches are under users/ARM/embedded-binutils-[version]-branch. Contribution is similar to GCC.
GDB
You can find the sources to Arm Embedded Binutils under git://sourceware.org/git/binutils-gdb.git. All embedded branches are under users/ARM/embedded-gdb-[version]-branch. Contribution is similar to GCC.
Newlib
You can find the sources under git://sourceware.org/git/newlib-cygwin.git. We contribute to master and the toolchain is based on master branch as well.
https://launchpad.net/gcc-linaro
https://launchpad.net/gcc-linaro/+packages
中文
https://github.com/gatieme/AderXCoding/tree/master/system/tools/cross_compile
介紹區別
Linux
表示:有OS(此處主要指的是Linux)操作系統的環境
比如,我用交叉編譯器,編譯一個helloworld程序,然后下載到嵌入式開發中的嵌入式Linux中運行,
就屬於,用此交叉編譯器,編譯出來的程序,是要運行於,帶OS,即嵌入式Linux系統,環境中的
此處,簡稱為,有OS的目標系統:Linux
bare-metal 直譯為:裸金屬
表示:無(此處主要指的是Linux)操作系統的環境,
比如,用此交叉編譯器,去編譯一個Uboot,或者是其他一個小程序,是運行在,無嵌入式Linux的時候,單獨運行的一個程序。
比如,你購買的嵌入式系統開發版,常常附帶一些小程序,比如點亮LED,跑馬燈等程序,就是這種,運行在無OS的環境的
此處,簡稱為:無OS系統的:bare-metal
關於,運行在有OS的Linux下,和,無OS的bare-metal,區別 是 一個運行OS,庫會有很多,依賴也會有很多。
而類似STM32F1系列(MCU ) 既可以 跑RTOS,也可以當單片機來用, 在初始化中 設置GPIO,時鍾晶振頻率,然后 就可以利用GPIO 輸出想要的東西。