Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 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 |
Vadim Bendebury | c253717 | 2014-05-19 15:43:47 -0700 | [diff] [blame] | 29 | if [ "${V}" = "1" ]; then |
Marc Jones | bb9490a | 2012-11-30 16:22:51 -0700 | [diff] [blame] | 30 | DEBUGME=1 |
| 31 | else |
| 32 | DEBUGME=0 |
| 33 | fi |
| 34 | |
| 35 | if [ $DEBUGME -eq 1 ]; then |
| 36 | echo "CC = $CC" |
| 37 | fi |
| 38 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 39 | # let's not recurse. |
Ronald G. Minnich | b575d67 | 2009-02-15 23:32:57 +0000 | [diff] [blame] | 40 | # This is a hack, I know, but it makes sure that really simple user errors |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 41 | # don't fork-bomb your machine. |
Patrick Georgi | a4a022c | 2011-02-14 19:24:37 +0000 | [diff] [blame] | 42 | if [ -n "$CC" ]; then |
Marc Jones | bb9490a | 2012-11-30 16:22:51 -0700 | [diff] [blame] | 43 | b=`basename "$CC"` |
Ronald G. Minnich | b575d67 | 2009-02-15 23:32:57 +0000 | [diff] [blame] | 44 | if [ "$b" = "lpgcc" ]; then |
| 45 | CC="" |
| 46 | fi |
Patrick Georgi | a4a022c | 2011-02-14 19:24:37 +0000 | [diff] [blame] | 47 | fi |
Ronald G. Minnich | b575d67 | 2009-02-15 23:32:57 +0000 | [diff] [blame] | 48 | |
Stefan Reinauer | c359124 | 2008-08-07 15:22:01 +0000 | [diff] [blame] | 49 | if [ "$CC" != "" ]; then |
| 50 | DEFAULT_CC=$CC |
| 51 | else |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 52 | DEFAULT_CC=gcc |
Stefan Reinauer | c359124 | 2008-08-07 15:22:01 +0000 | [diff] [blame] | 53 | fi |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 54 | |
| 55 | BASE=`dirname $0` |
| 56 | |
| 57 | # This will set the _LIBDIR and _INCDIR variables used below |
| 58 | . $BASE/lp.functions |
| 59 | |
Nico Huber | 3e0b3f1 | 2020-11-14 23:37:39 +0100 | [diff] [blame] | 60 | if [ $_LIBDIR != $_OBJ ]; then |
| 61 | _DOTCONFIG=$BASE/../libpayload.config |
| 62 | _XCOMPILE=$BASE/../libpayload.xcompile |
| 63 | else |
| 64 | _DOTCONFIG=$_OBJ/libpayload.config |
| 65 | _XCOMPILE=$_OBJ/xcompile |
| 66 | fi |
| 67 | |
Stefan Reinauer | 5429e26 | 2009-05-26 18:01:53 +0000 | [diff] [blame] | 68 | # include libpayload config |
Nico Huber | 3e0b3f1 | 2020-11-14 23:37:39 +0100 | [diff] [blame] | 69 | if [ -f $_DOTCONFIG ]; then |
| 70 | . $_DOTCONFIG |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 71 | else |
| 72 | echo "Can't find config" |
| 73 | exit 1 |
| 74 | fi |
Stefan Reinauer | 5429e26 | 2009-05-26 18:01:53 +0000 | [diff] [blame] | 75 | |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 76 | if [ "$CONFIG_LP_ARCH_ARM" = "y" ]; then |
Subrata Banik | f2d260d | 2024-05-17 06:02:08 +0000 | [diff] [blame] | 77 | _ARCHDIR=arm |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 78 | _ARCHEXTRA="" |
Subrata Banik | f2d260d | 2024-05-17 06:02:08 +0000 | [diff] [blame] | 79 | |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 80 | fi |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 81 | if [ "$CONFIG_LP_ARCH_ARM64" = "y" ]; then |
Subrata Banik | f2d260d | 2024-05-17 06:02:08 +0000 | [diff] [blame] | 82 | _ARCHDIR=arm64 |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 83 | _ARCHEXTRA="" |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 84 | fi |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 85 | if [ "$CONFIG_LP_ARCH_X86" = "y" ]; then |
Subrata Banik | f2d260d | 2024-05-17 06:02:08 +0000 | [diff] [blame] | 86 | _ARCHDIR=x86 |
Subrata Banik | afa3910 | 2024-05-18 12:26:40 +0000 | [diff] [blame^] | 87 | if [ "$CONFIG_LP_ARCH_X86_32" = "y" ]; then |
| 88 | _ARCHEXTRA="-m32 " |
| 89 | else |
| 90 | _ARCHEXTRA="-m64 " |
| 91 | fi |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 92 | fi |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 93 | if [ "$CONFIG_LP_ARCH_MOCK" = "y" ]; then |
Subrata Banik | f2d260d | 2024-05-17 06:02:08 +0000 | [diff] [blame] | 94 | _ARCHDIR=mock |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 95 | _ARCHEXTRA="" |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 96 | fi |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 97 | |
Subrata Banik | f2d260d | 2024-05-17 06:02:08 +0000 | [diff] [blame] | 98 | _ARCHINCDIR=$_INCDIR/$_ARCHDIR |
| 99 | _ARCHLIBDIR=$_LIBDIR/$_ARCHDIR |
| 100 | |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 101 | if [ -f $_LIBDIR/libpayload.ldscript ]; then |
| 102 | _LDDIR=$_LIBDIR |
Subrata Banik | f2d260d | 2024-05-17 06:02:08 +0000 | [diff] [blame] | 103 | elif [ -f $BASE/../arch/$_ARCHDIR/libpayload.ldscript ]; then |
| 104 | _LDDIR=$BASE/../arch/$_ARCHDIR |
Patrick Georgi | cb76136 | 2013-02-21 14:33:25 +0100 | [diff] [blame] | 105 | fi |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 106 | # Host arch should youse default linker script |
| 107 | if [ "$CONFIG_LP_ARCH_MOCK" = "y" ]; then |
| 108 | _LDSCRIPT="" |
| 109 | else |
| 110 | _LDSCRIPT="-Wl,-T,$_LDDIR/libpayload.ldscript" |
| 111 | fi |
Ulf Jordan | 6818a32 | 2009-02-10 21:12:35 +0000 | [diff] [blame] | 112 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 113 | trygccoption() { |
Patrick Georgi | 82867d3 | 2012-09-26 15:26:05 +0200 | [diff] [blame] | 114 | $DEFAULT_CC $1 -S -xc /dev/null -o /dev/null &> /dev/null |
| 115 | return $? |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 118 | DOLINK=1 |
| 119 | |
| 120 | # This variable will contain the command line that the user wants to |
| 121 | # pass to gas |
| 122 | |
| 123 | CMDLINE= |
| 124 | |
| 125 | # Process various flags that would change our behavior |
| 126 | |
| 127 | while [ $# -gt 0 ]; do |
| 128 | case $1 in |
Subrata Banik | afa3910 | 2024-05-18 12:26:40 +0000 | [diff] [blame^] | 129 | -m32|-fno-stack-protector|-m64) |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 130 | shift |
| 131 | continue |
| 132 | ;; |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 133 | -c) |
| 134 | DOLINK=0 |
| 135 | ;; |
| 136 | -debug-wrapper) |
| 137 | DEBUGME=1 |
| 138 | shift |
| 139 | continue |
| 140 | ;; |
Ulf Jordan | 6818a32 | 2009-02-10 21:12:35 +0000 | [diff] [blame] | 141 | -Wl,-T,*) |
| 142 | _LDSCRIPT="$1" |
| 143 | shift |
| 144 | continue |
| 145 | ;; |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 146 | *) |
| 147 | ;; |
| 148 | esac |
| 149 | |
| 150 | CMDLINE="$CMDLINE $1" |
| 151 | shift |
| 152 | done |
| 153 | |
Nico Huber | ec70383 | 2020-11-14 23:43:12 +0100 | [diff] [blame] | 154 | _CFLAGS="$_ARCHEXTRA -nostdinc -nostdlib -I$_INCDIR -I$_ARCHINCDIR -D__LIBPAYLOAD__=1" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 155 | |
Nico Huber | ec70383 | 2020-11-14 23:43:12 +0100 | [diff] [blame] | 156 | if [ $_LIBDIR = $_OBJ ]; then |
| 157 | _CFLAGS="$_CFLAGS -I$_OBJ" |
Vladimir Serbinenko | 571bec7 | 2014-01-15 22:04:12 +0100 | [diff] [blame] | 158 | |
Nico Huber | ec70383 | 2020-11-14 23:43:12 +0100 | [diff] [blame] | 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 |
Jakub Czapiga | e7006fb | 2021-12-16 16:11:30 +0000 | [diff] [blame] | 167 | |
Julius Werner | 23d2465 | 2022-05-27 19:07:14 -0700 | [diff] [blame] | 168 | _CFLAGS="$_CFLAGS -include $BASE/../../../src/commonlib/bsd/include/commonlib/bsd/compiler.h" |
Jakub Czapiga | e7006fb | 2021-12-16 16:11:30 +0000 | [diff] [blame] | 169 | _CFLAGS="$_CFLAGS -I$BASE/../../../src/commonlib/bsd/include" |
Julius Werner | c00c140 | 2024-03-15 14:08:14 -0700 | [diff] [blame] | 170 | if [ "$CONFIG_LP_GPL" = y ]; then |
| 171 | _CFLAGS="$_CFLAGS -I$BASE/../../../src/commonlib/include" |
| 172 | fi |
Jakub Czapiga | 395f5b3 | 2022-01-12 09:59:39 +0000 | [diff] [blame] | 173 | _CFLAGS="$_CFLAGS -I$BASE/../../../3rdparty/vboot/firmware/include" |
| 174 | else |
Julius Werner | 23d2465 | 2022-05-27 19:07:14 -0700 | [diff] [blame] | 175 | _CFLAGS="$_CFLAGS -include $BASE/../include/commonlib/bsd/compiler.h" |
Jakub Czapiga | 395f5b3 | 2022-01-12 09:59:39 +0000 | [diff] [blame] | 176 | _CFLAGS="$_CFLAGS -I$_VBOOTINCDIR" |
Vladimir Serbinenko | 571bec7 | 2014-01-15 22:04:12 +0100 | [diff] [blame] | 177 | fi |
| 178 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 179 | # Check for the -fno-stack-protector silliness |
| 180 | |
| 181 | trygccoption -fno-stack-protector |
| 182 | [ $? -eq 0 ] && _CFLAGS="$_CFLAGS -fno-stack-protector" |
| 183 | |
Julius Werner | 23d2465 | 2022-05-27 19:07:14 -0700 | [diff] [blame] | 184 | _CFLAGS="$_CFLAGS -include $BASE/../include/kconfig.h" |
Jacob Garber | c98baa7 | 2020-11-04 21:49:49 -0700 | [diff] [blame] | 185 | _CFLAGS="$_CFLAGS -I`$DEFAULT_CC $_ARCHEXTRA -print-search-dirs | head -n 1 | cut -d' ' -f2`include" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 186 | |
Jakub Czapiga | 49fff57 | 2022-03-02 12:18:11 +0100 | [diff] [blame] | 187 | if [ "$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 |
| 193 | fi |
| 194 | |
Nico Huber | 47722cf | 2022-02-22 02:08:11 +0100 | [diff] [blame] | 195 | _LDFLAGS="-L$_LIBDIR $_LDSCRIPT -static -Wl,--gc-sections" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 196 | |
| 197 | if [ $DOLINK -eq 0 ]; then |
| 198 | if [ $DEBUGME -eq 1 ]; then |
Paul Kocialkowski | 7572e66 | 2015-08-03 14:08:40 +0200 | [diff] [blame] | 199 | echo "$DEFAULT_CC $CMDLINE $_CFLAGS" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 200 | fi |
| 201 | |
Paul Kocialkowski | 7572e66 | 2015-08-03 14:08:40 +0200 | [diff] [blame] | 202 | $DEFAULT_CC $CMDLINE $_CFLAGS |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 203 | else |
Julius Werner | f96d905 | 2019-08-16 15:35:39 -0700 | [diff] [blame] | 204 | _LIBGCC=`$DEFAULT_CC $_ARCHEXTRA -print-libgcc-file-name` |
Julius Werner | 4bfa29e | 2015-08-20 14:36:34 -0700 | [diff] [blame] | 205 | |
Nico Huber | 3e0b3f1 | 2020-11-14 23:37:39 +0100 | [diff] [blame] | 206 | if [ "$CONFIG_LP_ARM64_A53_ERRATUM_843419" = y ] && |
| 207 | grep -q fix-cortex-a53-843419 $_XCOMPILE; then |
Stefan Reinauer | 805d44f | 2016-03-12 16:38:17 -0800 | [diff] [blame] | 208 | _LDFLAGS="$_LDFLAGS -Wl,--fix-cortex-a53-843419" |
Julius Werner | 4bfa29e | 2015-08-20 14:36:34 -0700 | [diff] [blame] | 209 | fi |
| 210 | |
Stefan Reinauer | 8218445 | 2016-03-12 16:18:17 -0800 | [diff] [blame] | 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 | |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 215 | if [ $DEBUGME -eq 1 ]; then |
Subrata Banik | 36e2b97 | 2024-05-16 15:19:22 +0530 | [diff] [blame] | 216 | echo "$DEFAULT_CC $_LDFLAGS $CMDLINE $_CFLAGS -lpayload $_LIBGCC" |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 217 | fi |
| 218 | |
Subrata Banik | 36e2b97 | 2024-05-16 15:19:22 +0530 | [diff] [blame] | 219 | $DEFAULT_CC $_LDFLAGS $CMDLINE $_CFLAGS -lpayload -xnone $_LIBGCC |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 220 | fi |