ARM——開發工具—編譯器

說起ARM開發,不得不說的就是編譯器了。大家都熟悉的gcc,這個平臺也有。

反正說起嵌入式開發,大家必然要提的就是toolchain,也叫工具鏈。還有叫交叉(CROSS)工具鏈。其實都差不多。爲什麼有這麼多版本的編譯器?

主要是市場決定的吧。不同的開發板會提供基於gnu標準修改的一些gcc、as、ld,一般elf文件還都是一樣的。大部分原因是不同外設等硬件導致的。

看看主流的ARM編譯器有哪些?

1.armcc是ARM官方編譯器,DS-5包含該工具。收費。

2.asm-linux-gnueabihf是GNU提供的編譯器,ubuntu可以直接sudo apt-get install gcc-arm-linux-gnueabihf下載。DS-5提供該編譯器。

3.asm-linux-gnueabi是GNU提供的編譯器,ubuntu可以直接sudo apt-get install gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi。

4.asm-none-gnueabi是CodeSourcery提供的編譯器。網上的Lite版本免費用,不過需要註冊。很多開源項目採用這個編譯器。


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

這裏就簡單介紹一下,asm-none-gnueabi的安裝吧。前兩個都是GUI安裝,沒什麼難度。現在的工具其實都比較簡單了。

1.下載arm-2010q1-202-arm-none-linux-gnueabi.bin,這個不用教了吧。

2.安裝./arm-2010q1-202-arm-none-linux-gnueabi.bin。如果不能運行,使用chmod 755 .。設置一下可以執行。如果提示不能安裝,看清楚,選個Y或者N就能安裝了。

3:設置環境變量

$gedit     ~/.bashrc

在.bashrc文件的末尾最後添加一行,來增加一個環境變量

export PATH="/opt/arm-2009q1/bin:$PATH"

4:使得剛纔的設置生效
$ source /.bashrc

5查看linux的環境變量
$echo $PATH
$printenv

6 測試安裝結果 輸入

$arm-none-linux-gnueabi-gcc

提示NO input file ,

這就大功告成了。找個代碼編譯一下吧。這個時候輸入arm-然後tab,應該會看到相關的工具。注意,編譯不同的東西,工具鏈可能需要更換。

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


下面簡單介紹一下,每個編譯工具的使用。

1.這個是DS-5的工具。IDE界面。看看Makefile就明白了。

# TrustZone Example Makefile
#
# Copyright (C) ARM Limited, 2011. All rights reserved.
#
# This makefile is intended for use with GNU make
# This example is intended to be built with the ARM Compiler armcc

TARGET=TrustZone-versatile.axf

CC=armcc
AS=armasm
LD=armlink
AR=armar
FE=fromelf

# Select build rules based on Windows or Unix
ifdef WINDIR
DONE=@if exist $(1) echo Build completed.
RM=if exist $(1) del /q $(1)
SHELL=$(WINDIR)\system32\cmd.exe
else
ifdef windir
DONE=@if exist $(1) echo Build completed.
RM=if exist $(1) del /q $(1)
SHELL=$(windir)\system32\cmd.exe
else
DONE=@if [ -f $(1) ]; then echo Build completed.; fi
RM=rm -f $(1)
endif
endif


all: $(TARGET)
	$(call DONE,$(TARGET))

rebuild: clean all

clean:
	$(call RM,*.o)
	$(call RM,$(TARGET))


$(TARGET): startup_normal.s main_normal.c scatter_normal.scat startup_secure.s main_secure.c bp147_tzpc.c bp147_tzpc.h monitor.s scatter_secure.scat
# Assemble common routines
	$(AS) -g --cpu=Cortex-A9.no_neon.no_vfp v7.s -o v7.o
# Compile normal world code
	$(AS)    -g --cpu=Cortex-A9.no_neon.no_vfp startup_normal.s  -o startup_normal.o
	$(CC) -c -g --cpu=Cortex-A9.no_neon.no_vfp -O1 main_normal.c -o main_normal.o
# Link normal world code and create binary
	$(LD) main_normal.o startup_normal.o v7.o --scatter=scatter_normal.scat --entry=normalStart -o normal.axf
	$(FE) --bin -o normal.bin normal.axf
# Compile secure world code
	$(AS)    -g --cpu=Cortex-A9.no_neon.no_vfp     startup_secure.s -o startup_secure.o
	$(CC) -c -g --cpu=Cortex-A9.no_neon.no_vfp -O1 main_secure.c -o main_secure.o
	$(CC) -c -g --cpu=Cortex-A9.no_neon.no_vfp -O1 bp147_tzpc.c -o bp147_tzpc.o
	$(AS)    -g --cpu=Cortex-A9.no_neon.no_vfp     monitor.s -o monitor.o
# Link final executable (secure + normal)
	$(LD) main_secure.o startup_secure.o v7.o monitor.o bp147_tzpc.o --scatter=scatter_secure.scat --entry=secureStart --keep="startup_secure.o(NORMAL_IMAGE)" -o $(TARGET)

2.也是DS-5中創建c工程,看看Makefile。

# C Application Example for ARM Linux
#  
# Copyright (C) ARM Limited, 2007-2012. All rights reserved.

# This makefile is intended for use with GNU make
#
# This project can be built as hard-float ABI or full software floating point ABI:
# FLOAT = hf
# or
# FLOAT = soft

FLOAT     = soft

TARGET = hello

ifeq ($(strip $(FLOAT)),hf)
ABI = -marm -mfloat-abi=hard
else
ABI = -marm -march=armv4t -mfloat-abi=soft
endif

CC_OPTS = -c -O1 -g -fno-omit-frame-pointer $(ABI)
OBJS = hello.o
STRIPPED_DIR = stripped

##########################################################################

CPP = arm-linux-gnueabihf-c++
CC  = arm-linux-gnueabihf-gcc
AR  = arm-linux-gnueabihf-ar
STRIP_APP = arm-linux-gnueabihf-strip -R .comment --strip-all
STRIP_LIB = arm-linux-gnueabihf-strip -R .comment --strip-unneeded


# Select build rules based on Windows or Linux
ifdef WINDIR
#  Building on Windows
RPATH=$$ORIGIN
WINPATH=$(subst /,\,$(1))
DONE=@if exist $(call WINPATH,$(1)) echo Build completed.
define REAL_RM
if exist $(call WINPATH,$(1)) del /q $(call WINPATH,$(1))

endef
RM=$(foreach file,$(1),$(call REAL_RM,$(file)))
SHELL=$(windir)\system32\cmd.exe
MD=if not exist $(1) mkdir $(1)
CP=copy
else
ifdef windir
#  Building on Windows
RPATH=$$ORIGIN
WINPATH=$(subst /,\,$(1))
DONE=@if exist $(call WINPATH,$(1)) echo Build completed.
define REAL_RM
if exist $(call WINPATH,$(1)) del /q $(call WINPATH,$(1))

endef
RM=$(foreach file,$(1),$(call REAL_RM,$(file)))
SHELL=$(windir)\system32\cmd.exe
MD=if not exist $(1) mkdir $(1)
CP=copy

else
#  Building on Linux
RPATH='$$ORIGIN'
DONE=@if [ -f $(1) ]; then echo Build completed.; fi
RM=rm -f $(1)
MD=@if [ ! -d $(1) ]; then mkdir $(1); fi
CP=cp
endif
endif

##########################################################################

all: $(TARGET)
		$(call DONE,$(TARGET))

rebuild: clean all

clean:
		$(call RM,$(OBJS))
		$(call RM,$(TARGET))
		$(call RM,$(STRIPPED_DIR)/$(TARGET))


# Compile the sources
$(OBJS): %.o: %.c
	$(CC) $(CC_OPTS) $< -o $@


# Link the objects together to create an executable
# Strip the host/debug version to create a stripped/nodebug version for downloading to the target
$(TARGET): $(OBJS)
	$(call MD,$(STRIPPED_DIR))
	$(CC) $(OBJS) -o $(TARGET) $(ABI)
	$(STRIP_APP) $(TARGET) -o $(STRIPPED_DIR)/$(TARGET)


3.這個是GNU的編譯器,看看Makefile。其實和第二個沒什麼區別。而且都能編譯通過。僅僅是可能燒寫到開發板上不能運行。

# C Application Example for ARM Linux
#  
# Copyright (C) ARM Limited, 2007-2012. All rights reserved.

# This makefile is intended for use with GNU make
#
# This project can be built as hard-float ABI or full software floating point ABI:
# FLOAT = hf
# or
# FLOAT = soft

FLOAT     = soft

TARGET = hello

ifeq ($(strip $(FLOAT)),hf)
ABI = -marm -mfloat-abi=hard
else
ABI = -marm -march=armv4t -mfloat-abi=soft
endif

CC_OPTS = -c -O1 -g -fno-omit-frame-pointer $(ABI)
OBJS = hello.o
STRIPPED_DIR = stripped

##########################################################################

CPP = arm-linux-gnueabi-c++
CC  = arm-linux-gnueabi-gcc
AR  = arm-linux-gnueabi-ar
STRIP_APP = arm-linux-gnueabi-strip -R .comment --strip-all
STRIP_LIB = arm-linux-gnueabi-strip -R .comment --strip-unneeded


# Select build rules based on Windows or Linux
ifdef WINDIR
#  Building on Windows
RPATH=$$ORIGIN
WINPATH=$(subst /,\,$(1))
DONE=@if exist $(call WINPATH,$(1)) echo Build completed.
define REAL_RM
if exist $(call WINPATH,$(1)) del /q $(call WINPATH,$(1))

endef
RM=$(foreach file,$(1),$(call REAL_RM,$(file)))
SHELL=$(windir)\system32\cmd.exe
MD=if not exist $(1) mkdir $(1)
CP=copy
else
ifdef windir
#  Building on Windows
RPATH=$$ORIGIN
WINPATH=$(subst /,\,$(1))
DONE=@if exist $(call WINPATH,$(1)) echo Build completed.
define REAL_RM
if exist $(call WINPATH,$(1)) del /q $(call WINPATH,$(1))

endef
RM=$(foreach file,$(1),$(call REAL_RM,$(file)))
SHELL=$(windir)\system32\cmd.exe
MD=if not exist $(1) mkdir $(1)
CP=copy

else
#  Building on Linux
RPATH='$$ORIGIN'
DONE=@if [ -f $(1) ]; then echo Build completed.; fi
RM=rm -f $(1)
MD=@if [ ! -d $(1) ]; then mkdir $(1); fi
CP=cp
endif
endif

##########################################################################

all: $(TARGET)
		$(call DONE,$(TARGET))

rebuild: clean all

clean:
		$(call RM,$(OBJS))
		$(call RM,$(TARGET))
		$(call RM,$(STRIPPED_DIR)/$(TARGET))


# Compile the sources
$(OBJS): %.o: %.c
	$(CC) $(CC_OPTS) $< -o $@


# Link the objects together to create an executable
# Strip the host/debug version to create a stripped/nodebug version for downloading to the target
$(TARGET): $(OBJS)
	$(call MD,$(STRIPPED_DIR))
	$(CC) $(OBJS) -o $(TARGET) $(ABI)
	$(STRIP_APP) $(TARGET) -o $(STRIPPED_DIR)/$(TARGET)



4.這個是CodeSourcery的編譯器,看看Makefile

# Build an ELF linux image

BOOTLOADER	= boot.S
#KERNEL		= ../../../kernel/linux-2.6.38-ael-11.06-patched/built/VE_V7/arch/arm/boot/Image

IMAGE       = ../normal.elf
LD_SCRIPT	= model.lds

CROSS_COMPILE	= arm-none-linux-gnueabi-

AS		= $(CROSS_COMPILE)as -g
LD		= $(CROSS_COMPILE)ld -g

all: $(IMAGE)

clean:
	rm -f $(IMAGE) boot.o

$(IMAGE): boot.o $(LD_SCRIPT) $(KERNEL)
	$(LD) -o $@ --script=$(LD_SCRIPT)

boot.o: $(BOOTLOADER)
	$(AS) -o $@ $<


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章