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 $@ $<


智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告