1#!/bin/sh 2## 3## Copyright (C) 2008 Advanced Micro Devices, Inc. 4## 5## Redistribution and use in source and binary forms, with or without 6## modification, are permitted provided that the following conditions 7## are met: 8## 1. Redistributions of source code must retain the above copyright 9## notice, this list of conditions and the following disclaimer. 10## 2. Redistributions in binary form must reproduce the above copyright 11## notice, this list of conditions and the following disclaimer in the 12## documentation and/or other materials provided with the distribution. 13## 3. The name of the author may not be used to endorse or promote products 14## derived from this software without specific prior written permission. 15## 16## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26## SUCH DAMAGE. 27 28# GCC wrapper for libpayload 29if [ "${V}" = "1" ]; then 30 DEBUGME=1 31else 32 DEBUGME=0 33fi 34 35if [ $DEBUGME -eq 1 ]; then 36 echo "CC = $CC" 37fi 38 39# let's not recurse. 40# This is a hack, I know, but it makes sure that really simple user errors 41# don't fork-bomb your machine. 42if [ -n "$CC" ]; then 43b=`basename "$CC"` 44if [ "$b" = "lpgcc" ]; then 45CC="" 46fi 47fi 48 49if [ "$CC" != "" ]; then 50DEFAULT_CC=$CC 51else 52DEFAULT_CC=gcc 53fi 54 55BASE=`dirname $0` 56 57# This will set the _LIBDIR and _INCDIR variables used below 58. $BASE/lp.functions 59 60if [ $_LIBDIR != $_OBJ ]; then 61 _DOTCONFIG=$BASE/../libpayload.config 62 _XCOMPILE=$BASE/../libpayload.xcompile 63else 64 _DOTCONFIG=$_OBJ/libpayload.config 65 _XCOMPILE=$_OBJ/xcompile 66fi 67 68# include libpayload config 69if [ -f $_DOTCONFIG ]; then 70 . $_DOTCONFIG 71else 72 echo "Can't find config" 73 exit 1 74fi 75 76if [ "$CONFIG_LP_ARCH_ARM" = "y" ]; then 77 _ARCHDIR=arm 78 _ARCHEXTRA="" 79 80fi 81if [ "$CONFIG_LP_ARCH_ARM64" = "y" ]; then 82 _ARCHDIR=arm64 83 _ARCHEXTRA="" 84fi 85if [ "$CONFIG_LP_ARCH_X86" = "y" ]; then 86 _ARCHDIR=x86 87 if [ "$CONFIG_LP_ARCH_X86_32" = "y" ]; then 88 _ARCHEXTRA="-m32 " 89 else 90 _ARCHEXTRA="-m64 " 91 fi 92fi 93if [ "$CONFIG_LP_ARCH_MOCK" = "y" ]; then 94 _ARCHDIR=mock 95 _ARCHEXTRA="" 96fi 97 98_ARCHINCDIR=$_INCDIR/$_ARCHDIR 99_ARCHLIBDIR=$_LIBDIR/$_ARCHDIR 100 101if [ -f $_LIBDIR/libpayload.ldscript ]; then 102 _LDDIR=$_LIBDIR 103elif [ -f $BASE/../arch/$_ARCHDIR/libpayload.ldscript ]; then 104 _LDDIR=$BASE/../arch/$_ARCHDIR 105fi 106# Host arch should youse default linker script 107if [ "$CONFIG_LP_ARCH_MOCK" = "y" ]; then 108 _LDSCRIPT="" 109else 110 _LDSCRIPT="-Wl,-T,$_LDDIR/libpayload.ldscript" 111fi 112 113trygccoption() { 114 $DEFAULT_CC $1 -S -xc /dev/null -o /dev/null &> /dev/null 115 return $? 116} 117 118DOLINK=1 119 120# This variable will contain the command line that the user wants to 121# pass to gas 122 123CMDLINE= 124 125# Process various flags that would change our behavior 126 127while [ $# -gt 0 ]; do 128 case $1 in 129 -m32|-fno-stack-protector|-m64) 130 shift 131 continue 132 ;; 133 -c) 134 DOLINK=0 135 ;; 136 -debug-wrapper) 137 DEBUGME=1 138 shift 139 continue 140 ;; 141 -Wl,-T,*) 142 _LDSCRIPT="$1" 143 shift 144 continue 145 ;; 146 *) 147 ;; 148 esac 149 150 CMDLINE="$CMDLINE $1" 151 shift 152done 153 154_CFLAGS="$_ARCHEXTRA -nostdinc -nostdlib -I$_INCDIR -I$_ARCHINCDIR -D__LIBPAYLOAD__=1" 155 156if [ $_LIBDIR = $_OBJ ]; then 157 _CFLAGS="$_CFLAGS -I$_OBJ" 158 159 if [ "$CONFIG_LP_PDCURSES" = y ]; then 160 _CFLAGS="$_CFLAGS -I$BASE/../curses/PDCurses -I$BASE/../curses/pdcurses-backend" 161 _CFLAGS="$_CFLAGS -I$BASE/../curses/form -I$BASE/../curses/menu" 162 fi 163 164 if [ "$CONFIG_LP_TINYCURSES" = y ]; then 165 _CFLAGS="$_CFLAGS -I$BASE/../curses" 166 fi 167 168 _CFLAGS="$_CFLAGS -include $BASE/../../../src/commonlib/bsd/include/commonlib/bsd/compiler.h" 169 _CFLAGS="$_CFLAGS -I$BASE/../../../src/commonlib/bsd/include" 170 if [ "$CONFIG_LP_GPL" = y ]; then 171 _CFLAGS="$_CFLAGS -I$BASE/../../../src/commonlib/include" 172 fi 173 _CFLAGS="$_CFLAGS -I$BASE/../../../3rdparty/vboot/firmware/include" 174else 175 _CFLAGS="$_CFLAGS -include $BASE/../include/commonlib/bsd/compiler.h" 176 _CFLAGS="$_CFLAGS -I$_VBOOTINCDIR" 177fi 178 179# Check for the -fno-stack-protector silliness 180 181trygccoption -fno-stack-protector 182[ $? -eq 0 ] && _CFLAGS="$_CFLAGS -fno-stack-protector" 183 184_CFLAGS="$_CFLAGS -include $BASE/../include/kconfig.h" 185_CFLAGS="$_CFLAGS -I`$DEFAULT_CC $_ARCHEXTRA -print-search-dirs | head -n 1 | cut -d' ' -f2`include" 186 187if [ "$CONFIG_LP_VBOOT_LIB" = y ]; then 188 if [ "$CONFIG_LP_VBOOT_TPM2_MODE" = y ]; then 189 _CFLAGS="$_CFLAGS -DTPM2_MODE" 190 else 191 _CFLAGS="$_CFLAGS -DTPM1_MODE" 192 fi 193fi 194 195_LDFLAGS="-L$_LIBDIR $_LDSCRIPT -static -Wl,--gc-sections" 196 197if [ $DOLINK -eq 0 ]; then 198 if [ $DEBUGME -eq 1 ]; then 199 echo "$DEFAULT_CC $CMDLINE $_CFLAGS" 200 fi 201 202 $DEFAULT_CC $CMDLINE $_CFLAGS 203else 204 _LIBGCC=`$DEFAULT_CC $_ARCHEXTRA -print-libgcc-file-name` 205 206 if [ "$CONFIG_LP_ARM64_A53_ERRATUM_843419" = y ] && 207 grep -q fix-cortex-a53-843419 $_XCOMPILE; then 208 _LDFLAGS="$_LDFLAGS -Wl,--fix-cortex-a53-843419" 209 fi 210 211 _LDFLAGS="$_LDFLAGS -Wl,--defsym=CONFIG_LP_BASE_ADDRESS=$CONFIG_LP_BASE_ADDRESS" 212 _LDFLAGS="$_LDFLAGS -Wl,--defsym=CONFIG_LP_HEAP_SIZE=$CONFIG_LP_HEAP_SIZE" 213 _LDFLAGS="$_LDFLAGS -Wl,--defsym=CONFIG_LP_STACK_SIZE=$CONFIG_LP_STACK_SIZE" 214 215 if [ $DEBUGME -eq 1 ]; then 216 echo "$DEFAULT_CC $_LDFLAGS $CMDLINE $_CFLAGS -lpayload $_LIBGCC" 217 fi 218 219 $DEFAULT_CC $_LDFLAGS $CMDLINE $_CFLAGS -lpayload -xnone $_LIBGCC 220fi 221