如何在windows下面编译u-boot
By semilog
最近想移植u-boot 到我的ARM开发板上,但是又不想在linux环境下编译,所以就想在 windows xp下面通过cygwin + arm-none-eabi-gcc 来编译 u-boot。
我从u-boot 官网上先了u-boot-2011.03 来移植,装了cygwin,又装了windows下比较流行的gnu arm gcc编译器 yagarto,本以为会很顺利,结果悲据了,一编译就出现如下现象:
Generating include/autoconf.mk
include/common.h:37:20: fatal error: config.h: No such file or directory
compilation terminated.
Generating include/autoconf.mk.dep
include/common.h:37:20: fatal error: config.h: No such file or directory
compilation terminated.
arm-none-eabi-gcc -DDO_DEPS_ONLY \
CONFIG_SYS_TEXT_BASE=0x0C100000 -I/cygdrive/e/svn/u-boot-2011/include -fno-built
in -ffreestanding -nostdinc
mi -msoft-float -Uarm -Wall -Wstrict-prototypes
lib/asm-offsets.c:18:20: fatal error: common.h: No such file or directory
compilation terminated.
Makefile:491: recipe for target `lib/asm-offsets.s' failed
make: *** [lib/asm-offsets.s] Error 1
提示找不到 config.h,common.h文件,好啦,我就到u-boot文件夹里面去找,结果是明明在那里。晕了。在网上找啊,找啊,查啊,才知道,是因为windows 文件路径表示方法和linux下面的不一样,因为u-boot是在linux正面编写和编译的。而我在windows下用的cygwin按理说是可以模拟出linux下面的运行环境的啊,为什么不行呢?关键就在这里,其实不是cygwin的错,而是所用编译器的问题,因为yagarto已经被编译成在windows下面不需要依赖于cygwin了,它自然就使用windows下面的路径,而u-boot里面的路径又都是unix下面的,所以就造成了编译时找不到文件路径的错误了。
In file included from /cygdrive/e/svn/u-boot-2011.03 /include/linux/compiler-gcc.h:87,
/cygdrive/e/svn/u-boot-2011.03/include/linux/compiler-gcc4.h:8:4: error: #error Your version of gcc miscompiles the __weak directive
/cygdrive/e/svn/u-boot-2011.03/config.mk:256: recipe for target `env_eeprom.o' failed
找到/include/linux/compiler-gcc4.h文件:
/* GCC 4.1.[01]miscompiles __weak */
#ifdef __KERNEL__
# if __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ <= 1
#
# endif
#endif
在网上找了一下,大家的说法是最新的2.6.29系列linux内核不支持4.1.1以下的版本,具体的没有研究过,不懂linux内核。不过也是的,就如介绍中的说法,u-boot就像一个linux的微内核一样,看来不是没有道理的。所以gg了,gnuarm-4.1.1版本是编不了新版的u-boot的。所以只能再换其他的编译器了。
http://www.oliverbehr.de/images/stories/projekte/GNU-ARM-Toolchain-WIN32-with-Cygwin-DLLs.7z
不知道怎么称乎它,只知道是自己编译出来的,不过要把bin文件夹里的cygwin的dll文件还有其他的一些文件全去掉才能正常编译。
当然,codeSourcery我也作了一些尝试,就是定义CYGPATH=cygpath,结果是可以编译了,链接的时候还是出错了。唉。
心里不甘心啊,所以我就照着这个上面http://www.oliverbehr.de/index.php?option=com_content&view=article&id=50:building-a-gnu-arm-toolchain&catid=39&Itemid=73
编译了属于自己的编译器,专门用来在cygwin下编译u-boot。如果有兴趣可以参考我上一篇:一步一步教你怎么编译GNU ARM GCC 交叉编译器 arm-none-eabi-gcc,你也可以编译属于你自己的gnu arm tools。
说了这么多,还没有说怎么编译u-boot,这个其实和linux下面的是一样的,以dave/B2板子为例:
(1)首先下载u-boot
你可以从http://www.denx.de/wiki/U-Boot/上面下载,上面有个FTP服务器ftp://ftp.denx.de/pub/u-boot/ 里面有所有的u-boot版本。
(2)安装cygwin 和cygwin下的Mingw
(3)写一个cygwin的简单的脚本
Build-uboot.bat
@ECHO OFF
SET CYGWIN_ROOT=d:\cygwin
SET LANG=C.UTF-8
SET ARM_GCC_ROOT=d:\gnuarm
SET CROSS_COMPILE=arm-elf-
SET COMPILER_BIN=%ARM_GCC_ROOT%\bin
SET PATH=%CYGWIN_ROOT%\bin;%COMPILER_BIN%;%PATH%
SET HOME=%~dp0
SET BUILD_DIR=./out
@bash --login -i
大概解释一下里面的两个变量:
1)SET ARM_GCC_ROOT=d:\gnuarm
2)SET CROSS_COMPILE=arm-elf-
(4)编译
把build-uboot.bat脚本放在u-boot-2011.03目录下,双击它,然后,分别输入:
>make B2_config
>make all
(5)错误解决
1)首先会出这个错
In file included from fdt_host.h:25:0,
../include/libfdt.h:126:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:162:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:163:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:164:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:165:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:166:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:167:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:168:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:169:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:170:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:171:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:390:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’
../include/libfdt.h:441:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
../include/libfdt.h:779:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
../include/libfdt.h:845:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
../include/libfdt.h:995:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
In file included from default_image.c:31:0:
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:359:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:369:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:370:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:371:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:372:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:373:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:374:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:375:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:382:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint8_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:383:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint8_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:384:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint8_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:385:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘uint8_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:387:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘char’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:392:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:408:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘ulong’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:413:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘uint32_t’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:417:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘ulong’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:427:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:428:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:429:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:430:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:431:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:432:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:433:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:440:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:441:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:442:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:443:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:445:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘void’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:459:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘int’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:463:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘int’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:467:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘int’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:471:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘int’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:549:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:551:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or
‘__attribute__’ before ‘int’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:565:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘ulong’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:577:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘ulong’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/include/image.h:590:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
__attribute__’ before ‘const’
default_image.c: In function ‘image_set_header’:
default_image.c:113:2: warning: implicit declaration of function ‘image_set_magic’
default_image.c:114:2: warning: implicit declaration of function ‘image_set_time’
default_image.c:115:2: warning: implicit declaration of function ‘image_set_size’
default_image.c:116:2: warning: implicit declaration of function ‘image_set_load’
default_image.c:117:2: warning: implicit declaration of function ‘image_set_ep’
default_image.c:118:2: warning: implicit declaration of function ‘image_set_dcrc’
default_image.c:119:2: warning: implicit declaration of function ‘image_set_os’
default_image.c:120:2: warning: implicit declaration of function ‘image_set_arch’
default_image.c:121:2: warning: implicit declaration of function ‘image_set_type’
default_image.c:122:2: warning: implicit declaration of function ‘image_set_comp’
default_image.c:124:2: warning: implicit declaration of function ‘image_set_name’
default_image.c:129:2: warning: implicit declaration of function ‘image_set_hcrc’
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/rules.mk:43: recipe for target `default_image.o' failed
make[1]: *** [default_image.o] Error 1
make[1]: Leaving directory `/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/tools'
Makefile:397: recipe for target `tools' failed
make: *** [tools] Error 2
找到出错的文件image.h,libfdt.h,将里面的inline改成__inline__即可。
这个错是因为在根目录下面的config.mk中启用了 -ansi,于是用了c89的标准,结果c89不支持 inline,所以出错
ifeq ($(HOSTOS),cygwin)
HOSTCFLAGS += -ansi
endif
也可以改成如下就可以了:
ifeq ($(HOSTOS),cygwin)
HOSTCFLAGS += -ansi
HOSTCFLAGS+= -std=c99
endif
2)接着会出这个错,这个其实是新版u-boot的bug
board.c: In function ‘__dram_init_banksize’:
board.c:233: error: ‘CONFIG_SYS_SDRAM_BASE’ undeclared (first use in this function)
board.c:233: error: (Each undeclared identifier is reported only once
board.c:233: error: for each function it appears in.)
board.c: In function ‘board_init_f’:
board.c:279: error: ‘CONFIG_SYS_INIT_SP_ADDR’ undeclared (first use in this function)
board.c:312: error: ‘CONFIG_SYS_SDRAM_BASE’ undeclared (first use in this function)
/cygdrive/e/svn/u-boot-2011.03a/u-boot-2011.03/config.mk:256: recipe for target
`board.o' failed
解决方法是在Include/configs/B2.h中定义下面两个宏:
#define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1
#define CONFIG_SYS_INIT_SP_ADDR 0x0c800000
好啦,到这里,等个20分钟,就会在u-boot根目录下生成u-boot.bin等文件,u-boot在windows下编译成功了