blob: 408ca71bbc40a4e08fcf25ab64261f344d749b3c [file] [log] [blame]
Jonathan A. Kollaschfb6f78e2015-07-06 08:22:45 -05001#!/usr/bin/env bash
Patrick Georgie82f4752010-02-10 20:31:38 +00002#
3# This file is part of the coreboot project.
4#
5# Copyright (C) 2007-2010 coresystems GmbH
Ronald G. Minniche820e5c2012-11-26 14:33:09 -08006# Copyright (C) 2012 Google Inc
Timothy Pearson82657ca2016-03-09 17:20:26 -06007# Copyright (C) 2016 Raptor Engineering, LLC
Patrick Georgie82f4752010-02-10 20:31:38 +00008#
9# This program is free software; you can redistribute it and/or modify
Patrick Georgi23d89cc2010-03-16 01:17:19 +000010# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; version 2 of the License.
Patrick Georgie82f4752010-02-10 20:31:38 +000012#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
Patrick Georgie82f4752010-02-10 20:31:38 +000018
Martin Rothd08eb062016-01-19 08:50:23 -070019# Usage: [--debug] [path to xgcc/bin directory]
20
21# Enable debug output
22if [ "$1" = "--debug" ]; then
23 shift
24 set -x
25fi
26
Ronald G. Minniche820e5c2012-11-26 14:33:09 -080027TMPFILE=""
Paul Kocialkowski15dd6c22015-08-03 16:46:29 +020028XGCCPATH=$1
29
Stefan Reinauere0383d22016-04-15 15:27:05 -070030# payloads under payloads/external crossgcc path
31if [ -d "$(pwd)/../../../../util/crossgcc/xgcc/bin/" ]
32then
33 XGCCPATH=${XGCCPATH:-"$(pwd)/../../../../util/crossgcc/xgcc/bin/"}
34fi
35
Paul Kocialkowski15dd6c22015-08-03 16:46:29 +020036# libpayload crossgcc path
Martin Roth033abe52016-01-05 15:44:02 -070037if [ -d "$(pwd)/../../util/crossgcc/xgcc/bin/" ]
Paul Kocialkowski15dd6c22015-08-03 16:46:29 +020038then
Martin Roth033abe52016-01-05 15:44:02 -070039 XGCCPATH=${XGCCPATH:-"$(pwd)/../../util/crossgcc/xgcc/bin/"}
Paul Kocialkowski15dd6c22015-08-03 16:46:29 +020040fi
41
42# coreboot crossgcc path
Martin Roth033abe52016-01-05 15:44:02 -070043if [ -d "$(pwd)/util/crossgcc/xgcc/bin/" ]
Paul Kocialkowski15dd6c22015-08-03 16:46:29 +020044then
Martin Roth033abe52016-01-05 15:44:02 -070045 XGCCPATH=${XGCCPATH:-"$(pwd)/util/crossgcc/xgcc/bin/"}
Paul Kocialkowski15dd6c22015-08-03 16:46:29 +020046fi
Ronald G. Minniche820e5c2012-11-26 14:33:09 -080047
48die() {
49 echo "ERROR: $*" >&2
50 exit 1
Patrick Georgie82f4752010-02-10 20:31:38 +000051}
Patrick Georgi0588d192009-08-12 15:00:51 +000052
Ronald G. Minniche820e5c2012-11-26 14:33:09 -080053clean_up() {
54 if [ -n "$TMPFILE" ]; then
55 rm -f "$TMPFILE" "$TMPFILE.c" "$TMPFILE.o"
Patrick Georgi0588d192009-08-12 15:00:51 +000056 fi
Ronald G. Minniche820e5c2012-11-26 14:33:09 -080057}
Patrick Georgi0588d192009-08-12 15:00:51 +000058
Patrick Georgiadc24132014-05-14 14:30:08 +020059trap clean_up EXIT
60
61
Ronald G. Minniche820e5c2012-11-26 14:33:09 -080062program_exists() {
63 type "$1" >/dev/null 2>&1
64}
Patrick Georgie82f4752010-02-10 20:31:38 +000065
Patrick Georgi004295d2014-05-14 14:26:07 +020066
Martin Roth2ba837d2016-01-05 15:55:44 -070067if [ "$("${XGCCPATH}/iasl" 2>/dev/null | grep -c ACPI)" -gt 0 ]; then
Patrick Georgi004295d2014-05-14 14:26:07 +020068 IASL=${XGCCPATH}iasl
69elif [ "$(iasl 2>/dev/null | grep -c ACPI)" -gt 0 ]; then
70 IASL=iasl
Patrick Georgi004295d2014-05-14 14:26:07 +020071fi
72
73if program_exists gcc; then
74 HOSTCC=gcc
75elif program_exists cc; then
76 HOSTCC=cc
77else
Daniele Forsi3bb0b722014-07-14 15:35:42 +020078 die "no host compiler found"
Patrick Georgi004295d2014-05-14 14:26:07 +020079fi
80
Martin Roth517d4a62016-01-13 20:52:44 -070081# try to find the core count using various methods
82CORES="$(getconf _NPROCESSORS_ONLN 2>/dev/null)"
83if [ -z "$CORES" ]; then
84 NPROC=$(command -v nproc)
85 if [ -n "$NPROC" ]; then
86 CORES="$($NPROC)"
87 fi
88fi
89if [ -z "$CORES" ]; then
90 SYSCTL=$(command -v sysctl)
91 if [ -n "$SYSCTL" ]; then
92 CORES="$(${SYSCTL} -n hw.ncpu 2>/dev/null)"
93 fi
94fi
95if [ -z "$CORES" ] && [ -f /proc/cpuinfo ]; then
96 CORES="$(grep 'processor' /proc/cpuinfo 2>/dev/null | wc -l)"
97fi
98
Patrick Georgi004295d2014-05-14 14:26:07 +020099cat <<EOF
100# platform agnostic and host tools
101IASL:=${IASL}
Paul Menzele9b7e252015-04-09 18:15:09 +0200102HOSTCC?=${HOSTCC}
Martin Roth517d4a62016-01-13 20:52:44 -0700103CPUS?=${CORES}
Patrick Georgi004295d2014-05-14 14:26:07 +0200104
105EOF
106
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800107testcc() {
Martin Roth7051dea2016-01-05 15:49:32 -0700108 local cc="$1"
109 local cflags="$2"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800110 local tmp_c="$TMPFILE.c"
111 local tmp_o="$TMPFILE.o"
112 rm -f "$tmp_c" "$tmp_o"
David Hendricksceb82da2012-12-20 14:24:08 -0800113 echo "void _start(void) {}" >"$tmp_c"
Martin Roth7051dea2016-01-05 15:49:32 -0700114 "$cc" -nostdlib -Werror $cflags -c "$tmp_c" -o "$tmp_o" >/dev/null 2>&1
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800115}
Marc Jones087b24d2012-02-22 11:46:17 -0700116
Julius Werner4bfa29e2015-08-20 14:36:34 -0700117testld() {
118 local gcc="$1"
119 local cflags="$2"
120 local ld="$3"
121 local ldflags="$4"
122 local tmp_o="$TMPFILE.o"
123 local tmp_elf="$TMPFILE.elf"
124 rm -f "$tmp_elf"
Martin Roth7051dea2016-01-05 15:49:32 -0700125 testcc "$gcc" "$cflags" &&
126 $ld -nostdlib -static $ldflags -o "$tmp_elf" "$tmp_o" >/dev/null 2>&1
Julius Werner4bfa29e2015-08-20 14:36:34 -0700127}
128
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800129testas() {
Vadim Bendeburyd2cb1f92015-04-25 13:15:58 -0700130 local gccprefix="$1"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800131 local twidth="$2"
132 local arch="$3"
133 local use_dash_twidth="$4"
Vadim Bendebury05a84722015-04-25 13:05:10 -0700134 local endian="$5"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800135 local obj_file="$TMPFILE.o"
136 local full_arch="elf$twidth-$arch"
137
138 rm -f "$obj_file"
139 [ -n "$use_dash_twidth" ] && use_dash_twidth="--$twidth"
Vadim Bendebury05a84722015-04-25 13:05:10 -0700140 [ -n "$endian" ] && endian="-$endian"
Martin Roth2ba837d2016-01-05 15:55:44 -0700141 "${gccprefix}as" $use_dash_twidth $endian -o "$obj_file" "$TMPFILE" \
Vadim Bendebury05a84722015-04-25 13:05:10 -0700142 2>/dev/null || return 1
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800143
144 # Check output content type.
Martin Roth2ba837d2016-01-05 15:55:44 -0700145 local obj_type="$(LANG=C LC_ALL='' "${gccprefix}"objdump -p "$obj_file" 2>/dev/null)"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800146 local obj_arch="$(expr "$obj_type" : '.*format \(.[a-z0-9-]*\)')"
147 [ "$obj_arch" = "$full_arch" ] || return 1
148
Patrick Georgi34de29a2015-06-04 13:45:40 +0200149 unset ASFLAGS LDFLAGS
150 unset CFLAGS_GCC CFLAGS_CLANG
151
152 if [ -n "$use_dash_twidth" ]; then
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800153 ASFLAGS="--$twidth"
Patrick Georgi532df292015-06-04 13:20:24 +0200154 CFLAGS_GCC="-m$twidth"
Patrick Georgi34de29a2015-06-04 13:45:40 +0200155 CFLAGS_CLANG="-m$twidth"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800156 LDFLAGS="-b $full_arch"
157
158 fi
159
160 # Special parameters only available in dash_twidth mode.
161 [ -n "$use_dash_twidth" ] && case "$full_arch" in
162 "elf32-i386" )
163 LDFLAGS="$LDFLAGS -melf_i386"
Patrick Georgi532df292015-06-04 13:20:24 +0200164 CFLAGS_GCC="$CFLAGS_GCC -Wl,-b,elf32-i386 -Wl,-melf_i386"
Patrick Georgi34de29a2015-06-04 13:45:40 +0200165 CFLAGS_CLANG="$CFLAGS_GCC -Wl,-b,elf32-i386 -Wl,-melf_i386"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800166 ;;
167 esac
168
169 return 0
170}
171
172detect_special_flags() {
173 local architecture="$1"
Stefan Reinauerae9f87f2015-03-13 22:52:47 +0100174 # Check for an operational -m32/-m64
175 testcc "$GCC" "$CFLAGS_GCC -m$TWIDTH " &&
176 CFLAGS_GCC="$CFLAGS_GCC -m$TWIDTH "
177
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800178 # Use bfd linker instead of gold if available:
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200179 testcc "$GCC" "$CFLAGS_GCC -fuse-ld=bfd" &&
Patrick Georgi532df292015-06-04 13:20:24 +0200180 CFLAGS_GCC="$CFLAGS_GCC -fuse-ld=bfd" && LINKER_SUFFIX='.bfd'
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800181
Paul Menzel246051c2016-10-27 08:28:55 +0200182 testcc "$GCC" "$CFLAGS_GCC -fno-stack-protector" &&
Patrick Georgi532df292015-06-04 13:20:24 +0200183 CFLAGS_GCC="$CFLAGS_GCC -fno-stack-protector"
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200184 testcc "$GCC" "$CFLAGS_GCC -Wl,--build-id=none" &&
Patrick Georgi532df292015-06-04 13:20:24 +0200185 CFLAGS_GCC="$CFLAGS_GCC -Wl,--build-id=none"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800186
187 case "$architecture" in
Patrick Georgiee467122014-05-14 14:28:21 +0200188 x86)
Patrick Georgiee467122014-05-14 14:28:21 +0200189 ;;
Stefan Reinauer7979dc02015-06-17 16:07:38 -0700190 x64)
Stefan Reinauer7979dc02015-06-17 16:07:38 -0700191 ;;
Julius Werner4bfa29e2015-08-20 14:36:34 -0700192 arm64)
193 testld "$GCC" "$CFLAGS_GCC" "${GCCPREFIX}ld${LINKER_SUFFIX}" \
194 "$LDFLAGS --fix-cortex-a53-843419" && \
195 LDFLAGS_ARM64_A53_ERRATUM_843419+=" --fix-cortex-a53-843419"
196 ;;
Vadim Bendeburyfddf75e2014-08-29 16:00:37 -0700197 mipsel)
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200198 testcc "$GCC" "$CFLAGS_GCC -mno-abicalls -fno-pic" && \
Patrick Georgi532df292015-06-04 13:20:24 +0200199 CFLAGS_GCC+=" -mno-abicalls -fno-pic"
Vadim Bendebury05a84722015-04-25 13:05:10 -0700200
Martin Rothc2054f32016-01-05 14:16:57 -0700201 # Enforce little endian mode.
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200202 testcc "$GCC" "$CFLAGS_GCC -EL" && \
Patrick Georgi532df292015-06-04 13:20:24 +0200203 CFLAGS_GCC+=" -EL"
Vadim Bendeburyfddf75e2014-08-29 16:00:37 -0700204 ;;
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800205 esac
206}
207
Patrick Georgi527f3922015-06-04 13:31:38 +0200208detect_compiler_runtime() {
Stefan Reinauer6404dff2015-06-08 19:54:01 +0200209 test -z "$GCC" || \
Martin Roth033abe52016-01-05 15:44:02 -0700210 CC_RT_GCC="$(${GCC} ${CFLAGS_GCC} -print-libgcc-file-name)"
Stefan Reinauer72dc21c2017-06-21 16:28:46 -0700211 if [ ${CLANG_RUNTIME} = "libgcc" ]; then
212 CC_RT_CLANG=${CC_RT_GCC}
213 else
214 test -z "$CLANG" || \
215 CC_RT_CLANG="$(${CLANG} ${CFLAGS_CLANG} -print-libgcc-file-name 2>/dev/null)"
216 fi
Patrick Georgi527f3922015-06-04 13:31:38 +0200217}
218
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800219report_arch_toolchain() {
220 cat <<EOF
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200221# elf${TWIDTH}-${TBFDARCH} toolchain (${GCC})
Patrick Georgid11ff6b2014-07-10 20:38:21 +0200222ARCH_SUPPORTED+=${TARCH}
Patrick Georgi511f8232014-10-31 16:48:00 +0100223SUBARCH_SUPPORTED+=${TSUPP-${TARCH}}
Martin Rothc4b684e2016-01-05 14:47:59 -0700224
225# GCC
226GCC_CC_${TARCH}:=${GCC}
227GCC_CFLAGS_${TARCH}:=${CFLAGS_GCC}
228GCC_COMPILER_RT_${TARCH}:=${CC_RT_GCC}
229GCC_COMPILER_RT_FLAGS_${TARCH}:=${CC_RT_EXTRA_GCC}
Martin Roth0cd9ff82016-02-01 17:33:37 -0700230EOF
231
232# Generally the x86 should build for i686 -- no sse/mmx
233# instructions since SMM modules are compiled using these
234# flags. Note that this doesn't prevent a project using
235# xcompile to explicitly specify -mmsse, etc flags.
236# The Quark processor doesn't support the instructions
237# introduced with the Pentium 6 architecture, so allow it
238# to use i586 instead.
239if [ "${TARCH}" = "x86_64" ] || [ "${TARCH}" = "x86_32" ]; then
240cat <<EOF
241
Lee Leahy6796d782017-06-20 14:33:28 -0700242ifneq (\$(CONFIG_USE_MARCH_586)\$(CONFIG_LP_USE_MARCH_586),)
Martin Roth0cd9ff82016-02-01 17:33:37 -0700243 GCC_CFLAGS_${TARCH} += -march=i586
244else
245 GCC_CFLAGS_${TARCH} += -march=i686
246endif
247EOF
248fi
249
250cat <<EOF
Martin Rothc4b684e2016-01-05 14:47:59 -0700251
252# Clang
253CLANG_CC_${TARCH}:=${CLANG}
254CLANG_CFLAGS_${TARCH}:=${CFLAGS_CLANG}
Damien Zammitadb026f2017-08-27 17:03:28 +1000255CLANG_CFLAGS_${TARCH}+=-Qunused-arguments -m${TWIDTH}
Martin Rothc4b684e2016-01-05 14:47:59 -0700256# tone down clang compiler warnings
Stefan Reinauer42b37f52017-06-27 00:27:32 +0200257CLANG_CFLAGS_${TARCH}+=-Wno-unused-variable -Wno-unused-function -Wno-tautological-compare
258CLANG_CFLAGS_${TARCH}+=-Wno-shift-overflow -Wno-address-of-packed-member -Wno-initializer-overrides
Martin Rothc4b684e2016-01-05 14:47:59 -0700259CLANG_COMPILER_RT_${TARCH}:=${CC_RT_CLANG}
260CLANG_COMPILER_RT_FLAGS_${TARCH}:=${CC_RT_EXTRA_CLANG}
261
Stefan Reinauerf53dbfa2015-07-09 00:26:49 +0200262ifeq (\$(CONFIG_COMPILER_GCC)\$(CONFIG_LP_COMPILER_GCC),y)
Martin Rothc4b684e2016-01-05 14:47:59 -0700263 CC_${TARCH}:=\$(GCC_CC_${TARCH})
264 CFLAGS_${TARCH}:=\$(GCC_CFLAGS_${TARCH})
265 COMPILER_RT_${TARCH}:=\$(GCC_COMPILER_RT_${TARCH})
266 COMPILER_RT_FLAGS_${TARCH}:=\$(GCC_COMPILER_RT_FLAGS_${TARCH})
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200267else
Martin Rothc4b684e2016-01-05 14:47:59 -0700268 CC_${TARCH}:=\$(CLANG_CC_${TARCH})
269 CFLAGS_${TARCH}:=\$(CLANG_CFLAGS_${TARCH})
270 COMPILER_RT_${TARCH}:=\$(CLANG_COMPILER_RT_${TARCH})
271 COMPILER_RT_FLAGS_${TARCH}:=\$(CLANG_COMPILER_RT_FLAGS_${TARCH})
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200272endif
Martin Roth0cd9ff82016-02-01 17:33:37 -0700273
Andrew Wucd9abf92013-09-03 20:39:48 +0800274CPP_${TARCH}:=${GCCPREFIX}cpp
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800275AS_${TARCH}:=${GCCPREFIX}as ${ASFLAGS}
Aaron Durbin73982c32013-03-22 19:35:56 -0500276LD_${TARCH}:=${GCCPREFIX}ld${LINKER_SUFFIX} ${LDFLAGS}
Martin Rothaf0216f2016-01-05 14:56:13 -0700277EOF
278
Martin Rotha6e77022016-01-07 14:57:26 -0700279 if [ "${TARCH}" = "arm64" ] && \
280 [ -n "${LDFLAGS_ARM64_A53_ERRATUM_843419}" ]; then
281 cat <<EOF
Martin Rothaf0216f2016-01-05 14:56:13 -0700282
Martin Rotha6e77022016-01-07 14:57:26 -0700283ifeq (\$(CONFIG_ARM64_A53_ERRATUM_843419),y)
Martin Rothaf0216f2016-01-05 14:56:13 -0700284 LD_${TARCH}+=${LDFLAGS_ARM64_A53_ERRATUM_843419}
Julius Werner4bfa29e2015-08-20 14:36:34 -0700285endif
Martin Rothaf0216f2016-01-05 14:56:13 -0700286
287EOF
Martin Rotha6e77022016-01-07 14:57:26 -0700288 fi # if [ "${TARCH}" = "arm64" ]...
Martin Rothaf0216f2016-01-05 14:56:13 -0700289
290 cat <<EOF
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800291NM_${TARCH}:=${GCCPREFIX}nm
292OBJCOPY_${TARCH}:=${GCCPREFIX}objcopy
293OBJDUMP_${TARCH}:=${GCCPREFIX}objdump
294READELF_${TARCH}:=${GCCPREFIX}readelf
295STRIP_${TARCH}:=${GCCPREFIX}strip
296AR_${TARCH}:=${GCCPREFIX}ar
Nico Huber44084092016-01-15 00:11:57 +0100297GNATBIND_${TARCH}:=${GCCPREFIX}gnatbind
Furquan Shaikh3c3a0fa2015-05-20 10:09:45 -0700298CROSS_COMPILE_${TARCH}:=${GCCPREFIX}
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800299
Martin Roth03f7a492016-01-05 14:21:02 -0700300
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800301EOF
Martin Roth03f7a492016-01-05 14:21:02 -0700302#The two blank lines above are intentional separators
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800303}
304
Vadim Bendeburyd2cb1f92015-04-25 13:15:58 -0700305# Architecture definitions
Ronald G. Minnichb135baa2015-12-02 20:24:15 +0000306SUPPORTED_ARCHITECTURES="arm arm64 mipsel riscv x64 x86 power8"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800307
Patrick Georgi74c86452016-01-25 18:15:08 +0100308# TARCH: local name for the architecture
309# (used as CC_${TARCH} in the build system)
310# TBFDARCHS: architecture name in binutils (eg elf32-${TBFDARCH})
311# TCLIST: first part of the compiler triplet (eg i386 in i386-elf)
312# TWIDTH: numerical argument for cpu mode: gcc -m${TWIDTH}
313# TSUPP: supported subarchs (for -mcpu=...)
314# TABI: typically elf, eabi or linux
315
Gabe Black51edd542013-09-30 23:00:33 -0700316arch_config_arm() {
317 TARCH="arm"
Vadim Bendeburya6b220d2014-08-27 15:30:19 -0700318 TBFDARCHS="littlearm"
Stefan Reinauer27522ad2016-01-29 17:31:34 -0800319 TCLIST="armv7-a armv7a arm"
Patrick Georgid387c632014-05-14 14:23:28 +0200320 TWIDTH="32"
Hakim Giydan43e5b572016-09-08 10:13:59 -0700321 TSUPP="arm armv4 armv7 armv7_m armv7_r"
Patrick Georgi0890a822014-05-14 14:48:31 +0200322 TABI="eabi"
Patrick Georgid387c632014-05-14 14:23:28 +0200323}
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800324
Marc Jonesc4dbdaf2015-01-16 13:19:04 -0700325arch_config_arm64() {
326 TARCH="arm64"
Vadim Bendeburya6b220d2014-08-27 15:30:19 -0700327 TBFDARCHS="littleaarch64"
Patrick Georgid387c632014-05-14 14:23:28 +0200328 TCLIST="aarch64"
329 TWIDTH="64"
Patrick Georgif3d8b9a2015-02-17 11:11:55 +0100330 TSUPP="arm64 armv8_64"
Patrick Georgi3bff5d92014-11-19 18:36:37 +0100331 TABI="elf"
Patrick Georgid387c632014-05-14 14:23:28 +0200332}
Ronald G. Minnich12785d92013-11-08 10:13:50 -0800333
Ronald G. Minnichb9a08092014-10-07 05:18:51 +0000334arch_config_riscv() {
335 TARCH="riscv"
Vadim Bendeburya6b220d2014-08-27 15:30:19 -0700336 TBFDARCHS="littleriscv"
Iru Cai9cc8cb22016-04-05 23:43:59 +0800337 TCLIST="riscv riscv64"
Ronald G. Minnichb9a08092014-10-07 05:18:51 +0000338 TWIDTH="64"
339 TABI="elf"
340}
341
Stefan Reinauerae9f87f2015-03-13 22:52:47 +0100342arch_config_x64() {
343 TARCH="x86_64"
344 TBFDARCHS="x86-64"
345 TCLIST="x86_64"
346 TWIDTH="64"
347 TABI="elf"
348}
349
Patrick Georgid387c632014-05-14 14:23:28 +0200350arch_config_x86() {
Patrick Georgib83f7de2014-05-17 14:20:11 +0200351 TARCH="x86_32"
Vadim Bendeburya6b220d2014-08-27 15:30:19 -0700352 TBFDARCHS="i386"
Patrick Georgid387c632014-05-14 14:23:28 +0200353 TCLIST="i386 x86_64"
354 TWIDTH="32"
Patrick Georgi0890a822014-05-14 14:48:31 +0200355 TABI="elf"
Patrick Georgi527f3922015-06-04 13:31:38 +0200356 CC_RT_EXTRA_GCC="--wrap __divdi3 --wrap __udivdi3 --wrap __moddi3 --wrap __umoddi3"
Patrick Georgid387c632014-05-14 14:23:28 +0200357}
358
Paul Burton6529c332014-05-27 15:18:42 +0100359arch_config_mipsel() {
Patrick Georgie0935bb2015-03-28 15:49:46 +0100360 TARCH="mips"
Vadim Bendeburya6b220d2014-08-27 15:30:19 -0700361 TBFDARCHS="tradlittlemips littlemips"
Paul Burton6529c332014-05-27 15:18:42 +0100362 TCLIST="mipsel"
363 TWIDTH="32"
Patrick Georgie0935bb2015-03-28 15:49:46 +0100364 TSUPP="mips mipsel"
Paul Burton6529c332014-05-27 15:18:42 +0100365 TABI="elf"
Vadim Bendebury05a84722015-04-25 13:05:10 -0700366 TENDIAN="EL"
Paul Burton6529c332014-05-27 15:18:42 +0100367}
368
Ronald G. Minnichb135baa2015-12-02 20:24:15 +0000369arch_config_power8() {
Patrick Georgid6577e12016-01-25 18:16:14 +0100370 TARCH="power8"
Timothy Pearson82657ca2016-03-09 17:20:26 -0600371 TBFDARCHS="powerpc"
372 TCLIST="powerpc64"
Ronald G. Minnichb135baa2015-12-02 20:24:15 +0000373 TWIDTH="64"
374 TSUPP="power8"
Timothy Pearson82657ca2016-03-09 17:20:26 -0600375 TABI="linux-gnu" # there is no generic ABI on ppc64
376 CC_RT_EXTRA_GCC="-mcpu=power8 -mbig-endian"
Ronald G. Minnichb135baa2015-12-02 20:24:15 +0000377}
378
Stefan Reinauer72dc21c2017-06-21 16:28:46 -0700379# Right now, the clang reference toolchain is not building compiler-rt builtins
380# for any of the cross compile architectures. Hence we use libgcc for now,
381# because that is available and lets us proceed with getting coreboot clang
382# ready. Toggle CLANG_RUNTIME if you want to experiment with compiler-rt.
383
384CLANG_RUNTIME="libgcc"
385# CLANG_RUNTIME="compiler-rt"
386
Patrick Georgie0187df2014-05-14 14:32:11 +0200387test_architecture() {
Vadim Bendeburyd2cb1f92015-04-25 13:15:58 -0700388 local architecture=$1
Vadim Bendebury05a84722015-04-25 13:05:10 -0700389 local endian gccprefix search
Patrick Georgie0187df2014-05-14 14:32:11 +0200390
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800391 GCCPREFIX="invalid"
Vadim Bendebury05a84722015-04-25 13:05:10 -0700392 unset TABI TARCH TBFDARCH TCLIST TENDIAN TSUPP TWIDTH
Patrick Georgi527f3922015-06-04 13:31:38 +0200393 unset CC_RT_EXTRA_GCC CC_RT_EXTRA_CLANG
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200394 unset GCC CLANG
Martin Roth2ba837d2016-01-05 15:55:44 -0700395 if type "arch_config_$architecture" > /dev/null; then
396 "arch_config_$architecture"
Patrick Georgid387c632014-05-14 14:23:28 +0200397 else
Daniele Forsi3bb0b722014-07-14 15:35:42 +0200398 die "no architecture definition for $architecture"
Patrick Georgid387c632014-05-14 14:23:28 +0200399 fi
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800400
401 # To override toolchain, define CROSS_COMPILE_$arch or CROSS_COMPILE as
402 # environment variable.
403 # Ex: CROSS_COMPILE_arm="armv7a-cros-linux-gnueabi-"
404 # CROSS_COMPILE_x86="i686-pc-linux-gnu-"
Martin Roth2ba837d2016-01-05 15:55:44 -0700405 search="$(eval echo "\$CROSS_COMPILE_$architecture" 2>/dev/null)"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800406 search="$search $CROSS_COMPILE"
407 for toolchain in $TCLIST; do
Patrick Georgi0890a822014-05-14 14:48:31 +0200408 search="$search $XGCCPATH$toolchain-$TABI-"
409 search="$search $toolchain-$TABI-"
Ronald G. Minnich12785d92013-11-08 10:13:50 -0800410 search="$search $toolchain-linux-gnu-"
Patrick Georgia1a6f752016-01-25 18:15:45 +0100411 search="$search $toolchain-linux-"
Ronald G. Minnichb9a08092014-10-07 05:18:51 +0000412 search="$search $toolchain-"
Vladimir Serbinenko63cf7cd2016-02-18 15:30:53 +0100413 search="$search $toolchain-linux-gnueabi-"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800414 done
Martin Roth03f7a492016-01-05 14:21:02 -0700415 echo "###########################################################################"
416 echo "# $architecture"
417 echo "# TARCH_SEARCH=$search"
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800418
419 # Search toolchain by checking assembler capability.
Vadim Bendeburya6b220d2014-08-27 15:30:19 -0700420 for TBFDARCH in $TBFDARCHS; do
Vadim Bendeburyd2cb1f92015-04-25 13:15:58 -0700421 for gccprefix in $search ""; do
422 program_exists "${gccprefix}as" || continue
Vadim Bendebury05a84722015-04-25 13:05:10 -0700423 for endian in $TENDIAN ""; do
Stefan Tauner98ab2272016-05-01 19:41:28 +0200424 { testas "$gccprefix" "$TWIDTH" "$TBFDARCH" \
425 "" "$endian" ||
Vadim Bendebury05a84722015-04-25 13:05:10 -0700426 testas "$gccprefix" "$TWIDTH" "$TBFDARCH" \
Stefan Tauner98ab2272016-05-01 19:41:28 +0200427 "TRUE" "$endian" ; } && \
428 testcc "${gccprefix}gcc" "$CFLAGS_GCC" && \
429 GCCPREFIX="$gccprefix" && \
430 break 3
Vadim Bendebury05a84722015-04-25 13:05:10 -0700431 done
Vadim Bendeburya6b220d2014-08-27 15:30:19 -0700432 done
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800433 done
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200434 if [ "invalid" != "$GCCPREFIX" ]; then
435 GCC="${GCCPREFIX}gcc"
436 fi
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800437
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200438 for clang_arch in $TCLIST invalid; do
Patrick Georgif1383202017-05-10 22:06:31 +0200439 for clang_prefix in $search $XGCCPATH ""; do
440 testcc "${clang_prefix}clang" "-target ${clang_arch}-$TABI -c" && break 2
441 done
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200442 done
443
444 if [ "invalid" != "$clang_arch" ]; then
445 # FIXME: this may break in a clang && !gcc configuration,
446 # but that's more of a clang limitation. Let's be optimistic
447 # that this will change in the future.
Patrick Georgif1383202017-05-10 22:06:31 +0200448 CLANG="${clang_prefix}clang"
Stefan Reinauer72dc21c2017-06-21 16:28:46 -0700449 CFLAGS_CLANG="-target ${clang_arch}-${TABI} --rtlib=${CLANG_RUNTIME} $CFLAGS_CLANG -ccc-gcc-name ${GCC}"
Patrick Georgi8b5a051c2015-06-04 13:44:41 +0200450 fi
Patrick Georgie0187df2014-05-14 14:32:11 +0200451}
452
Patrick Georgibe182ad2017-01-30 15:27:35 +0100453OUT="$(mktemp /tmp/temp.XXXXXX 2>/dev/null || echo /tmp/temp.coreboot.$RANDOM)"
454rm -f $OUT
455
Vadim Bendeburyd2cb1f92015-04-25 13:15:58 -0700456for architecture in $SUPPORTED_ARCHITECTURES; do
Patrick Georgibe182ad2017-01-30 15:27:35 +0100457 (
458 TMPFILE="$(mktemp /tmp/temp.XXXXXX 2>/dev/null || echo /tmp/temp.coreboot.$RANDOM)"
459 touch $TMPFILE
Martin Roth2ba837d2016-01-05 15:55:44 -0700460 test_architecture "$architecture"
Martin Roth31c4b642015-12-07 14:34:46 -0700461 detect_special_flags "$architecture"
462 detect_compiler_runtime "$architecture"
463 report_arch_toolchain
Patrick Georgibe182ad2017-01-30 15:27:35 +0100464 clean_up
465 ) > $OUT.$architecture &
466done
467wait
468
469for architecture in $SUPPORTED_ARCHITECTURES; do
470 cat $OUT.$architecture
471 rm -f $OUT.$architecture
Patrick Georgi0588d192009-08-12 15:00:51 +0000472done
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100473echo XCOMPILE_COMPLETE:=1