From 8af0d03fd49f9c88db98ef7b3c2d95bf1cd0f319 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Fri, 14 Dec 2012 13:05:21 -0800 Subject: libpayload: Initial ARMv7 port This compiles, but it's not tested yet. Change-Id: I2f73a814649aa36c39af3e77cefd8a968671f5c0 Signed-off-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/2035 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich --- payloads/libpayload/util/xcompile/xcompile | 239 +++++++++++++++++++++-------- 1 file changed, 176 insertions(+), 63 deletions(-) (limited to 'payloads/libpayload/util') diff --git a/payloads/libpayload/util/xcompile/xcompile b/payloads/libpayload/util/xcompile/xcompile index 5e9ce83f98..fdc521338d 100644 --- a/payloads/libpayload/util/xcompile/xcompile +++ b/payloads/libpayload/util/xcompile/xcompile @@ -3,6 +3,7 @@ # This file is part of the coreboot project. # # Copyright (C) 2007-2010 coresystems GmbH +# Copyright (C) 2012 Google Inc # # 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 @@ -18,86 +19,198 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # -testcc() -{ - echo "_start(void) {}" > .$$$$.c - $1 -nostdlib $2 .$$$$.c -o .$$$$.tmp 2>/dev/null >/dev/null - ret=$? - rm -f .$$$$.c .$$$$.tmp - return $ret +TMPFILE="" + +die() { + echo "ERROR: $*" >&2 + exit 1 } -for make in make gmake gnumake; do - if [ "`$make --version 2>/dev/null | grep -c GNU`" -gt 0 ]; then - MAKE=$make - break +clean_up() { + if [ -n "$TMPFILE" ]; then + rm -f "$TMPFILE" "$TMPFILE.c" "$TMPFILE.o" fi -done +} + +program_exists() { + type "$1" >/dev/null 2>&1 +} -GCCPREFIX=invalid -TMPFILE=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz` -touch $TMPFILE +testcc() { + local tmp_c="$TMPFILE.c" + local tmp_o="$TMPFILE.o" + rm -f "$tmp_c" "$tmp_o" + echo "_start(void) {}" >"$tmp_c" + "$1" -nostdlib -Werror $2 "$tmp_c" -o "$tmp_o" >/dev/null 2>&1 +} + +testas() { + local gccprefixes="$1" + local twidth="$2" + local arch="$3" + local use_dash_twidth="$4" + local obj_file="$TMPFILE.o" + local full_arch="elf$twidth-$arch" + + rm -f "$obj_file" + [ -n "$use_dash_twidth" ] && use_dash_twidth="--$twidth" + ${gccprefixes}as $use_dash_twidth -o "$obj_file" $TMPFILE 2>/dev/null || + return 1 + + # Check output content type. + local obj_type="$(${gccprefixes}objdump -p $obj_file)" + local obj_arch="$(expr "$obj_type" : '.*format \(.[a-z0-9-]*\)')" + [ "$obj_arch" = "$full_arch" ] || return 1 + + # Architecture matched. + GCCPREFIX="$gccprefixes" + + if [ -z "$use_dash_twidth" ]; then + ASFLAGS="" + CFLAGS="" + LDFLAGS="" + else + ASFLAGS="--$twidth" + CFLAGS="-m$twidth" + LDFLAGS="-b $full_arch" -# 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 - if ! which ${gccprefixes}as 2>/dev/null >/dev/null; then - continue - fi - rm -f ${TMPFILE}.o - if ${gccprefixes}as -o ${TMPFILE}.o ${TMPFILE}; then - TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o` - if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then - GCCPREFIX=$gccprefixes - ASFLAGS= - CFLAGS= - LDFLAGS= - break - fi fi - if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then - TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o` - if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then - GCCPREFIX=$gccprefixes - ASFLAGS=--32 - CFLAGS="-m32 " - LDFLAGS="-b elf32-i386" - break - fi + + # Special parameters only available in dash_twidth mode. + [ -n "$use_dash_twidth" ] && case "$full_arch" in + "elf32-i386" ) + LDFLAGS="$LDFLAGS -melf_i386" + CFLAGS="$CFLAGS -Wl,-b,elf32-i386 -Wl,-melf_i386" + ;; + esac + + return 0 +} + +detect_special_flags() { + local architecture="$1" + # GCC 4.6 is much more picky about unused variables. + # Turn off it's warnings for now: + testcc "$CC" "$CFLAGS -Wno-unused-but-set-variable " && + CFLAGS="$CFLAGS -Wno-unused-but-set-variable " + + # Use bfd linker instead of gold if available: + testcc "$CC" "$CFLAGS -fuse-ld=bfd" && + CFLAGS="$CFLAGS -fuse-ld=bfd" && LINKER_SUFFIX='.bfd' + + 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" + + case "$architecture" in + arm ) + # testcc "$CC" "$CFLAGS -mcpu=cortex-a9" && + # CFLAGS="$CFLAGS -mcpu=cortex-a9" + testcc "$CC" "\ +$CFLAGS -ffixed-r8 -msoft-float -marm -mabi=aapcs-linux \ +-mno-thumb-interwork -march=armv7 -mno-thumb-interwork" && CFLAGS="\ +$CFLAGS -ffixed-r8 -msoft-float -marm -mabi=aapcs-linux \ +-mno-thumb-interwork -march=armv7 -mno-thumb-interwork" + ;; + esac +} + +report_arch_toolchain() { + cat <&2 + continue fi + CC="${GCCPREFIX}"gcc + + detect_special_flags "$architecture" + report_arch_toolchain done -rm -f $TMPFILE ${TMPFILE}.o -if [ "$GCCPREFIX" = "invalid" ]; then - echo '$(error no suitable gcc found)' - exit 1 +if [ "$(${XGCCPATH}/iasl 2>/dev/null | grep -c ACPI)" -gt 0 ]; then + IASL=${XGCCPATH}iasl +else + IASL=iasl 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 +if program_exists gcc; then HOSTCC=gcc else HOSTCC=cc fi -cat << EOF -# elf${TWIDTH}-${TARCH} toolchain -AS:=${GCCPREFIX}as ${ASFLAGS} -CC:=${GCCPREFIX}gcc ${CFLAGS} -CPP:=${GCCPREFIX}cpp -AR:=${GCCPREFIX}ar -LD:=${GCCPREFIX}ld ${LDFLAGS} -STRIP:=${GCCPREFIX}strip -NM:=${GCCPREFIX}nm -OBJCOPY:=${GCCPREFIX}objcopy -OBJDUMP:=${GCCPREFIX}objdump +cat <