2014-05-14 14:14:38 +02:00
|
|
|
#!/bin/bash
|
2010-02-10 21:31:38 +01:00
|
|
|
#
|
|
|
|
# This file is part of the coreboot project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007-2010 coresystems GmbH
|
2012-11-26 23:33:09 +01:00
|
|
|
# Copyright (C) 2012 Google Inc
|
2010-02-10 21:31:38 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2010-03-16 02:17:19 +01:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
2010-02-10 21:31:38 +01:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2013-02-23 18:37:27 +01:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2010-02-10 21:31:38 +01:00
|
|
|
#
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
TMPFILE=""
|
2014-05-14 14:26:07 +02:00
|
|
|
XGCCPATH=${1:-"`pwd`/util/crossgcc/xgcc/bin/"}
|
2012-11-26 23:33:09 +01:00
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "ERROR: $*" >&2
|
|
|
|
exit 1
|
2010-02-10 21:31:38 +01:00
|
|
|
}
|
2009-08-12 17:00:51 +02:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
clean_up() {
|
|
|
|
if [ -n "$TMPFILE" ]; then
|
|
|
|
rm -f "$TMPFILE" "$TMPFILE.c" "$TMPFILE.o"
|
2009-08-12 17:00:51 +02:00
|
|
|
fi
|
2012-11-26 23:33:09 +01:00
|
|
|
}
|
2009-08-12 17:00:51 +02:00
|
|
|
|
2014-05-14 14:30:08 +02:00
|
|
|
# Create temporary file(s).
|
|
|
|
TMPFILE="$(mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz)"
|
|
|
|
touch "$TMPFILE"
|
|
|
|
trap clean_up EXIT
|
|
|
|
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
program_exists() {
|
|
|
|
type "$1" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2014-05-14 14:26:07 +02:00
|
|
|
|
|
|
|
if [ "$(${XGCCPATH}/iasl 2>/dev/null | grep -c ACPI)" -gt 0 ]; then
|
|
|
|
IASL=${XGCCPATH}iasl
|
|
|
|
elif [ "$(iasl 2>/dev/null | grep -c ACPI)" -gt 0 ]; then
|
|
|
|
IASL=iasl
|
|
|
|
else
|
2014-07-14 15:35:42 +02:00
|
|
|
die "no iasl found"
|
2014-05-14 14:26:07 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if program_exists gcc; then
|
|
|
|
HOSTCC=gcc
|
|
|
|
elif program_exists cc; then
|
|
|
|
HOSTCC=cc
|
|
|
|
else
|
2014-07-14 15:35:42 +02:00
|
|
|
die "no host compiler found"
|
2014-05-14 14:26:07 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
# platform agnostic and host tools
|
|
|
|
IASL:=${IASL}
|
|
|
|
HOSTCC:=${HOSTCC}
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
testcc() {
|
|
|
|
local tmp_c="$TMPFILE.c"
|
|
|
|
local tmp_o="$TMPFILE.o"
|
|
|
|
rm -f "$tmp_c" "$tmp_o"
|
2012-12-20 23:24:08 +01:00
|
|
|
echo "void _start(void) {}" >"$tmp_c"
|
2012-11-26 23:33:09 +01:00
|
|
|
"$1" -nostdlib -Werror $2 "$tmp_c" -o "$tmp_o" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
testas() {
|
2015-04-25 22:15:58 +02:00
|
|
|
local gccprefix="$1"
|
2012-11-26 23:33:09 +01:00
|
|
|
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"
|
2015-04-25 22:15:58 +02:00
|
|
|
${gccprefix}as $use_dash_twidth -o "$obj_file" $TMPFILE 2>/dev/null ||
|
2012-11-26 23:33:09 +01:00
|
|
|
return 1
|
|
|
|
|
|
|
|
# Check output content type.
|
2015-04-25 22:15:58 +02:00
|
|
|
local obj_type="$(${gccprefix}objdump -p $obj_file)"
|
2012-11-26 23:33:09 +01:00
|
|
|
local obj_arch="$(expr "$obj_type" : '.*format \(.[a-z0-9-]*\)')"
|
|
|
|
[ "$obj_arch" = "$full_arch" ] || return 1
|
|
|
|
|
|
|
|
# Architecture matched.
|
2015-04-25 22:15:58 +02:00
|
|
|
GCCPREFIX="$gccprefix"
|
2012-11-26 23:33:09 +01:00
|
|
|
|
|
|
|
if [ -z "$use_dash_twidth" ]; then
|
|
|
|
ASFLAGS=""
|
|
|
|
CFLAGS=""
|
|
|
|
LDFLAGS=""
|
|
|
|
else
|
|
|
|
ASFLAGS="--$twidth"
|
|
|
|
CFLAGS="-m$twidth"
|
|
|
|
LDFLAGS="-b $full_arch"
|
2012-02-22 19:46:17 +01:00
|
|
|
|
2009-08-12 17:00:51 +02:00
|
|
|
fi
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
# 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
|
2009-08-12 17:00:51 +02:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
return 0
|
|
|
|
}
|
2010-02-10 21:31:38 +01:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
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'
|
2010-02-10 21:31:38 +01:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
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
|
2014-05-14 14:28:21 +02:00
|
|
|
x86)
|
|
|
|
testcc "$CC" "$CFLAGS -Wa,--divide" &&
|
|
|
|
CFLAGS="$CFLAGS -Wa,--divide"
|
2013-10-10 19:44:11 +02:00
|
|
|
# Always build for i686 -- no sse/mmx instructions since SMM
|
|
|
|
# modules are compiled using these flags. Note that this
|
|
|
|
# doesn't prevent a project using xcompile to explicitly
|
|
|
|
# specify -mmsse, etc flags.
|
|
|
|
CFLAGS="$CFLAGS -march=i686"
|
2014-05-14 14:28:21 +02:00
|
|
|
;;
|
2014-08-30 01:00:37 +02:00
|
|
|
mipsel)
|
|
|
|
testcc "$CC" "$CFLAGS -mno-abicalls -fno-pic" && \
|
2015-04-25 22:15:58 +02:00
|
|
|
CFLAGS+=" -mno-abicalls -fno-pic"
|
2014-08-30 01:00:37 +02:00
|
|
|
;;
|
2012-11-26 23:33:09 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
report_arch_toolchain() {
|
|
|
|
cat <<EOF
|
2012-12-06 02:12:10 +01:00
|
|
|
# elf${TWIDTH}-${TBFDARCH} toolchain (${GCCPREFIX}gcc)
|
2014-07-10 20:38:21 +02:00
|
|
|
ARCH_SUPPORTED+=${TARCH}
|
2014-10-31 16:48:00 +01:00
|
|
|
SUBARCH_SUPPORTED+=${TSUPP-${TARCH}}
|
2014-05-17 15:08:47 +02:00
|
|
|
CC_${TARCH}:=${GCCPREFIX}gcc
|
|
|
|
CFLAGS_${TARCH}:=${CFLAGS}
|
2013-09-03 14:39:48 +02:00
|
|
|
CPP_${TARCH}:=${GCCPREFIX}cpp
|
2012-11-26 23:33:09 +01:00
|
|
|
AS_${TARCH}:=${GCCPREFIX}as ${ASFLAGS}
|
2013-03-23 01:35:56 +01:00
|
|
|
LD_${TARCH}:=${GCCPREFIX}ld${LINKER_SUFFIX} ${LDFLAGS}
|
2012-11-26 23:33:09 +01:00
|
|
|
NM_${TARCH}:=${GCCPREFIX}nm
|
|
|
|
OBJCOPY_${TARCH}:=${GCCPREFIX}objcopy
|
|
|
|
OBJDUMP_${TARCH}:=${GCCPREFIX}objdump
|
|
|
|
READELF_${TARCH}:=${GCCPREFIX}readelf
|
|
|
|
STRIP_${TARCH}:=${GCCPREFIX}strip
|
|
|
|
AR_${TARCH}:=${GCCPREFIX}ar
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:15:58 +02:00
|
|
|
# Architecture definitions
|
|
|
|
SUPPORTED_ARCHITECTURES="arm arm64 mipsel riscv x86"
|
2012-11-26 23:33:09 +01:00
|
|
|
|
ARM: Generalize armv7 as arm.
There are ARM systems which are essentially heterogeneous multicores where
some cores implement a different ARM architecture version than other cores. A
specific example is the tegra124 which boots on an ARMv4 coprocessor while
most code, including most of the firmware, runs on the main ARMv7 core. To
support SOCs like this, the plan is to generalize the ARM architecture so that
all versions are available, and an SOC/CPU can then select what architecture
variant should be used for each component of the firmware; bootblock,
romstage, and ramstage.
Old-Change-Id: I22e048c3bc72bd56371e14200942e436c1e312c2
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://chromium-review.googlesource.com/171338
Reviewed-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit 8423a41529da0ff67fb9873be1e2beb30b09ae2d)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
ARM: Split out ARMv7 code and make it possible to have other arch versions.
We don't always want to use ARMv7 code when building for ARM, so we should
separate out the ARMv7 code so it can be excluded, and also make it possible
to include code for some other version of the architecture instead, all per
build component for cases where we need more than one architecture version
at a time.
The tegra124 bootblock will ultimately need to be ARMv4, but until we have
some ARMv4 code to switch over to we can leave it set to ARMv7.
Old-Change-Id: Ia982c91057fac9c252397b7c866224f103761cc7
Reviewed-on: https://chromium-review.googlesource.com/171400
Reviewed-by: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit 799514e6060aa97acdcf081b5c48f965be134483)
Squashed two related patches for splitting ARM support into general
ARM support and ARMv7 specific pieces.
Change-Id: Ic6511507953a2223c87c55f90252c4a4e1dd6010
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6782
Tested-by: build bot (Jenkins)
2013-10-01 08:00:33 +02:00
|
|
|
arch_config_arm() {
|
|
|
|
TARCH="arm"
|
2014-08-28 00:30:19 +02:00
|
|
|
TBFDARCHS="littlearm"
|
2014-05-14 14:23:28 +02:00
|
|
|
TCLIST="armv7a armv7-a"
|
|
|
|
TWIDTH="32"
|
2014-10-21 20:18:20 +02:00
|
|
|
TSUPP="arm armv4 armv7 armv7_m"
|
2014-05-14 14:48:31 +02:00
|
|
|
TABI="eabi"
|
2014-05-14 14:23:28 +02:00
|
|
|
}
|
|
|
|
|
2015-01-16 21:19:04 +01:00
|
|
|
arch_config_arm64() {
|
|
|
|
TARCH="arm64"
|
2014-08-28 00:30:19 +02:00
|
|
|
TBFDARCHS="littleaarch64"
|
2014-05-14 14:23:28 +02:00
|
|
|
TCLIST="aarch64"
|
|
|
|
TWIDTH="64"
|
2015-02-17 11:11:55 +01:00
|
|
|
TSUPP="arm64 armv8_64"
|
2014-11-19 18:36:37 +01:00
|
|
|
TABI="elf"
|
2014-05-14 14:23:28 +02:00
|
|
|
}
|
|
|
|
|
2014-10-07 07:18:51 +02:00
|
|
|
arch_config_riscv() {
|
|
|
|
TARCH="riscv"
|
2014-08-28 00:30:19 +02:00
|
|
|
TBFDARCHS="littleriscv"
|
2014-10-07 07:18:51 +02:00
|
|
|
TCLIST="riscv"
|
|
|
|
TWIDTH="64"
|
|
|
|
TABI="elf"
|
|
|
|
}
|
|
|
|
|
2014-05-14 14:23:28 +02:00
|
|
|
arch_config_x86() {
|
2014-05-17 14:20:11 +02:00
|
|
|
TARCH="x86_32"
|
2014-08-28 00:30:19 +02:00
|
|
|
TBFDARCHS="i386"
|
2014-05-14 14:23:28 +02:00
|
|
|
TCLIST="i386 x86_64"
|
|
|
|
TWIDTH="32"
|
2014-05-14 14:48:31 +02:00
|
|
|
TABI="elf"
|
2014-05-14 14:23:28 +02:00
|
|
|
}
|
|
|
|
|
2014-05-27 16:18:42 +02:00
|
|
|
arch_config_mipsel() {
|
2015-03-28 15:49:46 +01:00
|
|
|
TARCH="mips"
|
2014-08-28 00:30:19 +02:00
|
|
|
TBFDARCHS="tradlittlemips littlemips"
|
2014-05-27 16:18:42 +02:00
|
|
|
TCLIST="mipsel"
|
|
|
|
TWIDTH="32"
|
2015-03-28 15:49:46 +01:00
|
|
|
TSUPP="mips mipsel"
|
2014-05-27 16:18:42 +02:00
|
|
|
TABI="elf"
|
|
|
|
}
|
|
|
|
|
2014-05-14 14:32:11 +02:00
|
|
|
test_architecture() {
|
2015-04-25 22:15:58 +02:00
|
|
|
local architecture=$1
|
|
|
|
local gccprefix search
|
2014-05-14 14:32:11 +02:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
GCCPREFIX="invalid"
|
2015-02-17 11:11:55 +01:00
|
|
|
unset TARCH TBFDARCH TCLIST TWIDTH TSUPP TABI
|
2014-05-14 14:23:28 +02:00
|
|
|
if type arch_config_$architecture > /dev/null; then
|
|
|
|
arch_config_$architecture
|
|
|
|
else
|
2014-07-14 15:35:42 +02:00
|
|
|
die "no architecture definition for $architecture"
|
2014-05-14 14:23:28 +02:00
|
|
|
fi
|
2012-11-26 23:33:09 +01:00
|
|
|
|
|
|
|
# To override toolchain, define CROSS_COMPILE_$arch or CROSS_COMPILE as
|
|
|
|
# environment variable.
|
|
|
|
# Ex: CROSS_COMPILE_arm="armv7a-cros-linux-gnueabi-"
|
|
|
|
# CROSS_COMPILE_x86="i686-pc-linux-gnu-"
|
|
|
|
search="$(eval echo \$CROSS_COMPILE_$architecture 2>/dev/null)"
|
|
|
|
search="$search $CROSS_COMPILE"
|
|
|
|
for toolchain in $TCLIST; do
|
2014-05-14 14:48:31 +02:00
|
|
|
search="$search $XGCCPATH$toolchain-$TABI-"
|
|
|
|
search="$search $toolchain-$TABI-"
|
2013-11-08 19:13:50 +01:00
|
|
|
search="$search $toolchain-linux-gnu-"
|
2014-10-07 07:18:51 +02:00
|
|
|
search="$search $toolchain-"
|
2012-11-26 23:33:09 +01:00
|
|
|
done
|
|
|
|
echo "# $architecture TARCH_SEARCH=$search"
|
|
|
|
|
|
|
|
# Search toolchain by checking assembler capability.
|
2014-08-28 00:30:19 +02:00
|
|
|
for TBFDARCH in $TBFDARCHS; do
|
2015-04-25 22:15:58 +02:00
|
|
|
for gccprefix in $search ""; do
|
|
|
|
program_exists "${gccprefix}as" || continue
|
|
|
|
testas "$gccprefix" "$TWIDTH" "$TBFDARCH" "" && break
|
|
|
|
testas "$gccprefix" "$TWIDTH" "$TBFDARCH" "TRUE" && break
|
2014-08-28 00:30:19 +02:00
|
|
|
done
|
|
|
|
[ "$GCCPREFIX" = "invalid" ] || break
|
2012-11-26 23:33:09 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$GCCPREFIX" = "invalid" ]; then
|
|
|
|
echo "Warning: no suitable GCC for $architecture." >&2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
CC="${GCCPREFIX}"gcc
|
|
|
|
|
|
|
|
detect_special_flags "$architecture"
|
|
|
|
report_arch_toolchain
|
2014-05-14 14:32:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# This loops over all supported architectures.
|
2015-04-25 22:15:58 +02:00
|
|
|
for architecture in $SUPPORTED_ARCHITECTURES; do
|
2014-05-14 14:32:11 +02:00
|
|
|
test_architecture $architecture
|
2012-11-26 23:33:09 +01:00
|
|
|
done
|