1#!/usr/bin/env bash 2 3srcdir=$(cd "$(dirname "$0")"; pwd) 4prefix=/usr/local 5cc=gcc 6ld=ld 7objcopy=objcopy 8objdump=objdump 9ar=ar 10addr2line=addr2line 11arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'` 12host=$arch 13cross_prefix= 14endian="" 15pretty_print_stacks=yes 16environ_default=yes 17u32_long= 18vmm="qemu" 19errata_force=0 20erratatxt="errata.txt" 21 22usage() { 23 cat <<-EOF 24 Usage: $0 [options] 25 26 Options include: 27 --arch=ARCH architecture to compile for ($arch) 28 --processor=PROCESSOR processor to compile for ($arch) 29 --vmm=VMM virtual machine monitor to compile for (qemu 30 or kvmtool, default is qemu) (arm/arm64 only) 31 --cross-prefix=PREFIX cross compiler prefix 32 --cc=CC c compiler to use ($cc) 33 --ld=LD ld linker to use ($ld) 34 --prefix=PREFIX where to install things ($prefix) 35 --endian=ENDIAN endianness to compile for (little or big, ppc64 only) 36 --[enable|disable]-pretty-print-stacks 37 enable or disable pretty stack printing (enabled by default) 38 --[enable|disable]-default-environ 39 enable or disable the generation of a default environ when 40 no environ is provided by the user (enabled by default) 41 --erratatxt=FILE specify a file to use instead of errata.txt. Use 42 '--erratatxt=' to ensure no file is used. 43EOF 44 exit 1 45} 46 47while [[ "$1" = -* ]]; do 48 opt="$1"; shift 49 arg= 50 if [[ "$opt" = *=* ]]; then 51 arg="${opt#*=}" 52 opt="${opt%%=*}" 53 fi 54 case "$opt" in 55 --prefix) 56 prefix="$arg" 57 ;; 58 --arch) 59 arch="$arg" 60 ;; 61 --processor) 62 processor="$arg" 63 ;; 64 --vmm) 65 vmm="$arg" 66 ;; 67 --cross-prefix) 68 cross_prefix="$arg" 69 ;; 70 --endian) 71 endian="$arg" 72 ;; 73 --cc) 74 cc="$arg" 75 ;; 76 --ld) 77 ld="$arg" 78 ;; 79 --enable-pretty-print-stacks) 80 pretty_print_stacks=yes 81 ;; 82 --disable-pretty-print-stacks) 83 pretty_print_stacks=no 84 ;; 85 --enable-default-environ) 86 environ_default=yes 87 ;; 88 --disable-default-environ) 89 environ_default=no 90 ;; 91 --erratatxt) 92 erratatxt="$arg" 93 ;; 94 --help) 95 usage 96 ;; 97 *) 98 usage 99 ;; 100 esac 101done 102 103if [ "$erratatxt" ] && [ ! -f "$erratatxt" ]; then 104 echo "erratatxt: $erratatxt does not exist or is not a regular file" 105 exit 1 106fi 107 108arch_name=$arch 109[ "$arch" = "aarch64" ] && arch="arm64" 110[ "$arch_name" = "arm64" ] && arch_name="aarch64" 111 112[ -z "$processor" ] && processor="$arch" 113 114if [ "$processor" = "arm64" ]; then 115 processor="cortex-a57" 116elif [ "$processor" = "arm" ]; then 117 processor="cortex-a15" 118fi 119 120if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then 121 testdir=x86 122elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then 123 testdir=arm 124 if [ "$vmm" = "qemu" ]; then 125 arm_uart_early_addr=0x09000000 126 elif [ "$vmm" = "kvmtool" ]; then 127 arm_uart_early_addr=0x3f8 128 errata_force=1 129 else 130 echo '--vmm must be one of "qemu" or "kvmtool"!' 131 usage 132 fi 133elif [ "$arch" = "ppc64" ]; then 134 testdir=powerpc 135 firmware="$testdir/boot_rom.bin" 136 if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then 137 echo "You must provide endianness (big or little)!" 138 usage 139 fi 140else 141 testdir=$arch 142fi 143if [ ! -d "$srcdir/$testdir" ]; then 144 echo "$testdir does not exist!" 145 exit 1 146fi 147if [ -f "$srcdir/$testdir/run" ]; then 148 ln -fs "$srcdir/$testdir/run" $testdir-run 149fi 150 151# check if uint32_t needs a long format modifier 152cat << EOF > lib-test.c 153__UINT32_TYPE__ 154EOF 155u32_long=$("$cross_prefix$cc" -E lib-test.c | grep -v '^#' | grep -q long && echo yes) 156rm -f lib-test.c 157 158# Are we in a separate build tree? If so, link the Makefile 159# and shared stuff so that 'make' and run_tests.sh work. 160if test ! -e Makefile; then 161 echo "linking Makefile..." 162 ln -s "$srcdir/Makefile" . 163 164 echo "linking tests..." 165 mkdir -p $testdir 166 ln -sf "$srcdir/$testdir/run" $testdir/ 167 ln -sf "$srcdir/$testdir/unittests.cfg" $testdir/ 168 ln -sf "$srcdir/run_tests.sh" 169 170 echo "linking scripts..." 171 ln -sf "$srcdir/scripts" 172 173 echo "linking errata.txt..." 174 ln -sf "$srcdir/errata.txt" 175fi 176 177# link lib/asm for the architecture 178rm -f lib/asm 179asm="asm-generic" 180if [ -d "$srcdir/lib/$arch/asm" ]; then 181 asm="$srcdir/lib/$arch/asm" 182elif [ -d "$srcdir/lib/$testdir/asm" ]; then 183 asm="$srcdir/lib/$testdir/asm" 184fi 185mkdir -p lib 186ln -sf "$asm" lib/asm 187 188 189# create the config 190cat <<EOF > config.mak 191SRCDIR=$srcdir 192PREFIX=$prefix 193HOST=$host 194ARCH=$arch 195ARCH_NAME=$arch_name 196PROCESSOR=$processor 197CC=$cross_prefix$cc 198LD=$cross_prefix$ld 199OBJCOPY=$cross_prefix$objcopy 200OBJDUMP=$cross_prefix$objdump 201AR=$cross_prefix$ar 202ADDR2LINE=$cross_prefix$addr2line 203TEST_DIR=$testdir 204FIRMWARE=$firmware 205ENDIAN=$endian 206PRETTY_PRINT_STACKS=$pretty_print_stacks 207ENVIRON_DEFAULT=$environ_default 208ERRATATXT=$erratatxt 209U32_LONG_FMT=$u32_long 210EOF 211 212cat <<EOF > lib/config.h 213#ifndef CONFIG_H 214#define CONFIG_H 1 215/* 216 * Generated file. DO NOT MODIFY. 217 * 218 */ 219 220EOF 221if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then 222cat <<EOF >> lib/config.h 223 224#define CONFIG_UART_EARLY_BASE ${arm_uart_early_addr} 225#define CONFIG_ERRATA_FORCE ${errata_force} 226 227EOF 228fi 229echo "#endif" >> lib/config.h 230