如何在windows下面编译u-boot (原发于:2012-07-24 23:16:59)

如何在windows下面编译u-boot

By semilog    2012-7-22

最近想移植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,本以为会很顺利,结果悲据了,一编译就出现如下现象:

 $ make all

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 \

        -g  -Os   -fno-common -ffixed-r8 -msoft-float            -D__KERNEL__ -D

CONFIG_SYS_TEXT_BASE=0x0C100000 -I/cygdrive/e/svn/u-boot-2011/include -fno-built

in -ffreestanding -nostdinc      -isystem d:/yagarto/bin/../lib/gcc/arm-none-eabi/4.7.1/include -pipe  -DCONFIG_ARM -D__ARM__         -march=armv4 -mtune=arm7td

mi -msoft-float -Uarm -Wall -Wstrict-prototypes    \

        -o lib/asm-offsets.s lib/asm-offsets.c -c -S

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.hcommon.h文件,好啦,我就到u-boot文件夹里面去找,结果是明明在那里。晕了。在网上找啊,找啊,查啊,才知道,是因为windows 文件路径表示方法和linux下面的不一样,因为u-boot是在linux正面编写和编译的。而我在windows下用的cygwin按理说是可以模拟出linux下面的运行环境的啊,为什么不行呢?关键就在这里,其实不是cygwin的错,而是所用编译器的问题,因为yagarto已经被编译成在windows下面不需要依赖于cygwin了,它自然就使用windows下面的路径,而u-boot里面的路径又都是unix下面的,所以就造成了编译时找不到文件路径的错误了。

         所以解决的方法简单啦,就是找到可以在windows下编译的arm gcc编译器。找来找去发现只找到两个地方有,一个就是gnuarm,网址 http://www.gnuarm.com/,它在windows下的版本是依赖于cygwin的,但是又有一个很坑爹的地方,它的版本,我能找到的是gnuarm4.1.1,而在,虽然在http://www2.amontec.com/gnuarm/上面存在着gnuarm4.2.0,但是下载下来根本就运行不了,而在http://www.gnuarm.org/ 上面虽然曾经存在过gnuarm4.3.2,但是这个网址已不存在了,所以gnuarm4.3.2也就无从找起了。关键的问题是,你用gnuarm4.1.1编译老版本的u-boot是可以的,没有问题,但是在编译新版本的u-boot时,比如我用的u-boot-2011.03,会出现下面的错误:

In file included from /cygdrive/e/svn/u-boot-2011.03 /include/linux/compiler-gcc.h:87,

                 from /cygdrive/e/svn/u-boot-2011_test/include/linux/compiler.h:40,

                 from env_eeprom.c:36:

/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

#  error Your version of gcc miscompiles the __weak directive

# endif

#endif

在网上找了一下,大家的说法是最新的2.6.29系列linux内核不支持4.1.1以下的版本,具体的没有研究过,不懂linux内核。不过也是的,就如介绍中的说法,u-boot就像一个linux的微内核一样,看来不是没有道理的。所以gg了,gnuarm-4.1.1版本是编不了新版的u-boot的。所以只能再换其他的编译器了。

       然后,我就在网上找啊,试啊,先后试过yagartodevkitARMWinARMLinarocodeSourcerySysGCC gcc-arm-embedded,都不行,最后找到一个:

http://www.oliverbehr.de/images/stories/projekte/GNU-ARM-Toolchain-WIN32-with-Cygwin-DLLs.7z

不知道怎么称乎它,只知道是自己编译出来的,不过要把bin文件夹里的cygwindll文件还有其他的一些文件全去掉才能正常编译。

当然,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

     这个很重要,直接装最新版的cygwin,要不然不能安其他软件,一定要装cygwin下面的Mingw,千万不要安装windows下单独运行的Mingw,那样会导致windows路径和linux下的路径差别,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

大概解释一下里面的两个变量:

1SET ARM_GCC_ROOT=d:\gnuarm

         这个就是你的gnu arm gcc 编译器所在路径

2SET CROSS_COMPILE=arm-elf-

         这个很重要,u-boot要用到这个变量,在/arch/arm/config.mk里面定义,要改成对应的arm编译器如arm-none-eabi-

4)编译

build-uboot.bat脚本放在u-boot-2011.03目录下,双击它,然后,分别输入:

>make B2_config

>make all

5)错误解决

1)首先会出这个错

In file included from fdt_host.h:25:0,

                 from mkimage.h:35,

                 from default_image.c:30:

../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

 __attribute__’ before ‘int’

/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.hlibfdt.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-bootbug

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-bootwindows下编译成功了

你可能感兴趣的:(GNU编译器,makefile,bootloader)