Patchwork add arm toolchain support

login
register
about
Submitter Hamo
Date 2011-05-23 12:14:46
Message ID <BANLkTinYiyHCcNr-ih8CM3oLgHEAWXksug@mail.gmail.com>
Download mbox | patch
Permalink /patch/2984/
State New
Headers show

Comments

Hamo - 2011-05-23 12:14:46
This patch added arm toolchain support for coreboot building system.

xcompile will find the different toolchain for X86 and ARM
architectures and when
we decided the target architecture using `make menuconfig` or so, makefile will
choose the right toolchain.

Signed-off-by: Yang Bai <hamo.by@gmail.com>
Marc Jones - 2011-05-23 19:54:06
Hi Hamo,

Thanks for the patch. I know you need this for your ARM development,
but we should wait for an ARM target before committing this.

This fundamentally changes how .xcompile is used and included by
coreboot. I think that I would prefer that the xcompile script accept
a flag for using the ARM toolchain over the x86 tools and still set
the compiler variables.

Marc


On Mon, May 23, 2011 at 6:14 AM, Hamo <hamo.by@gmail.com> wrote:
> This patch added arm toolchain support for coreboot building system.
>
> xcompile will find the different toolchain for X86 and ARM
> architectures and when
> we decided the target architecture using `make menuconfig` or so, makefile will
> choose the right toolchain.
>
> Signed-off-by: Yang Bai <hamo.by@gmail.com>
...

> -       if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then
> -               TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
> +       if [ ${TARCH} == "i386" ]; then
> +           if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then
> +               TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o | grep "file format"`
>                if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
> -                       GCCPREFIX=$gccprefixes
> -                       ASFLAGS=--32
> -                       CFLAGS="-m32 "
> -                       LDFLAGS="-b elf32-i386"
> -                       break
> +                   GCCPREFIX=$gccprefixes
> +                   ASFLAGS=--32
> +                   CFLAGS="-m32 "
> +                   LDFLAGS="-b elf32-i386"
> +                   break
>                fi
> +           fi
>        fi
> -done
> -rm -f $TMPFILE ${TMPFILE}.o
> +    done
> +    rm -f $TMPFILE ${TMPFILE}.o
>

Be careful with whitespace changes. Try not to put to many in with
code changes.

> -if [ "$GCCPREFIX" = "invalid" ]; then
> -       echo '$(error no suitable gcc found)'
> -       exit 1
> -fi
> -
> -CC="${GCCPREFIX}gcc"
> -testcc "$CC" "$CFLAGS-Wa,--divide " && CFLAGS="$CFLAGS-Wa,--divide "
> -testcc "$CC" "$CFLAGS-fno-stack-protector " &&
> CFLAGS="$CFLAGS-fno-stack-protector "
> -testcc "$CC" "$CFLAGS-Wl,--build-id=none " &&
> CFLAGS="$CFLAGS-Wl,--build-id=none "
> -
> -if which gcc 2>/dev/null >/dev/null; then
> -       HOSTCC=gcc
> -else
> -       HOSTCC=cc
> -fi
> -
> -cat << EOF
> +    if [ "$GCCPREFIX" != "invalid" ]; then
> +       CC="${GCCPREFIX}gcc"
> +       testcc "$CC" "$CFLAGS-Wa,--divide " && CFLAGS="$CFLAGS-Wa,--divide "
> +       testcc "$CC" "$CFLAGS-fno-stack-protector " &&
> CFLAGS="$CFLAGS-fno-stack-protector "
> +       testcc "$CC" "$CFLAGS-Wl,--build-id=none " &&
> CFLAGS="$CFLAGS-Wl,--build-id=none "
> +       cat << EOF
>  # elf${TWIDTH}-${TARCH} toolchain
> -AS:=${GCCPREFIX}as ${ASFLAGS}
> -CC:=${GCCPREFIX}gcc ${CFLAGS}
> -AR:=${GCCPREFIX}ar
> -LD:=${GCCPREFIX}ld ${LDFLAGS}
> -STRIP:=${GCCPREFIX}strip
> -NM:=${GCCPREFIX}nm
> -OBJCOPY:=${GCCPREFIX}objcopy
> -OBJDUMP:=${GCCPREFIX}objdump
> -
> -# native toolchain
> -HOSTCC:=${HOSTCC}
> +AS_${TARCH}:=${GCCPREFIX}as ${ASFLAGS}
> +CC_${TARCH}:=${GCCPREFIX}gcc ${CFLAGS}
> +AR_${TARCH}:=${GCCPREFIX}ar
> +LD_${TARCH}:=${GCCPREFIX}ld ${LDFLAGS}
> +STRIP_${TARCH}:=${GCCPREFIX}strip
> +NM_${TARCH}:=${GCCPREFIX}nm
> +OBJCOPY_${TARCH}:=${GCCPREFIX}objcopy
> +OBJDUMP_${TARCH}:=${GCCPREFIX}objdump
>  EOF
> +   else
> +       cat <<EOF
> +# elf${TWIDTH}-${TARCH} toolchain
> +NO_${TARCH}_TOOLCHAIN:=1
> +EOF
> +    fi
>
> +unset AS CC AR LD STRIP NM OBJCOPY OBJDUMP GCCPREFIX ASFLAGS CFLAGS
> LDFLAGS CARCH
> +
> +done



> Index: Makefile
> ===================================================================
> --- Makefile    (revision 6567)
> +++ Makefile    (working copy)
> @@ -101,7 +101,42 @@
>
>  include $(HAVE_DOTCONFIG)
>
> +# Set the toolchain variables
> +# FOR X86
> +ifeq ($(CONFIG_ARCH_X86),y)
> +ifeq ($(NO_i386_TOOLCHAIN),1)
> +$(error No suitable gcc for X86 found)
> +else
>  ifneq ($(INNER_SCANBUILD),y)
> +CC:=$(CC_i386)
> +endif
> +AS:=$(AS_i386)
> +AR:=$(AR_i386)
> +LD:=$(LD_i386)
> +STRIP:=$(STRIP_i386)
> +NM:=$(NM_i386)
> +OBJCOPY:=$(OBJCOPY_i386)
> +OBJDUMP:=$(OBJDUMP_i386)
> +endif
> +endif
> +
> +# FOR ARM
> +ifeq ($(CONFIG_ARCH_ARM),y)
> +ifeq ($(NO_littlearm_TOOLCHAIN),1)
> +$(error No suitable gcc for ARM found)
> +else
> +CC:=$(CC_littlearm)
> +AS:=$(AS_littlearm)
> +AR:=$(AR_littlearm)
> +LD:=$(LD_littlearm)
> +STRIP:=$(STRIP_littlearm)
> +NM:=$(NM_littlearm)
> +OBJCOPY:=$(OBJCOPY_littlearm)
> +OBJDUMP:=$(OBJDUMP_littlearm)
> +endif
> +endif
> +
> +ifneq ($(INNER_SCANBUILD),y)
>  ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
>  CC:=clang -m32
>  HOSTCC:=clang

I think that these makefile changes shouldn't be needed as long as
coreboot is including the correct settings from the .xcompile file.

Marc
Patrick Georgi - 2011-05-25 13:14:38
Am 23.05.2011 14:14, schrieb Hamo:
> +ifeq ($(CONFIG_ARCH_X86),y)
> +ifeq ($(NO_i386_TOOLCHAIN),1)
> +$(error No suitable gcc for X86 found)
> +else
>  ifneq ($(INNER_SCANBUILD),y)
> +CC:=$(CC_i386)
> +endif
> +AS:=$(AS_i386)
> +AR:=$(AR_i386)
> +LD:=$(LD_i386)
That could be implemented somewhat more generic by using nested variable
expansion:

CC:=$(CC_$(CONFIG_ARCH))

and have Kconfig select the right ARCH value depending on the other
booleans:

config ARCH
     string
     default X86 if ARCH_X86
     default ARM if ARCH_ARM

And the test for "suitable toolchain found" can be generalized by
testing for _some_ value in $(CC) after the assignements happened:

ifeq ($(CC),)
$(error no toolchain for architecture '$(CONFIG_ARCH)' found)
endif


Patrick
Patrick Georgi - 2011-05-25 13:16:40
Am 23.05.2011 21:54, schrieb Marc Jones:
> This fundamentally changes how .xcompile is used and included by
> coreboot. I think that I would prefer that the xcompile script accept
> a flag for using the ARM toolchain over the x86 tools and still set
> the compiler variables.
We create .xcompile much earlier than the decision which toolchain is
necessary for the current build.

In case full abuild runs (see buildbot) that could be a single
invocation of util/xcompile/xcompile when configuring for the first
board, after which .xcompile is reused for all others.

It would be much more intrusive to change the way we create .xcompile
than what Hamo does here.


Patrick
Hamo - 2011-05-25 14:37:06
Hi Marc,
I am working on porting coreboot to qemu-arm (versatilepb) mainboard,
and after I finish it, we can commit it together with this patch. But
now, the most important thing is changing the CBFS structure.

On Tue, May 24, 2011 at 3:54 AM, Marc Jones <marcj303@gmail.com> wrote:
> Hi Hamo,
>
> Thanks for the patch. I know you need this for your ARM development,
> but we should wait for an ARM target before committing this.
>
> This fundamentally changes how .xcompile is used and included by
> coreboot. I think that I would prefer that the xcompile script accept
> a flag for using the ARM toolchain over the x86 tools and still set
> the compiler variables.
>
> Marc
>
>
>
> Be careful with whitespace changes. Try not to put to many in with
> code changes.

Thanks. I will care about it next time.
>
>
> I think that these makefile changes shouldn't be needed as long as
> coreboot is including the correct settings from the .xcompile file.
>
makefile uses CC(AS, LD and others) as the default compiler, but now,
xcompile generated CC_ARCH. So we need to bind the right CC_ARCH
variable(and others of cause) to CC.
> Marc
> --
> http://se-eng.com
>
Marc Jones - 2011-05-25 17:14:37
On Wed, May 25, 2011 at 7:16 AM, Patrick Georgi <patrick@georgi-clan.de> wrote:
> Am 23.05.2011 21:54, schrieb Marc Jones:
>> This fundamentally changes how .xcompile is used and included by
>> coreboot. I think that I would prefer that the xcompile script accept
>> a flag for using the ARM toolchain over the x86 tools and still set
>> the compiler variables.
> We create .xcompile much earlier than the decision which toolchain is
> necessary for the current build.
>
> In case full abuild runs (see buildbot) that could be a single
> invocation of util/xcompile/xcompile when configuring for the first
> board, after which .xcompile is reused for all others.
>
> It would be much more intrusive to change the way we create .xcompile
> than what Hamo does here.
>

I see. I didn't think about abuild.

Marc

Patch

Index: src/Kconfig
===================================================================
--- src/Kconfig	(revision 6567)
+++ src/Kconfig	(working copy)
@@ -116,10 +116,19 @@ 
 	bool
 	default n

+# This option is used to set the architecture of a mainboard to ARM.
+config ARCH_ARM
+        bool
+	default n
+
 if ARCH_X86
 source src/arch/x86/Kconfig
 endif

+if ARCH_ARM
+source src/arch/arm/Kconfig
+endif
+
 menu "Chipset"

 comment "CPU"
Index: src/arch/arm/Kconfig
===================================================================
--- src/arch/arm/Kconfig	(revision 0)
+++ src/arch/arm/Kconfig	(revision 0)
@@ -0,0 +1,3 @@ 
+menu "Architecture (ARM)"
+
+endmenu
Index: util/xcompile/xcompile
===================================================================
--- util/xcompile/xcompile	(revision 6567)
+++ util/xcompile/xcompile	(working copy)
@@ -3,6 +3,7 @@ 
 # This file is part of the coreboot project.
 #
 # Copyright (C) 2007-2010 coresystems GmbH
+# Copyright (C) 2011 Yang Bai <hamo.by@gmail.com>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -34,20 +35,27 @@ 
 	fi
 done

-GCCPREFIX=invalid
-TMPFILE=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
-touch $TMPFILE
+TWIDTH=32
+for TARCH in i386 littlearm; do

-# This should be a loop over all supported architectures
-TARCH=i386
-TWIDTH=32
-for gccprefixes in `pwd`/util/crossgcc/xgcc/bin/${TARCH}-elf-
${TARCH}-elf- ""; do
+    GCCPREFIX=invalid
+
+    if [ ${TARCH} == "i386" ]; then
+	CARCH=${TARCH}-elf
+    elif [ ${TARCH} == "littlearm" ]; then
+	CARCH=arm-none-eabi
+    fi
+
+    TMPFILE=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
+    touch $TMPFILE
+
+    for gccprefixes in `pwd`/util/crossgcc/xgcc/bin/${CARCH}- ${CARCH}- ""; do
 	if ! which ${gccprefixes}as 2>/dev/null >/dev/null; then
-		continue
+	    continue
 	fi
 	rm -f ${TMPFILE}.o
 	if ${gccprefixes}as -o ${TMPFILE}.o ${TMPFILE}; then
-		TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
+		TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o | grep "file format"`
 		if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
 			GCCPREFIX=$gccprefixes
 			ASFLAGS=
@@ -56,47 +64,44 @@ 
 			break
 		fi
 	fi
-	if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then
-		TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
+	if [ ${TARCH} == "i386" ]; then
+	    if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then
+		TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o | grep "file format"`
 		if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
-			GCCPREFIX=$gccprefixes
-			ASFLAGS=--32
-			CFLAGS="-m32 "
-			LDFLAGS="-b elf32-i386"
-			break
+		    GCCPREFIX=$gccprefixes
+		    ASFLAGS=--32
+		    CFLAGS="-m32 "
+		    LDFLAGS="-b elf32-i386"
+		    break
 		fi
+	    fi
 	fi
-done
-rm -f $TMPFILE ${TMPFILE}.o
+    done
+    rm -f $TMPFILE ${TMPFILE}.o

-if [ "$GCCPREFIX" = "invalid" ]; then
-	echo '$(error no suitable gcc found)'
-	exit 1
-fi
-
-CC="${GCCPREFIX}gcc"
-testcc "$CC" "$CFLAGS-Wa,--divide " && CFLAGS="$CFLAGS-Wa,--divide "
-testcc "$CC" "$CFLAGS-fno-stack-protector " &&
CFLAGS="$CFLAGS-fno-stack-protector "
-testcc "$CC" "$CFLAGS-Wl,--build-id=none " &&
CFLAGS="$CFLAGS-Wl,--build-id=none "
-
-if which gcc 2>/dev/null >/dev/null; then
-	HOSTCC=gcc
-else
-	HOSTCC=cc
-fi
-
-cat << EOF
+    if [ "$GCCPREFIX" != "invalid" ]; then
+	CC="${GCCPREFIX}gcc"
+	testcc "$CC" "$CFLAGS-Wa,--divide " && CFLAGS="$CFLAGS-Wa,--divide "
+	testcc "$CC" "$CFLAGS-fno-stack-protector " &&
CFLAGS="$CFLAGS-fno-stack-protector "
+	testcc "$CC" "$CFLAGS-Wl,--build-id=none " &&
CFLAGS="$CFLAGS-Wl,--build-id=none "
+	cat << EOF
 # elf${TWIDTH}-${TARCH} toolchain
-AS:=${GCCPREFIX}as ${ASFLAGS}
-CC:=${GCCPREFIX}gcc ${CFLAGS}
-AR:=${GCCPREFIX}ar
-LD:=${GCCPREFIX}ld ${LDFLAGS}
-STRIP:=${GCCPREFIX}strip
-NM:=${GCCPREFIX}nm
-OBJCOPY:=${GCCPREFIX}objcopy
-OBJDUMP:=${GCCPREFIX}objdump
-
-# native toolchain
-HOSTCC:=${HOSTCC}
+AS_${TARCH}:=${GCCPREFIX}as ${ASFLAGS}
+CC_${TARCH}:=${GCCPREFIX}gcc ${CFLAGS}
+AR_${TARCH}:=${GCCPREFIX}ar
+LD_${TARCH}:=${GCCPREFIX}ld ${LDFLAGS}
+STRIP_${TARCH}:=${GCCPREFIX}strip
+NM_${TARCH}:=${GCCPREFIX}nm
+OBJCOPY_${TARCH}:=${GCCPREFIX}objcopy
+OBJDUMP_${TARCH}:=${GCCPREFIX}objdump
 EOF
+   else
+	cat <<EOF
+# elf${TWIDTH}-${TARCH} toolchain
+NO_${TARCH}_TOOLCHAIN:=1
+EOF
+    fi

+unset AS CC AR LD STRIP NM OBJCOPY OBJDUMP GCCPREFIX ASFLAGS CFLAGS
LDFLAGS CARCH
+
+done
Index: Makefile
===================================================================
--- Makefile	(revision 6567)
+++ Makefile	(working copy)
@@ -101,7 +101,42 @@ 

 include $(HAVE_DOTCONFIG)

+# Set the toolchain variables
+# FOR X86
+ifeq ($(CONFIG_ARCH_X86),y)
+ifeq ($(NO_i386_TOOLCHAIN),1)
+$(error No suitable gcc for X86 found)
+else
 ifneq ($(INNER_SCANBUILD),y)
+CC:=$(CC_i386)
+endif
+AS:=$(AS_i386)
+AR:=$(AR_i386)
+LD:=$(LD_i386)
+STRIP:=$(STRIP_i386)
+NM:=$(NM_i386)
+OBJCOPY:=$(OBJCOPY_i386)
+OBJDUMP:=$(OBJDUMP_i386)
+endif
+endif
+
+# FOR ARM
+ifeq ($(CONFIG_ARCH_ARM),y)
+ifeq ($(NO_littlearm_TOOLCHAIN),1)
+$(error No suitable gcc for ARM found)
+else
+CC:=$(CC_littlearm)
+AS:=$(AS_littlearm)
+AR:=$(AR_littlearm)
+LD:=$(LD_littlearm)
+STRIP:=$(STRIP_littlearm)
+NM:=$(NM_littlearm)
+OBJCOPY:=$(OBJCOPY_littlearm)
+OBJDUMP:=$(OBJDUMP_littlearm)
+endif
+endif
+
+ifneq ($(INNER_SCANBUILD),y)
 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
 CC:=clang -m32
 HOSTCC:=clang