本文是U-boot移植到UP-ARM2410-S上时编译过程的笔记
系统环境:ubuntu 9.04
交叉编译器:gcc 4.3.3
在board下为开发板供应商名称新建一个目录,取名uptech
# mkdir uptech
在 uptech 下为所用的开发板新建一个目录
# cd uptech
# mkdir uptech2410
UP-ARM2410-S为arm920t的处理器,与之接近的为/board/samsung/smdk2410,将smdk2410目录下的所有文件都拷贝到
uptech2410下
# cp ../samsung/smdk2410/config.mk uptech2410
# cp ../samsung/smdk2410/ flash.c uptech2410
# cp ../samsung/smdk2410/lowlevel_init.s uptech2410
# cp ../samsung/smdk2410/smdk2410.c uptech2410
# cp ../samsung/smdk2410/Makefile uptech2410
在include/configs/中建立配置头文件,其中大都是编译uptech2410时用到的一些宏
cp smdk2410.h uptech2410.h
uptech2410_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t uptech2410 uptech s3c24×0
arm arm920t uptech2410 uptech s3c24×0为make uptech2410时传进去的参数,分别代表:CPU的架构、CPU的类型、 开发板的型号(BOARD),uptech: 开发商vender)、s3c24×0: 片上系统(SOC)。
这些参数在编译时都会作为参数作为进入对应的目录用。其中arm920t对应于cpu/arm920t子目录。uptech2410对应/board/uptech/up2410,如果参数中的开发商uptech 设为NULL,那么上面第一步直接在/board目录下新建uptech2410就可以了,否则会出现NO Target 的错误,另外我在编译中将s3c24×0写成s3c2410也出现类似的错误
make uptech2410_config //实际执行./mkconfig arm arm920t uptech2410 uptech s3c24×0
make
1 出现如下错误信息
make[1]: arm-linux-gcc: Command not found
make[1]: *** [hello_world.o] Error 127
make[1]: Leaving directory `/home/bingc/work/u-boot-2009.08-rc1/examples/standalone’
make: *** [examples/standalone] Error 2
从错误信息可以得知,交叉编译器没有设置好,我们可以在make时加上CROSS_COMPILE=arm-none-linux-gnueabi-作为参数传进去
另外我们也可以更改配置文件纠正这个错误.打开Makefile 文件查找关键字 CROSS,可以看到:
# load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk
export ARCH CPU BOARD VENDOR SOC# set default to nothing for native builds
ifeq ($(HOSTARCH),$(ARCH))
CROSS_COMPILE ?=
endif
根据include 进入 config.mk文件,查找关键字 CROSS,可以看到:
# Include the make variables (CC, etc…)
#
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
LDR = $(CROSS_COMPILE)ldr
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB = $(CROSS_COMPILE)RANLIB
可以看出此处定义的为make时所用到的一些变量,因此可以在此处添加
CROSS_COMPILE=arm-none-linux-gnueabi-
注意:此处的gnueabi-中的字符'i’和'-’间不能有空格,否则会不识别该参数而报错
2 修正后继续编译,出现如下错误信息
make[1]: Entering directory `/home/bingc/work/u-boot-2009.08-rc1/board/uptech/uptech2410′
make[1]: *** No rule to make target `.depend’, needed by `libuptech2410.a’. Stop.
make[1]: Leaving directory `/home/bingc/work/u-boot-2009.08-rc1/board/uptech/uptech2410′
make: *** [board/uptech/uptech2410/libuptech2410.a] Error 2
可以看出找不到目标uptech,进入/uptech/uptech2410目录下的makefile查看,发现
COBJS := smdk2410.o flash.o
恍然大悟!原来在开始将smdk2410复制到uptech2410时makefile中编译后的目标没有做对应的更改,因此将smdk2410.o改为uptech2410.o
3 接着编译
make clean
make uptech2410_config
make
还是出现了错误:
arm-none-linux-gnueabi-ld: error: Source object /usr/local/arm-2009q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a(_dvmd_lnx.o) has EABI version 5, but target u-boot has EABI version 0
arm-none-linux-gnueabi-ld: failed to merge target specific data of file /usr/local/arm-2009q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a(_dvmd_lnx.o)
/usr/local/arm-2009q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a(_dvmd_lnx.o): In `__aeabi_ldiv0′
(.text+0×8): undefined reference to `raise’
make: *** [u-boot] Error 1
这里出现了除0异常,在google搜索undefined reference to `raise’ 得到这样的信息
On Thu, Jan 17, 2008 at 06:44:51PM +0300, Alexander Vasiliev wrote:> 1) The uboot (the universal boolloader> http://www.denx.de/wiki/UBoot/WebHome) is not creation of mine and> it's hard for me to say what it exactly needs. But it is builded by> other toolchain (MontaVista) without problems.>> 2) 'raise' should be placed in libc. libc is provided by "Code> sourcery". Is it correct? Or some path should be setted? I set PATH> only to 'arm-2007q3/bin'.The `raise' is part of the C library standard, and it isprovided by Codesourcery's C library. Uboot does not use a C library, itdefines its own s, therefore the source for uboot may need to beupdated when the compiler is updated. Montavista provides excellentvalue by building uboot and fixing such issues themselves.The workaround is provide an implementation of `raise' for uboot.
原文链接:http://www.codesourcery.com/archives/arm-gnu/msg01672.html
从信息中可以得知,'raise’异常是C库抛出的,uboot调用的是自己的库,再
google 关键字 `__aeabi_ldiv0' 看到如下信息:
U-Boot is not a GNU/Linux application. However, you're using theGNU/Linux toolchain to compile it -- so the libraries assume thepresence of a GNU/Linux C library. In this case, the division routinewants to call "raise" to signal a division-by-zero exception
……like our "ARM EABI" toolchains. There are often these kindsof problems with U-Boot when moving between different architectures ortoolchain versions because the U-Boot source code has tricks to try tomake the GNU/Linux toolchain work, and those tricks only work withparticular toolchains.
原文链接:http://www.codesourcery.com/archives/arm-gnu/msg02332.html
我们知道arm用的是精简指令集,没有专门的除法运算,更没有处理这种异常的机制。从信息中可以看出uboot调用的是自己的库,我们用的编译器gcc 4.3.3是有EABI工具链,这点从arm-none-linux-gnueabi很清楚可以看出。于是在uboot 搜索div0.c这个文件
# find | xargs grep div0.c
显示:
./lib_arm/.depend:div0.o: div0.c
Binary file ./u-boot matches
于是进入/lib_arm查看,找到div0.c,但没有生成div0.o可以看出没有选用uboot中的关于除0的函数。因此我们打开/lib_arm下的makefile 查找关键字div0
GLCOBJS += div0.o
根据GLCOBJS 往上逐层查看其依赖关系:GLCOBJS->LGOBJS->LIBGCC 可以看出div0需要依赖LIBGCC,继续搜索LIBGCC,有下面的条件编译语句
ifdef USE_PRIVATE_LIBGCC
all: $(LIB) $(LIBGCC)
else
all: $(LIB)
endif
因此,我们要让USE_PRIVATE_LIBGCC为真.在该Makefile 的开始定义USE_PRIVATE_LIBGCC=yes或在顶层Makefile中加入export USE_PRIVATE_LIBGCC =yes 都报错,再在该Makefile下搜索关键字USE_PRIVATE_LIBGCC,看到下面的代码段:
258 ifdef USE_PRIVATE_LIBGCC
259 ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
260 PLATFORM_LIBGCC = -L $(OBJTREE)/lib_$(ARCH) -lgcc
261 else
262 PLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC) -lgcc
263 endif
264 else
265 PLATFORM_LIBGCC = -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-na me`) -lgcc
266 endif
267 PLATFORM_LIBS += $(PLATFORM_LIBGCC)
268 export PLATFORM_LIBS
这就要求USE_PRIVATE_LIBGCC在此之前就有定义,于是在顶层目录的config.mk中的用到export 的地方添加.
#########################################################################
export HOSTCC HOSTCFLAGS CROSS_COMPILE \
AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
export USE_PRIVATE_LIBGCC =yes
#########################################################################
再编译,终于通过了。。。
arm -L /usr/local/arm-2009q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3 -lgcc -Map u-boot.map -o u-boot
arm-none-linux-gnueabi-objcopy -O srec u-boot u-boot.srec
arm-none-linux-gnueabi-objcopy –gap-fill=0xff -O binary u-boot u-boot.bin
联系客服